Why should I know this?

Android의 시작부터 디버깅하기 JNI_OnLoad 본문

Knowledge/Android

Android의 시작부터 디버깅하기 JNI_OnLoad

die4taoam 2019. 2. 18. 23:13



안드로이드에서 Application의 시작부터 Debugging을 하고 싶다면 JNI_OnLoad부터 시작해야 한다.

해당 지점은 아래처럼 찾을 수 있다.





Dump of assembler code for function dvmLoadNativeCode(char const*, Object*, char**):
   0x40957c08 <+0>:     stmdb   sp!, {r4, r5, r6, r7, r8, r9, r10, r11, lr}
   0x40957c0c <+4>:     mov     r6, r1
   0x40957c0e <+6>:     ldr     r1, [pc, #604]  ; (0x40957e6c <dvmLoadNativeCode(char const*, Object*, char**)+612>)
   0x40957c10 <+8>:     sub     sp, #36 ; 0x24
   0x40957c12 <+10>:    ldr.w   r11, [pc, #604] ; 0x40957e70 <dvmLoadNativeCode(char const*, Object*, char**)+616>
   0x40957c16 <+14>:    mov     r5, r2
   0x40957c18 <+16>:    add     r1, pc
   0x40957c1a <+18>:    movs    r2, #7
   0x40957c1c <+20>:    add     r11, pc
   0x40957c1e <+22>:    mov     r4, r0
   0x40957c20 <+24>:    blx     0x40925528
   0x40957c24 <+28>:    cbz     r0, 0x40957c38 <dvmLoadNativeCode(char const*, Object*, char**)+48>
   0x40957c26 <+30>:    ldr     r1, [pc, #588]  ; (0x40957e74 <dvmLoadNativeCode(char const*, Object*, char**)+620>)
   0x40957c28 <+32>:    mov     r0, r4
   0x40957c2a <+34>:    movs    r2, #7
   0x40957c2c <+36>:    add     r1, pc
   0x40957c2e <+38>:    blx     0x40925528


(gdb) b 418
Note: breakpoint 1 also set at pc 0x40957d76.
Breakpoint 2 at 0x40957d76: file dalvik/vm/Native.cpp, line 418.
(gdb) list *0x40957d76
0x40957d76 is in dvmLoadNativeCode(char const*, Object*, char**) (dalvik/vm/Native.cpp:418).
413
414             bool result = true;
415             void* vonLoad;
416             int version;
417
418             vonLoad = dlsym(handle, "JNI_OnLoad");
419             if (vonLoad == NULL) {
420                 ALOGD("No JNI_OnLoad found in %s %p, skipping init",
421                     pathName, classLoader);
422             } else {
(gdb) x/i Native.cpp:418
No symbol "Native" in current context.
(gdb) x/i *0x40957d76
   0x4650494d:  movs    r0, r0
(gdb) x/i 0x40957d76
   0x40957d76 <dvmLoadNativeCode(char const*, Object*, char**)+366>:    ldr     r1, [pc, #308]  ; (0x40957eac <dvmLoadNativeCode(char const*, Object*, char**)+676>)
(gdb) x/10i 0x40957d76
   0x40957d76 <dvmLoadNativeCode(char const*, Object*, char**)+366>:    ldr     r1, [pc, #308]  ; (0x40957eac <dvmLoadNativeCode(char const*, Object*, char**)+676>)
   0x40957d78 <dvmLoadNativeCode(char const*, Object*, char**)+368>:    mov     r0, r10
   0x40957d7a <dvmLoadNativeCode(char const*, Object*, char**)+370>:    add     r1, pc
   0x40957d7c <dvmLoadNativeCode(char const*, Object*, char**)+372>:    blx     0x409256d8
   0x40957d80 <dvmLoadNativeCode(char const*, Object*, char**)+376>:    mov     r8, r0
   0x40957d82 <dvmLoadNativeCode(char const*, Object*, char**)+378>:    cbnz    r0, 0x40957d98 <dvmLoadNativeCode(char const*, Object*, char**)+400>
   0x40957d84 <dvmLoadNativeCode(char const*, Object*, char**)+380>:    ldr     r1, [pc, #296]  ; (0x40957eb0 <dvmLoadNativeCode(char const*, Object*, char**)+680>)
   0x40957d86 <dvmLoadNativeCode(char const*, Object*, char**)+382>:    movs    r0, #3
   0x40957d88 <dvmLoadNativeCode(char const*, Object*, char**)+384>:    ldr     r2, [pc, #296]  ; (0x40957eb4 <dvmLoadNativeCode(char const*, Object*, char**)+684>)
   0x40957d8a <dvmLoadNativeCode(char const*, Object*, char**)+386>:    mov     r3, r4
(gdb) b 417

Comments