问题
I am trying to enable pretty printing for STL in Eclipse. These are my versions:
- Eclipse Version: 2018-09 (4.9.0)
- gdb 7.11.1
- Xubuntu 16.04
- gcc 7.4.0
- g++ 7.4.0
I have read various guides and this is what I did (I copied the answers from other SO qns):
STEP 1: Download the pretty printers:
$ cd /home/ali/Downloads
$ svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
STEP 2: Edit gdbinit
$ subl /home/ali/.gdbinit
Paste the following in .gdbinit:
python
import sys
sys.path.insert(0, '/home/ali/Downloads/python/')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
end
I have also tried the one that comes with gcc, that is:
sys.path.insert(0, '/usr/bin/gcc-8/python')
Also, I have added the lines to printers.py:
if length > 100: length = 100
STEP 3: Setup Eclipse
In the GDB settings for Eclipse (Window->Preferences->C/C++->Debug->GDB), set the GDB command file path to the .gdbinit file you just created. Also, in the same tab, check the box for Pretty Printing.
For any existing debug configurations (Run->Debug Configurations) which require pretty-printing, select the debug configuration, then set the GDB command file path on the Debugger tab.
STEP 4: Testing GDB
You can verify that GDB is pretty-printing as follows (once the first two steps of the previous procedure have been completed):
Save the following code in a file named test.cpp:
#include <map>
int main() {
std::map<char, int> first;
first['a'] = 10;
first['b'] = 20;
}
Compile with g++:
$ g++ -g -o test test.cpp
Run gdb:
$ gdb test
Set a break point:
(gdb) b test.cpp:5
This will output:
Breakpoint 1 at 0x40093f: file src/test.cpp, line 5.
Run the program:
(gdb) run
Starting program: /path/to/test
When the break point is hit, the gdb prompt will be displayed. Print the map with the following command:
(gdb) p first
If all is well, you should see the following output:
$1 = std::map with 1 elements = {[97 'a'] = 10}
I still do not get pretty printing in Eclipse (its working fine using gdb in Terminal):
seq_of_probs = {<No data fields>}}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
where seq_of_probs is of type std::vector<std::string>
Could someone please suggest any steps that is missing or wrong? I have been trying for a day now.
Things off my mind:
Does DSF-GDB or CDI-GDB matter? I do not know which one my Eclipse is using.
In Eclipse, my default gdb debugger is gdb. I changed it to usr/bin/gdb. Either way, both didn't work.
Is the gdb that my Eclipse is using python-enabled? My gdb version should be python-enabled. Or is there another binary for that?
Edit:
Now I am getting this error:
Multiple errors reported.
1) Failed to execute MI command:
-var-create - * state
Error message from debugger back end:
Cannot instantiate printer for default visualiser
2) Unable to create variable object
3) Failed to execute MI command:
-var-create - * state
Error message from debugger back end:
Cannot instantiate printer for default visualiser
state is a vector.
UPDATE:
So I think pretty printing is working in Eclipse when I am using gcc 4.8 and g++ 4.8. This is what I got:
Name : test
Details:std::vector of length 3, capacity 4 = {1, 2, 3}
Default:{...}
Decimal:{...}
Hex:{...}
Binary:{...}
Octal:{...}
Name : [0]
Details:N/A (child of pretty-printed object)
Default:1
Decimal:1
Hex:0x1
Binary:1
Octal:01
I hope this provide further clues to what needs to be fixed. Any ideas?
来源:https://stackoverflow.com/questions/56585630/enable-pretty-printing-in-eclipse-c