📄 debugview.cpp
字号:
int CDebugView::GetLineY(CPoint point)
{
int i=(point.y-17)/16;
return i*16+17;
}
void CDebugView::DrawCaret(CPoint point)
{
try{
CPen pen(PS_SOLID,1,RGB(0,0,0));
CPen* oldPen;
CClientDC dc(this);
oldPen=dc.SelectObject(&pen);
dc.MoveTo(point.x,point.y);
dc.LineTo(point.x,point.y+12);
dc.SelectObject(oldPen);
}
catch(CResourceException* e)
{
e->ReportError();
}
catch(...)
{
}
}
void CDebugView::ClearCaret()
{
try{
CPen pen(PS_SOLID,1,RGB(255,255,255));
CPen* oldPen;
CClientDC dc(this);
oldPen=dc.SelectObject(&pen);
dc.MoveTo(m_point.x,m_point.y);
dc.LineTo(m_point.x,m_point.y+12);
dc.SelectObject(oldPen);
}
catch(CResourceException* e)
{
e->ReportError();
}
catch(...)
{
}
}
void CDebugView::OnActionStep()
{
if(!m_bProExist)
{
ReportState("not have any program be loaded to the memory");
return;
}
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
m_wPC=pCPU->GetPC();//hold the last PC
//change caret pos
//specify the flags y position
//execute
if(pCPU)
{
pCPU->SetContinue(TRUE);
pCPU->Excute();
//flush the cscreen
FlushDisplay();
m_caretPos.y=((m_wPC-pCPU->GetIP())/2-m_uFirstVisualPos)*16+17;
DrawFlag(m_caretPos);
AnylizeCode();
}
else
{
ReportState("can't find the simulator cpu");
return;
}
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
//flush the moniter windows
CMemoryDlg* pMemoryDlg=pMainFrame->GetMemoryDlg();
CRegisterDlg* pRegDlg=pMainFrame->GetRegisterDlg();
CStackDlg* pStackDlg=pMainFrame->GetStackDlg();
CVariableDlg* pVarDlg=pMainFrame->GetVariableDlg();
if(pMemoryDlg)
pMemoryDlg->FlushDisplay();
if(pRegDlg)
pRegDlg->FlushRegister();
if(pStackDlg)
pStackDlg->FlushStack();
if(pVarDlg)
pVarDlg->FlushVariable();
}
void CDebugView::OnActionGo()
{
if(!m_bProExist)
{
ReportState("no program exist in the memory");
}
else
{
//get the simulator speed
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
int speed=pApp->GetSimulatorSpeed();
//excute the program
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pOutputWindow=pMainFrame->GetOutputWindow();
pOutputWindow->ResetContent();
pApp->GetSimulatorCPU()->SetContinue(TRUE);
SetTimer(1,100*speed,NULL);
}
}
void CDebugView::OnTimer(UINT nIDEvent)
{
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
m_wPC=pCPU->GetPC();//hold the last PC
//change caret pos
//specify the flags y position
//execute
if(pCPU)
{
if(pCPU->GetContinue())
{
pCPU->Excute();
//flush the cscreen
FlushDisplay();
AnylizeCode();
}
else
{
KillTimer(1);
}
}
else
{
ReportState("can't find the simulator cpu");
return;
}
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
//flush the moniter windows
CMemoryDlg* pMemoryDlg=pMainFrame->GetMemoryDlg();
CRegisterDlg* pRegDlg=pMainFrame->GetRegisterDlg();
CStackDlg* pStackDlg=pMainFrame->GetStackDlg();
CVariableDlg* pVarDlg=pMainFrame->GetVariableDlg();
if(pMemoryDlg)
pMemoryDlg->FlushDisplay();
if(pRegDlg)
pRegDlg->FlushRegister();
if(pStackDlg)
pStackDlg->FlushStack();
if(pVarDlg)
pVarDlg->FlushVariable();
//check if go to the end
if((pCPU->GetPC()-pCPU->GetIP())>=m_wCodeSegSize)
{
KillTimer(1);
}
CScrollView::OnTimer(nIDEvent);
}
void CDebugView::OnActionStepout()
{
if(!m_bProExist)
{
ReportState("not have any program be loaded to the memory");
return;
}
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
m_wPC=pCPU->GetPC();//hold the last PC
//change caret pos
//specify the flags y position
//execute
if(pCPU)
{
pCPU->SetContinue(TRUE);
pCPU->Excute();
//flush the cscreen
FlushDisplay();
m_caretPos.y=((m_wPC-pCPU->GetIP())/2-m_uFirstVisualPos)*16+17;
DrawFlag(m_caretPos);
AnylizeCode();
}
else
{
ReportState("can't find the simulator cpu");
return;
}
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
//flush the moniter windows
CMemoryDlg* pMemoryDlg=pMainFrame->GetMemoryDlg();
CRegisterDlg* pRegDlg=pMainFrame->GetRegisterDlg();
CStackDlg* pStackDlg=pMainFrame->GetStackDlg();
CVariableDlg* pVarDlg=pMainFrame->GetVariableDlg();
if(pMemoryDlg)
pMemoryDlg->FlushDisplay();
if(pRegDlg)
pRegDlg->FlushRegister();
if(pStackDlg)
pStackDlg->FlushStack();
if(pVarDlg)
pVarDlg->FlushVariable();
}
void CDebugView::OnActionStepover()
{
if(!m_bProExist)
{
ReportState("not have any program be loaded to the memory");
return;
}
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
m_wPC=pCPU->GetPC();//hold the last PC
//change caret pos
//specify the flags y position
//execute
if(pCPU)
{
pCPU->SetContinue(TRUE);
pCPU->Excute();
//flush the cscreen
FlushDisplay();
m_caretPos.y=((m_wPC-pCPU->GetIP())/2-m_uFirstVisualPos)*16+17;
DrawFlag(m_caretPos);
AnylizeCode();
}
else
{
ReportState("can't find the simulator cpu");
return;
}
CMainFrame* pMainFrame=(CMainFrame*)AfxGetMainWnd();
//flush the moniter windows
CMemoryDlg* pMemoryDlg=pMainFrame->GetMemoryDlg();
CRegisterDlg* pRegDlg=pMainFrame->GetRegisterDlg();
CStackDlg* pStackDlg=pMainFrame->GetStackDlg();
CVariableDlg* pVarDlg=pMainFrame->GetVariableDlg();
if(pMemoryDlg)
pMemoryDlg->FlushDisplay();
if(pRegDlg)
pRegDlg->FlushRegister();
if(pStackDlg)
pStackDlg->FlushStack();
if(pVarDlg)
pVarDlg->FlushVariable();
}
void CDebugView::OnActionStopdebug()
{
KillTimer(1);
}
void CDebugView::AddVarInfo(char *strVarName, UNSHORT uAddr)
{
if(m_wVarNum>=2048)
{
ReportState("the m_varInfo is full can't add varinfo to it");
return;
}
strcpy(m_varInfo[m_wVarNum].varName,strVarName);
m_varInfo[m_wVarNum].uVarAddr=uAddr;
m_wVarNum++;
}
void CDebugView::ResetVarInfo()
{
m_wVarNum=0;
}
void CDebugView::LoadMapInfo()
{
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CString str;
char* strCurFile=pApp->GetCurFileName();
if(!strCurFile)
{
ReportState("haven't any DFYexe file been loaded ,so I do't know to load witch map file");
return;
}
else//have open a file
{
int nSize=strlen(strCurFile);
char* strMapFile=new char[nSize+5];
strcpy(strMapFile,strCurFile);
strcat(strMapFile,".map");
ifstream mapfile;
mapfile.open(strMapFile,ios::in);
if(!mapfile)
{
str.Format("can't open file: \'%s\' ,or the file is not exist",strMapFile);
ReportState(str);
}
else//can open the map file
{
//load file header
MapFileHeader header;
mapfile>>header.wFileVersion>>header.wRecordNum;
SetBreakInfoSize(header.wRecordNum);
m_mapInfo=new MapFileInfo[header.wRecordNum];
m_uCodeLineNum=header.wRecordNum;
for(int i=0;i<header.wRecordNum;i++)
mapfile>>m_mapInfo[i].bIsCode>>m_mapInfo[i].uAddr;
}//end:can open the map file
mapfile.close();
}//end:have open a file
}
void CDebugView::OnDestroy()
{
if(m_mapInfo)
delete[] m_mapInfo;
KillTimer(1);
CScrollView::OnDestroy();
// TODO: Add your message handler code here
}
void CDebugView::OnEditSetbreakpoint()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pOutputWindow=pFrame->GetOutputWindow();
pOutputWindow->ResetContent();
if(!m_bProExist)
{
ReportState("you can't set break point ,no program exist");
return;
}
if(m_uLineIndex<0||m_uLineIndex>m_uCodeLineNum)
{
MessageBox("can't set break point in this line ,it out of range");
ReportState("set break point failed");
return;
}
else//in the range
{
if(m_mapInfo[m_uLineIndex-1].bIsCode)//can set break point in this line
{
if(m_breakInfo[m_uLineIndex-1].bIsSet)//if the break point have been setted
ReportState("the break point has been seted");
else//if the break point haven't been setted before
{
m_breakInfo[m_uLineIndex-1].bIsSet=TRUE;
ReportState("set break point succeed");
DrawBreakPoint(m_caretPos2);
//inset the int 3 instruction to the program
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU *pCPU=pApp->GetSimulatorCPU();
if(!pCPU)
{
ReportState("can't get cpu");
return;
}
else//get the cpu
{
WORD wIP=pCPU->GetIP();
Memory* pMemory=pApp->GetSimulatorMemory();
if(!pMemory)
{
ReportState("can't get memory");
return;
}
else//get the memory
{
UNSHORT uAddr=m_mapInfo[m_uLineIndex-1].uAddr+wIP;
//reserve the code to m_breakInfo
WORD wData=0;
pMemory->ReadMemory(uAddr,wData);
DWORD dwCode=DWORD(wData<<16);
pMemory->ReadMemory(uAddr+1,wData);
dwCode+=wData;
m_breakInfo[m_uLineIndex-1].dwCode=dwCode;
pMemory->WriteMemory(uAddr,0X3800);
pMemory->WriteMemory(uAddr+1,0X3);
}//end: get the memory
}//end:get the cpu
}//end: the break point haven't been setted before
}//end:can set break point in this line
else
{
MessageBox("can't set break point in this line ,it is not a code line");
ReportState("set break point failed");
return;
}
}//end: in the range
}
void CDebugView::SetBreakInfoSize(UNSHORT uSize)
{
if(m_breakInfo)delete[] m_breakInfo;
m_breakInfo=new BreakInfo[uSize];
for(int i=0;i<uSize;i++)
{
m_breakInfo[i].bIsSet=FALSE;
m_breakInfo[i].dwCode=0;
}
}
void CDebugView::DrawBreakPoint(CPoint point)
{
try{
CBrush whiteBrush(RGB(255,0,0));
CClientDC dc(this);
CRect rect(point.x,point.y,point.x+12,point.y+12);
dc.FillRect(&rect,&whiteBrush);
}
catch(CResourceException* e)
{
e->ReportError();
}
catch(...)
{
}
}
void CDebugView::OnEditClearbreakpiont()
{
CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
COutputWindow* pOutputWindow=pFrame->GetOutputWindow();
pOutputWindow->ResetContent();
if(!m_bProExist)
{
ReportState("you can't clear point ,no program exist");
return;
}
if(m_uLineIndex<0||m_uLineIndex>m_uCodeLineNum)
{
MessageBox("can't clear break point in this line ,no break point set");
ReportState("clear break point failed");
return;
}
else//in the range
{
if(m_mapInfo[m_uLineIndex-1].bIsCode)//can set break point in this line
{
if(m_breakInfo[m_uLineIndex-1].bIsSet)//if the break point have been setted
{
m_breakInfo[m_uLineIndex-1].bIsSet=FALSE;
ReportState("clear break point succeed");
ClearBreakPoint(m_caretPos2);
//get the code
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU *pCPU=pApp->GetSimulatorCPU();
if(!pCPU)
{
ReportState("can't get cpu");
return;
}
else//get the cpu
{
pCPU->SetContinue(TRUE);//make the cpu can run
WORD wIP=pCPU->GetIP();
Memory* pMemory=pApp->GetSimulatorMemory();
if(!pMemory)
{
ReportState("can't get memory");
return;
}
else//get the memory
{
UNSHORT uAddr=m_mapInfo[m_uLineIndex-1].uAddr+wIP;
//reserve the code to m_breakInfo
DWORD dwCode=m_breakInfo[m_uLineIndex-1].dwCode;
m_breakInfo[m_uLineIndex-1].dwCode=dwCode;
WORD wData=WORD(dwCode>>16);
pMemory->WriteMemory(uAddr,wData);
wData=WORD(dwCode&0X0000FFFF);
pMemory->WriteMemory(uAddr+1,wData);
}//end: get the memory
}//end:get the cpu
}
else//if the break point haven't been setted before
{
ReportState("the break point haven't been set before");
}//end: the break point haven't been setted before
}//end:can set break point in this line
else
{
MessageBox("can't set break point in this line ,it is not a code line");
ReportState("set break point failed");
return;
}
}//end: in the range
}
void CDebugView::ClearBreakPoint(CPoint point)
{
try{
CBrush whiteBrush(RGB(255,255,255));
CClientDC dc(this);
CRect rect(point.x,point.y,point.x+12,point.y+12);
dc.FillRect(&rect,&whiteBrush);
}
catch(CResourceException* e)
{
e->ReportError();
}
catch(...)
{
}
}
void CDebugView::OnRButtonDown(UINT nFlags, CPoint point)
{
//pop up the menu
CMenu* pMenu=new CMenu();
pMenu->LoadMenu(IDR_DEBUGTYPE);
CMenu* ppMenu=pMenu->GetSubMenu(1);
BOOL bItem=ppMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x+10,point.y+110,this);
CScrollView::OnRButtonDown(nFlags, point);
}
UNSHORT CDebugView::GetLineNumFromAddr(UNSHORT uAddr)
{
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
if(!pCPU)
{
ReportState("can't get the cpu");
return 1;
}
WORD wIP=pCPU->GetIP();
for(int i=1;i<m_uCodeLineNum;i++)
{
if(m_mapInfo[i].uAddr==uAddr-wIP)
return i+1;//return the linumber
}
return 1;//the first line must be NULL ,comment or 'START' ,but not code line
}
void CDebugView::OnActionReset()
{
KillTimer(1);
CDFYSimulatorApp* pApp=(CDFYSimulatorApp*)AfxGetApp();
CPU* pCPU=pApp->GetSimulatorCPU();
if(pCPU)
{
m_wPC=pCPU->GetIP();
pCPU->SetContinue(TRUE);
}
char* fileName=pApp->GetCurFileName();
int nSize=strlen(fileName);
char* strDFYexeFile=new char[nSize+7];
strcpy(strDFYexeFile,fileName);
strcat(strDFYexeFile,".DFYexe");
CDebugChildFrame* pFrame=(CDebugChildFrame*)GetParent();
pFrame->LoadFileToMemory(strDFYexeFile);
}
void CDebugView::SetIP(WORD wIP)
{
m_uIP=wIP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -