Developer forums (C::B DEVELOPMENT STRICTLY!) > Development

Some thoughts on doing breakpoints persistent

<< < (4/9) > >>

ollydbg:

--- Quote from: oBFusCATed on June 16, 2009, 06:06:08 pm ---We talk about data per project.
If a plugin needs some global configuration, the core can(must) still provide an interface for storing settings.

--- End quote ---

Yes, There are many *.ini files  for plugin global settings in APPDATA folder.

Edit:
Some global settings were using XML format, such as "default.conf"
Others use INI file format.


For example the BrowseTracker.ini

--- Code: ---BrowseMarksEnabled=1
BrowseMarksStyle=0
BrowseMarksToggleKey=0
LeftMouseDelay=400
BrowseMarksClearAllMethod=0

--- End code ---

I'm not sure the core supply method to access these ini files.


Edit2

I found in cbproject.cpp, there are some code do the "your_project_name.layout" file IO.


--- Code: ---bool cbProject::SaveLayout()
{
    if (m_Filename.IsEmpty())
        return false;

    wxFileName fname(m_Filename);
    fname.SetExt(_T("layout"));
    ProjectLayoutLoader loader(this);
    return loader.Save(fname.GetFullPath());
}

bool cbProject::LoadLayout()
{
   if (m_Filename.IsEmpty())
        return false;
    int openmode = Manager::Get()->GetConfigManager(_T("project_manager"))->ReadInt(_T("/open_files"), (long int)1);
    bool result = false;

    if(openmode==2)
    {
        // Do not open any files
        result = true;
    }
    else
    {
        Manager::Get()->GetEditorManager()->HideNotebook();
        if(openmode == 0) // Open all files
        {
            FilesList::Node* node = m_Files.GetFirst();
            while(node)
            {
                ProjectFile* f = node->GetData();
                Manager::Get()->GetEditorManager()->Open(f->file.GetFullPath(),0,f);
                node = node->GetNext();
            }
            result = true;
        }
        else if(openmode == 1)// Open last open files
        {
            wxFileName fname(m_Filename);
            fname.SetExt(_T("layout"));
            ProjectLayoutLoader loader(this);
            if (loader.Open(fname.GetFullPath()))
            {
                typedef std::map<int, ProjectFile*> open_files_map;
                open_files_map open_files;

                // Get all files to open and sort them according to their tab-position:
                FilesList::Node* node = m_Files.GetFirst();
                while(node)
                {
                    ProjectFile* f = node->GetData();
                    if (f->editorOpen)
                        open_files[f->editorTabPos] = f;
                    node = node->GetNext();
                }

                // Load all requested files
                std::vector<LoaderBase*> filesInMemory;
                for (open_files_map::iterator it = open_files.begin(); it != open_files.end(); ++it)
                {
                    filesInMemory.push_back(Manager::Get()->GetFileManager()->Load((*it).second->file.GetFullPath()));
                }
                // Open all requested files:
                size_t i = 0;
                for (open_files_map::iterator it = open_files.begin(); it != open_files.end(); ++it)
                {
                    cbEditor* ed = Manager::Get()->GetEditorManager()->Open(filesInMemory[i], (*it).second->file.GetFullPath(),0,(*it).second);
                    if (ed)
                        ed->SetProjectFile((*it).second);
                    ++i;
                }

                ProjectFile* f = loader.GetTopProjectFile();
                if (f)
                {
                    Manager::Get()->GetLogManager()->DebugLog(_T("Top Editor: ") + f->file.GetFullPath());
                    EditorBase* eb = Manager::Get()->GetEditorManager()->Open(f->file.GetFullPath());
                    if(eb)
                        eb->Activate();
                }
//                Manager::Get()->GetAppWindow()->Thaw();
            }
            result = true;
        }
        else
            result = false;
        Manager::Get()->GetEditorManager()->ShowNotebook();
    }
    return result;
}

--- End code ---

ollydbg:
Hi, I'm doing a simple test.
Here is a breakpoints layout file

