Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: syheliel on May 03, 2021, 04:10:11 am

Title: Debug will not stop when exception 'std::out_of_range' appears
Post by: syheliel on May 03, 2021, 04:10:11 am
I have the following code. After executing, a message terminate called after throwing an instance of 'std::out_of_range' will appear. But in debug mode, this exception will not be caught.
My expectation result is that debug mode can stop on the corresponding line on s.substr(2,33);

Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<iostream>
#include<cmath>
typedef long long ll;
using namespace std;

int main() {
string s = "2" ;
s.substr(2,33);
    return 0;
}
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: oBFusCATed on May 03, 2021, 09:29:18 am
Settings -> Debugger -> Your config -> Catch C++ exceptions
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: syheliel on May 04, 2021, 06:44:03 am
It doesn't work for me. Here is my environment:

Code
Name             : Code::Blocks
Version          : 20.03-r11983
SDK Version      : 2.0.0
Scintilla Version: 3.7.5
Author           : The Code::Blocks Team
E-mail           : [email protected]
Website          : http://www.codeblocks.org

wxWidgets Library (wxMSW port)
Version 3.1.3 (Unicode: wchar_t, debug level: 1),
compiled at Nov  1 2019 18:53:26

Runtime version of toolkit used is 10.0.

wx3.1.3 - gcc 8.1.0 (Windows,unicode)

Does any additional information can help?
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: oBFusCATed on May 04, 2021, 10:16:22 am
Yes, enable full debugger log and post a session.
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: BlueHazzard on May 04, 2021, 10:30:32 am
Yes, enable full debugger log and post a session.
To do this:
Settings->Debugger->Common->Full debug log
Start debugger
post the content of the "Debugger" tab from the log view at the bottom
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: syheliel on May 04, 2021, 05:03:28 pm
here is the debug log: :P
Code
[debug]Reading symbols from D:/git/codeblock/bin/Debug/codeblock.exe...done.
[debug](gdb)
[debug]> set prompt >>>>>>cb_gdb:

Setting breakpoints

[debug]>>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 8.1
[debug]Copyright (C) 2018 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "x86_64-w64-mingw32".
[debug]Type "show configuration" for configuration details.
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]Find the GDB manual and other documentation resources online at:
[debug]<http://www.gnu.org/software/gdb/documentation/>.
[debug]For help, type "help".
[debug]Type "apropos word" to search for commands related to "word".
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 8.1

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 200
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> directory D:/git/codeblock/
[debug]Source directories searched: D:/git/codeblock;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: D:\git\codeblock\bin\Debug\codeblock.exe

Child process PID: 14676

[debug][New Thread 14676.0x6bf8]
[debug][New Thread 14676.0x8b4c]
[debug][New Thread 14676.0x65ac]
[debug][New Thread 14676.0x8dfc]
[debug]Thread 1 hit Catchpoint 1 (exception thrown), 0x000000006fd41c08 in libstdc++-6!.cxa_throw () from D:\Program Files (x86)\scoop\apps\gcc\current\bin\libstdc++-6.dll
[debug]>>>>>>cb_gdb:
[debug]> info frame

Debugger finished with status 1
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: BlueHazzard on May 04, 2021, 05:20:25 pm
Sadly the debugger (gdb) shipped with the latest codeblocks has some strange bugs and crashes from time to time. You sadly hit one of this bugs and your gdb is crashing....

So you have to update gdb to a newer version...
An easy way to do it:
Download the compiler from http://www.winlibs.com/ (for example https://github.com/brechtsanders/winlibs_mingw/releases/download/10.3.0-11.1.0-8.0.0-r2/winlibs-x86_64-posix-seh-gcc-10.3.0-mingw-w64-8.0.0-r2.zip )

extract it and replace the gdb.exe on your system with the gdb.exe from this archive.

Sadly this gdb is not python enabled... I have not found any newer gdb for windows with enabled python...
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: gd_on on May 04, 2021, 05:29:32 pm
Quote
Sadly this gdb is not python enabled... I have not found any newer gdb for windows with enabled python...
And the one distributed in Msys2, does-it has enabled python ?
Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: BlueHazzard on May 04, 2021, 08:44:25 pm
yes msys2 has python support. Nice!
Code
$ gdb
GNU gdb (GDB) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-msys".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Traceback (most recent call last):
  File "<string>", line 3, in <module>
ModuleNotFoundError: No module named 'libstdcxx'
/etc/gdbinit:6: Error in sourced command file:
Error while executing Python code.
(gdb) python
>

Title: Re: Debug will not stop when exception 'std::out_of_range' appears
Post by: syheliel on May 05, 2021, 04:48:47 am
Sadly the debugger (gdb) shipped with the latest codeblocks has some strange bugs and crashes from time to time. You sadly hit one of this bugs and your gdb is crashing....

So you have to update gdb to a newer version...
An easy way to do it:
Download the compiler from http://www.winlibs.com/ (for example https://github.com/brechtsanders/winlibs_mingw/releases/download/10.3.0-11.1.0-8.0.0-r2/winlibs-x86_64-posix-seh-gcc-10.3.0-mingw-w64-8.0.0-r2.zip )

extract it and replace the gdb.exe on your system with the gdb.exe from this archive.

Sadly this gdb is not python enabled... I have not found any newer gdb for windows with enabled python...
Thank you! It really works!