User forums > Using Code::Blocks
How can watch the contents of std::containers?
cacb:
This is interesting information. Does a similar solution for debugging std::vector and other containers exist under linux and g++? I have seen similar issues as described and would appreciate info on how to improve debugging with containers.
hongwenjun:
--- Code: ---// map::crbegin/crend
#include <iostream>
#include <map>
int main ()
{
std::map<char,int> mymap;
mymap['b'] = 100;
mymap['a'] = 200;
mymap['c'] = 300;
std::cout << "mymap backwards:";
for (auto rit = mymap.crbegin(); rit != mymap.crend(); ++rit)
std::cout << " [" << rit->first << ':' << rit->second << ']';
std::cout << '\n';
return 0;
}
--- End code ---
Codeblocks is just an IDE, helping users to run compiler and debugger commands
--- Code: ----------------- Debug GNU GCC Compiler)---------------
[ 50.0%] g++.exe -Wall -fexceptions -g -std=c++11 main.cpp -o main.o
[100.0%] g++.exe -o 234.exe main.o
-------------- GNU gdb (GDB) 8.1 ------------------------
[debug]Command-line: C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname -quiet -args R:/www/234/bin/Debug/234.exe
[debug]Working dir : R:\www\234
C:\CodeBlocks\MinGW\bin\gdb.exe -nx -fullname -quiet -args R:/www/234/bin/Debug/234.exe
[debug]> set prompt >>>>>>cb_gdb:
[debug]Reading symbols from R:/www/234/bin/Debug/234.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 8.1
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
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]> source C:\CodeBlocks\MinGW\etc\gdbinit
[debug]Traceback (most recent call last):
[debug] File "<string>", line 4, in <module>
[debug] File "c:\codeblocks\mingw\share\gdb/python/../../gcc-8.1.0/python/libstdcxx/v6/printers.py", line 1606, in register_libstdcxx_printers
[debug] gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
[debug] File "c:\codeblocks\mingw\share\gdb/python/gdb/printing.py", line 152, in register_pretty_printer
[debug] printer.name)
[debug]RuntimeError: pretty-printer already registered: libstdc++-v6
[debug]C:\CodeBlocks\MinGW\etc\gdbinit:6: Error in sourced command file:
[debug]Error while executing Python code.
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> directory R:/www/234/
Error while executing Python code.
[debug]Source directories searched: R:/www/234;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "R:/www/234/main.cpp:11"
[debug]Breakpoint 2 at 0x4015a3: file R:\www\234\main.cpp, line 11.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: R:\www\234\bin\Debug\234.exe
PID:2996
[debug][New Thread 2996.0x1308]
[debug]Breakpoint 2, main () at R:\www\234\main.cpp:11
[debug]R:\www\234\main.cpp:11:151:beg:0x4015a3
[debug]>>>>>>cb_gdb:
R:\www\234\main.cpp:11
[debug]> show language
[debug]The current source language is "auto; currently c++".
[debug]>>>>>>cb_gdb:
[debug]> info locals
[debug]mymap = std::map with 2 elements = {[97 'a'] = 200, [98 'b'] = 100}
[debug]>>>>>>cb_gdb:
[debug]> info args
[debug]No arguments.
[debug]>>>>>>cb_gdb:
--- End code ---
BlueHazzard:
--- Quote from: cacb on May 15, 2020, 06:38:03 pm ---This is interesting information. Does a similar solution for debugging std::vector and other containers exist under linux and g++? I have seen similar issues as described and would appreciate info on how to improve debugging with containers.
--- End quote ---
Pretty print python scripts for gdb work on windows like on linux.. The same way, just the paths have to be correct...
if the scripts are not present on your system you can download them from here:
https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3/python
chameleon:
I tried this, and finally I have a solution.
The basic idea is:
Try latest mingw64 distribution for compilation for availability of latest c++2a support.
Try Code::Blocks mingw64 distribution for debugging with an older gdb.
Do the above, the same time.
- Download latest mingw64 g++(10.1) and gdb(9.1) for windows from here: www.winlibs.com (sorry for ad, but I use that version of mingw64).
- This version has gdb(9.1) compiled without python support.
- Place that mingw64 distribution on c:\program files\mingw64
- Download latest Code::Blocks with mingw64 which has g++(8.1) and gdb(8.1).
- This version has gdb(8.1) compiled with python support.
- Place that mingw64 distribution on c:\program files\mingw
- Use for compilation g++(10.1) from c:\program files\mingw64 distribution
- Use for debugging gdb(8.1) from c:\program files\mingw distribution, but first place "source $(TARGET_COMPILER_DIR)etc\gdbinit" on debugger initialization commands,as previous posts stated.
ollydbg:
Releases brechtsanders/winlibs_mingw
It looks like winlibs' GDB has python support now, see this issue: the selected build of GDB does not support Python scripting. it cannot be used in qt creator. Issue 2 brechtsanders/winlibs_mingw
Navigation
[0] Message Index
[*] Previous page
Go to full version