News:

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

Main Menu

Pretty Printers working only for global variables

Started by Sab, May 16, 2015, 01:20:45 PM

Previous topic - Next topic

Sab

Windows 7-64 bit
C::B 13.12
gdb 7.7
g++ 4.9.2

For me if I use vector as a local variable, not able to see value of vectors during debugging but if I declare vector as global variable pretty printers are working. Same is happening for std::strings.
And when I tried std::queue, std::map pretty printers are not working. I have attached screenshots of configuration and debugging window.

How can I view other STL containers?

ollydbg

I don't have such issue.
One suggestion: you need to uncheck the "Enable watch scripts" option.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

I uncheck the "Enable watch scripts" option and the pretty printers are not working then I noticed the Error while executing Python code., googled and tried the following.


My stl.gdb

python
import sys
sys.path.insert(0, '')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end


I am getting following error while executing while debugging in Code Block


source C:\MinGW\bin\stl.gdb
Traceback (most recent call last):
  File "<string>", line 3, in <module>
ImportError: No module named libstdcxx.v6.printers
C:\MinGW\bin\stl.gdb:5: Error in sourced command file:
Error while executing Python code.


and following error from command prompt


(gdb) source C:\MinGW\bin\stl.gdb
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "c:\mingw\share\gdb/python/../../gcc-4.9.2/python/libstdcxx/v6/printers.p
y", line 1023, in register_libstdcxx_printers
    gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
  File "c:\mingw\share\gdb/python/gdb/printing.py", line 146, in register_pretty
_printer
    printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
C:\MinGW\bin\stl.gdb:6: Error in sourced command file:
Error while executing Python code.
(gdb)


then I removed
register_libstdcxx_printers (None)
from my stl.gdb and I didn't get any error in command prompt but getting same error in code block

What should I do?

Edit:My gdb version 7.8.1

I tried to debug in command line:

Breakpoint 1, main ()
    at D:\Program\Practice Program\PrettyPrinterCheck\main.cpp:41
41          cout<<s;
(gdb) print p
$1 = {first = 13, second = 14}
(gdb) print m
$2 = std::map with 1 elements = {[2] = 1}
(gdb) print v
$3 = std::vector of length 1, capacity 1 = {10}
(gdb) print q
$4 = std::queue wrapping: std::deque with 2 elements = {10, 11}
(gdb) print s
$5 = "Hello"


ollydbg

Quote from: Sab on May 16, 2015, 05:05:03 PM

(gdb) source C:\MinGW\bin\stl.gdb
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "c:\mingw\share\gdb/python/../../gcc-4.9.2/python/libstdcxx/v6/printers.p
y", line 1023, in register_libstdcxx_printers
    gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
  File "c:\mingw\share\gdb/python/gdb/printing.py", line 146, in register_pretty
_printer
    printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
C:\MinGW\bin\stl.gdb:6: Error in sourced command file:
Error while executing Python code.
(gdb)


then I removed
register_libstdcxx_printers (None)
from my stl.gdb and I didn't get any error in command prompt
Yes, you should remove that line, because the std pretty printer is registered when it is imported, see my answer here:
http://stackoverflow.com/a/28404772/154911

Quote
but getting same error in code block

What should I do?

Edit:My gdb version 7.8.1

I tried to debug in command line:

Breakpoint 1, main ()
    at D:\Program\Practice Program\PrettyPrinterCheck\main.cpp:41
41          cout<<s;
(gdb) print p
$1 = {first = 13, second = 14}
(gdb) print m
$2 = std::map with 1 elements = {[2] = 1}
(gdb) print v
$3 = std::vector of length 1, capacity 1 = {10}
(gdb) print q
$4 = std::queue wrapping: std::deque with 2 elements = {10, 11}
(gdb) print s
$5 = "Hello"

From the command line, I see it works OK, but you should get the same result in C::B, I have no idea, do you have two different version of GDBs in your system?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

I have only one GDB. I have attached my settings->compiler->toolchain config.

my current stl.gdb file


python
import sys
sys.path.insert(0, 'C:\MinGW\share\gcc-4.9.2\python')
from libstdcxx.v6.printers import register_libstdcxx_printers
end


after this I am not getting any error in C::B debugger prompt but still pretty printers are not working in C:B while in command prompt it is  working.

oBFusCATed

One way to check if gdb's pretty printers are working is to stop at a breakpoint, switch to the debugger's log and execute the "info pretty-printer" command. It should list your pretty printers that are currently active. Also another command you can try is "print myVector" to see the raw output of gdb.
(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!]

ollydbg

Quote from: Sab on May 17, 2015, 01:35:44 PM
I have only one GDB. I have attached my settings->compiler->toolchain config.

my current stl.gdb file


