Patch #2775 2009-06-20 13:13
ollydbg
Watches and breakpoints persistent- Download
- 2775-Watches_and_br.patch (7.5 KB)
- Category
- Plugin::FeatureAdd
- Status
- Open
- Close date
- Assigned to
- ollydbg
Index: debuggergdb.cpp
===================================================================
--- debuggergdb.cpp (revision 5679)
+++ debuggergdb.cpp (working copy)
@@ -13,6 +13,8 @@
#include <wx/dialog.h>
#include <wx/msgdlg.h>
#include <wx/tokenzr.h>
+#include "tinyxml/tinyxml.h"
+#include "tinyxml/tinywxuni.h"
#include <manager.h>
#include <configmanager.h>
@@ -532,6 +534,8 @@
Manager::Get()->RegisterEventSink(cbEVT_COMPILER_FINISHED, new cbEventFunctor<DebuggerGDB, CodeBlocksEvent>(this, &DebuggerGDB::OnCompilerFinished));
Manager::Get()->RegisterEventSink(cbEVT_BUILDTARGET_SELECTED, new cbEventFunctor<DebuggerGDB, CodeBlocksEvent>(this, &DebuggerGDB::OnBuildTargetSelected));
+
+ Manager::Get()->RegisterEventSink(cbEVT_PROJECT_OPEN, new cbEventFunctor<DebuggerGDB, CodeBlocksEvent>(this, &DebuggerGDB::OnProjectOpened));
}
void DebuggerGDB::OnRelease(bool appShutDown)
@@ -2757,7 +2761,154 @@
}
}
}
+void DebuggerGDB::OnProjectOpened(CodeBlocksEvent& event)
+{
+ // allow others to catch this
+ event.Skip();
+ LoadStateFromFile(event.GetProject());
+
+}
+bool DebuggerGDB::SaveStateToFile(cbProject* prj){
+ //There are two types of state we should save:
+ //1, breakpoints
+ //2, watches
+
+ //Create a file according to the m_pProject
+ wxString projectFilename = prj->GetFilename();
+ if (projectFilename.IsEmpty())
+ return false;
+ //saved file name&extention
+ wxFileName fname(projectFilename);
+ fname.SetExt(_T("bps"));
+
+ //XML file IO
+ const char* ROOT_TAG = "Debugger_layout_file";
+
+ TiXmlDocument doc;
+ doc.SetCondenseWhiteSpace(false);
+ doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
+ TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG)));
+ if (!rootnode)
+ return false;
+
+ //Save breakpoints, get breakpoints_list
+ TiXmlElement* breakpointsidx = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("BreakpointsList")));
+ BreakpointsList &breakPointsList = m_State.GetBreakpointsList();
+ for (int i = breakPointsList.GetCount() - 1; i >= 0; --i)
+ {
+ DebuggerBreakpoint* bp = breakPointsList[i];
+ //Only save the breakpoints belong to the current project
+ if (bp->userData == prj)
+ {
+ TiXmlElement* node = static_cast<TiXmlElement*>(breakpointsidx->InsertEndChild(TiXmlElement("Breakpoint")));
+ //Change the absolute location to relative location
+ wxFileName location(bp->filename);
+ location.MakeRelativeTo(prj->GetBasePath());
+ //Add file and line
+ node->SetAttribute("file", cbU2C(location.GetFullPath()));
+ node->SetAttribute("position", bp->line);
+ }
+ }
+
+ //Save Watches
+ TiXmlElement* watchesidx = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("WatchesList")));
+ size_t wc = (m_pTree->GetWatches()).GetCount();
+ if (wc>0)
+ {
+ // iterate over each watch and write them to the file buffer
+ for (size_t i = 0; i < wc; ++i)
+ {
+ Watch& w = (m_pTree->GetWatches())[i];
+ TiXmlElement* node = static_cast<TiXmlElement*>(watchesidx->InsertEndChild(TiXmlElement("Watch")));
+ node->SetAttribute("variable", cbU2C(w.keyword));
+ }
+
+ }
+
+ //Save XML to harddisk
+ return cbSaveTinyXMLDocument(&doc, fname.GetFullPath());
+
+}
+
+bool DebuggerGDB::LoadStateFromFile(cbProject* prj){
+
+
+ wxString projectFilename = prj->GetFilename();
+ if (projectFilename.IsEmpty())
+ return false;
+ wxFileName fname(projectFilename);
+ fname.SetExt(_T("bps"));
+
+ //Open XML file
+ TiXmlDocument doc;
+ if (!TinyXML::LoadDocument(fname.GetFullPath(), &doc))
+ return false;
+
+ TiXmlElement* root;
+ TiXmlElement* elem;
+ TiXmlElement* group;
+
+
+ root = doc.FirstChildElement("Debugger_layout_file");
+ if (!root)
+ {
+ return false;
+ }
+
+ //Load breakpoints
+ group = root->FirstChildElement("BreakpointsList");
+ elem = group->FirstChildElement("Breakpoint");
+
+ while (elem)
+ {
+ wxString location = cbC2U(elem->Attribute("file"));
+ ProjectFile* pf;
+ if (location.IsEmpty())
+ {
+ break;
+ }
+ else
+ pf = prj->GetFileByFilename(location);
+
+ wxString filenamePath = pf->file.GetFullPath();
+
+ int line = 0;
+ if (not elem->QueryIntAttribute("position", &line) == TIXML_SUCCESS)
+ break;
+
+ cbEditor* ed = Manager::Get()->GetEditorManager()->IsBuiltinOpen( filenamePath );
+ if (ed==NULL){
+ m_State.AddBreakpoint(filenamePath,line); //add breakpoints silentsly
+ }
+ else{
+ ed->AddBreakpoint(line);
+
+ }
+ elem = elem->NextSiblingElement();
+ }
+
+
+ //Load watche
download for full patch...
History
mortenmacfly 2009-06-30 10:50
Patch is incomplete.
GetBreakpointsList() method is missing in DebugeerState.
Please update.
ollydbg 2009-06-30 13:23
Sorry!
now, it was updated.
mortenmacfly 2012-12-14 19:42
handing back to you, ollydbg. What do do with it?
ollydbg 2012-12-15 04:13
Discussion goes to here:
http://forums.codeblocks.org/index.php/topic,10704.msg73335.html#msg73335
I think we should save all the bps, watches, bookmarks in one file.