static bool getWindbgInterfaces(JNIEnv* env, jobject obj) { // get windbg interfaces .. IDebugClient* ptrIDebugClient = 0; if (DebugCreate(__uuidof(IDebugClient), (PVOID*) &ptrIDebugClient) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to create IDebugClient object!", false); } env->SetLongField(obj, ptrIDebugClient_ID, (jlong) ptrIDebugClient); IDebugControl* ptrIDebugControl = 0; if (ptrIDebugClient->QueryInterface(__uuidof(IDebugControl), (PVOID*) &ptrIDebugControl) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugControl", false); } env->SetLongField(obj, ptrIDebugControl_ID, (jlong) ptrIDebugControl); IDebugDataSpaces* ptrIDebugDataSpaces = 0; if (ptrIDebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (PVOID*) &ptrIDebugDataSpaces) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugDataSpaces object!", false); } env->SetLongField(obj, ptrIDebugDataSpaces_ID, (jlong) ptrIDebugDataSpaces); SAOutputCallbacks* ptrIDebugOutputCallbacks = new SAOutputCallbacks(); ptrIDebugOutputCallbacks->AddRef(); env->SetLongField(obj, ptrIDebugOutputCallbacks_ID, (jlong) ptrIDebugOutputCallbacks); CHECK_EXCEPTION_(false); IDebugAdvanced* ptrIDebugAdvanced = 0; if (ptrIDebugClient->QueryInterface(__uuidof(IDebugAdvanced), (PVOID*) &ptrIDebugAdvanced) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugAdvanced object!", false); } env->SetLongField(obj, ptrIDebugAdvanced_ID, (jlong) ptrIDebugAdvanced); IDebugSymbols* ptrIDebugSymbols = 0; if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSymbols), (PVOID*) &ptrIDebugSymbols) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSymbols object!", false); } env->SetLongField(obj, ptrIDebugSymbols_ID, (jlong) ptrIDebugSymbols); IDebugSystemObjects* ptrIDebugSystemObjects = 0; if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSystemObjects), (PVOID*) &ptrIDebugSystemObjects) != S_OK) { THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSystemObjects object!", false); } env->SetLongField(obj, ptrIDebugSystemObjects_ID, (jlong) ptrIDebugSystemObjects); return true; }
HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags) { IDebugClient *DebugClient = NULL; HRESULT Hr= S_OK; *Version = DEBUG_EXTENSION_VERSION(1, 0); *Flags = 0; // Connect to client if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK) { return Hr; } // Get the windbg-style extension APIS PDEBUG_CONTROL DebugControl; if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { ExtensionApis.nSize = sizeof (ExtensionApis); Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis); DebugControl->Release(); } // done DebugClient->Release(); return Hr; }
void CALLBACK DebugExtensionNotify(ULONG Notify, ULONG64 Argument) { UNREFERENCED_PARAMETER(Argument); // // The first time we actually connect to a target // /* *New debugger extensions get new debugger interfaces by calling *DebugCreate(__uuidof (IDebugClient), &DebugClient)) *DebugClient->QueryInterface(_uuidof(Interface_you_want) */ if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected)) { IDebugClient *DebugClient; HRESULT Hr; PDEBUG_CONTROL DebugControl; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) == S_OK) { // // Get the architecture type. // if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { //jc:QueryInterface must fill in DebugControl if ((Hr = DebugControl->GetActualProcessorType( &TargetMachine)) == S_OK) { Connected = TRUE; } DebugControl->Release(); } DebugClient->Release(); } } if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE) { Connected = FALSE; TargetMachine = 0; } return; }
void LateSymbolInfo::loadMinidump(std::wstring& dumppath, bool delete_when_done) { // Method credit to http://stackoverflow.com/a/8119364/21501 if (debugClient5 || debugControl4 || debugSymbols3) { //throw SleepyException(L"Minidump symbols already loaded."); // maybe the user moved a .pdb to somewhere where we can now find it? unloadMinidump(); } IDebugClient *debugClient = NULL; SetLastError(0); comenforce(DebugCreate(__uuidof(IDebugClient), (void**)&debugClient), "DebugCreate"); comenforce(debugClient->QueryInterface(__uuidof(IDebugClient5 ), (void**)&debugClient5 ), "QueryInterface(IDebugClient5)" ); comenforce(debugClient->QueryInterface(__uuidof(IDebugControl4), (void**)&debugControl4), "QueryInterface(IDebugControl4)"); comenforce(debugClient->QueryInterface(__uuidof(IDebugSymbols3), (void**)&debugSymbols3), "QueryInterface(IDebugSymbols3)"); comenforce(debugClient5->SetOutputCallbacksWide(debugOutputCallbacks), "IDebugClient5::SetOutputCallbacksWide"); comenforce(debugSymbols3->SetSymbolOptions(SYMOPT_UNDNAME | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST | SYMOPT_AUTO_PUBLICS | SYMOPT_DEBUG), "IDebugSymbols::SetSymbolOptions"); std::wstring sympath; prefs.AdjustSymbolPath(sympath, true); comenforce(debugSymbols3->SetSymbolPathWide(sympath.c_str()), "IDebugSymbols::SetSymbolPath"); comenforce(debugClient5->OpenDumpFileWide(dumppath.c_str(), NULL), "IDebugClient4::OpenDumpFileWide"); comenforce(debugControl4->WaitForEvent(0, INFINITE), "IDebugControl::WaitForEvent"); // Since we can't just enumerate all symbols in all modules referenced by the minidump, // we have to keep the debugger session open and query symbols as requested by the // profiler GUI. debugClient->Release(); // but keep the other ones // If we are given a temporary file, clean it up later if (delete_when_done) file_to_delete = dumppath; }
void CALLBACK DebugExtensionNotify(ULONG Notify, ULONG64 Argument) { static BOOL Connected; UNREFERENCED_PARAMETER(Argument); // The first time we actually connect to a target if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected)) { IDebugClient *DebugClient = NULL; HRESULT Hr; PDEBUG_CONTROL DebugControl = NULL; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) == S_OK) { // // Get the architecture type. // if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { ULONG TargetMachine; if ((Hr = DebugControl->GetActualProcessorType( &TargetMachine)) == S_OK) { Connected = TRUE; } //NotifyOnTargetAccessible(DebugControl); DebugControl->Release(); } DebugClient->Release(); } } // The target is gone if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE) Connected = FALSE; return; }
HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags) { HRESULT hRes=S_OK; IDebugClient *DebugClient; PDEBUG_CONTROL DebugControl; *Version = DEBUG_EXTENSION_VERSION(EXT_MAJOR_VER, EXT_MINOR_VER); *Flags = 0; if (FAILED(hRes=DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient))) return hRes; if (SUCCEEDED(hRes=DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl))) { // Get the windbg-style extension APIS ExtensionApis.nSize = sizeof (ExtensionApis); hRes = DebugControl->GetWindbgExtensionApis64(&ExtensionApis); DebugControl->Release(); dprintf("[sync] DebugExtensionInitialize, ExtensionApis loaded\n"); } DebugClient->Release(); g_ExtClient = NULL; g_Synchronized = FALSE; g_hPollCompleteEvent = CreateEvent(NULL, true, false, NULL); if (g_hPollCompleteEvent == NULL) { dprintf("[sync] Command polling feature init failed\n"); return E_FAIL; } InitializeCriticalSection(&g_CritSectPollRelease); if(SUCCEEDED(LoadConfigurationFile())) dprintf("[sync] Configuration file loaded\n -> set HOST to %s:%s\n", g_DefaultHost, g_DefaultPort); return hRes; }
//jc: this in the init routine. Runs on load. HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags) { IDebugClient *DebugClient; PDEBUG_CONTROL DebugControl; HRESULT Hr; *Version = DEBUG_EXTENSION_VERSION(1, 0); *Flags = 0; Hr = S_OK; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK) { return Hr; } if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { // // Get the windbg-style extension APIS // ExtensionApis.nSize = sizeof (ExtensionApis); Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis); DebugControl->Release(); } dprintf("[Byakugan] Successfully loaded!\n"); DebugClient->Release(); return (Hr); }
extern "C" HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags) { IDebugClient *DebugClient; PDEBUG_CONTROL DebugControl; HRESULT Hr; *Version = DEBUG_EXTENSION_VERSION(1, 0); *Flags = 0; Hr = S_OK; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK) { return Hr; } if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { ExtensionApis.nSize = sizeof(ExtensionApis); Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis); DebugControl->Release(); } DebugClient->Release(); return Hr; }
void CALLBACK DebugExtensionNotify(ULONG Notify, ULONG64 /*Argument*/) { // // The first time we actually connect to a target, get the page size // if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected)) { IDebugClient *DebugClient; PDEBUG_DATA_SPACES DebugDataSpaces; PDEBUG_CONTROL DebugControl; HRESULT Hr; ULONG64 Page; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) == S_OK) { // // Get the page size and PAE enable flag // if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugDataSpaces), (void **)&DebugDataSpaces)) == S_OK) { if ((Hr = DebugDataSpaces->ReadDebuggerData( DEBUG_DATA_MmPageSize, &Page, sizeof(Page), NULL)) == S_OK) { PageSize = (ULONG)(ULONG_PTR)Page; } DebugDataSpaces->Release(); } // // Get the architecture type. // if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) == S_OK) { if ((Hr = DebugControl->GetActualProcessorType( &TargetMachine)) == S_OK) { Connected = TRUE; } ULONG Qualifier; if ((Hr = DebugControl->GetDebuggeeType(&g_TargetClass, &Qualifier)) == S_OK) { } DebugControl->Release(); } DebugClient->Release(); } } if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE) { Connected = FALSE; PageSize = 0; TargetMachine = 0; } return; }
HRESULT CALLBACK DebugExtensionInitialize(PULONG Version, PULONG Flags) { IDebugClient *DebugClient; PDEBUG_CONTROL DebugControl; HRESULT Hr; *Version = DEBUG_EXTENSION_VERSION(1, 0); *Flags = 0; if (g_Initialized) { return S_OK; } g_Initialized = true; if ((Hr = DebugCreate(__uuidof(IDebugClient), (void **)&DebugClient)) != S_OK) { return Hr; } if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&DebugControl)) != S_OK) { return Hr; } ExtensionApis.nSize = sizeof (ExtensionApis); if ((Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis)) != S_OK) { return Hr; } // Fixes the "Unable to read dynamic function table entries" error messages by disabling the WinDbg security // feature that prevents the loading of unknown out of proc tack walkers. DebugControl->Execute(DEBUG_OUTCTL_IGNORE, ".settings set EngineInitialization.VerifyFunctionTableCallbacks=false", DEBUG_EXECUTE_NOT_LOGGED | DEBUG_EXECUTE_NO_REPEAT); ExtQuery(DebugClient); if (IsMiniDumpFileNODAC()) { ExtOut ( "----------------------------------------------------------------------------\n" "The user dump currently examined is a minidump. Consequently, only a subset\n" "of sos.dll functionality will be available. If needed, attaching to the live\n" "process or debugging a full dump will allow access to sos.dll's full feature\n" "set.\n" "To create a full user dump use the command: .dump /ma <filename>\n" "----------------------------------------------------------------------------\n"); } ExtRelease(); OnUnloadTask::Register(CleanupEventCallbacks); g_pCallbacksClient = DebugClient; EventCallbacks* pCallbacksObj = new EventCallbacks(DebugClient); IDebugEventCallbacks* pCallbacks = NULL; pCallbacksObj->QueryInterface(__uuidof(IDebugEventCallbacks), (void**)&pCallbacks); pCallbacksObj->Release(); if(FAILED(Hr = g_pCallbacksClient->SetEventCallbacks(pCallbacks))) { ExtOut ("SOS: Failed to register callback events\n"); pCallbacks->Release(); return Hr; } pCallbacks->Release(); #ifndef _ARM_ // Make sure we do not tear down the debugger when a security function fails // Since we link statically against CRT this will only affect the SOS module. _set_invalid_parameter_handler(_SOS_invalid_parameter); #endif DebugControl->Release(); return S_OK; }