lldb で関数の呼び出し履歴(バックトレース)を表示するには、bt
コマンドを使います。
#include <stdio.h>
void sample1()
{
printf("sample 1\n");
}
void sample2()
{
sample1();
}
void sample3()
{
sample2();
}
int main(void)
{
sample3();
return 0;
}
$ # Intel Mac + macOS Big Sur (11.2) + Apple clang 12.0.0
$ clang -g sample.cpp -o sample
$ lldb sample
(lldb) target create "sample"
Current executable set to '/path/to/sample' (x86_64).
(lldb) b sample1
Breakpoint 1: where = sample`sample1() + 4 at sample.cpp:5:5, address = 0x0000000100003f34
(lldb) run
Process 2220 launched: '/path/to/sample' (x86_64)
Process 2220 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100003f34 sample`sample1() at sample.cpp:5:5
2
3 void sample1()
4 {
-> 5 printf("sample 1\n");
6 }
7
8 void sample2()
Target 0: (sample) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
* frame #0: 0x0000000100003f34 sample`sample1() at sample.cpp:5:5
frame #1: 0x0000000100003f59 sample`sample2() at sample.cpp:10:5
frame #2: 0x0000000100003f69 sample`sample3() at sample.cpp:15:5
frame #3: 0x0000000100003f84 sample`main at sample.cpp:20:5
frame #4: 0x00007fff204f3621 libdyld.dylib`start + 1
frame #5: 0x00007fff204f3621 libdyld.dylib`start + 1
参考資料
-
The LLVM Compiler Infrastructure
https://llvm.org/ -
lldb で使えるコマンド一覧
https://yokaze.github.io/2018/01/06/