Upgrade to Pro — share decks privately, control downloads, hide ads and more …

poから始めるlldb

 poから始めるlldb

Atsuya Sato

July 14, 2018
Tweet

More Decks by Atsuya Sato

Other Decks in Technology

Transcript

  1. address.c #include <stdio.h> void addrcat(char *a, char *d) { while(*a)

    { // ຤ඌ·ͰϙΠϯλΛਐΊΔ a++; } *a++ = '@'; // @Λ௥Ճ͢Δ while(*d) { // dͷࢦ͢ΞυϨεʹจࣈ͕֨ೲ͞Ε͍ͯΔؒ *a++ = *d++; // aʹίϐʔ } } int main(void) { char account[100]; char domain[100]; scanf("%s", account); scanf("%s", domain); addrcat(account, domain); printf("%s\n", account); return 0; }
  2. $ lldb address (lldb) target create “address” Current executable set

    to ‘address’ (x86_64). (lldb) run //ϓϩάϥϜΛ࣮ߦ͢Δ Process 21476 launched: '/Users/AtsuyaSato/Desktop/test-lldb/ address' (x86_64) 1015006 fun.ac.jp [email protected] Process 21476 exited with status = 0 (0x00000000)
  3.  addrcat(account, domain); (lldb) breakpoint set --file address.c --line 20

    //address.cͷ20ߦ ໨ʹϒϨʔΫϙΠϯτΛுΔ Breakpoint 1: where = address`main + 91 at address.c:20, address = x0000000100000f1bb1015006
  4. (lldb) run Process 22308 launched: '/Users/AtsuyaSato/Desktop/test-lldb/address' (x86_64) 1015006 fun.ac.jp Process

    22308 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100000f1b address`main at address.c:20 17 scanf("%s", account); 18 scanf("%s", domain); 19 -> 20 addrcat(account, domain); 21 printf("%s\n", account); 22 return 0; 23 } Target 0: (address) stopped.  addrcat(account, domain);
  5. (lldb) next //1ߦ෼ॲཧΛਐΊΔɻؔ਺͸εςοϓΦʔόʔ Process 22308 stopped * thread #1, queue

    = 'com.apple.main-thread', stop reason = step over frame #0: 0x0000000100000f31 address`main at address.c:21 18 scanf("%s", domain); 19 20 addrcat(account, domain); -> 21 printf("%s\n", account); 22 return 0; 23 } Target 0: (address) stopped.
  6. (lldb) breakpoint set --name “addrcat" //addrcatͱ͍͏ؔ਺ʹϒϨʔΫϙΠϯτΛுΔ Breakpoint 5: where =

    address`addrcat + 12 at address.c:4, address = 0x0000000100000e4c (lldb) run Process 23416 launched: '/Users/AtsuyaSato/Desktop/test-lldb/address' (x86_64) b1015006 fun.ac.jp Process 23416 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 5.1 frame #0: 0x0000000100000e4c address`addrcat(a="b1015006", d="fun.ac.jp") at address.c:4 1 #include <stdio.h> 2 3 void addrcat(char *a, char *d) { -> 4 while(*a) { // ຤ඌ·ͰϙΠϯλΛਐΊΔ 5 a++; 6 } 7 *a++ = '@'; // @Λ௥Ճ͢Δ Target 0: (address) stopped.
  7. (lldb) breakpoint set --line 20 Breakpoint 1: where = address`main

    + 91 at address.c:20, address = 0x0000000100000f1b (lldb) breakpoint command add 1 //1൪ͷBreakpointʹίϚ ϯυΛઃఆ Enter your debugger command(s). Type 'DONE' to end. > thread jump --by 1 // ݱࡏͷεϨουͰ1ߦεΩοϓ͢Δ (lldb) breakpoint modify --auto-continue 1 // 1൪ͷBreakpoint ͕ϒϨʔΫͨ͠ࡍʹࣗಈͰcontinue͢ΔΑ͏ʹมߋ  addrcat(account, domain);
  8. (lldb) run Process 23852 launched: '/Users/AtsuyaSato/Desktop/ test-lldb/address' (x86_64) b1015006 fun.ac.jp

    (lldb) thread jump --by 1 //commandʹΑͬͯίʔυΠϯ δΣΫγϣϯ͞Εͨ b1015006 //addrcat(account, domain); ͕εΩοϓ͞Εͨ ͨΊɺग़ྗ͞Εͨaccount͸domain͕݁߹͞Ε͍ͯͳ͍ Process 23852 exited with status = 0 (0x00000000)