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.