News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Debug will not stop when exception 'std::out_of_range' appears

Started by syheliel, May 03, 2021, 04:10:11 AM

Previous topic - Next topic

syheliel

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);

#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;
}

oBFusCATed

Settings -> Debugger -> Your config -> Catch C++ exceptions
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

syheliel

It doesn't work for me. Here is my environment:

Name             : Code::Blocks
Version          : 20.03-r11983
SDK Version      : 2.0.0
Scintilla Version: 3.7.5
Author           : The Code::Blocks Team
E-mail           : info@codeblocks.org
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?

oBFusCATed

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

BlueHazzard

Quote from: oBFusCATed on May 04, 2021, 10:16:22 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

syheliel

here is the debug log: :P
[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

BlueHazzard

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...

gd_on

QuoteSadly 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 ?
Windows 11 64 bits (25H2), svn C::B (last version or almost!), wxWidgets 3.3.2, Msys2 Compilers 16.1.0, 64 bits (seh, posix : gcc, g++ and gfortran in C:\msys64\mingw64) or 32 bits (dwarf2, posix  in C:\msys64\mingw32).

BlueHazzard

yes msys2 has python support. Nice!

$ 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
>


syheliel

Quote from: 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...
Thank you! It really works!