--- Code: ---<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<BreakPoints_layout_file>
<BreakPoint file="C:/test/test_for_cb_forum/main.cpp" position="58" />
<BreakPoint file="C:/test/test_for_cb_forum/main.cpp" position="74" />
<BreakPoint file="C:/test/test_for_cb_forum/main.cpp" position="71" />
<BreakPoint file="C:/test/test_for_cb_forum/main.cpp" position="68" />
<BreakPoint file="C:/test/test_for_cb_forum/main.cpp" position="66" />
</BreakPoints_layout_file>

--- End code ---

My question is:
Is there any way I can change the absolute file name to relative file name?

Since my code is like this:


--- Code: ---// ----------------------------------------------------------------------------
bool BreakPointsLayout::Save(const wxString& filename, BreakpointsList &breakPointsList)
// ----------------------------------------------------------------------------
{
    const char* ROOT_TAG = "BreakPoints_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;


    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 == m_pProject)
        {
            Manager::Get()->GetLogManager()->DebugLog(F(_T("Got one")));
            TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("BreakPoint")));
            node->SetAttribute("file", cbU2C(bp->filename));
            node->SetAttribute("position", bp->line);
            //RemoveBreakpoint(i, true);
        }
    }


    return cbSaveTinyXMLDocument(&doc, filename);
}

--- End code ---

bp->filename is a full name.

But in debugger_def.h


--- Code: ---struct DebuggerBreakpoint
{
enum BreakpointType
{
bptCode = 0, ///< Normal file/line breakpoint
bptFunction, ///< Function signature breakpoint
bptData ///< Data breakpoint
};

    /** Constructor.
      * Sets default values for members.
      */
    DebuggerBreakpoint()
        : type(bptCode),
        line(0),
        index(-1),
        temporary(false),
        enabled(true),
        active(true),
        useIgnoreCount(false),
        ignoreCount(0),
        useCondition(false),
        wantsCondition(false),
        address(0),
        alreadySet(false),
        breakOnRead(false),
        breakOnWrite(true),
        userData(0)
    {}
    BreakpointType type; ///< The type of this breakpoint.
    wxString filename; ///< The filename for the breakpoint (kept as relative).

--- End code ---

It said the file name should  keep as relative. :(


Any Comments?

Thanks

Jenna:
You can use the MakeRelativeTo-function of wxFileName.

The code below is not tested !


--- Code: ---    wxFileName fname;

    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 == m_pProject)
        {
            Manager::Get()->GetLogManager()->DebugLog(F(_T("Got one")));
            TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("BreakPoint")));
            fname.Assign(bp->filename);
            if (fname.IsAbsolute())
            {
                fname.MakeRelativeTo(m_pProject->GetBasePath());
            }
            node->SetAttribute("file", cbU2C(fname.GetFullPath()));
            node->SetAttribute("position", bp->line);
            //RemoveBreakpoint(i, true);
        }
    }

--- End code ---

Instead of m_pProject->GetBasePath() it might also make sense to use m_pProject->GetCommonTopLevelPath().
Depends on what the debugger-plugin wants.

No time to look into it at themoment.

ollydbg:
Thanks for your help. Now, using the MakeRelativeTo() function ,I can save and load the saved breakpoints( simple position based breakpoints)

There is only one thing left. Since when I load the project, the BreakpointsList were successfully loaded from a projectname.bps file. But the UI has not notified. See the image below:


Breakpoints on Line 77 73 and 71 were loaded, but they were not shown on the editor. Even I add another breakpoint on line 59.

Then only way to show the breakpoints icon in the editor is "reopen the main.cpp file", see below:



So, I need a way to "notify the editor" after all the breakpoints were loaded.

Jenna:
Do you use AddBreakpoint from debugger-plugin or from editor ?

You can use the function from cbEditor, if the source-file is already opened and set notifyDebugger to true or use the function from debugger-plugin, if the file is not (yet) opened.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version