yashinomi / sysdev2020_advanced

0 stars 0 forks source link

Class 2. Exercise 2; log #2

Closed yashinomi closed 4 years ago

yashinomi commented 4 years ago

用意した add_print.cを使用。

$ clang -g add_print.c -o bin/add_print
$ gdb bin/add_print

試しに7行目にブレークポイントを貼る。

(gdb) b add_print.c:7
Breakpoint 1 at 0x100003f5d: file add_print.c, line 7.
(gdb) run
Starting program: /PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/add_print 
Unable to find Mach task port for process-id 68137: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

エラー????

yashinomi commented 4 years ago

macOS のセキュリティ機構の問題らしい? 参考にしたQiitaの記事

yashinomi commented 4 years ago

時間かかりそうだから後回し

yashinomi commented 4 years ago

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) run
Process 68185 launched: '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/add_print' (x86_64)
5
Process 68185 exited with status = 0 (0x00000000) 
(lldb) b add_print.c:7
Breakpoint 1: where = add_print`main + 29 at add_print.c:7:6, address = 0x0000000100003f5d
(lldb) run
Process 68194 launched: '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/add_print' (x86_64)
Process 68194 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f5d add_print`main at add_print.c:7:6
   4    {
   5        int a = 3;
   6        int b, c = 2;
-> 7        b = a + c;
   8        printf("%d\n", b);
   9        return 0;
   10   }
Target 0: (add_print) stopped.
(lldb) p a
(int) $0 = 3
(lldb) po a
3