[LLDB] デバッガによる変数確認、逆アセンブル他

[M1 Mac, Big Sur 11.6.8, clang 13.0.0, NO IDE]

ポインタpのメモリ領域を確保して、空のままLLDBでその格納内容とメモリアドレスを確認しました。

正常なコードなので最終行で停止させ、printコマンドでポインタpのアドレスを出力しています。ついでにレジスタの状態や逆アセンブルを出力しました。

#include <cppstd.h>

int main() {
    char *p;

    p = (char*)malloc(sizeof(char));

    printf("ポインタpが格納しているcharは %s\n", *p);
    printf("ポインタpのアドレス(10進数)は %d\n", p);
    printf("ポインタpのアドレス(16進数)は %x\n", p);

    return 0;
}
$ lldb -f test
(lldb) target create "test"
Current executable set to '/test' (arm64).
(lldb) b 12
Breakpoint 1: where = test`main + 120 at test.cpp:12:5, address = 0x0000000100003ed8
(lldb) r
Process 87108 launched: '/test' (arm64)
ポインタpが格納しているcharは (null)
ポインタpのアドレス(10進数)は 2125136
ポインタpのアドレス(16進数)は 206d50
Process 87108 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100003ed8 test`main at test.cpp:12:5
   9   	    printf("ポインタpのアドレス(10進数)は %d\n", p);
   10  	    printf("ポインタpのアドレス(16進数)は %x\n", p);
   11  	
-> 12  	    return 0;
   13  	}
   14  	
   15  	
Target 0: (test) stopped.
(lldb) print p
(char *) $0 = 0x0000000100206d50 ""
(lldb) register read
General Purpose Registers:
        x0 = 0x0000000000000000
        x1 = 0x0000000000000000
        x2 = 0x00000000000120a8
        x3 = 0x0000000100808e31
        x4 = 0x000000016fdff140
        x5 = 0x000000016fdff540
        x6 = 0x000000000000000a
        x7 = 0x0000000000000000
        x8 = 0x00000001000cbdec  dyld`_main_thread + 172
        x9 = 0x00000001ff69c8d0  libsystem_kernel.dylib`errno
       x10 = 0x0000000000000002
       x11 = 0x00000000fffffffd
       x12 = 0x0000010000000000
       x13 = 0x0000000000000000
       x14 = 0x0000000000000000
       x15 = 0x0000000000000000
       x16 = 0x00000001942097d8  libsystem_kernel.dylib`__error
       x17 = 0x0000000202cc5650  (void *)0x00000001942097d8: __error
       x18 = 0x0000000000000000
       x19 = 0x0000000000000000
       x20 = 0x0000000000000000
       x21 = 0x0000000000000000
       x22 = 0x0000000000000000
       x23 = 0x0000000000000000
       x24 = 0x0000000000000000
       x25 = 0x0000000000000000
       x26 = 0x0000000000000000
       x27 = 0x0000000000000000
       x28 = 0x000000016fdff598
        fp = 0x000000016fdff560
        lr = 0x6310000100003ed4 (0x0000000100003ed4) test`main + 116 at test.cpp:10:5
        sp = 0x000000016fdff540
        pc = 0x0000000100003ed8  test`main + 120 at test.cpp:12:5
      cpsr = 0x20000000

(lldb) di
test`main:
    0x100003e60 <+0>:   sub    sp, sp, #0x30             ; =0x30 
    0x100003e64 <+4>:   stp    x29, x30, [sp, #0x20]
    0x100003e68 <+8>:   add    x29, sp, #0x20            ; =0x20 
    0x100003e6c <+12>:  mov    w8, #0x0
    0x100003e70 <+16>:  str    w8, [sp, #0xc]
    0x100003e74 <+20>:  stur   wzr, [x29, #-0x4]
    0x100003e78 <+24>:  mov    x0, #0x1
    0x100003e7c <+28>:  bl     0x100003ee4               ; symbol stub for: malloc
    0x100003e80 <+32>:  str    x0, [sp, #0x10]
    0x100003e84 <+36>:  ldr    x8, [sp, #0x10]
    0x100003e88 <+40>:  ldrsb  w10, [x8]
    0x100003e8c <+44>:  adrp   x0, 0
    0x100003e90 <+48>:  add    x0, x0, #0xf2c            ; =0xf2c 
    0x100003e94 <+52>:  mov    x9, sp
    0x100003e98 <+56>:  mov    x8, x10
    0x100003e9c <+60>:  str    x8, [x9]
    0x100003ea0 <+64>:  bl     0x100003ef0               ; symbol stub for: printf
    0x100003ea4 <+68>:  ldr    x8, [sp, #0x10]
    0x100003ea8 <+72>:  adrp   x0, 0
    0x100003eac <+76>:  add    x0, x0, #0xf5a            ; =0xf5a 
    0x100003eb0 <+80>:  mov    x9, sp
    0x100003eb4 <+84>:  str    x8, [x9]
    0x100003eb8 <+88>:  bl     0x100003ef0               ; symbol stub for: printf
    0x100003ebc <+92>:  ldr    x8, [sp, #0x10]
    0x100003ec0 <+96>:  adrp   x0, 0
    0x100003ec4 <+100>: add    x0, x0, #0xf88            ; =0xf88 
    0x100003ec8 <+104>: mov    x9, sp
    0x100003ecc <+108>: str    x8, [x9]
    0x100003ed0 <+112>: bl     0x100003ef0               ; symbol stub for: printf
    0x100003ed4 <+116>: ldr    w0, [sp, #0xc]
->  0x100003ed8 <+120>: ldp    x29, x30, [sp, #0x20]
    0x100003edc <+124>: add    sp, sp, #0x30             ; =0x30 
    0x100003ee0 <+128>: ret    
(lldb) exit
Quitting LLDB will kill one or more processes. Do you really want to proceed: [Y/n] y
$