From 908b9ec03d9ceafd4b58fcf616ddda107d1099cb Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 26 Mar 2018 17:50:37 +0000 Subject: [PATCH] Convert variable stuff to vector (breakpoints one day as well) Keep track of whether the variable did actually change and skip expensive draw calls if nothing changed. Skip generation of temporary copy by switching to ++i instead of i++ for non basic data. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4088 --- src/debug/debug.cpp | 106 ++++++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 42 deletions(-) diff --git a/src/debug/debug.cpp b/src/debug/debug.cpp index f93b2985..99aa12ab 100644 --- a/src/debug/debug.cpp +++ b/src/debug/debug.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -244,26 +245,31 @@ bool GetDescriptorInfo(char* selname, char* out1, char* out2) class CDebugVar { public: - CDebugVar(char* _name, PhysPt _adr) { adr=_adr; safe_strncpy(name,_name,16); }; + CDebugVar(char* _name, PhysPt _adr) { adr=_adr; safe_strncpy(name,_name,16); hasvalue = false; value = 0; }; - char* GetName(void) { return name; }; - PhysPt GetAdr (void) { return adr; }; + char* GetName (void) { return name; }; + PhysPt GetAdr (void) { return adr; }; + void SetValue(bool has, Bit16u val) { hasvalue = has; value=val; }; + Bit16u GetValue(void) { return value; }; + bool HasValue(void) { return hasvalue; }; private: PhysPt adr; - char name[16]; + char name[16]; + bool hasvalue; + Bit16u value; public: - static void InsertVariable (char* name, PhysPt adr); - static CDebugVar* FindVar (PhysPt adr); - static void DeleteAll (); - static bool SaveVars (char* name); - static bool LoadVars (char* name); + static void InsertVariable(char* name, PhysPt adr); + static CDebugVar* FindVar (PhysPt adr); + static void DeleteAll (); + static bool SaveVars (char* name); + static bool LoadVars (char* name); - static std::list varList; + static std::vector varList; }; -std::list CDebugVar::varList; +std::vector CDebugVar::varList; /********************/ @@ -419,7 +425,7 @@ void CBreakpoint::ActivateBreakpoints() { // activate all breakpoints std::list::iterator i; - for (i = BPoints.begin(); i != BPoints.end(); i++) + for (i = BPoints.begin(); i != BPoints.end(); ++i) (*i)->Activate(true); } @@ -427,7 +433,7 @@ void CBreakpoint::DeactivateBreakpoints() { // deactivate all breakpoints std::list::iterator i; - for (i = BPoints.begin(); i != BPoints.end(); i++) + for (i = BPoints.begin(); i != BPoints.end(); ++i) (*i)->Activate(false); } @@ -435,7 +441,7 @@ void CBreakpoint::ActivateBreakpointsExceptAt(PhysPt adr) { // activate all breakpoints, except those at adr std::list::iterator i; - for (i = BPoints.begin(); i != BPoints.end(); i++) { + for (i = BPoints.begin(); i != BPoints.end(); ++i) { CBreakpoint* bp = (*i); // Do not activate breakpoints at adr if (bp->GetType() == BKPNT_PHYSICAL && bp->GetLocation() == adr) @@ -453,7 +459,7 @@ bool CBreakpoint::CheckBreakpoint(Bitu seg, Bitu off) // Search matching breakpoint std::list::iterator i; CBreakpoint* bp; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { bp = (*i); if ((bp->GetType()==BKPNT_PHYSICAL) && bp->IsActive() && (bp->GetSegment()==seg) && (bp->GetOffset()==off)) { // Found, @@ -513,7 +519,7 @@ bool CBreakpoint::CheckIntBreakpoint(PhysPt adr, Bit8u intNr, Bit16u ahValue, Bi // Search matching breakpoint std::list::iterator i; CBreakpoint* bp; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { bp = (*i); if ((bp->GetType()==BKPNT_INTERRUPT) && bp->IsActive() && (bp->GetIntNr()==intNr)) { if (((bp->GetValue()==BPINT_ALL) || (bp->GetValue()==ahValue)) && ((bp->GetOther()==BPINT_ALL) || (bp->GetOther()==alValue))) { @@ -536,7 +542,7 @@ void CBreakpoint::DeleteAll() { std::list::iterator i; CBreakpoint* bp; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { bp = (*i); bp->Activate(false); delete bp; @@ -551,7 +557,7 @@ bool CBreakpoint::DeleteByIndex(Bit16u index) int nr = 0; std::list::iterator i; CBreakpoint* bp; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { if (nr==index) { bp = (*i); (BPoints.erase)(i); @@ -566,13 +572,14 @@ bool CBreakpoint::DeleteByIndex(Bit16u index) CBreakpoint* CBreakpoint::FindPhysBreakpoint(Bit16u seg, Bit32u off, bool once) { + if (BPoints.empty()) return 0; #if !C_HEAVY_DEBUG PhysPt adr = GetAddress(seg, off); #endif // Search for matching breakpoint std::list::iterator i; CBreakpoint* bp; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { bp = (*i); #if C_HEAVY_DEBUG // Heavy debugging breakpoints are triggered by matching seg:off @@ -592,7 +599,7 @@ CBreakpoint* CBreakpoint::FindPhysBreakpoint(Bit16u seg, Bit32u off, bool once) CBreakpoint* CBreakpoint::FindOtherActiveBreakpoint(PhysPt adr, CBreakpoint* skip) { std::list::iterator i; - for (i = BPoints.begin(); i != BPoints.end(); i++) { + for (i = BPoints.begin(); i != BPoints.end(); ++i) { CBreakpoint* bp = (*i); if (bp != skip && bp->GetType() == BKPNT_PHYSICAL && bp->GetLocation() == adr && bp->IsActive()) return bp; @@ -624,7 +631,7 @@ void CBreakpoint::ShowList(void) // iterate list int nr = 0; std::list::iterator i; - for(i=BPoints.begin(); i != BPoints.end(); i++) { + for(i=BPoints.begin(); i != BPoints.end(); ++i) { CBreakpoint* bp = (*i); if (bp->GetType()==BKPNT_PHYSICAL) { DEBUG_ShowMsg("%02X. BP %04X:%04X\n",nr,bp->GetSegment(),bp->GetOffset()); @@ -2228,7 +2235,7 @@ void CDebugVar::InsertVariable(char* name, PhysPt adr) void CDebugVar::DeleteAll(void) { - std::list::iterator i; + std::vector::iterator i; CDebugVar* bp; for(i=varList.begin(); i != varList.end(); i++) { bp = static_cast(*i); @@ -2239,17 +2246,19 @@ void CDebugVar::DeleteAll(void) CDebugVar* CDebugVar::FindVar(PhysPt pt) { - std::list::iterator i; + if (varList.empty()) return 0; + + std::vector::size_type s = varList.size(); CDebugVar* bp; - for(i=varList.begin(); i != varList.end(); i++) { - bp = static_cast(*i); - if (bp->GetAdr()==pt) return bp; + for(std::vector::size_type i = 0; i != s; i++) { + bp = static_cast(varList[i]); + if (bp->GetAdr() == pt) return bp; }; return 0; }; bool CDebugVar::SaveVars(char* name) { - if (varList.size()>65535) return false; + if (varList.size() > 65535) return false; FILE* f = fopen(name,"wb+"); if (!f) return false; @@ -2258,7 +2267,7 @@ bool CDebugVar::SaveVars(char* name) { Bit16u num = (Bit16u)varList.size(); fwrite(&num,1,sizeof(num),f); - std::list::iterator i; + std::vector::iterator i; CDebugVar* bp; for(i=varList.begin(); i != varList.end(); i++) { bp = static_cast(*i); @@ -2368,33 +2377,46 @@ static void OutputVecTable(char* filename) { static void DrawVariables(void) { if (CDebugVar::varList.empty()) return; - std::list::iterator i; CDebugVar *dv; char buffer[DEBUG_VAR_BUF_LEN]; + std::vector::size_type s = CDebugVar::varList.size(); + bool windowchanges = false; - int idx = 0; - for(i=CDebugVar::varList.begin(); i != CDebugVar::varList.end(); i++, idx++) { + for(std::vector::size_type i = 0; i != s; i++) { - if (idx == 4*3) { + if (i == 4*3) { /* too many variables */ break; } - dv = static_cast(*i); - + dv = static_cast(CDebugVar::varList[i]); Bit16u value; - if (mem_readw_checked(dv->GetAdr(),&value)) + bool varchanges = false; + bool has_no_value = mem_readw_checked(dv->GetAdr(),&value); + if (has_no_value) { snprintf(buffer,DEBUG_VAR_BUF_LEN, "%s", "??????"); - else - snprintf(buffer,DEBUG_VAR_BUF_LEN, "0x%04x", value); + dv->SetValue(false,0); + varchanges = true; + } else { + if ( dv->HasValue() && dv->GetValue() == value) { + ; //It already had a value and it didn't change (most likely case) + } else { + dv->SetValue(true,value); + snprintf(buffer,DEBUG_VAR_BUF_LEN, "0x%04x", value); + varchanges = true; + } + } - int y = idx / 3; - int x = (idx % 3) * 26; - mvwprintw(dbg.win_var, y, x, dv->GetName()); - mvwprintw(dbg.win_var, y, (x + DEBUG_VAR_BUF_LEN + 1) , buffer); + if (varchanges) { + int y = i / 3; + int x = (i % 3) * 26; + mvwprintw(dbg.win_var, y, x, dv->GetName()); + mvwprintw(dbg.win_var, y, (x + DEBUG_VAR_BUF_LEN + 1) , buffer); + windowchanges = true; //Something has changed in this window + } } - wrefresh(dbg.win_var); + if (windowchanges) wrefresh(dbg.win_var); }; #undef DEBUG_VAR_BUF_LEN // HEAVY DEBUGGING STUFF