Author Topic: Pretty printers std::shared_ptr  (Read 1251 times)

Offline Suryavarman

  • Multiple posting newcomer
  • *
  • Posts: 80
    • Suryavarman
Pretty printers std::shared_ptr
« on: March 16, 2021, 05:41:29 pm »
With GDB I want to watch std::shared_ptr<T>::get() result.

To do that i have try to setup the pretty printers.

I have follow some links:
http://forums.codeblocks.org/index.php?topic=23590.0
http://wiki.codeblocks.org/index.php/Pretty_Printers

And to do that i have quiclky copy past the python command from codelite (it's work with codelite)
Code
python
import sys
sys.path.insert(0, '/home/gandi/.codelite/gdb_printers')

from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)

from qt4 import register_qt4_printers
register_qt4_printers (None)

from wx import register_wx_printers
register_wx_printers (None)

end

It doesn't work CB report an error from python code.

I have modify the ${HOME}/.gdbinit  file:
Code
python 
import sys

sys.path.append('blabla/.config/Epic/GDBPrinters/')
from UE4Printers import register_ue4_printers
register_ue4_printers(None)
print("Registered pretty printers for UE4 classes")

# sys.path.append('/blabla/gcc/libstdc++-v3/python')
import libstdcxx
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
print("Enregistrement des «belles écritures» pour libstdc++.")

end


In a terminal i test the gdb app and the python code work:
Code
$ gdb
GNU gdb (GDB) 10.1-5.mga8 (Mageia release 8)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-mageia-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Registered pretty printers for UE4 classes
Enregistrement des «belles écritures» pour libstdc++.
(gdb)

I try this new python code inside codeblocks (Debugger settings)
Same result:
Code
Debugger name and version: GNU gdb (GDB) 10.1-5.mga8 (Mageia release 8)
Error while executing Python code.

Here my small code to test the GDB  watcher.
Code
#include <iostream>
#include <string>
#include <memory>


struct Node
{
    std::string m_Toto;
};

typedef std::shared_ptr<Node> NodePtr;

int main()
{
    printf("Hello World");
   
    NodePtr toto{new Node{"Toto"}};
   
    std::cout << toto->m_Toto << std::endl;
   

    return 0;
}

Here my CB build information:
Code
Name             : Code::Blocks
Version          : svn-r12302
SDK Version      : 2.6.0
Scintilla Version: 3.7.5
Author           : The Code::Blocks Team
E-mail           : [email protected]
Website          : http://www.codeblocks.org

wxWidgets Library (wxGTK port)
Version 3.1.4 (Unicode: wchar_t, debug level: 0),
compiled at Mar 11 2021 22:48:45

Runtime version of toolkit used is 3.24.
Compile-time GTK+ version is 3.24.24.

My linux:
Mageia8 gcc10
« Last Edit: March 16, 2021, 06:20:13 pm by Suryavarman »

Offline Suryavarman

  • Multiple posting newcomer
  • *
  • Posts: 80
    • Suryavarman
Re: Pretty printers std::shared_ptr
« Reply #1 on: March 16, 2021, 05:48:24 pm »
Ok If i turn on the option : «Disable startup scripts (-nx) (GDB only) then the python code compiles fine.

But it doens't change the watcher result. I can't watch the result of  std::shared_ptr<T>::get()
« Last Edit: March 16, 2021, 07:23:53 pm by Suryavarman »

Offline cacb

  • Regular
  • ***
  • Posts: 485
Re: Pretty printers std::shared_ptr
« Reply #2 on: March 16, 2021, 07:30:39 pm »
Try watching *toto

I wish it would be possible to expand the pointer without dereferencing it, but last time i tried the above worked:

http://forums.codeblocks.org/index.php/topic,24360.msg166304.html#msg166304

Offline Suryavarman

  • Multiple posting newcomer
  • *
  • Posts: 80
    • Suryavarman
Re: Pretty printers std::shared_ptr
« Reply #3 on: March 16, 2021, 07:55:35 pm »
Yes *toto works.


Offline Suryavarman

  • Multiple posting newcomer
  • *
  • Posts: 80
    • Suryavarman
Re: Pretty printers std::shared_ptr
« Reply #4 on: March 16, 2021, 08:13:50 pm »
After python code I add the command «enable pretty-printer» but nothing has change.
From cb console:
Code
[debug]>>>>>>cb_gdb:0 printers enabled
[debug]> directory /blabla/Test_gdb/Tes_gdb/
[debug]172 of 172 printers enabled

In a terminal:

Code
$gdb
(gdb) help all
(gdb) enable pretty-printer -- GDB command to enable the specified pretty-printer.
(gdb) enable pretty-printer
0 printers enabled
172 of 172 printers enabled

« Last Edit: March 16, 2021, 08:16:08 pm by Suryavarman »