Author Topic: How to exclude the other plugins when debugging  (Read 4698 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
How to exclude the other plugins when debugging
« on: October 28, 2022, 01:18:38 am »
Hi, if you would like to debug a single plugin, say you want to debug the clangd_client plugin, I think only two plugins are necessary, one is the clangd_client itself, the other is the compiler plugin, all the other plugins are not necessary. When debugging under Windows, you always need build the whole workspace, which includes all the plugins. While those plugins can be "Disabled" in the plugin manager, but please note that even they are disabled, the dlls are still loaded, which take a lot of time for the GDB to load those debug symbols.

So, to accelerate the debugging process, I would like to see a method to only keep one or two dlls. A simple method should that we can delete the un-needed dlls, but the bad thing is if you hit the build button, they will be built again.

My initial idea is that we can supply a command line option when the debugee(codeblocks.exe) starts, the command option specifies the plugins we needed.

Any ideas?

BTW: I think I have post a similar question several years ago, but I just can't find it when searching the forum.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: How to exclude the other plugins when debugging
« Reply #1 on: October 28, 2022, 01:41:44 am »
Any reason why just using an separate CB "profile" will not work?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to exclude the other plugins when debugging
« Reply #2 on: October 28, 2022, 02:00:13 am »
Any reason why just using an separate CB "profile" will not work?

Tim S.

Hi, Tim, we do use a "profile" named "debug" for debugging. (not the "default" profile)

But in the profile file, can we "disable" loading the plugins?

Please note that "disable the plugin" means the plugin is loaded, but not active. In this case, the dll includes its debug symbol are still loaded.
« Last Edit: October 28, 2022, 02:21:08 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to exclude the other plugins when debugging
« Reply #3 on: October 28, 2022, 05:04:03 am »
I think this is the function we are going to hack:

Code
int PluginManager::ScanForPlugins(const wxString& path)
{
    static const wxString PluginsMask = platform::windows                      ? _T("*.dll")
                                      : (platform::darwin || platform::macosx) ? _T("*.dylib")
                                      :                                          _T("*.so");
    int count = 0;
    if (!wxDirExists(path))
        return count;
    wxDir dir(path);

    if (!dir.IsOpened())
        return count;

    bool batch = Manager::IsBatchBuild();
    wxArrayString bbplugins;
    if (batch)
        bbplugins = cbReadBatchBuildPlugins();

    wxString filename;
    wxString failed;
    bool ok = dir.GetFirst(&filename, PluginsMask, wxDIR_FILES);
    while (ok)
    {
        if (batch)
        {
            // for batch builds, we will load only those plugins that the
            // user has set (default only compiler.dll)
            bool matched = false;
            for (size_t i = 0; i < bbplugins.GetCount(); ++i)
            {
                if (bbplugins[i] == filename)
                {
                    matched = true;
                    break;
                }
            }
            if (!matched)
            {
                ok = dir.GetNext(&filename);
                continue;
            }
        }

        // load manifest
        m_pCurrentlyLoadingManifestDoc = nullptr;
        if (ReadManifestFile(filename))
        {
            if (LoadPlugin(path + wxFILE_SEP_PATH + filename))
                ++count;
            else
                failed << _T('\n') << filename;
        }
        if (m_pCurrentlyLoadingManifestDoc)
        {
            delete m_pCurrentlyLoadingManifestDoc;
            m_pCurrentlyLoadingManifestDoc = nullptr;
        }
        ok = dir.GetNext(&filename);
    }
    Manager::Get()->GetLogManager()->Log(F(_("Loaded %d plugins"), count));
    if (!failed.IsEmpty())
    {
        InfoWindow::Display(_("Warning"),
                            _("One or more plugins were not loaded.\n"
                            "This usually happens when a plugin is built for\n"
                            "a different version of the Code::Blocks SDK.\n"
                            "Check the application log for more info.\n\n"
                            "List of failed plugins:\n") + failed,
                            15000, 3000);
    }
    return count;
}

I think if we can add another option, such as:

Code
    if (batch or debugging_plugin_mode)
        bbplugins = cbReadBatchBuildPlugins();

We can only load a minimal set of the plugins.
What do you think of this idea?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to exclude the other plugins when debugging
« Reply #4 on: October 28, 2022, 10:05:50 am »
Code
From cf00e61a5c44ff1ecdb1e1b4a58d840d5364c3a0 Mon Sep 17 00:00:00 2001
From: asmwarrior <a@b.com>
Date: Fri, 28 Oct 2022 16:02:25 +0800
Subject: When the personality is "debug-plugin", we only load limited plugins


diff --git a/src/sdk/pluginmanager.cpp b/src/sdk/pluginmanager.cpp
index 559df706..04d93aa9 100644
--- a/src/sdk/pluginmanager.cpp
+++ b/src/sdk/pluginmanager.cpp
@@ -971,6 +971,14 @@ int PluginManager::ScanForPlugins(const wxString& path)
         return count;
 
     bool batch = Manager::IsBatchBuild();
+
+    // when debugging a single plugin, we need to loaded very limited dlls
+    // because if we load a lot of dlls and their debug symbols will make GDB slow
+    // only enable this option if the personality name is "debug-plugin"
+    wxString personality(Manager::Get()->GetPersonalityManager()->GetPersonality());
+    if (personality == "debug-plugin")
+        batch = true;
+
     wxArrayString bbplugins;
     if (batch)
         bbplugins = cbReadBatchBuildPlugins();


This is the patch to enable this feature.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to exclude the other plugins when debugging
« Reply #5 on: November 05, 2022, 12:52:49 am »
I'm going to commit this hack patch to svn repo if other devs don't have objections.

Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: How to exclude the other plugins when debugging
« Reply #6 on: November 19, 2022, 03:21:46 am »
I committed this change in svn repo now, rev 13048.


EDIT

If you want to debug both compiler plugin and codecompletion plugin, you need to specify this section of the "debug-plugin.conf" like below:

Code
		<BATCH_BUILD_PLUGINS>
<astr>
<s>
<![CDATA[compiler.dll]]>
</s>
<s>
<![CDATA[codecompletion.dll]]>
</s>
</astr>
</BATCH_BUILD_PLUGINS>
« Last Edit: March 02, 2024, 09:46:23 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.