3

I recently noticed that running a program inside gdb in windows makes it a lot slower, and I want to know why.

Here's an example:

  • It is a pure C++03 project, compiled with mingw32 (gcc 4.8.1, 32 bits).
  • It is statically linked against libstdc++ and libgcc, no other lib is used.
  • It is a cpu and memory intensive non-parallel process (a mesh edition operation, lots of news and deletes and queries to data structures involved).
  • The problem is not start-up time, the whole process is painfully slow.
  • Debug build (-O0 -g2) runs in 8 secs outside gdb, but in 140 secs within gdb.
  • Tested from command line, just launching gdb and just typing "run" (no breakpoints defined).
  • I also tested a release build (optimized, and without debugging information), and it is still much slower inside gdb (3 secs vs 140 secs; yes, it takes the same time as the not optimized version inside gdb).
  • Tested with gdb 7.5 and 7.6 from mingw32 project, and with a gdb 7.8 compiled by me (all of them without python support).
  • I usually develop on a GNU/Linux box, and there I can't notice speed differences between running with or withoud gdb.

I want to know what is gdb doing that is making it run so slowly. I have some basic understanding of how a debugger works, but I cannot figure out what is it doing here, and googling didn't helped me this time.

2
  • Some extra info: I've just profiled the app with gprof, with and without gdb and results are very similar, the extra time does not seems to be there. I've also compiled gdb with -pg, but haven't found anything strange so far.
    – Zaskar
    Dec 9, 2014 at 19:24
  • 2
    Out of curiosity, have you tried running this with a different windows debugger like ollydbg, VS integrated debugger, windbg etc.? How do their run-time performance compare to mingw-gdb?
    – greatwolf
    Dec 12, 2014 at 5:48

2 Answers 2

5

I've finally found the problem, thanks to greatwolf for asking me to test other debuggers. Ollydbg takes the same time as gdb, so it's not a gdb problem, its a Windows problem. This tip changed my search criteria and then I've found this article* that explains the problem very well and gives a really simple solution: define an environment varible _NO_DEBUG_HEAP to 1. This will disable the use of a special heap system windows provides and c++ programs use.

* Here's the link: http://preshing.com/20110717/the-windows-heap-is-slow-when-launched-from-the-debugger/

1
  • This works under my MSYS2's 64bit GCC compiler + GDB, it make the debugging session very fast, thanks!
    – ollydbg23
    Oct 1, 2020 at 15:18
1

I once had issues with gdb being incredibly slow and I remember disabling nls (native language support, i.e. the translations of all the messages) would remedy this.

The configure time option is --disable-nls. I might have just been mistaken as to what is the true cause, but it's worth a shot for you anyways.

My bug report from back then is here, although the conclusion there would be that I was mistaken. If you can provide further insight into this, that would be great!

2
  • I compiled the latest gdb version (7.8.1) myself with and without that option, and there was no difference. I read about it before, but I think it was related to the loading of huge shared libraries (such as qt).
    – Zaskar
    Dec 9, 2014 at 14:44
  • @Zaskar While the Qt part might be true I'm using it on both a Debian and Win10 system. On Debian things load much faster (including all the Debian-relevant libraries) while on Win10 it loads a ton of other Windows-related libraries which take probably 2/3 of the loading times during a debugging session. Aug 1, 2016 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.