User forums > Using Code::Blocks
Load and save watch file in 12.11
MortenMacFly:
--- Quote from: oBFusCATed on January 20, 2013, 02:00:37 pm ---What patch? Link?
--- End quote ---
Well I didn't find it - the one of ollydbg was to save BP's imho.
However, from SVN I extracted the old two methods that did the job. See here:
--- Code: ---void DebuggerTree::OnLoadWatchFile(wxCommandEvent& event)
{
WatchesArray fromFile = m_Watches; // copy current watches
// ToDo:
// - Currently each watch is imported as WatchType "Unspecified". This should
// be changed that the file contains another (optional) column with the type.
// - Change "Watch files" format to XML?
// - With the current implementation sometimes the debugger tree gets weird.
// - (Maybe) verify that watches are not already present?
wxString fname;
wxFileDialog dlg (Manager::Get()->GetAppWindow(),
_T("Load debugger watch file"),
_T(""),
_T(""),
_T("Watch files (*.watch)|*.watch|Any file (*)|*"),
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR | compatibility::wxHideReadonly);
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
wxTextFile tf(dlg.GetPath());
if (tf.Open())
{
// iterate over each line of file and send to debugger
wxString cmd = tf.GetFirstLine();
while(true)
{
if (!cmd.IsEmpty()) // Skip empty lines
{
// Manager::Get()->GetLogManager()->DebugLog(_T("Adding watch \"%s\" to debugger:"), keyword);
AddWatch(cmd, Undefined, false); // do not notify about new watch (we 'll do it when done)
}
if (tf.Eof()) break;
cmd = tf.GetNextLine();
}
tf.Close(); // release file handle
// notify about changed watches
NotifyForChangedWatches();
}
else
Manager::Get()->GetLogManager()->DebugLog(_T("Error opening debugger watch file: ") + fname);
}
void DebuggerTree::OnSaveWatchFile(wxCommandEvent& event)
{
// Verify that there ARE watches to save
size_t wc = m_Watches.GetCount();
if (wc<1)
{
cbMessageBox(_("There are no watches in the list to save."),
_("Save Watches"), wxICON_ERROR);
return;
}
wxString fname;
wxFileDialog dlg (Manager::Get()->GetAppWindow(),
_T("Save debugger watch file"),
_T(""),
_T(""),
_T("Watch files (*.watch)|*.watch|Any file (*)|*"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
wxTextFile tf(dlg.GetPath());
bool bSuccess = false;
// Create() will fail if the file exist -> must use Open() if file exist
if (tf.Exists())
{
bSuccess = tf.Open();
if (bSuccess) tf.Clear(); // remove old content (if any)
}
else
bSuccess = tf.Create();
if (bSuccess)
{
// iterate over each watch and write them to the file buffer
for (size_t i = 0; i < wc; ++i)
{
Watch& w = m_Watches[i];
tf.AddLine(w.keyword);
}
tf.Write(); // Write buffer to file
tf.Close(); // release file handle
}
else
Manager::Get()->GetLogManager()->DebugLog(_T("Error opening debugger watch file: ") + fname);
}
--- End code ---
oBFusCATed:
The code is basic. If you just want the keyword saved, it is pretty simple to add, but I doubt it will be enough.
MortenMacFly:
--- Quote from: oBFusCATed on January 20, 2013, 03:13:08 pm ---but I doubt it will be enough.
--- End quote ---
Why not? Its more convenient than having nothing like that. From a quick check of watchesdlg.h it should be even possible in a general way applicable to all debugger plugin unless they define a more sophisticated way... Its similar to hat happens if you change a symbol in that dialog. But you should know better. :-)
oBFusCATed:
Yes, it will be pretty easy. But if I do it I want to implement the full version, which saves everything. I don't want to support the old limited format.
Navigation
[0] Message Index
[*] Previous page
Go to full version