diff --git a/src/debug/debug.cpp b/src/debug/debug.cpp index 06d492fd..42881792 100644 --- a/src/debug/debug.cpp +++ b/src/debug/debug.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: debug.cpp,v 1.79 2006-05-22 20:29:50 qbix79 Exp $ */ +/* $Id: debug.cpp,v 1.80 2006-06-16 14:51:31 qbix79 Exp $ */ #include "dosbox.h" #if C_DEBUG @@ -26,6 +26,8 @@ #include #include #include +#include +#include using namespace std; #include "debug.h" @@ -265,8 +267,8 @@ enum EBreakpoint { BKPNT_UNKNOWN, BKPNT_PHYSICAL, BKPNT_INTERRUPT, BKPNT_MEMORY, class CBreakpoint { public: - CBreakpoint (void) { location = 0; active = once = false; segment = 0; offset = 0; intNr = 0; ahValue = 0; type = BKPNT_UNKNOWN; }; + CBreakpoint(void); void SetAddress (Bit16u seg, Bit32u off) { location = GetAddress(seg,off); type = BKPNT_PHYSICAL; segment = seg; offset = off; }; void SetAddress (PhysPt adr) { location = adr; type = BKPNT_PHYSICAL; }; void SetInt (Bit8u _intNr, Bit16u ah) { intNr = _intNr, ahValue = ah; type = BKPNT_INTERRUPT; }; @@ -320,10 +322,16 @@ public: static CBreakpoint* ignoreOnce; }; +CBreakpoint::CBreakpoint(void): +location(0), +active(false),once(false), +segment(0),offset(0),intNr(0),ahValue(0), +type(BKPNT_UNKNOWN) { }; + void CBreakpoint::Activate(bool _active) { - if (GetType()==BKPNT_PHYSICAL) { #if !C_HEAVY_DEBUG + if (GetType()==BKPNT_PHYSICAL) { if (_active) { // Set 0xCC and save old value Bit8u data = mem_readb(location); @@ -337,8 +345,8 @@ void CBreakpoint::Activate(bool _active) mem_writeb(location,oldData); }; } -#endif } +#endif active = _active; }; @@ -381,7 +389,7 @@ void CBreakpoint::ActivateBreakpoints(PhysPt adr, bool activate) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); // Do not activate, when bp is an actual adress if (activate && (bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==adr)) { // Do not activate :) @@ -404,7 +412,7 @@ bool CBreakpoint::CheckBreakpoint(Bitu seg, Bitu off) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); if ((bp->GetType()==BKPNT_PHYSICAL) && bp->IsActive() && (bp->GetSegment()==seg) && (bp->GetOffset()==off)) { // Ignore Once ? if (ignoreOnce==bp) { @@ -467,7 +475,7 @@ bool CBreakpoint::CheckIntBreakpoint(PhysPt adr, Bit8u intNr, Bit16u ahValue) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); if ((bp->GetType()==BKPNT_INTERRUPT) && bp->IsActive() && (bp->GetIntNr()==intNr)) { if ((bp->GetValue()==BPINT_ALL) || (bp->GetValue()==ahValue)) { // Ignoie it once ? @@ -497,7 +505,7 @@ void CBreakpoint::DeleteAll() std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); bp->Activate(false); delete bp; }; @@ -513,7 +521,7 @@ bool CBreakpoint::DeleteByIndex(Bit16u index) CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { if (nr==index) { - bp = static_cast(*i); + bp = (*i); (BPoints.erase)(i); bp->Activate(false); delete bp; @@ -530,7 +538,7 @@ bool CBreakpoint::DeleteBreakpoint(PhysPt where) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==where)) { (BPoints.erase)(i); bp->Activate(false); @@ -548,7 +556,7 @@ bool CBreakpoint::IsBreakpoint(PhysPt adr) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetSegment()==adr)) { return true; }; @@ -566,7 +574,7 @@ bool CBreakpoint::IsBreakpointDrawn(PhysPt adr) std::list::iterator i; CBreakpoint* bp; for(i=BPoints.begin(); i != BPoints.end(); i++) { - bp = static_cast(*i); + bp = (*i); if ((bp->GetType()==BKPNT_PHYSICAL) && (bp->GetLocation()==adr)) { // Only draw, if breakpoint is not only once, return !bp->GetOnce(); @@ -581,7 +589,7 @@ void CBreakpoint::ShowList(void) int nr = 0; std::list::iterator i; for(i=BPoints.begin(); i != BPoints.end(); i++) { - CBreakpoint* bp = static_cast(*i); + CBreakpoint* bp = (*i); if (bp->GetType()==BKPNT_PHYSICAL) { DEBUG_ShowMsg("%02X. BP %04X:%04X\n",nr,bp->GetSegment(),bp->GetOffset()); nr++; @@ -699,31 +707,33 @@ static void DrawRegisters(void) { SetColor(SegValue(cs)!=oldsegs[cs].val);oldsegs[cs].val=SegValue(cs);mvwprintw (dbg.win_reg,1,31,"%04X",SegValue(cs)); /*Individual flags*/ + Bitu changed_flags = reg_flags ^ oldflags; + oldflags = reg_flags; - SetColor((reg_flags ^ oldflags)&FLAG_CF); + SetColor(changed_flags&FLAG_CF); mvwprintw (dbg.win_reg,1,53,"%01X",GETFLAG(CF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_ZF); + SetColor(changed_flags&FLAG_ZF); mvwprintw (dbg.win_reg,1,56,"%01X",GETFLAG(ZF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_SF); + SetColor(changed_flags&FLAG_SF); mvwprintw (dbg.win_reg,1,59,"%01X",GETFLAG(SF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_OF); + SetColor(changed_flags&FLAG_OF); mvwprintw (dbg.win_reg,1,62,"%01X",GETFLAG(OF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_AF); + SetColor(changed_flags&FLAG_AF); mvwprintw (dbg.win_reg,1,65,"%01X",GETFLAG(AF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_PF); + SetColor(changed_flags&FLAG_PF); mvwprintw (dbg.win_reg,1,68,"%01X",GETFLAG(PF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_DF); + SetColor(changed_flags&FLAG_DF); mvwprintw (dbg.win_reg,1,71,"%01X",GETFLAG(DF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_IF); + SetColor(changed_flags&FLAG_IF); mvwprintw (dbg.win_reg,1,74,"%01X",GETFLAG(IF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_TF); + SetColor(changed_flags&FLAG_TF); mvwprintw (dbg.win_reg,1,77,"%01X",GETFLAG(TF) ? 1:0); - SetColor((reg_flags ^ oldflags)&FLAG_IOPL); + SetColor(changed_flags&FLAG_IOPL); mvwprintw (dbg.win_reg,2,72,"%01X",GETFLAG(IOPL)>>12); - oldflags=reg_flags; + SetColor(cpu.cpl ^ oldcpucpl); mvwprintw (dbg.win_reg,2,78,"%01X",cpu.cpl); @@ -737,7 +747,7 @@ static void DrawRegisters(void) { mvwprintw(dbg.win_reg,0,76,"Real"); // Selector info, if available - if ((cpu.pmode) && curSelectorName[0]) { + if ((cpu.pmode) && curSelectorName[0]) { char out1[200], out2[200]; GetDescriptorInfo(curSelectorName,out1,out2); mvwprintw(dbg.win_reg,2,28,out1); @@ -755,6 +765,7 @@ static void DrawCode(void) Bit32u disEIP = codeViewData.useEIP; PhysPt start = GetAddress(codeViewData.useCS,codeViewData.useEIP); char dline[200];Bitu size;Bitu c; + static char line20[21] = " "; for (int i=0;i<10;i++) { saveSel = false; @@ -786,19 +797,29 @@ static void DrawCode(void) if (drawsize>10) { toolarge = true; drawsize = 9; }; for (c=0;c=drawsize*2;c--) waddch(dbg.win_code,' '); - + if (toolarge) { waddstr(dbg.win_code,".."); drawsize++; }; + // Spacepad up to 20 characters + if(drawsize && (drawsize < 10)) { + line20[20 - drawsize*2] = 0; + waddstr(dbg.win_code,line20); + line20[20 - drawsize*2] = ' '; + } else waddstr(dbg.win_code,line20); + char* res = 0; if (showExtend) res = AnalyzeInstruction(dline, saveSel); + // Spacepad it up to 28 characters + size_t dline_len = strlen(dline); + if(dline_len < 28) for (c = dline_len; c < 28;c++) dline[c] = ' '; dline[28] = 0; waddstr(dbg.win_code,dline); - if (strlen(dline)<28) for (c=28-strlen(dline);c>0;c--) waddch(dbg.win_code,' '); - if (showExtend) { + // Spacepad it up to 20 characters + size_t res_len = strlen(res); + if(res_len && (res_len < 21)) { waddstr(dbg.win_code,res); - for (c=strlen(res);c<20;c++) waddch(dbg.win_code,' '); - } else { - for (c=0;c<20;c++) waddch(dbg.win_code,' '); - } + line20[20-res_len] = 0; + waddstr(dbg.win_code,line20); + line20[20-res_len] = ' '; + } else waddstr(dbg.win_code,line20); + start+=size; disEIP+=size; @@ -810,14 +831,14 @@ static void DrawCode(void) wattrset(dbg.win_code,0); if (!debugging) { - mvwprintw(dbg.win_code,10,0,"(Running)",codeViewData.inputStr); - } else if (codeViewData.inputMode) { - mvwprintw(dbg.win_code,10,0,"-> %s_ ",codeViewData.inputStr); - } else { - mvwprintw(dbg.win_code,10,0," "); - for (c=0;c<50;c++) waddch(dbg.win_code,' '); - }; - + mvwprintw(dbg.win_code,10,0,"(Running)",codeViewData.inputStr); + } else { + if(!*codeViewData.inputStr) { //Clear old commands + mvwprintw(dbg.win_code,10,0," "); + } + mvwprintw(dbg.win_code,10,0,"-> %s_ ",codeViewData.inputStr); + } + wrefresh(dbg.win_code); } @@ -842,41 +863,45 @@ static void SetCodeWinStart() Bit32u GetHexValue(char* str, char*& hex) { Bit32u value = 0; - + Bit32u regval = 0; hex = str; while (*hex==' ') hex++; - if (strstr(hex,"EAX")==hex) { hex+=3; return reg_eax; }; - if (strstr(hex,"EBX")==hex) { hex+=3; return reg_ebx; }; - if (strstr(hex,"ECX")==hex) { hex+=3; return reg_ecx; }; - if (strstr(hex,"EDX")==hex) { hex+=3; return reg_edx; }; - if (strstr(hex,"ESI")==hex) { hex+=3; return reg_esi; }; - if (strstr(hex,"EDI")==hex) { hex+=3; return reg_edi; }; - if (strstr(hex,"EBP")==hex) { hex+=3; return reg_ebp; }; - if (strstr(hex,"ESP")==hex) { hex+=3; return reg_esp; }; - if (strstr(hex,"EIP")==hex) { hex+=3; return reg_eip; }; - if (strstr(hex,"AX")==hex) { hex+=2; return reg_ax; }; - if (strstr(hex,"BX")==hex) { hex+=2; return reg_bx; }; - if (strstr(hex,"CX")==hex) { hex+=2; return reg_cx; }; - if (strstr(hex,"DX")==hex) { hex+=2; return reg_dx; }; - if (strstr(hex,"SI")==hex) { hex+=2; return reg_si; }; - if (strstr(hex,"DI")==hex) { hex+=2; return reg_di; }; - if (strstr(hex,"BP")==hex) { hex+=2; return reg_bp; }; - if (strstr(hex,"SP")==hex) { hex+=2; return reg_sp; }; - if (strstr(hex,"IP")==hex) { hex+=2; return reg_ip; }; - if (strstr(hex,"CS")==hex) { hex+=2; return SegValue(cs); }; - if (strstr(hex,"DS")==hex) { hex+=2; return SegValue(ds); }; - if (strstr(hex,"ES")==hex) { hex+=2; return SegValue(es); }; - if (strstr(hex,"FS")==hex) { hex+=2; return SegValue(fs); }; - if (strstr(hex,"GS")==hex) { hex+=2; return SegValue(gs); }; - if (strstr(hex,"SS")==hex) { hex+=2; return SegValue(ss); }; + if (strstr(hex,"EAX")==hex) { hex+=3; regval = reg_eax; }; + if (strstr(hex,"EBX")==hex) { hex+=3; regval = reg_ebx; }; + if (strstr(hex,"ECX")==hex) { hex+=3; regval = reg_ecx; }; + if (strstr(hex,"EDX")==hex) { hex+=3; regval = reg_edx; }; + if (strstr(hex,"ESI")==hex) { hex+=3; regval = reg_esi; }; + if (strstr(hex,"EDI")==hex) { hex+=3; regval = reg_edi; }; + if (strstr(hex,"EBP")==hex) { hex+=3; regval = reg_ebp; }; + if (strstr(hex,"ESP")==hex) { hex+=3; regval = reg_esp; }; + if (strstr(hex,"EIP")==hex) { hex+=3; regval = reg_eip; }; + if (strstr(hex,"AX")==hex) { hex+=2; regval = reg_ax; }; + if (strstr(hex,"BX")==hex) { hex+=2; regval = reg_bx; }; + if (strstr(hex,"CX")==hex) { hex+=2; regval = reg_cx; }; + if (strstr(hex,"DX")==hex) { hex+=2; regval = reg_dx; }; + if (strstr(hex,"SI")==hex) { hex+=2; regval = reg_si; }; + if (strstr(hex,"DI")==hex) { hex+=2; regval = reg_di; }; + if (strstr(hex,"BP")==hex) { hex+=2; regval = reg_bp; }; + if (strstr(hex,"SP")==hex) { hex+=2; regval = reg_sp; }; + if (strstr(hex,"IP")==hex) { hex+=2; regval = reg_ip; }; + if (strstr(hex,"CS")==hex) { hex+=2; regval = SegValue(cs); }; + if (strstr(hex,"DS")==hex) { hex+=2; regval = SegValue(ds); }; + if (strstr(hex,"ES")==hex) { hex+=2; regval = SegValue(es); }; + if (strstr(hex,"FS")==hex) { hex+=2; regval = SegValue(fs); }; + if (strstr(hex,"GS")==hex) { hex+=2; regval = SegValue(gs); }; + if (strstr(hex,"SS")==hex) { hex+=2; regval = SegValue(ss); }; while (*hex) { - if ((*hex>='0') && (*hex<='9')) value = (value<<4)+*hex-'0'; else - if ((*hex>='A') && (*hex<='F')) value = (value<<4)+*hex-'A'+10; - else break; // No valid char + if ((*hex>='0') && (*hex<='9')) value = (value<<4)+*hex-'0'; + else if ((*hex>='A') && (*hex<='F')) value = (value<<4)+*hex-'A'+10; + else { + if(*hex == '+') {hex++;return regval + value + GetHexValue(hex,hex); }; + if(*hex == '-') {hex++;return regval + value - GetHexValue(hex,hex); }; + break; // No valid char + } hex++; }; - return value; + return regval + value; }; bool ChangeRegister(char* str) @@ -911,34 +936,38 @@ bool ChangeRegister(char* str) if (strstr(hex,"CF")==hex) { hex+=2; SETFLAGBIT(CF,GetHexValue(hex,hex)); } else if (strstr(hex,"DF")==hex) { hex+=2; SETFLAGBIT(DF,GetHexValue(hex,hex)); } else if (strstr(hex,"IF")==hex) { hex+=2; SETFLAGBIT(IF,GetHexValue(hex,hex)); } else - if (strstr(hex,"OF")==hex) { hex+=3; SETFLAGBIT(OF,GetHexValue(hex,hex)); } else - if (strstr(hex,"ZF")==hex) { hex+=3; SETFLAGBIT(ZF,GetHexValue(hex,hex)); } else - if (strstr(hex,"PF")==hex) { hex+=3; SETFLAGBIT(PF,GetHexValue(hex,hex)); } else - if (strstr(hex,"SF")==hex) { hex+=3; SETFLAGBIT(SF,GetHexValue(hex,hex)); } else + if (strstr(hex,"OF")==hex) { hex+=2; SETFLAGBIT(OF,GetHexValue(hex,hex)); } else + if (strstr(hex,"ZF")==hex) { hex+=2; SETFLAGBIT(ZF,GetHexValue(hex,hex)); } else + if (strstr(hex,"PF")==hex) { hex+=2; SETFLAGBIT(PF,GetHexValue(hex,hex)); } else + if (strstr(hex,"SF")==hex) { hex+=2; SETFLAGBIT(SF,GetHexValue(hex,hex)); } else { return false; }; return true; }; -bool ParseCommand(char* str) -{ +bool ParseCommand(char* str) { char* found = str; for(char* idx = found;*idx != 0; idx++) *idx = toupper(*idx); found = trim(found); + string s_found(found); + istringstream stream(s_found); + string command; + stream >> command; + string::size_type next = s_found.find_first_not_of(' ',command.size()); + if(next == string::npos) next = command.size(); + s_found.erase(0,next); + found = const_cast(s_found.c_str()); - found = strstr(str,"MEMDUMP "); - if (found) { // Insert variable - found+=8; + if (command == "MEMDUMP") { // Dump memory to file Bit16u seg = (Bit16u)GetHexValue(found,found); found++; Bit32u ofs = GetHexValue(found,found); found++; Bit32u num = GetHexValue(found,found); found++; SaveMemory(seg,ofs,num); return true; }; - found = strstr(str,"MEMDUMPBIN "); - if (found) { // Insert variable - found+=11; + + if (command == "MEMDUMPBIN") { // Dump memory to file bineary Bit16u seg = (Bit16u)GetHexValue(found,found); found++; Bit32u ofs = GetHexValue(found,found); found++; Bit32u num = GetHexValue(found,found); found++; @@ -946,60 +975,52 @@ bool ParseCommand(char* str) return true; }; - found = strstr(str,"IV "); - if (found) { // Insert variable - found+=3; + if (command == "IV") { // Insert variable Bit16u seg = (Bit16u)GetHexValue(found,found); found++; Bit32u ofs = (Bit16u)GetHexValue(found,found); found++; char name[16]; for (int i=0; i<16; i++) { - if ((found[i]!=' ') && (found[i]!=0)) name[i] = found[i]; + if (found[i] && (found[i]!=' ')) name[i] = found[i]; else { name[i] = 0; break; }; }; name[15] = 0; - + + if(!name[0]) return false; DEBUG_ShowMsg("DEBUG: Created debug var %s at %04X:%04X\n",name,seg,ofs); CDebugVar::InsertVariable(name,GetAddress(seg,ofs)); return true; - } - - found = strstr(str,"SV "); - if (found) { // Save variables - found+=3; - char name[13]; - for (int i=0; i<12; i++) { - if ((found[i]!=' ') && (found[i]!=0)) name[i] = found[i]; - else { name[i] = 0; break; }; - }; - name[12] = 0; - if (CDebugVar::SaveVars(name)) DEBUG_ShowMsg("DEBUG: Variable list save (%s) : ok.\n",name); - else DEBUG_ShowMsg("DEBUG: Variable list save (%s) : failure\n",name); - return true; - } + }; - found = strstr(str,"LV "); - if (found) { // load variables - found+=3; + if (command == "SV") { // Save variables char name[13]; for (int i=0; i<12; i++) { - if ((found[i]!=' ') && (found[i]!=0)) name[i] = found[i]; + if (found[i] && (found[i]!=' ')) name[i] = found[i]; else { name[i] = 0; break; }; }; - name[12] = 0; - if (CDebugVar::LoadVars(name)) DEBUG_ShowMsg("DEBUG: Variable list load (%s) : ok.\n",name); - else DEBUG_ShowMsg("DEBUG: Variable list load (%s) : failure\n",name); + name[12] = 0; + if(!name[0]) return false; + DEBUG_ShowMsg("DEBUG: Variable list save (%s) : %s.\n",name,(CDebugVar::SaveVars(name)?"ok":"failure")); return true; - } - found = strstr(str,"SR "); - if (found) { // Set register value - found+=2; - if (ChangeRegister(found)) DEBUG_ShowMsg("DEBUG: Set Register success.\n"); - else DEBUG_ShowMsg("DEBUG: Set Register failure.\n"); + }; + + if (command == "LV") { // load variables + char name[13]; + for (int i=0; i<12; i++) { + if (found[i] && (found[i]!=' ')) name[i] = found[i]; + else { name[i] = 0; break; }; + }; + name[12] = 0; + if(!name[0]) return false; + DEBUG_ShowMsg("DEBUG: Variable list load (%s) : %s.\n",name,(CDebugVar::SaveVars(name)?"ok":"failure")); return true; - } - found = strstr(str,"SM "); - if (found) { // Set memory with following values - found+=3; + }; + + if (command == "SR") { // Set register value + DEBUG_ShowMsg("DEBUG: Set Register success.\n",(ChangeRegister(found)?"success":"failure")); + return true; + }; + + if (command == "SM") { // Set memory with following values Bit16u seg = (Bit16u)GetHexValue(found,found); found++; Bit32u ofs = GetHexValue(found,found); found++; Bit16u count = 0; @@ -1013,53 +1034,48 @@ bool ParseCommand(char* str) }; DEBUG_ShowMsg("DEBUG: Memory changed.\n"); return true; - } + }; - found = strstr(str,"BP "); - if (found) { // Add new breakpoint - found+=3; + if (command == "BP") { // Add new breakpoint Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":" Bit32u ofs = GetHexValue(found,found); CBreakpoint::AddBreakpoint(seg,ofs,false); DEBUG_ShowMsg("DEBUG: Set breakpoint at %04X:%04X\n",seg,ofs); return true; - } + }; + #if C_HEAVY_DEBUG - found = strstr(str,"BPM "); - if (found) { // Add new breakpoint - found+=3; + + if (command == "BPM") { // Add new breakpoint Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":" Bit32u ofs = GetHexValue(found,found); CBreakpoint::AddMemBreakpoint(seg,ofs); DEBUG_ShowMsg("DEBUG: Set memory breakpoint at %04X:%04X\n",seg,ofs); return true; - } - found = strstr(str,"BPPM "); - if (found) { // Add new breakpoint - found+=4; + }; + + if (command == "BPPM") { // Add new breakpoint Bit16u seg = (Bit16u)GetHexValue(found,found);found++; // skip ":" Bit32u ofs = GetHexValue(found,found); CBreakpoint* bp = CBreakpoint::AddMemBreakpoint(seg,ofs); - if (bp) - { + if (bp) { bp->SetType(BKPNT_MEMORY_PROT); DEBUG_ShowMsg("DEBUG: Set prot-mode memory breakpoint at %04X:%08X\n",seg,ofs); } return true; - } - found = strstr(str,"BPLM "); - if (found) { // Add new breakpoint - found+=4; - Bitu ofs = GetHexValue(found,found); + }; + + if (command == "BPLM") { // Add new breakpoint + Bit32u ofs = GetHexValue(found,found); CBreakpoint* bp = CBreakpoint::AddMemBreakpoint(0,ofs); if (bp) bp->SetType(BKPNT_MEMORY_LINEAR); DEBUG_ShowMsg("DEBUG: Set linear memory breakpoint at %08X\n",ofs); return true; - } + }; + #endif - found = strstr(str,"BPINT"); - if (found) { // Add Interrupt Breakpoint - found+=5; + + if (command == "BPINT") { // Add Interrupt Breakpoint Bit8u intNr = (Bit8u)GetHexValue(found,found); bool all = !(*found);found++; Bit8u valAH = (Bit8u)GetHexValue(found,found); @@ -1071,18 +1087,16 @@ bool ParseCommand(char* str) DEBUG_ShowMsg("DEBUG: Set interrupt breakpoint at INT %02X AH=%02X\n",intNr,valAH); } return true; - } - found = strstr(str,"BPLIST"); - if (found) { + }; + + if (command == "BPLIST") { DEBUG_ShowMsg("Breakpoint list:\n"); DEBUG_ShowMsg("-------------------------------------------------------------------------\n"); CBreakpoint::ShowList(); return true; }; - found = strstr(str,"BPDEL"); - if (found) { // Delete Breakpoints - found+=5; + if (command == "BPDEL") { // Delete Breakpoints Bit8u bpNr = (Bit8u)GetHexValue(found,found); if ((bpNr==0x00) && (*found=='*')) { // Delete all CBreakpoint::DeleteAll(); @@ -1092,202 +1106,150 @@ bool ParseCommand(char* str) CBreakpoint::DeleteByIndex(bpNr); } return true; - } - found = strstr(str,"C "); - if (found==(char*)str) { // Set code overview - found++; + }; + + if (command == "C") { // Set code overview Bit16u codeSeg = (Bit16u)GetHexValue(found,found); found++; Bit32u codeOfs = GetHexValue(found,found); DEBUG_ShowMsg("DEBUG: Set code overview to %04X:%04X\n",codeSeg,codeOfs); codeViewData.useCS = codeSeg; codeViewData.useEIP = codeOfs; return true; - } - found = strstr(str,"D "); - if (found==(char*)str) { // Set data overview - found++; + }; + + if (command == "D") { // Set data overview dataSeg = (Bit16u)GetHexValue(found,found); found++; dataOfs = GetHexValue(found,found); DEBUG_ShowMsg("DEBUG: Set data overview to %04X:%04X\n",dataSeg,dataOfs); return true; - } + }; + #if C_HEAVY_DEBUG - found = strstr(str,"LOG "); - if (found) { // Create Cpu log file - found+=4; - DEBUG_ShowMsg("DEBUG: Starting log\n"); - cpuLogFile.open("LOGCPU.TXT"); - if (!cpuLogFile.is_open()) { - DEBUG_ShowMsg("DEBUG: Logfile couldn't be created.\n"); - return false; - } - cpuLogFile << hex << noshowbase << setfill('0') << uppercase; - cpuLog = true; + + if (command == "LOG") { // Create Cpu normal log file cpuLogType = 1; - cpuLogCounter = GetHexValue(found,found); - - debugging=false; - CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true); - ignoreAddressOnce = SegPhys(cs)+reg_eip; - DOSBOX_SetNormalLoop(); - return true; + command = "logcode"; } - found = strstr(str,"LOGS "); - if (found) { // Create Cpu log file - found+=4; - DEBUG_ShowMsg("DEBUG: Starting log\n"); - cpuLogFile.open("LOGCPU.TXT"); - if (!cpuLogFile.is_open()) { - DEBUG_ShowMsg("DEBUG: Logfile couldn't be created.\n"); - return false; - } - cpuLogFile << hex << noshowbase << setfill('0') << uppercase; - cpuLog = true; + if (command == "LOGS") { // Create Cpu short log file cpuLogType = 0; - cpuLogCounter = GetHexValue(found,found); - - debugging=false; - CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true); - ignoreAddressOnce = SegPhys(cs)+reg_eip; - DOSBOX_SetNormalLoop(); - return true; + command = "logcode"; } - found = strstr(str,"LOGL "); - if (found) { // Create Cpu log file - found+=4; + if (command == "LOGL") { // Create Cpu long log file + cpuLogType = 2; + command = "logcode"; + } + + if (command == "logcode") { //Shared code between all logs DEBUG_ShowMsg("DEBUG: Starting log\n"); cpuLogFile.open("LOGCPU.TXT"); if (!cpuLogFile.is_open()) { DEBUG_ShowMsg("DEBUG: Logfile couldn't be created.\n"); return false; } + //Initialize log object cpuLogFile << hex << noshowbase << setfill('0') << uppercase; cpuLog = true; - cpuLogType = 2; cpuLogCounter = GetHexValue(found,found); - debugging=false; + debugging = false; CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true); ignoreAddressOnce = SegPhys(cs)+reg_eip; DOSBOX_SetNormalLoop(); return true; - } + }; + #endif - found = strstr(str,"INTT "); - if (found) { // Create Cpu log file - found+=4; + + if (command == "INTT") { //trace int. Bit8u intNr = (Bit8u)GetHexValue(found,found); DEBUG_ShowMsg("DEBUG: Tracing INT %02X\n",intNr); CPU_HW_Interrupt(intNr); SetCodeWinStart(); return true; - } - found = strstr(str,"INT "); - if (found) { // Create Cpu log file - found+=4; + }; + + if (command == "INT") { // start int. Bit8u intNr = (Bit8u)GetHexValue(found,found); DEBUG_ShowMsg("DEBUG: Starting INT %02X\n",intNr); - CBreakpoint::AddBreakpoint (SegValue(cs),reg_eip, true); + CBreakpoint::AddBreakpoint(SegValue(cs),reg_eip, true); CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip-1,true); - debugging=false; + debugging = false; DrawCode(); DOSBOX_SetNormalLoop(); CPU_HW_Interrupt(intNr); return true; - } - found = strstr(str,"SELINFO "); - if (found) { - found += 8; - while (found[0]==' ') found++; + }; + + if (command == "SELINFO") { + while (found[0] == ' ') found++; char out1[200],out2[200]; GetDescriptorInfo(found,out1,out2); - DEBUG_ShowMsg("SelectorInfo %s:\n",found); - DEBUG_ShowMsg("%s\n",out1); - DEBUG_ShowMsg("%s\n",out2); + DEBUG_ShowMsg("SelectorInfo %s:\n%s\n%s\n",found,out1,out2); }; - found = strstr(str,"GDT"); - if (found) { - LogGDT(); - } + if (command == "GDT") {LogGDT(); return true;} + + if (command == "LDT") {LogLDT(); return true;} + + if (command == "IDT") {LogIDT(); return true;} + + if (command == "PAGING") {LogPages(found); return true;} - found = strstr(str,"LDT"); - if (found) { - LogLDT(); - } + if (command == "CPU") {LogCPUInfo(); return true;} - found = strstr(str,"IDT"); - if (found) { - LogIDT(); - } - - found = strstr(str,"PAGING"); - if (found) { - found += 6; - while (found[0]==' ') found++; - LogPages(found); - } - - found = strstr(str,"CPU"); - if (found) { - LogCPUInfo(); - } - - found = strstr(str,"INTVEC "); - if (found) - { - found += 7; - while (found[0]==' ') found++; - if (found[0] != 0) + if (command == "INTVEC") { + if (found[0] != 0) { OutputVecTable(found); - } + return true; + } + }; - found = strstr(str,"INTHAND "); - if (found) - { - found += 8; - while (found[0]==' ') found++; - if (found[0] != 0) - { + if (command == "INTHAND") { + if (found[0] != 0) { Bit8u intNr = (Bit8u)GetHexValue(found,found); DEBUG_ShowMsg("DEBUG: Set code overview to interrupt handler %X\n",intNr); codeViewData.useCS = mem_readw(intNr*4+2); codeViewData.useEIP = mem_readw(intNr*4); return true; } - } + }; + + if(command == "EXTEND") { //Toggle additional data. + showExtend = !showExtend; + return true; + }; + + if(command == "TIMERIRQ") { //Start a timer irq + DEBUG_RaiseTimerIrq(); + DEBUG_ShowMsg("Debug: Timer Int started.\n"); + return true; + }; + #if C_HEAVY_DEBUG - found = strstr(str,"HEAVYLOG"); - if (found) { // Create Cpu log file + if (command == "HEAVYLOG") { // Create Cpu log file logHeavy = !logHeavy; - if (logHeavy) DEBUG_ShowMsg("DEBUG: Heavy cpu logging on.\n"); - else DEBUG_ShowMsg("DEBUG: Heavy cpu logging off.\n"); + DEBUG_ShowMsg("DEBUG: Heavy cpu logging %s.\n",logHeavy?"on":"off"); return true; - } - found = strstr(str,"ZEROPROTECT"); - if (found) { //toggle zero protection + }; + + if (command == "ZEROPROTECT") { //toggle zero protection zeroProtect = !zeroProtect; - if (zeroProtect) DEBUG_ShowMsg("DEBUG: Zero code execution protection on.\n"); - else DEBUG_ShowMsg("DEBUG: Zero code execution protection off.\n"); + DEBUG_ShowMsg("DEBUG: Zero code execution protection %s.\n",zeroProtect?"on":"off"); return true; - } + }; + #endif - if ((*str=='H') || (*str=='?')) { - DEBUG_ShowMsg("Debugger keys:\n"); + if (command == "HELP" || command == "?") { + DEBUG_ShowMsg("Debugger commands (enter all values in hex or as register):\n"); DEBUG_ShowMsg("--------------------------------------------------------------------------\n"); DEBUG_ShowMsg("F5 - Run.\n"); DEBUG_ShowMsg("F9 - Set/Remove breakpoint.\n"); DEBUG_ShowMsg("F10/F11 - Step over / trace into instruction.\n"); DEBUG_ShowMsg("Up/Down - Move code view cursor.\n"); - DEBUG_ShowMsg("Return - Enable command line input.\n"); - DEBUG_ShowMsg("D/E/S/X/B - Set data view to DS:SI/ES:DI/SS:SP/DS:DX/ES:BX.\n"); - DEBUG_ShowMsg("R/F - Scroll data view.\n"); - DEBUG_ShowMsg("V - Toggle additional info.\n"); - DEBUG_ShowMsg("Debugger commands (enter all values in hex or as register):\n"); - DEBUG_ShowMsg("--------------------------------------------------------------------------\n"); + DEBUG_ShowMsg("Page Up/Down - Scroll data view.\n"); DEBUG_ShowMsg("BP [segment]:[offset] - Set breakpoint.\n"); DEBUG_ShowMsg("BPINT [intNr] * - Set interrupt breakpoint.\n"); DEBUG_ShowMsg("BPINT [intNr] [ah] - Set interrupt breakpoint with ah.\n"); @@ -1325,11 +1287,13 @@ bool ParseCommand(char* str) DEBUG_ShowMsg("LDT - Lists descriptors of the LDT.\n"); DEBUG_ShowMsg("IDT - Lists descriptors of the IDT.\n"); DEBUG_ShowMsg("PAGING [page] - Display content of page table.\n"); + DEBUG_ShowMsg("EXTEND - Toggle additional info.\n"); + DEBUG_ShowMsg("TIMERIRQ - Run the system timer.\n"); - DEBUG_ShowMsg("H - Help\n"); + DEBUG_ShowMsg("HELP - Help\n"); - return TRUE; - } + return true; + }; return false; }; @@ -1507,143 +1471,92 @@ char* AnalyzeInstruction(char* inst, bool saveSelector) Bit32u DEBUG_CheckKeys(void) { - - if (codeViewData.inputMode) { - int key = getch(); - if (key>0) { - switch (key) { - case 0x0A: codeViewData.inputMode = FALSE; - ParseCommand(codeViewData.inputStr); - break; - case 0x107: //backspace (linux) - case 0x7f: //backspace in some terminal emulators (linux) - case 0x08: // delete - if (strlen(codeViewData.inputStr)>0) codeViewData.inputStr[strlen(codeViewData.inputStr)-1] = 0; - break; - default : if ((key>=32) && (key<=128) && (strlen(codeViewData.inputStr)<253)) { - Bit32u len = strlen(codeViewData.inputStr); - codeViewData.inputStr[len] = char(key); - codeViewData.inputStr[len+1] = 0; - } - break; - } - DEBUG_DrawScreen(); - } - return 0; - }; - - int key=getch(); Bits ret=0; + int key=getch(); if (key>0) { switch (toupper(key)) { - case '1': - CPU_Cycles = 100; - ret=(*cpudecoder)(); - break; - case '2': - CPU_Cycles = 500; - ret=(*cpudecoder)(); - break; - case '3': - CPU_Cycles = 1000; - ret=(*cpudecoder)(); - break; - case '4': - CPU_Cycles = 5000; - ret=(*cpudecoder)(); - break; - case '5': - CPU_Cycles = 10000; - ret=(*cpudecoder)(); - break; - case 'q': - CPU_Cycles = 5; - ret=(*cpudecoder)(); - break; - case 'D': dataSeg = SegValue(ds); - if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_esi; - else dataOfs = reg_si; - break; - case 'E': dataSeg = SegValue(es); - if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_edi; - else dataOfs = reg_di; - break; - case 'X': dataSeg = SegValue(ds); - if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_edx; - else dataOfs = reg_dx; - break; - case 'B': dataSeg = SegValue(es); - if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_ebx; - else dataOfs = reg_bx; - break; - case 'S': dataSeg = SegValue(ss); - if (cpu.pmode && !(reg_flags & FLAG_VM)) dataOfs = reg_esp; - else dataOfs = reg_sp; - break; + case KEY_PPAGE : dataOfs -= 16; break; + case KEY_NPAGE : dataOfs += 16; break; - case 'R' : dataOfs -= 16; break; - case 'F' : dataOfs += 16; break; - case 'H' : strcpy(codeViewData.inputStr,"H "); - ParseCommand(codeViewData.inputStr); - break; - case 'T' : DEBUG_RaiseTimerIrq(); - DEBUG_ShowMsg("Debug: Timer Int started.\n"); - break; - case 'V' : showExtend = !showExtend; - break; - - case 0x0A : // Return : input - codeViewData.inputMode = true; - codeViewData.inputStr[0] = 0; - break; case KEY_DOWN: // down - if (codeViewData.cursorPos<9) codeViewData.cursorPos++; - else codeViewData.useEIP += codeViewData.firstInstSize; - break; + if (codeViewData.cursorPos<9) codeViewData.cursorPos++; + else codeViewData.useEIP += codeViewData.firstInstSize; + break; case KEY_UP: // up - if (codeViewData.cursorPos>0) codeViewData.cursorPos--; - else codeViewData.useEIP -= 1; - break; - case KEY_HOME: // Home: scroll log page up - DEBUG_RefreshPage(-1); - break; - case KEY_END: // End: scroll log page down - DEBUG_RefreshPage(1); - break; - case KEY_F(5): // Run Programm - debugging=false; - CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true); - ignoreAddressOnce = SegPhys(cs)+reg_eip; - DOSBOX_SetNormalLoop(); - break; - case KEY_F(9): // Set/Remove TBreakpoint - { PhysPt ptr = GetAddress(codeViewData.cursorSeg,codeViewData.cursorOfs); - if (CBreakpoint::IsBreakpoint(ptr)) CBreakpoint::DeleteBreakpoint(ptr); - else CBreakpoint::AddBreakpoint(codeViewData.cursorSeg, codeViewData.cursorOfs, false); + if (codeViewData.cursorPos>0) codeViewData.cursorPos--; + else { + Bitu bytes = 0; + char dline[200]; + Bitu size = 0; + Bit32u newEIP = codeViewData.useEIP - 1; + if(codeViewData.useEIP) { + for (; bytes < 10; bytes++) { + PhysPt start = GetAddress(codeViewData.useCS,newEIP); + size = DasmI386(dline, start, newEIP, cpu.code.big); + if(codeViewData.useEIP == newEIP+size) break; + newEIP--; } + if (bytes>=10) newEIP = codeViewData.useEIP - 1; + } + codeViewData.useEIP = newEIP; + } + break; + case KEY_HOME: // Home: scroll log page up + DEBUG_RefreshPage(-1); + break; + case KEY_END: // End: scroll log page down + DEBUG_RefreshPage(1); + break; + case KEY_F(5): // Run Programm + debugging=false; + CBreakpoint::ActivateBreakpoints(SegPhys(cs)+reg_eip,true); + ignoreAddressOnce = SegPhys(cs)+reg_eip; + DOSBOX_SetNormalLoop(); + break; + case KEY_F(9): // Set/Remove TBreakpoint + { PhysPt ptr = GetAddress(codeViewData.cursorSeg,codeViewData.cursorOfs); + if (CBreakpoint::IsBreakpoint(ptr)) CBreakpoint::DeleteBreakpoint(ptr); + else CBreakpoint::AddBreakpoint(codeViewData.cursorSeg, codeViewData.cursorOfs, false); + } break; case KEY_F(10): // Step over inst - if (StepOver()) return 0; - else { - exitLoop = false; - skipFirstInstruction = true; // for heavy debugger - CPU_Cycles = 1; - Bitu ret=(*cpudecoder)(); - SetCodeWinStart(); - CBreakpoint::ignoreOnce = 0; - } - break; + if (StepOver()) return 0; + else { + exitLoop = false; + skipFirstInstruction = true; // for heavy debugger + CPU_Cycles = 1; + ret=(*cpudecoder)(); + SetCodeWinStart(); + CBreakpoint::ignoreOnce = 0; + } + break; case KEY_F(11): // trace into - exitLoop = false; - skipFirstInstruction = true; // for heavy debugger - CPU_Cycles = 1; - ret = (*cpudecoder)(); - SetCodeWinStart(); - CBreakpoint::ignoreOnce = 0; - break; + exitLoop = false; + skipFirstInstruction = true; // for heavy debugger + CPU_Cycles = 1; + ret = (*cpudecoder)(); + SetCodeWinStart(); + CBreakpoint::ignoreOnce = 0; + break; + case 0x0A: //Parse typed Command + codeViewData.inputMode = true; + if(ParseCommand(codeViewData.inputStr)) codeViewData.inputStr[0] = 0; + break; + case 0x107: //backspace (linux) + case 0x7f: //backspace in some terminal emulators (linux) + case 0x08: // delete + if (strlen(codeViewData.inputStr)>0) codeViewData.inputStr[strlen(codeViewData.inputStr)-1] = 0; + break; + default : if ((key>=32) && (key<=128) && (strlen(codeViewData.inputStr)<253)) { + Bit32u len = strlen(codeViewData.inputStr); + codeViewData.inputStr[len] = char(key); + codeViewData.inputStr[len+1] = 0; + } + break; + } - if (ret<0) return ret; - if (ret>0){ + if (ret<0) return ret; + if (ret>0) { ret=(*CallBack_Handlers[ret])(); if (ret) { exitLoop=true; @@ -1685,7 +1598,7 @@ void DEBUG_Enable(bool pressed) { DOSBOX_SetLoop(&DEBUG_Loop); if(!showhelp) { showhelp=true; - DEBUG_ShowMsg("***| PRESS \"H\" TO SHOW ALL COMMANDS. PRESS \"RETURN\" TO ENTER COMMANDMODE. |***\n"); + DEBUG_ShowMsg("***| TYPE HELP (+ENTER) TO GET AN OVERVIEW OF ALL COMMANDS |***\n"); } KEYBOARD_ClrBuffer(); } diff --git a/src/debug/debug_gui.cpp b/src/debug/debug_gui.cpp index 0b6e8f11..44473df7 100644 --- a/src/debug/debug_gui.cpp +++ b/src/debug/debug_gui.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: debug_gui.cpp,v 1.29 2006-04-11 19:02:33 qbix79 Exp $ */ +/* $Id: debug_gui.cpp,v 1.30 2006-06-16 14:51:31 qbix79 Exp $ */ #include "dosbox.h" @@ -144,13 +144,13 @@ static void DrawBars(void) { /* Show the Register bar */ mvaddstr(dbg.win_reg->_begy-1,0, "---(Register Overview )---"); /* Show the Data Overview bar perhaps with more special stuff in the end */ - mvaddstr(dbg.win_data->_begy-1,0,"---(Data Overview Scroll: r/f )---"); + mvaddstr(dbg.win_data->_begy-1,0,"---(Data Overview Scroll: page up/down)---"); /* Show the Code Overview perhaps with special stuff in bar too */ - mvaddstr(dbg.win_code->_begy-1,0,"---(Code Overview Scroll: up/down )---"); + mvaddstr(dbg.win_code->_begy-1,0,"---(Code Overview Scroll: up/down )---"); /* Show the Variable Overview bar */ mvaddstr(dbg.win_var->_begy-1,0, "---(Variable Overview )---"); /* Show the Output OverView */ - mvaddstr(dbg.win_out->_begy-1,0, "---(OutPut/Input Scroll: home/end )---"); + mvaddstr(dbg.win_out->_begy-1,0, "---(OutPut/Input Scroll: home/end )---"); attrset(0); } @@ -199,7 +199,7 @@ static void LOG_Init(Section * sec) { }else{ debuglog=0; } - sect->AddDestroyFunction(LOG_Destroy); + sect->AddDestroyFunction(&LOG_Destroy); char buf[1024]; for (Bitu i=1;i