Author Topic: Load and save watch file in 12.11  (Read 16081 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Load and save watch file in 12.11
« Reply #15 on: January 20, 2013, 03:03:31 pm »
What patch? Link?
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);
}
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Load and save watch file in 12.11
« Reply #16 on: January 20, 2013, 03:13:08 pm »
The code is basic. If you just want the keyword saved, it is pretty simple to add, but I doubt it will be enough.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Load and save watch file in 12.11
« Reply #17 on: January 20, 2013, 03:19:28 pm »
but I doubt it will be enough.
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. :-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Load and save watch file in 12.11
« Reply #18 on: January 20, 2013, 03:25:04 pm »
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]