1f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#include <inttypes.h>
2f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
3f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/*
4f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Dump the fixed-purpose ARM registers, along with some other info.
5f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project *
6f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * This function MUST be compiled in ARM mode -- THUMB will yield bogus
7f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * results.
8f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project *
9f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * This will NOT preserve r0-r3/ip.
10f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */
11f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmMterpDumpArmRegs(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3)
12f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project{
13f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    register uint32_t rPC       asm("r4");
14f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    register uint32_t rFP       asm("r5");
15f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    register uint32_t rGLUE     asm("r6");
161da12167d913efde56ec3b40491524b051679f2cAndy McFadden    register uint32_t rINST     asm("r7");
171da12167d913efde56ec3b40491524b051679f2cAndy McFadden    register uint32_t rIBASE    asm("r8");
18f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    register uint32_t r9        asm("r9");
19f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    register uint32_t r10       asm("r10");
20f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
21b31b30131bbf58280a515c40027aa958b81b5cd6Carl Shapiro    //extern char dvmAsmInstructionStart[];
22f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
23f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3);
241da12167d913efde56ec3b40491524b051679f2cAndy McFadden    printf("    : rPC=%08x rFP=%08x rGLUE=%08x rINST=%08x\n",
251da12167d913efde56ec3b40491524b051679f2cAndy McFadden        rPC, rFP, rGLUE, rINST);
261da12167d913efde56ec3b40491524b051679f2cAndy McFadden    printf("    : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10);
27f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
28b31b30131bbf58280a515c40027aa958b81b5cd6Carl Shapiro    //MterpGlue* glue = (MterpGlue*) rGLUE;
29b31b30131bbf58280a515c40027aa958b81b5cd6Carl Shapiro    //const Method* method = glue->method;
30f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("    + self is %p\n", dvmThreadSelf());
31f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    //printf("    + currently in %s.%s %s\n",
3285745e148153894aac52ad3d7f6a36a7767b45a0Mike Lockwood    //    method->clazz->descriptor, method->name, method->shorty);
33f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    //printf("    + dvmAsmInstructionStart = %p\n", dvmAsmInstructionStart);
34f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    //printf("    + next handler for 0x%02x = %p\n",
35f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    //    rINST & 0xff, dvmAsmInstructionStart + (rINST & 0xff) * 64);
36f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project}
37f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
38f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/*
39f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Dump the StackSaveArea for the specified frame pointer.
40f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */
41f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmDumpFp(void* fp, StackSaveArea* otherSaveArea)
42f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project{
43f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    StackSaveArea* saveArea = SAVEAREA_FROM_FP(fp);
44f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea);
45f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#ifdef EASY_GDB
46f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("  prevSave=%p, prevFrame=%p savedPc=%p meth=%p curPc=%p\n",
47f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        saveArea->prevSave, saveArea->prevFrame, saveArea->savedPc,
48f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        saveArea->method, saveArea->xtra.currentPc);
49f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#else
50f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("  prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n",
51f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        saveArea->prevFrame, saveArea->savedPc,
52f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        saveArea->method, saveArea->xtra.currentPc,
53f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        *(u4*)fp);
54f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#endif
55f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project}
56f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
57f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/*
58f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Does the bulk of the work for common_printMethod().
59f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */
60f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmMterpPrintMethod(Method* method)
61f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project{
62f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    /*
63f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project     * It is a direct (non-virtual) method if it is static, private,
64f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project     * or a constructor.
65f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project     */
66a80b76553c2b9f33c4063ae8c69c5362d961de81Andy McFadden    bool isDirect =
67f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        ((method->accessFlags & (ACC_STATIC|ACC_PRIVATE)) != 0) ||
68f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project        (method->name[0] == '<');
69f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
70f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    char* desc = dexProtoCopyMethodDescriptor(&method->prototype);
71a80b76553c2b9f33c4063ae8c69c5362d961de81Andy McFadden
72f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    printf("<%c:%s.%s %s> ",
73f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project            isDirect ? 'D' : 'V',
74f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project            method->clazz->descriptor,
75f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project            method->name,
76f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project            desc);
77f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project
78f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project    free(desc);
79f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project}
80