yashinomi / sysdev2020_advanced

0 stars 0 forks source link

Class 2. Exercise 5. log #5

Closed yashinomi closed 3 years ago

yashinomi commented 3 years ago

数字の合計を行うプログラムを書いた。

yashinomi commented 3 years ago
$ clang -g sum.c -o bin/sum

lldbを実行

lldb bin/sum                                                                          [15:49:30]
(lldb) target create "bin/sum"
Current executable set to '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/sum' (x86_64).
(lldb) start 1 10
error: 'start' is not a valid command.
(lldb) r
Process 69575 launched: '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/sum' (x86_64)
Process 69575 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00007fff6e75af09 libsystem_c.dylib`strtol_l + 80
libsystem_c.dylib`strtol_l:
->  0x7fff6e75af09 <+80>: movb   (%rbx), %sil
    0x7fff6e75af0c <+83>: movzbl %sil, %edi
    0x7fff6e75af10 <+87>: testb  %dil, %dil
    0x7fff6e75af13 <+90>: js     0x7fff6e75af1c            ; <+99>
Target 0: (sum) stopped.
(lldb) r 1 10
There is a running process, kill it and restart?: [Y/n] Y
Process 69575 exited with status = 9 (0x00000009) 
Process 69582 launched: '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/sum' (x86_64)
55
Process 69582 exited with status = 0 (0x00000000) 
(lldb) watchpoint set variable sum
error: invalid thread
(lldb) watch list
No watchpoints currently set.
(lldb) watch set var sum
error: invalid thread
(lldb) th info
error: Process must be launched.
(lldb) rn
error: 'rn' is not a valid command.
(lldb) r
Process 69593 launched: '/PathToWorkspacesysdev2020_advanced/debug_test_codes/bin/sum' (x86_64)
55
Process 69593 exited with status = 0 (0x00000000) 
(lldb) b sum.c:4
Breakpoint 1: where = sum`main + 22 at sum.c:6:9, address = 0x0000000100003f16
(lldb) r
Process 70000 launched: '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/bin/sum' (x86_64)
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003f16 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:6:9
   3    
   4    
   5    int main(int argc, char const *argv[]){
-> 6        int sum = 0;
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
Target 0: (sum) stopped.
(lldb) watch set var sum
Watchpoint created: Watchpoint 1: addr = 0x7ffeefbff4ec size = 4 state = enabled type = w
    declare @ '/PathToWorkspace/sysdev2020_advanced/debug_test_codes/sum.c:6'
    watchpoint spec = 'sum'
    new value: 0
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 0
new value: 0
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f1d sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:7:20
   4    
   5    int main(int argc, char const *argv[]){
   6        int sum = 0;
-> 7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
   10       for (int i = beg; i <= end; i++){
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 0
new value: 1
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 1
new value: 3
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) r
There is a running process, kill it and restart?: [Y/n] n
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 3
new value: 6
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 6
new value: 10
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 10
new value: 15
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 15
new value: 21
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 21
new value: 28
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 28
new value: 36
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 36
new value: 45
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) po sum
45

(lldb) c
Process 70000 resuming

Watchpoint 1 hit:
old value: 45
new value: 55
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x0000000100003f58 sum`main(argc=3, argv=0x00007ffeefbff520) at sum.c:10:34
   7        int beg = atoi(argv[1]);
   8        int end = atoi(argv[2]);
   9    
-> 10       for (int i = beg; i <= end; i++){
   11           sum += i;
   12       }
   13       printf("%d\n", sum);
Target 0: (sum) stopped.
(lldb) c
Process 70000 resuming
55

Watchpoint 1 hit:
old value: 55
new value: 32767
Process 70000 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = watchpoint 1
    frame #0: 0x00007fff6e77b17c libsystem_c.dylib`_tlv_exit
libsystem_c.dylib`_tlv_exit:
->  0x7fff6e77b17c <+0>: jmpq   *0x2680cbd6(%rip)         ; (void *)0x00007fff6e6a9dea: _tlv_exit

libsystem_c.dylib`abort_with_payload:
    0x7fff6e77b182 <+0>: jmpq   *0x2680cbd8(%rip)         ; (void *)0x00007fff6e80e408: abort_with_payload

libsystem_c.dylib`access:
    0x7fff6e77b188 <+0>: jmpq   *0x2680cbda(%rip)         ; (void *)0x00007fff6e7ed680: access

libsystem_c.dylib`asl_append:
    0x7fff6e77b18e <+0>: jmpq   *0x2680cbdc(%rip)         ; (void *)0x00007fff6e6f7911: asl_append
Target 0: (sum) stopped.

gdbの命令がそのまま使えない。