Closed yashinomi closed 4 years ago
今まで使っていた add_print に int3命令を埋め込む。 変更結果はこんな感じ。
$ clang -g add_print.c -o bin/add_print
再び lldb で実行。
$ lldb bin/add_print (lldb) target create "bin/add_print" Current executable set to '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/add_print' (x86_64). (lldb) b add_print.c:7 Breakpoint 1: where = add_print`main + 29 at add_print.c:7:2, address = 0x0000000100003f5d (lldb) r Process 69085 launched: /PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/add_print' (x86_64) Process 69085 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100003f5d add_print`main at add_print.c:7:2 4 { 5 int a = 3; 6 int b, c = 2; -> 7 asm("int3"); 8 b = a + c; 9 printf("%d\n", b); 10 return 0; Target 0: (add_print) stopped. (lldb) c Process 69085 resuming Process 69085 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0) frame #0: 0x0000000100003f5e add_print`main at add_print.c:8:6 5 int a = 3; 6 int b, c = 2; 7 asm("int3"); -> 8 b = a + c; 9 printf("%d\n", b); 10 return 0; 11 } Target 0: (add_print) stopped.
想定通り実行
デバッガを使わないで通常通り実行
$ ./bin/add_print [1] 69221 trace trap ./bin/add_print
講義通り、中断される
今まで使っていた add_print に int3命令を埋め込む。 変更結果はこんな感じ。
再び lldb で実行。