User forums > Using Code::Blocks

gdb stop on c++ exceptions

<< < (2/3) > >>

thomas:
__cxa_end_catch almost works.
If you hit "step to next line" after breaking on that, it stops right after the catch clause, and the debugger wakes up and everything looks nicely.

thomas:
... and I know why it doesn't work.

list __cxa_throw
No line number known for __cxa_throw.

The symbol __cxa_throw has no corresponding line in the source file. So although the debugger will break on it, it won't find it.

However:
info line *4199509
Line 10 of "D:\devel\ex\main.cpp" starts at address 0x401455 <main+53> and ends at 0x401483 <main+99>.
D:\devel\ex\main.cpp:10:103:beg:0x401455
At D:\devel\ex\main.cpp:10

So, the debugger plugin would need a little update, taking the value of EIP and query the line number like this.

Ingrater:
It does work now, but it doesn't result in a backtrace I could use. So I'm staying for the moment with manually creating an backtrace interrupt until I find a better solution.

thomas:
I've been playing with this for a bit, since I said "oh heck, this would be immensely helpful"... but there seems to be no safe way to get it to work every time.
Breaking on __cxa_throw... no problem.
Getting EIP and dumping the disassembly... no problem.
Dumping any other registers... no problem.
Finding the source line number... works 50% of the time, and doesn't 50% of the time.

thomas:
Reading the documentation reveals that gdb has a dedicated, standard command to catch exceptions.
catch throw will break when an exception is thrown just before the stack is unwound (there are other commands for breaking after unwinding too, but those are less useful). It works just fine, except the debugger plugin doesn't find a source line number, since the exception doesn't have one.

info frame shows __cxa_throw as the first entry, and the containing function, address and line number where the throw statement can be found in the second entry. It works surprisingly well. Ok, actually, since the entire exception handling is built on top of that, that's not surprising at all, duh :)

So, to make breaking on exceptions really work (including setting the little yellow wedge on the source line), the debugger plugin would have to:
1. send catch throw at startup
2. do everything as usual when waking up, but if frame[0] has no line number and is called __cxa_throw (or maybe match against something more permissive, such as /__.*throw/ ), use the line number of frame[1] instead.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version