📄 debuginterface.cpp
字号:
// DebugInterface.cpp: implementation of the CDebugInterface class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "VisualJava.h"
#include "DebugInterface.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
static const UINT wm_MsgRequest = RegisterWindowMessage("43F453AB-326C-4443-950D-7B5389385AA1");
// number of characters in memory-mapped file
static const DWORD dwMemoryFileSize = 4 * 1024;
// memory-mapped file name
static const LPCTSTR sMemoryFileName = _T("D9287E19-6F9E-45fa-897C-D392F73A0F2F");
// memory mapping file common for all instances:
static HANDLE m_hFileMapping = NULL; // memory mapped file
static LPVOID m_pViewOfFile = NULL; // view of file, contains text in edit box
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void DebugMsgProc(int nMsg,void* jniEnv)
{
switch(nMsg)
{
case DEBUG_MSG_SINGLESTEP:
{
break;
}
case DEBUG_MSG_BREAKPOINT:
{
MessageBox(0,"Break point set","notification",MB_OK);
break;
}
case DEBUG_MSG_FRAMPOP:
{
break;
}
case DEBUG_MSG_EXCEPTION:
{
break;
}
case DEBUG_MSG_USERDEFINED:
{
break;
}
case DEBUG_MSG_THREADSTART:
{
break;
}
case DEBUG_MSG_THREADEND:
{
break;
}
case DEBUG_MSG_PREPARECLASS:
{
break;
}
case DEBUG_MSG_LOADCLASS:
{
break;
}
case DEBUG_MSG_UNLOADCLASS:
{
break;
}
case DEBUG_MSG_FIELDACCESS:
{
break;
}
case DEBUG_MSG_FIELDMODIFICATION:
{
break;
}
case DEBUG_MSG_CATCHEXCEPTION:
{
break;
}
case DEBUG_MSG_METHODENTRY:
{
break;
}
case DEBUG_MSG_METHODEXIT:
{
break;
}
case DEBUG_MSG_VMINIT:
{
::PostMessage(HWND_BROADCAST,wm_MsgRequest,0,0);
/*
/**InitDebuger();**
JNIEnv* pjniEnv = (JNIEnv*)jniEnv;
JavaVM ** ppVm = NULL;
pjniEnv->GetJavaVM(ppVm);
ASSERT(ppVm != NULL);
JVMDI_Interface_1 *pjvmdi;
(*ppVm)->GetEnv((void**)&pjvmdi, JVMDI_VERSION_1);
jclass nBreakClass = pjniEnv->FindClass("JSoft");
jmethodID nBreakMethod = pjniEnv->GetMethodID(nBreakClass,
"addButtons","(Ljavax/swing/JToolBar;)V");
jint *entryCountPtr = 0;
JVMDI_line_number_entry **tablePtr = NULL;
pjvmdi->GetLineNumberTable(nBreakClass,nBreakMethod,
entryCountPtr,tablePtr);
*/
break;
}
case DEBUG_MSG_VMDEATH:
{
break;
}
}
}
void OnSingleStep(JNIEnv *env)
{
}
void OnBreakPoint(JNIEnv *env)
{
}
void OnFramePop(JNIEnv *env)
{
}
void OnException(JNIEnv *env)
{
}
void OnUserDefined(JNIEnv *env)
{
}
void OnThreadStart(JNIEnv *env)
{
}
void OnThreadEnd(JNIEnv *env)
{
}
void OnPrepareClass(JNIEnv *env)
{
}
void OnLoadClass(JNIEnv *env)
{
}
void OnUnLoadClass(JNIEnv *env)
{
}
void OnFieldAccess(JNIEnv *env)
{
}
void OnFieldModification(JNIEnv *env)
{
}
void OnCatchException(JNIEnv *env)
{
}
void OnMethodEntry(JNIEnv *env)
{
}
void OnMethodExit(JNIEnv *env)
{
}
void OnVMinit(JNIEnv *env)
{
}
void OnVMdeath(JNIEnv *env)
{
}
void BreakPoint(int nLineIndex)
{
CString str;
str.Format("%d",nLineIndex);
str = "<request NAME = BREAKPOINT><data>"+str+"</data></request>";
LPTSTR lszpLine = str.GetBuffer(str.GetLength()+1);str.ReleaseBuffer();
WriteToMemMapFile(lszpLine);
}
#include <fstream.h>
#include <stdlib.h>
void InitDebuger()
{
/**
// create the Single Writer/Multiple Reader Guard
m_pLock = new CIPCReadWriteLock(
sReadWriteLockName,
dwMaxWait);
**/
// Create file mapping which can contain dwMemoryFileSize characters
m_hFileMapping = CreateFileMapping(
INVALID_HANDLE_VALUE, // system paging file
NULL, // security attributes
PAGE_READWRITE, // protection
0, // high-order DWORD of size
dwMemoryFileSize*sizeof(TCHAR), // low-order DWORD of size
sMemoryFileName); // name
DWORD dwError = GetLastError(); // if ERROR_ALREADY_EXISTS
// this instance is not first (other instance created file mapping)
if ( ! m_hFileMapping )
{
MessageBox(NULL,NULL,_T("Creating of file mapping failed"),MB_OK);
}
else
{
m_pViewOfFile = MapViewOfFile(
m_hFileMapping, // handle to file-mapping object
FILE_MAP_ALL_ACCESS, // desired access
0,
0,
0); // map all file
/*
ofstream wt;
wt.seekp(0L,ios::end);
wt.open("\\My Documents\\JVMDI_client\\memfile.txt");
wt<<m_pViewOfFile<<endl;
wt.close();*/
if ( ! m_pViewOfFile )
{
// MessageBox(_T("MapViewOfFile failed"));
}
// Now we have m_pViewOfFile memory block which is common for
// all instances of this program
}
if( dwError == ERROR_ALREADY_EXISTS)
{
// Some other instance is already running,
// get text from existing file mapping
//ReadMemMapFile();
}
}
void ReadMemMapFile(LPTSTR& lpText)
{
if(m_pViewOfFile)
lstrcpy(lpText,(LPTSTR) m_pViewOfFile);
}
void WriteToMemMapFile(LPTSTR lpText)
{
if(m_pViewOfFile)
{
LPTSTR lszpBuff = lstrcpy((LPTSTR) m_pViewOfFile,lpText);
DWORD dwError = GetLastError();
//memcpy(m_pViewOfFile,lpText,dwMemoryFileSize);
//::PostMessage(HWND_BROADCAST,wm_MsgRequest,0,0);
AfxGetMainFrame()->SendMessage(wm_MsgRequest,0,0);
}
}
// AfxGetMainFrame()->SendMessage(wm_MsgRequest,DEBUG_MSG_BREAKPOINT,(LPARAM)lszpLine);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -