/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
// this is source code windbg based SA debugger agent to debug
// Dr. Watson dump files and process snapshots.
#ifdef _M_IA64
#else
#error "SA windbg back-end is not supported for your cpu!"
#endif
#include <limits.h>
#include <windows.h>
#ifndef STDMETHODV
#endif
#define DEBUG_NO_IMPLEMENTATION
#include <dbgeng.h>
#include <dbghelp.h>
// simple template to manage array delete across early (error) returns
template <class T>
class AutoArrayPtr {
T* m_ptr;
public:
}
~AutoArrayPtr() {
delete [] m_ptr;
}
T* asPtr() {
return m_ptr;
}
};
class AutoJavaString {
const char* m_buf;
public:
}
~AutoJavaString() {
}
operator const char* () {
return m_buf;
}
};
// field and method IDs we want here
return;}
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: initIDs
* Signature: ()V
*/
"ptrIDebugOutputCallbacks", "J");
"ptrIDebugSymbols", "J");
"ptrIDebugSystemObjects", "J");
"setThreadIntegerRegisterSet", "(J[J)V");
}
// class for IDebugOutputCallbacks
char* m_msgBuffer;
public:
}
~SAOutputCallbacks() {
clearBuffer();
}
const char* getBuffer() const {
return m_msgBuffer;
}
void clearBuffer() {
if (m_msgBuffer) {
m_msgBuffer = 0;
}
}
};
return m_refCount;
}
retVal = m_refCount;
if (retVal == 0) {
delete this;
}
return retVal;
}
*ppInterface = 0;
*ppInterface = (IDebugOutputCallbacks*) this;
AddRef();
}
return res;
}
if (m_msgBuffer == 0) {
if (m_msgBuffer == 0) {
return S_FALSE;
}
} else {
if (m_msgBuffer == 0) {
return S_FALSE;
}
}
return S_OK;
}
// get windbg interfaces ..
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to create IDebugClient object!", false);
}
!= S_OK) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugControl", false);
}
!= S_OK) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugDataSpaces object!", false);
}
CHECK_EXCEPTION_(false);
!= S_OK) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugAdvanced object!", false);
}
!= S_OK) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSymbols object!", false);
}
if (ptrIDebugClient->QueryInterface(__uuidof(IDebugSystemObjects), (PVOID*) &ptrIDebugSystemObjects)
!= S_OK) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: not able to get IDebugSystemObjects object!", false);
}
return true;
}
const char* buf;
CHECK_EXCEPTION_(false);
CHECK_EXCEPTION_(false);
CHECK_EXCEPTION_(false);
return true;
}
// open the dump file
CHECK_EXCEPTION_(false);
return false;
}
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: OpenDumpFile failed!", false);
}
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
}
return true;
}
return false;
}
CHECK_EXCEPTION_(false);
/***********************************************************************************
We are attaching to a process in 'read-only' mode. i.e., we do not want to
usage this should suffice. We are not intending to use this for full-fledged
ProcessControl implementation to be used with BugSpotAgent.
Please refer to DEBUG_ATTACH_NONINVASIVE mode source comments from dbgeng.h.
In this mode, debug engine does not call DebugActiveProrcess. i.e., we are not
actually debugging at all. We can safely 'detach' from the process anytime
we want and debuggee process is left as is on all Windows variants.
This also makes JDI-on-SA installation/usage simpler because with this we would
not need a tool like ServiceInstaller from http://www.kcmultimedia.com/smaster.
***********************************************************************************/
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: AttachProcess failed!", false);
}
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: WaitForEvent failed!", false);
}
return true;
}
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberModules failed!", false);
}
THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate debug module params!", false);
}
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleParameters failed!", false);
}
for (int u = 0; u < (int)loaded; u++) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetModuleNames failed!", false);
}
CHECK_EXCEPTION_(false);
CHECK_EXCEPTION_(false);
}
return true;
}
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetNumberThreads failed!", false);
}
if (ptrSysThreadIds.asPtr() == 0) {
THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
}
if (ptrThreadIds.asPtr() == 0) {
THROW_NEW_DEBUGGER_EXCEPTION_("out of memory to allocate thread ids!", false);
}
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdsByIndex failed!", false);
}
CHECK_EXCEPTION_(false);
// for each thread, get register context and save it.
for (ULONG t = 0; t < numThreads; t++) {
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetCurrentThread failed!", false);
}
CHECK_EXCEPTION_(false);
CHECK_EXCEPTION_(false);
// copy register values from the CONTEXT struct
#ifdef _M_IA64
// Segment Registers and processor flags
// Integer registers
// Program counter
#endif
CHECK_EXCEPTION_(false);
CHECK_EXCEPTION_(false);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetCurrentThreadSystemId failed!", false);
}
CHECK_EXCEPTION_(false);
}
return true;
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: attach0
*/
JNIEXPORT void JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_attach0__Ljava_lang_String_2Ljava_lang_String_2
return;
}
return;
}
return;
}
return;
}
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: attach0
* Signature: (I)V
*/
return;
}
return;
}
return;
}
return;
}
}
CHECK_EXCEPTION_(false);
if (ptrIDebugDataSpaces != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugOutputCallbacks != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugAdvanced != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugSymbols != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugSystemObjects != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugControl != 0) {
}
CHECK_EXCEPTION_(false);
if (ptrIDebugClient != 0) {
}
return true;
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: detach0
* Signature: ()V
*/
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: readBytesFromProcess0
* Signature: (JJ)[B
*/
JNIEXPORT jbyteArray JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_readBytesFromProcess0
CHECK_EXCEPTION_(0);
CHECK_EXCEPTION_(0);
CHECK_EXCEPTION_(0);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: ReadVirtual failed!", 0);
}
return 0;
}
CHECK_EXCEPTION_(0);
return byteArray;
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: getThreadIdFromSysId0
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_getThreadIdFromSysId0
CHECK_EXCEPTION_(0);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: GetThreadIdBySystemId failed!", 0);
}
}
// manage COM 'auto' pointers (to avoid multiple Release
// calls at every early (exception) returns). Similar to AutoArrayPtr.
template <class T>
class AutoCOMPtr {
T* m_ptr;
public:
}
~AutoCOMPtr() {
if (m_ptr) {
}
}
T* operator->() {
return m_ptr;
}
};
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: consoleExecuteCommand0
*/
JNIEXPORT jstring JNICALL Java_sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal_consoleExecuteCommand0
CHECK_EXCEPTION_(0);
CHECK_EXCEPTION_(0);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: CreateClient failed!", 0);
}
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: QueryInterface (IDebugControl) failed", 0);
}
CHECK_EXCEPTION_(0);
THROW_NEW_DEBUGGER_EXCEPTION_("Windbg Error: SetOutputCallbacks failed!", 0);
}
if (output == 0) {
output = "";
}
return res;
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: lookupByName0
*/
CHECK_EXCEPTION_(0);
CHECK_EXCEPTION_(0);
} else {
}
return (jlong) 0;
}
}
/*
* Class: sun_jvm_hotspot_debugger_windbg_WindbgDebuggerLocal
* Method: lookupByAddress0
*/
CHECK_EXCEPTION_(0);
!= S_OK) {
return 0;
}
CHECK_EXCEPTION_(0);
CHECK_EXCEPTION_(0);
return res;
}