0

After placing the stl-views.gdb so that gdb picks up this file, i am able to print contents of map where its type are basic:

map<int,int> m1;   //Or map<string,int> or some such basic type
m1. push_back(1,2)
m1. push_back(2,4);

In GDB:

pmap m1 int int     //This works fine

But consider the following example : e.g.

map<string,vector<string>> m1;   
m1["Node1"].push_back("N1S1");
m1["Node1"].push_back("N1S2");
m1["Node1"].push_back("N1S3");

m1["Node2"].push_back("N2S1");
m1["Node2"].push_back("N2S2");
m1["Node2"].push_back("N2S3");

In GDB:

pmap m1 string vector<string>   //It says elem[0].right: No symbol "vector<string>" in current context

How do i print value of a key "Node1" . I am expecting it to print a vector of strings as N1S1 N1S2 and N1S3

anurag86
  • 1,635
  • 1
  • 16
  • 31
  • Why do you need stl-views? gdb can display standard containers for quite some time. – n. m. could be an AI Aug 01 '21 at 12:08
  • https://stackoverflow.com/a/2467863/50617 – Employed Russian Aug 02 '21 at 20:27
  • @Employed Russian - I don't think i will be able to use that in my organization. Is there a way i can print the keys and values of map. For `map , p m1` , the `_M_header` has 3 pointers namely parent,left, right. But with this parent pointer how can i print the first and second(i.e. key and value of current node). e.g. if the parent is `0x616c20` (which is same pointer as that of iterator pointing to this (Key,Value) node and if i do `0x616c20 ->first` , it won't work at all. I am asking this so that i can use same solution for complex maps like `map>` Any tips/links – anurag86 Aug 03 '21 at 03:38
  • @EmployedRussian won't be able to copy paste so typing it. Its a `map m` with `(122,123), (222,234)` as its nodes. Currently iterator pointed at `(222,234)` . `p m` shows _`M_node_count=2` with `_M_parent=0x616c20` , `_M_left=0x616c20` and `_M_right=0x616c50`, iterator `it1` pointing to `_M_right`, so `p it1` shows `{ _M_node=0x616c50}` and `p* it1` shows `(std::pair &) @0x616c70: { first = 222, second=234 }` but if i do `p *0x616c50` it shows `0` . How do i have access to pair using `0x616c50` . – anurag86 Aug 03 '21 at 04:10

0 Answers0