Vscode-cpptools: Break point for "All Exceptions"

Created on 7 Apr 2018  路  9Comments  路  Source: microsoft/vscode-cpptools

Is there an option to automatically stop the debugger at an exception, such as used in others vscode debuggers (option for "All Exceptions"at the breakpoints panel ) ?

I could not find anything related to it in the documentation.

Feature Request debugger

Most helpful comment

You can do this by adding -interpreter-exec console \"catch throw <INSERT-EXCEPTION>\"

Where? It is quite infuriating to have to type something similar in the console (you need "stopAtEntry": true) whenever I launch a debugger session. I just want to have it defined in one configuration of the launch.json so when I launch a debug session, it can execute that line then run the program until the exception raises.

EDIT1:
I happen to make it work with:

            "setupCommands": [
                ...,
                {
                    "description": "Enable all-exceptions",
                    "text": "catch throw",
                    "ignoreFailures": true
                }
            ]

but I suspect it may not be the right way to do so. Should it be

                ...,
                {
                    "description": "Enable all-exceptions",
                    "text": "-exec \"catch throw\"",
                    "ignoreFailures": true
                }
            ]

?
EDIT2:
The first works but not the second so I revert to the first.

All 9 comments

This is currently not implemented due to GDB /MI having no support for exceptions.

From: https://github.com/Microsoft/MIEngine/blob/d2966de86bbde2743442c220f2054a9dc3b14a5c/src/MICore/CommandFactories/MICommandFactory.cs#L557

// NOTES:
// GDB /MI has no support for exceptions. Though they do have it through the non-MI through a 'catch' command. Example:
// catch throw MyException
// Catchpoint 3 (throw)
// =breakpoint-created,bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0xa1b5f830",what="exception throw",catch-type="throw",thread-groups=["i1"],regexp="MyException",times="0"}
// Documentation: http://www.sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html#Set-Catchpoints

// LLDB-MI has no support for exceptions. Though they do have it through the non-MI breakpoint command. Example:
// break set -F std::range_error
// And they do have it in their API:
// SBTarget::BreakpointCreateForException

@caiofcm What OS are you on and what you are debugging?

I am on Debian/Ubuntu, and my goal was to debug c++ executable applications with gcc/gdb.

@caiofcm Since there is no support in GDB via MI, there is no current way to support it. However, there is a work around by using the catch mentioned in the comment above. This will only catch the exceptions you specify. You can do this by adding -interpreter-exec console \"catch throw <INSERT-EXCEPTION>\"

I have the same problem under Windows 10, I use GDB from MinGW-x64. Are there any better solutions for this case?

You can do this by adding -interpreter-exec console \"catch throw <INSERT-EXCEPTION>\"

Where? It is quite infuriating to have to type something similar in the console (you need "stopAtEntry": true) whenever I launch a debugger session. I just want to have it defined in one configuration of the launch.json so when I launch a debug session, it can execute that line then run the program until the exception raises.

EDIT1:
I happen to make it work with:

            "setupCommands": [
                ...,
                {
                    "description": "Enable all-exceptions",
                    "text": "catch throw",
                    "ignoreFailures": true
                }
            ]

but I suspect it may not be the right way to do so. Should it be

                ...,
                {
                    "description": "Enable all-exceptions",
                    "text": "-exec \"catch throw\"",
                    "ignoreFailures": true
                }
            ]

?
EDIT2:
The first works but not the second so I revert to the first.

How come it is possible in QT Creator, using the same gdb, but in VSCode it's not?

The solution mentioned by @hlide worked for me.

Looks like GDB now supports setting breakpoint on exception using GDB/MI interface. https://sourceware.org/gdb/onlinedocs/gdb/C_002b_002b-Exception-GDB_002fMI-Catchpoint-Commands.html#C_002b_002b-Exception-GDB_002fMI-Catchpoint-Commands

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arl picture arl  路  3Comments

igorPhelype picture igorPhelype  路  3Comments

narutse picture narutse  路  3Comments

montery8 picture montery8  路  3Comments

SkyRiderMike picture SkyRiderMike  路  3Comments