Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can gdb be set to break on any throw? [duplicate]

Tags:

c++

exception

gdb

I am debugging code with exception throwing and exception handling. I would like gdb to break immediately when an exception is thrown, so i can inspect the state of the program and the call stack. How can I make gdb break when any exception is thrown?

like image 262
zr. Avatar asked Feb 14 '12 10:02

zr.


People also ask

How do I set a break in GDB?

You can also set breakpoints on function names. To do this, just type "break [functionname]". gdb will stop your program just before that function is called. Breakpoints stay set when your program ends, so you do not have to reset them unless you quit gdb and restart it.

Why is GDB not stopping at breakpoint?

GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped.

What does breakpoint do in GDB?

A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.

How do you set a breakpoint in a line in GDB?

Set a breakpoint at line linenum in the current source file. The current source file is the last file whose source text was printed. The breakpoint will stop your program just before it executes any of the code on that line. Set a breakpoint at line linenum in source file filename .


1 Answers

You can do this with the catch throw command. See here:

catch event

Stop when event occurs. The event can be any of the following:

throw [regexp]

rethrow [regexp]

catch [regexp]

The throwing, re-throwing, or catching of a C++ exception.

If regexp is given, then only exceptions whose type matches the regular expression will be caught.

like image 197
Daniel Hershcovich Avatar answered Sep 20 '22 16:09

Daniel Hershcovich