gdb: How do I pause during loop execution?
Have you tried simply running your executable in gdb, and then just hitting ^C (Ctrl+C) when you want to interrupt it? That should drop you to gdb's prompt, where you can simply run the where
command to see where you are, and then carry on execution with continue
.
If you find yourself in a irrelevant thread (e.g. a looping UI thread), use thread
, info threads
and thread n
to go to the correct one, then execute where
.
Related videos on Youtube
![Engineer](https://i.stack.imgur.com/vRzuV.png?s=256&g=1)
Engineer
War & Adventure, an FPS/RTS under development In top 0.2% on gamedev.stackexchange.com Tutorials and articles: Eye-Openers: Generating and Smoothing 2D Terrain in Unity Eye-Openers: Mesh-based 2D Side-scroller Terrain in Unity Eye-Openers: Infinite Streaming 2D Side-scroller Terrain in Unity Open Source Projects: arc - a realtime applications framework primarily for games, for C & JS. orb - a small, simple OpenGL & OpenGL ES rendering engine and associated tools, for C. Interests: Efficient code Procedural world algorithms Tools development Rendering & Visualization Tech: OpenGL, WebGL, C, JS, Unity, C#, Java, Flash.
Updated on July 09, 2022Comments
-
Engineer almost 2 years
I'm writing a software renderer in g++ under mingw32 in Windows 7, using NetBeans 7 as my IDE.
I've been needing to profile it of late, and this need has reached critical mass now that I'm past laying down the structure. I looked around, and to me this answer shows the most promise in being simultaneously cross-platform and keeping things simple.
The gist of that approach is that possibly the most basic (and in many ways, the most accurate) way to profile/optimise is to simply sample the stack directly every now and then by halting execution... Unfortunately, NetBeans won't pause. So I'm trying to find out how to do this sampling with gdb directly.
I don't know a great deal about gdb. What I can tell from the man pages though, is that you set breakpoints before running your executable. That doesn't help me.
Does anyone know of a simple approach to getting gdb (or other gnu tools) to either:
- Sample the stack when I say so (preferable)
- Take a whole bunch of samples at random intervals over a given period
...give my stated configuration?
-
Yaniro over 12 yearsSetting a breakpoint at a certain file and a certain line or at a certain method for a certain class won't help you? unknownroad.com/rtfm/gdbtut/gdbbreak.html
-
Engineer over 12 years@Yaniro, Sadly no. It needs to be time-spaced sampling, as stated in that answer I linked to, in order to have the desired effect. If I do it only in a particularly place in code, I won't see where most of the time is being spent, I'll only see those locations where the breakpoints sit.
-
Ciro Santilli OurBigBook.com over 8 yearsPossible duplicate of pause gdb without breakpoint
-
Engineer over 12 yearsOK, it is receiving SIGINT now, which is great. Thank you. Only problem is that every time I halt it, I find myself in NlsUpdateSystemLocale() (in kernel32.dll) -- I think it's looking at the wrong thread. If you have any tips, they'd be welcome. Marking as accepted.
-
Engineer over 12 yearsFigured it out, gdb apparently doesn't (always?) know what the correct thread is, it just picks the one at the top of the thread list, at least in my mingw install. I just had to do gdb commands
thread
,info threads
andthread n
where n was the number of my running program's thread. Thanks again. -
Ciro Santilli OurBigBook.com over 8 yearsCtrl + C not working for some people: stackoverflow.com/questions/5857300/…
-
Aaron Franke almost 3 yearsHow do I interrupt it without Ctrl+C? I'm debugging an issue where a program locks up the entire desktop environment, so I no longer have access to the terminal where I ran GDB. Can I interrupt after a specified time, like 10 seconds after the program starts?