Author Topic: Speedup GDB debugging  (Read 10416 times)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Speedup GDB debugging
« on: October 07, 2021, 12:32:49 am »
If you are on windows you may know the problem:
Debugging with GDB is PAINFULLY slow...
I finally have found a 10 year old workaround: https://stackoverflow.com/questions/27380443/why-is-gdb-so-slow-in-windows
To use this in codeblocks:
1) Settings-> Environment-> Environment Variables->Add:
Key =
Code
_NO_DEBUG_HEAP
Value =
Code
1
2) Ok
3) Project->Properties->EnvVars option->Select environment....->defaukt

For me this is speeding up the gdb startup fo 200%

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5906
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Speedup GDB debugging
« Reply #1 on: October 08, 2021, 08:36:05 am »
I meet the same issue before. Especially if you code has many "new" and "delete" function calls, GDB will be quite slow.

Setting such environment variable will speed up the debugee a lot!
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 Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1549
Re: Speedup GDB debugging
« Reply #2 on: October 08, 2021, 08:39:09 am »
Step 3 generates an "EnVars Plugin Warning, The project contained a reference to an envvar set ('default') that could not be found".

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Speedup GDB debugging
« Reply #3 on: October 08, 2021, 11:32:43 am »
With my latest local build I do not get the warnings when setting up step 3, but if I go back into Project->Properties I get the warning. The EnvVars options tab shows the correct data as does the Settings-> Environment-> Environment Variables dialog data.

The warning is also shown when I go back into the Settings-> Environment-> Environment Variables and exit (it shows 3 times...).

The warning dialog info is:
[Window Title]
EnvVars Plugin Warning

[Content]
Warning: The project contained a reference to an envvar set
('default') that could not be found.

[OK]


Hope this extra info is of some help.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1549
Re: Speedup GDB debugging
« Reply #4 on: October 08, 2021, 02:58:39 pm »
I think the EnvVars plugin is buggy, whatever set you select in Project->Properties->EnvVars options is never found.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Speedup GDB debugging
« Reply #5 on: October 08, 2021, 11:55:09 pm »
This patch fixes it for me...
No idea why the old code was there, it made no sense if a default set was set...
Code
Index: src/plugins/contrib/envvars/envvars_common.cpp
===================================================================
--- src/plugins/contrib/envvars/envvars_common.cpp (revision 12529)
+++ src/plugins/contrib/envvars/envvars_common.cpp (working copy)
@@ -229,8 +229,8 @@
     set_path.Empty();
 
   ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("envvars"));
-  if (!cfg || set_path.IsEmpty())
-    return set_path;
+  if (!cfg)
+    return wxString();
 
   if (!check_exists)
     return _T("/sets/")+set_name;

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Speedup GDB debugging
« Reply #6 on: October 09, 2021, 12:53:15 am »
I did a local build with the patch and the warnings no longer occur.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1549
Re: Speedup GDB debugging
« Reply #7 on: October 12, 2021, 07:17:55 pm »
@bluehazzard, do you plan to commit the patch or should someone post a ticket so this is not lost?. Currently the envvars plugin does not work at all with projects, so IMHO it is a major bug.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Speedup GDB debugging
« Reply #8 on: October 12, 2021, 09:40:36 pm »
@bluehazzard, do you plan to commit the patch or should someone post a ticket so this is not lost?. Currently the envvars plugin does not work at all with projects, so IMHO it is a major bug.

Have you found other problems too?

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1549
Re: Speedup GDB debugging
« Reply #9 on: October 13, 2021, 12:01:37 pm »
While the patch fixes the warning about set not found, the plugin does not set the specified variables. I have written a test console program that prints the value of an environment variable called TEST_VAR, and created two sets with different values for the variable; whatever set you select in Project Options, the printed value is the same.

Code
#include <windows.h>
#include <stdio.h>

int main()
  {
  char Buffer[256];

  const DWORD res = GetEnvironmentVariable("TEST_VAR", Buffer, sizeof(Buffer));
  if (!res)
    {
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), Buffer, sizeof(Buffer), NULL);
    printf("Error %s", Buffer);
    }
  else
    printf("TEST_VAR = %s", Buffer);

  return 0;
  }

The expected behaviour is: the plugin sets the variable to the value indicated in the specified set

EDIT: if you close the project and reopen it, you get again the "set not found" warnings. I will study this deeper and create a ticket.
« Last Edit: October 13, 2021, 12:06:49 pm by Miguel Gimenez »

Offline MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Speedup GDB debugging
« Reply #10 on: October 19, 2021, 07:14:56 pm »
Slow debugging in codeblock is this normal! The debugger code itself is very slow, all windows: watch, dissasemble, register, etc use a complete update of their area, even if they only need to update one symbol. Moreover, the used wxwidget has fatal flaws, which, after a while, practically lead to the debugger freezing. That is, at first the debugger works quickly, but then, it starts to slow down significantly due to errors in wxwidget.

Wxwidget has different functions that work in the same way or with minimal differences, replacing resource-intensive functions with less resource-intensive ones will lead to less memory leaks and stabilize the situation.
« Last Edit: October 19, 2021, 08:58:59 pm by MicroSourceCode »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1549
Re: Speedup GDB debugging
« Reply #11 on: October 20, 2021, 10:21:29 am »
I have just created ticket 1145 fixing the EnvVars plugin