10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // this is source code windbg based SA debugger agent to debug
26 // Dr. Watson dump files and process snapshots.
27
28 #include "sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal.h"
29
30 #ifdef _M_IA64
31 #include "sun_jvm_hotspot_debugger_ia64_IA64ThreadContext.h"
32 #define NPRGREG sun_jvm_hotspot_debugger_ia64_IA64ThreadContext_NPRGREG
33 #elif _M_IX86
34 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
35 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
36 #elif _M_AMD64
37 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
38 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
39 #else
40 #error "SA windbg back-end is not supported for your cpu!"
41 #endif
42
43 #include <limits.h>
44 #include <windows.h>
45
46 #ifndef STDMETHODV
47 #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method
48 #endif
49
50 #define DEBUG_NO_IMPLEMENTATION
51 #include <dbgeng.h>
52 #include <dbghelp.h>
53
474 CHECK_EXCEPTION_(false);
475
476 // for each thread, get register context and save it.
477 for (ULONG t = 0; t < numThreads; t++) {
478 if (ptrIDebugSystemObjects->SetCurrentThreadId(ptrThreadIds.asPtr()[t]) != S_OK) {
479 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetCurrentThread failed!", false);
480 }
481
482 jlongArray regs = env->NewLongArray(NPRGREG);
483 CHECK_EXCEPTION_(false);
484
485 jboolean isCopy = JNI_FALSE;
486 jlong* ptrRegs = env->GetLongArrayElements(regs, &isCopy);
487 CHECK_EXCEPTION_(false);
488
489 // copy register values from the CONTEXT struct
490 CONTEXT context;
491 memset(&context, 0, sizeof(CONTEXT));
492
493 #undef REG_INDEX
494 #ifdef _M_IA64
495 #define REG_INDEX(x) sun_jvm_hotspot_debugger_ia64_IA64ThreadContext_##x
496
497 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG;
498 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
499
500 ptrRegs[REG_INDEX(GR0)] = 0; // always 0
501 ptrRegs[REG_INDEX(GR1)] = context.IntGp; // r1
502 ptrRegs[REG_INDEX(GR2)] = context.IntT0; // r2-r3
503 ptrRegs[REG_INDEX(GR3)] = context.IntT1;
504 ptrRegs[REG_INDEX(GR4)] = context.IntS0; // r4-r7
505 ptrRegs[REG_INDEX(GR5)] = context.IntS1;
506 ptrRegs[REG_INDEX(GR6)] = context.IntS2;
507 ptrRegs[REG_INDEX(GR7)] = context.IntS3;
508 ptrRegs[REG_INDEX(GR8)] = context.IntV0; // r8
509 ptrRegs[REG_INDEX(GR9)] = context.IntT2; // r9-r11
510 ptrRegs[REG_INDEX(GR10)] = context.IntT3;
511 ptrRegs[REG_INDEX(GR11)] = context.IntT4;
512 ptrRegs[REG_INDEX(GR12)] = context.IntSp; // r12 stack pointer
513 ptrRegs[REG_INDEX(GR13)] = context.IntTeb; // r13 teb
514 ptrRegs[REG_INDEX(GR14)] = context.IntT5; // r14-r31
515 ptrRegs[REG_INDEX(GR15)] = context.IntT6;
516 ptrRegs[REG_INDEX(GR16)] = context.IntT7;
517 ptrRegs[REG_INDEX(GR17)] = context.IntT8;
518 ptrRegs[REG_INDEX(GR18)] = context.IntT9;
519 ptrRegs[REG_INDEX(GR19)] = context.IntT10;
520 ptrRegs[REG_INDEX(GR20)] = context.IntT11;
521 ptrRegs[REG_INDEX(GR21)] = context.IntT12;
522 ptrRegs[REG_INDEX(GR22)] = context.IntT13;
523 ptrRegs[REG_INDEX(GR23)] = context.IntT14;
524 ptrRegs[REG_INDEX(GR24)] = context.IntT15;
525 ptrRegs[REG_INDEX(GR25)] = context.IntT16;
526 ptrRegs[REG_INDEX(GR26)] = context.IntT17;
527 ptrRegs[REG_INDEX(GR27)] = context.IntT18;
528 ptrRegs[REG_INDEX(GR28)] = context.IntT19;
529 ptrRegs[REG_INDEX(GR29)] = context.IntT20;
530 ptrRegs[REG_INDEX(GR30)] = context.IntT21;
531 ptrRegs[REG_INDEX(GR31)] = context.IntT22;
532
533 ptrRegs[REG_INDEX(INT_NATS)] = context.IntNats;
534 ptrRegs[REG_INDEX(PREDS)] = context.Preds;
535
536 ptrRegs[REG_INDEX(BR_RP)] = context.BrRp;
537 ptrRegs[REG_INDEX(BR1)] = context.BrS0; // b1-b5
538 ptrRegs[REG_INDEX(BR2)] = context.BrS1;
539 ptrRegs[REG_INDEX(BR3)] = context.BrS2;
540 ptrRegs[REG_INDEX(BR4)] = context.BrS3;
541 ptrRegs[REG_INDEX(BR5)] = context.BrS4;
542 ptrRegs[REG_INDEX(BR6)] = context.BrT0; // b6-b7
543 ptrRegs[REG_INDEX(BR7)] = context.BrT1;
544
545 ptrRegs[REG_INDEX(AP_UNAT)] = context.ApUNAT;
546 ptrRegs[REG_INDEX(AP_LC)] = context.ApLC;
547 ptrRegs[REG_INDEX(AP_EC)] = context.ApEC;
548 ptrRegs[REG_INDEX(AP_CCV)] = context.ApCCV;
549 ptrRegs[REG_INDEX(AP_DCR)] = context.ApDCR;
550
551 ptrRegs[REG_INDEX(RS_PFS)] = context.RsPFS;
552 ptrRegs[REG_INDEX(RS_BSP)] = context.RsBSP;
553 ptrRegs[REG_INDEX(RS_BSPSTORE)] = context.RsBSPSTORE;
554 ptrRegs[REG_INDEX(RS_RSC)] = context.RsRSC;
555 ptrRegs[REG_INDEX(RS_RNAT)] = context.RsRNAT;
556
557 ptrRegs[REG_INDEX(ST_IPSR)] = context.StIPSR;
558 ptrRegs[REG_INDEX(ST_IIP)] = context.StIIP;
559 ptrRegs[REG_INDEX(ST_IFS)] = context.StIFS;
560
561 ptrRegs[REG_INDEX(DB_I0)] = context.DbI0;
562 ptrRegs[REG_INDEX(DB_I1)] = context.DbI1;
563 ptrRegs[REG_INDEX(DB_I2)] = context.DbI2;
564 ptrRegs[REG_INDEX(DB_I3)] = context.DbI3;
565 ptrRegs[REG_INDEX(DB_I4)] = context.DbI4;
566 ptrRegs[REG_INDEX(DB_I5)] = context.DbI5;
567 ptrRegs[REG_INDEX(DB_I6)] = context.DbI6;
568 ptrRegs[REG_INDEX(DB_I7)] = context.DbI7;
569
570 ptrRegs[REG_INDEX(DB_D0)] = context.DbD0;
571 ptrRegs[REG_INDEX(DB_D1)] = context.DbD1;
572 ptrRegs[REG_INDEX(DB_D2)] = context.DbD2;
573 ptrRegs[REG_INDEX(DB_D3)] = context.DbD3;
574 ptrRegs[REG_INDEX(DB_D4)] = context.DbD4;
575 ptrRegs[REG_INDEX(DB_D5)] = context.DbD5;
576 ptrRegs[REG_INDEX(DB_D6)] = context.DbD6;
577 ptrRegs[REG_INDEX(DB_D7)] = context.DbD7;
578
579 #elif _M_IX86
580 #define REG_INDEX(x) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##x
581
582 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
583 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
584
585 ptrRegs[REG_INDEX(GS)] = context.SegGs;
586 ptrRegs[REG_INDEX(FS)] = context.SegFs;
587 ptrRegs[REG_INDEX(ES)] = context.SegEs;
588 ptrRegs[REG_INDEX(DS)] = context.SegDs;
589
590 ptrRegs[REG_INDEX(EDI)] = context.Edi;
591 ptrRegs[REG_INDEX(ESI)] = context.Esi;
592 ptrRegs[REG_INDEX(EBX)] = context.Ebx;
593 ptrRegs[REG_INDEX(EDX)] = context.Edx;
594 ptrRegs[REG_INDEX(ECX)] = context.Ecx;
595 ptrRegs[REG_INDEX(EAX)] = context.Eax;
596
597 ptrRegs[REG_INDEX(FP)] = context.Ebp;
598 ptrRegs[REG_INDEX(PC)] = context.Eip;
599 ptrRegs[REG_INDEX(CS)] = context.SegCs;
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 // this is source code windbg based SA debugger agent to debug
26 // Dr. Watson dump files and process snapshots.
27
28 #include "sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal.h"
29
30 #ifdef _M_IX86
31 #include "sun_jvm_hotspot_debugger_x86_X86ThreadContext.h"
32 #define NPRGREG sun_jvm_hotspot_debugger_x86_X86ThreadContext_NPRGREG
33 #elif _M_AMD64
34 #include "sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext.h"
35 #define NPRGREG sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_NPRGREG
36 #else
37 #error "SA windbg back-end is not supported for your cpu!"
38 #endif
39
40 #include <limits.h>
41 #include <windows.h>
42
43 #ifndef STDMETHODV
44 #define STDMETHODV(method) virtual HRESULT STDMETHODVCALLTYPE method
45 #endif
46
47 #define DEBUG_NO_IMPLEMENTATION
48 #include <dbgeng.h>
49 #include <dbghelp.h>
50
471 CHECK_EXCEPTION_(false);
472
473 // for each thread, get register context and save it.
474 for (ULONG t = 0; t < numThreads; t++) {
475 if (ptrIDebugSystemObjects->SetCurrentThreadId(ptrThreadIds.asPtr()[t]) != S_OK) {
476 THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetCurrentThread failed!", false);
477 }
478
479 jlongArray regs = env->NewLongArray(NPRGREG);
480 CHECK_EXCEPTION_(false);
481
482 jboolean isCopy = JNI_FALSE;
483 jlong* ptrRegs = env->GetLongArrayElements(regs, &isCopy);
484 CHECK_EXCEPTION_(false);
485
486 // copy register values from the CONTEXT struct
487 CONTEXT context;
488 memset(&context, 0, sizeof(CONTEXT));
489
490 #undef REG_INDEX
491 #ifdef _M_IX86
492 #define REG_INDEX(x) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##x
493
494 context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
495 ptrIDebugAdvanced->GetThreadContext(&context, sizeof(CONTEXT));
496
497 ptrRegs[REG_INDEX(GS)] = context.SegGs;
498 ptrRegs[REG_INDEX(FS)] = context.SegFs;
499 ptrRegs[REG_INDEX(ES)] = context.SegEs;
500 ptrRegs[REG_INDEX(DS)] = context.SegDs;
501
502 ptrRegs[REG_INDEX(EDI)] = context.Edi;
503 ptrRegs[REG_INDEX(ESI)] = context.Esi;
504 ptrRegs[REG_INDEX(EBX)] = context.Ebx;
505 ptrRegs[REG_INDEX(EDX)] = context.Edx;
506 ptrRegs[REG_INDEX(ECX)] = context.Ecx;
507 ptrRegs[REG_INDEX(EAX)] = context.Eax;
508
509 ptrRegs[REG_INDEX(FP)] = context.Ebp;
510 ptrRegs[REG_INDEX(PC)] = context.Eip;
511 ptrRegs[REG_INDEX(CS)] = context.SegCs;
|