#How to print STL objects like std::vectors with gdb

46 messages · Page 1 of 1 (latest)

sinful swallowBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

rapid dune
#
std::vector<Statement*> body;
#

I'm on windows and I use w64devkit

silver hamlet
dull nova
#

This one might work too?

rapid dune
#

I've already seen all these links when trying to figure it out by myself but I'll try again just incase I missed something

agile goblet
#

there are pretty printers for most STL types bundled with libstdc++, at least on linux

#

I'm guessing either they are not bundled or gdb cannot pick them up; or whatever ide you're using just ignores them

summer moon
#

Damn, if only we could use them for ostream <<

rapid dune
#
#include <iostream>
#include <vector>

int main() {
    std::vector<int> myVec = {1, 2, 5, 6, 7};
    std::cin.get();
}
#

g++ test.cpp -g

#

`gdb a.exe
Reading symbols from a.exe...
(gdb) break test.cpp:6
Breakpoint 1 at 0x140001478: file main.cpp, line 6.
(gdb) run
[New Thread 11300.0xc88]

Thread 1 hit Breakpoint 1, main () at test.cpp:6
6 std::cin.get();
(gdb) print myVec
$1 = {<std::_Vector_base<int, std::allocator<int> >> = {
_M_impl = {<std::allocator<int>> = {<std::__new_allocator<int>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<int, std::allocator<int> >::_Vector_impl_data> = {_M_start = 0x14e645616a0, _M_finish = 0x14e645616b4, _M_end_of_storage = 0x14e645616b4}, <No data fields>}}, <No data fields>}
(gdb)
`

sinful swallowBOT
#

@rapid dune Has your question been resolved? If so, run !solved :)

rapid dune
#

unfortunetly not wheatly

rapid dune
#

I've made some progress

dull nova
#

Nice

#

I’ll check it tomorrow

rapid dune
#

the problem is when I run gdb it tells me:

#

I added the lines it told me into the file but the msg won't go away

#

?!?!?!??!

sinful swallowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

rapid dune
#

!howto ask

sinful swallowBOT
# rapid dune !howto ask
How to Ask A Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What To Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error) 🏆 Gold Standard: Minimal Reproducible Example
Where To Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C/C++ snippets
  • OnlineGDB for interaction, debugging ⛔ Do not post screenshots, let alone photos of your screen!
agile goblet
#

you added the add-load-safe-path ... line to a file that gdb never actually reads

#

so obviously it has no effect

rapid dune
#

Do you know how I could fix that?

agile goblet
#

there was a typo, fixed now

rapid dune
#

@agile goblet sry it took my a while... I'm a little confused, where should I run that command?

rapid dune
#

ahh i was using cmd

agile goblet
#

then what is this?

rapid dune
#

that was before

#

Now i'm having a whole bunch of issues:

  • gdb only loads .gdbinit if I'm in C:\Users\jakec
  • I have to run $env:HOME = "C:\\Users\\jakec" every time I want to use it which means vscode debug won't work
agile goblet
#

but does pretty printing work at least?

rapid dune
#

yup

agile goblet
#

you mean like this?

$1 = std::vector of length 3, capacity 4 = {std::vector of length 1, capacity 1 = {"1"}, std::vector of length 1, capacity 1 = {"2"}, std::vector of length 1, capacity 1 = {"3"}}
#
  • gdb only loads .gdbinit if I'm in C:\Users\jakec
    that does look odd; does it print anything when the file is not loaded?
sinful swallowBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

rapid dune
#

@agile goblet It doesn't look like that but that is my desired result

rapid dune
#

it randomly started working? nvm

#

!solved