SlideShare a Scribd company logo
1 of 26
Xcodeで値を表示する
「iOS 11 Programming」刊行記念 Night
自己紹介
● 荒巻 賢一
● 趣味
○ ピアノ、テニス、競技プログラミング、ボルダリング
● ライフワーク
○ デバッグ
Agenda
● Xcodeで値を表示することについて調べてみた
ある日の不具合
● safeAreaInsetsが反映されない
○ UIScrollViewのsubviewにSafeAreaInsetが反映されないこ
とがある
View Hierarchyで見る
● あるviewまではsafeAreaInsetsが
正しく、subviewで正しくない
View Hierarchyで見る
Viewを右クリックし、Print Descriptionで
idがわかる
Printing description of $12:
<UIView: 0x7fde56eaad00; frame = (0 0; 812 375);
autoresize = W+H; layer = <CALayer:
0x60000043a3e0>>
デバッグコンソールで調べる
● デバッガからexpressionコマンド
(短縮形: pまたはpo)で確認して
みる
idからsafeAreaInsetsを調べる
エラー
(lldb) p [0x7fde56eaad00 safeAreaInsets]
error: warning: receiver type 'long' is not 'id' or interface pointer,
consider casting it to 'id'
error: no known method '-safeAreaInsets'; cast the message send
to the method's return type
idからsafeAreaInsetsを調べる
idでキャストしろと言われたのでやってみる
(lldb) p [(id)0x7fde56eaad00 safeAreaInsets]
error: no known method '-safeAreaInsets'; cast the message send
to the method's return type
idからsafeAreaInsetsを調べる
UIViewにキャストしてみる
(lldb) p [(UIView*)0x7fde56eaad00 safeAreaInsets]
(UIEdgeInsets) $13 = (top = 32, left = 0, bottom = 21, right = 0)
idからsafeAreaInsetsを調べる
しかしsuperviewでは正常に出力されない
(lldb) p [[(UIView*)0x7fd688f0e670 superview] safeAreaInsets]
(UIEdgeInsets _Nullable) $14 = {}
idからsafeAreaInsetsを調べる
戻り値をキャストすればよかった
(lldb) p (UIEdgeInsets)[0x7fde56eaad00 safeAreaInsets]
(UIEdgeInsets) $15 = (top = 32, left = 0, bottom = 21, right = 0)
(lldb) p (UIEdgeInsets)[[0x7fde56eaad00 superview] safeAreaInsets]
(UIEdgeInsets) $16 = (top = 32, left = 44, bottom = 21, right = 44)
戻り値の型がid以外のときはキャストが必要
疑問
● なぜこのような違いが生まれるのか?
● expressionコマンドは何をしているのか?
LLDBをビルドしてみる
● XcodeのデバッガはLLDB
○ https://lldb.llvm.org/
● デバッガをステップ実行させれば挙動がわかるので
は?
※ XcodeのLLDBとは一部異なる可能性があります
LLDB上でLLDBを実行する
● LLDB in LLDB
LLDB in LLDB(黒)
XcodeのLLDB(青)
ブレークポイントを設定する
● Expressionコマンドに関係しそうな場所にブレーク
ポイントを設定してステップ実行してみる
○ UserExpression::Evaluate
expressionコマンドの式の処理
1. 式をコンパイルする
2. メッセージを組み立てる
3. オブジェクトにメッセージを送る
4. 結果を表示する
式をコンパイルする
● パースして構文木(Clang AST)を得る
○ ClangExpressionParser::Parse
● 文法エラーや、存在しないセレクタを指定した場合
はここでエラーになる
メッセージを組み立てる (インラインアセンブラ)
1. オブジェクトのクラスを取得する
2. respondsToSelector:でYESを返すかどうか調べる
3. メッセージを送る
AppleObjCRuntimeV2::CreateObjectChecker
戻り値のための領域を準備する
● 呼び出し規約により場合わけ
○ ObjcObjectChecker::InstrumentInstruction
○ idのとき eMsgSend_fpret
○ 構造体のとき eMsgSend_stret
■ safeAreaInsetsはこっち
オブジェクトにメッセージを送る
● ターゲットプログラム上に新しいスレッドを作って
オブジェクトにメッセージを送る
○ UserExpression::Execute
結果を表示する
● ValueObject::Dump
● CommandInterpreter::PrintCommandOutput
余談: 実行できるがデバッガで表示できない
● respondsToSelector: にNOを返すと表示できない
○ 例えばNSProxyを継承してrespondsToSelector:
が未実装のとき
デバッグオプション (--debug or -g)
メッセージ送信のコードが見られる
(lldb) expression --debug -- [view safeAreaInsets]
Execution was halted at the first instruction of the expression
function because "debug" was requested.
Use "thread return -x" to return to the state before expression
evaluation.
まとめ
● 値を表示するときにも動的にコンパイルと実行が行
われている
● safeAreaInsetsの表示にキャストが必要なのは、呼
び出し規約の違いに起因している
● iOS Engineer
● Android Engineer
● Web, Front-end & Back-end
● Site Reliability
● Ad Services
● Machine Learning
● and more…!
https://smartnews.workable.com
We’re Hiring!We’re Hiring!

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Xcodeで値を表示する