public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* Why I cannot see content of std::vector in the gdb?
@ 2021-10-06  2:17 unlvsur unlvsur
  2021-10-06  8:56 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: unlvsur unlvsur @ 2021-10-06  2:17 UTC (permalink / raw)
  To: unlvsur unlvsur via Libstdc++

c++ - Inspecting standard container (std::map) contents with gdb - Stack Overflow<https://stackoverflow.com/questions/427589/inspecting-standard-container-stdmap-contents-with-gdb>

I just saw your (jwakely) answer that libstdc++ supports pretty printer for gdb. But it does not work? Any configs I missed here?

g++ -o a a.cc -g -std=c++20 -I../fast_io/include

gdb ./a
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./a...
(gdb) dir
Reinitialize source path to empty? (y or n) n
(gdb) l
1       #include<vector>
2       #include<fast_io.h>
3
4       int main()
5       {
6               std::vector<int> vec{2,4,6,1,204,6,5};
7               for(auto const& e : vec)
8                       println(e);
9       }
(gdb) break 7
Breakpoint 1 at 0x40129e: file a.cc, line 7.
(gdb) r
Starting program: /home/cqwrteur/fast_io_cleanup/temp/a

Breakpoint 1, main () at a.cc:7
7               for(auto const& e : vec)
(gdb) print vec
$1 = {<std::_Vector_base<int, std::allocator<int> >> = {
    _M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<int, std::allocator<int> >::_Vector_impl_data> = {_M_start = 0x4072a0, _M_finish = 0x4072bc,
        _M_end_of_storage = 0x4072bc}, <No data fields>}}, <No data fields>}
(gdb)

Sent from Mail<https://go.microsoft.com/fwlink/?LinkId=550986> for Windows


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Why I cannot see content of std::vector in the gdb?
  2021-10-06  2:17 Why I cannot see content of std::vector in the gdb? unlvsur unlvsur
@ 2021-10-06  8:56 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-10-06  8:56 UTC (permalink / raw)
  To: unlvsur unlvsur; +Cc: unlvsur unlvsur via Libstdc++

On Wed, 6 Oct 2021 at 03:18, unlvsur unlvsur wrote:
>
> c++ - Inspecting standard container (std::map) contents with gdb - Stack Overflow<https://stackoverflow.com/questions/427589/inspecting-standard-container-stdmap-contents-with-gdb>
>
> I just saw your (jwakely) answer that libstdc++ supports pretty printer for gdb. But it does not work? Any configs I missed here?

That should work, and does work for me.

Obviously your GDB needs to have Python support compiled in. Check
"show auto-load python-scripts" and "info auto-load python-scripts"
and see what it prints out.

See https://sourceware.org/gdb/current/onlinedocs/gdb/Python-Auto_002dloading.html

My ~/.gdbinit has these lines to enable me to load the printers.py
scripts from all my self-installed GCC builds under ~/gcc-version:

add-auto-load-safe-path /home/jwakely/gcc-versions/
add-auto-load-safe-path /home/jwakely/src/gcc/build-x86/gcc/.gdbinit

(The second line is for debugging GCC itself, via the gdb helpers that
are part of the GCC sources).

Note that auto-loading the libstdc++ printers only works for
libstdc++.so and not libstdc++.a, so if you built your gcc with
--disable-shared then you'll need to manually load the printers.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-06  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06  2:17 Why I cannot see content of std::vector in the gdb? unlvsur unlvsur
2021-10-06  8:56 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).