python
import sys
sys.path.insert(0, 'C:\MinGW\share\gcc-4.9.2\python')
from libstdcxx.v6.printers import register_libstdcxx_printers
end


after this I am not getting any error in C::B debugger prompt but still pretty printers are not working in C:B while in command prompt it is  working.
I want to see the "full debugger log" when the problem you mentioned in the first post happens. I mean the log message when you have problems in shown in yy.png.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

Quote from: ollydbg on May 17, 2015, 03:15:04 PM
I want to see the "full debugger log" when the problem you mentioned in the first post happens. I mean the log message when you have problems in shown in yy.png.

I have attached the files debugger-first.txt is the first one and debugger-now.txt is the current one.

first config : as present in the first post screenshots and stl.gdb:


python
import sys
sys.path.insert(0, '')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end


path to stl.gdb - C:\MinGW\bin\stl.gdb

sorry for the bad attachment name in my first post.

I tried re-installing code :: block still no use. MinGW I currently have - x86_64-4.9.2-release-posix-seh-rt_v4-rev2



ollydbg

Hi, Sab.
I looked the two txt files.
debuglog-now.txt looks correct, and debuglog-first.txt is wrong. Because I see

Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector

which means you did not turn off the watch script in debuglog-first.txt.

But I don't see the variables like "m, v, q, s" in the debuglog-now.txt, so what is the problem right now?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

Sorry, I thought u wanted the gdb starting log, I have attached the one with print command

ollydbg

[debug]> print q
[debug]$4 = {c = {<std::_Deque_base<int, std::allocator<int> >> = {_M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_map = 0x5427e0, _M_map_size = 8, _M_start = {_M_cur = 0x544d00, _M_first = 0x544d00, _M_last = 0x544f00, _M_node = 0x5427f8}, _M_finish = {_M_cur = 0x544d08, _M_first = 0x544d00, _M_last = 0x544f00, _M_node = 0x5427f8}}}, <No data fields>}}
[debug]>>>>>>cb_gdb:

$4 = {c = {<std::_Deque_base<int, std::allocator<int> >> = {_M_impl = {<std::allocator<int>> = {<__gnu_cxx::new_allocator<int>> = {<No data fields>}, <No data fields>}, _M_map = 0x5427e0, _M_map_size = 8, _M_start = {_M_cur = 0x544d00, _M_first = 0x544d00, _M_last = 0x544f00, _M_node = 0x5427f8}, _M_finish = {_M_cur = 0x544d08, _M_first = 0x544d00, _M_last = 0x544f00, _M_node = 0x5427f8}}}, <No data fields>}}
> print m

[debug]> print m
[debug]$5 = {_M_t = {_M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<No data fields>}, <No data fields>}, _M_key_compare = {<std::binary_function<int, int, bool>> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red, _M_parent = 0x544fc0, _M_left = 0x544fc0, _M_right = 0x544fc0}, _M_node_count = 1}}}
[debug]>>>>>>cb_gdb:

$5 = {_M_t = {_M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<int const, int> > >> = {<No data fields>}, <No data fields>}, _M_key_compare = {<std::binary_function<int, int, bool>> = {<No data fields>}, <No data fields>}, _M_header = {_M_color = std::_S_red, _M_parent = 0x544fc0, _M_left = 0x544fc0, _M_right = 0x544fc0}, _M_node_count = 1}}}


It looks like pretty printer is not installed correctly. (But I do see you have
[debug]> source C:\MinGW\bin\stl.gdb
In the log message.

What is the result when you type "info pretty-printer" in C::B's gdb debug panel?

Also, can you show the full log when you debug the same command in the windows command line.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

Quote from: ollydbg on May 18, 2015, 04:00:40 PM

What is the result when you type "info pretty-printer" in C::B's gdb debug panel?

Also, can you show the full log when you debug the same command in the windows command line.


> info pretty-printer

[debug]> info pretty-printer
[debug]global pretty-printers:
[debug]  builtin
[debug]    mpx_bound128
[debug]>>>>>>cb_gdb:

global pretty-printers:
  builtin
    mpx_bound128



Now pretty printers are not working in cmd too.

ollydbg

Quote from: Sab on May 18, 2015, 05:19:55 PM


> info pretty-printer

[debug]> info pretty-printer
[debug]global pretty-printers:
[debug]  builtin
[debug]    mpx_bound128
[debug]>>>>>>cb_gdb:

global pretty-printers:
  builtin
    mpx_bound128



Now pretty printers are not working in cmd too.
Interesting, so you could try to add the line "register_libstdcxx_printers (None)" back to stl.gdb file, and see whether it works again.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Sab

Quote from: ollydbg on May 19, 2015, 02:19:02 AM
Interesting, so you could try to add the line "register_libstdcxx_printers (None)" back to stl.gdb file, and see whether it works again.

Its working :o I have attached screenshot of watcher and debugger log.