GDB debugging is often used to install the CDT plug-in eclipse To Write c ++ code.
However, for vector, map, and other STL content, the address information at the start and end can only be displayed during debugging, Which is unfriendly.
After studying the configuration for a while, the configuration is successful. The configuration details are described below for your reference.
1. Use SVN to download SVN: // gcc.gnu.org/svn/gcc/trunk/libstdc##-v3/python
2. The official website says this printer has a bug. Open the previously detected folder, locate printers. py in Python/libstdcxx/V6, and open it. Find row 614th. Then add the following red code
Len = header. dereference () ['_ m_length']
If Len> 100:
Len = 100 # Here the value can be modified
If hasattr (PTR, "lazy_string "):
3. Create. gdbinit in your user path. I use the root user, so the created file is/root/. gdbinit, And the content is
Python
Import sys
SYS. Path. insert (0, '/root/python ')
From libstdcxx. v6.printers import register_libstdcxx_printers (none)
End
4. Download GDB
Skip this step if STL can be properly displayed during GDB debugging.
I use centos5.5 and GDB is version 7.0, which does not seem to be supported. Therefore, I downloaded the latest version 7.5. I need to install python2.6, which is unavailable in version 2.4. I did not try other versions. I use 2.6.5. Download the source code package and compile and install it.
DGB download path http://mirror.bjtu.edu.cn/gnu/gdb.
Compilation Method:
Ldflags =-L/usr/lib./configure -- With-Python
Make
I replaced the compiled GDB with the original/usr/bin/GDB. You can keep a backup of the original GDB.
5. Command Line Testing
Source code:
# Include <vector>
Using namespace STD;
Int main ()
{
Vector <int> VEC;
VEC. push_back (1 );
VEC. push_back (2 );
VEC. push_back (3 );
Return 0;
}
After debugging with GDB, the VEC result is:
$1 = STD: vector of length 3, capacity 4 = {1, 2, 3}
6. Configure eclipse
Officially, modify the parameters in WINDOW> preferences> C/C ++> debug> GDB. At the beginning, I didn't use the debugging function in my environment. Later I found that the debugging function was not used in eclipse. I first debugged the code. Then let's look at the gdb option.
Only one item needs to be configured here, that is, GDB command file. What I configure is/root/. gdbinit, which can be filled in according to your actual situation.
In addition, if the original GDB is not replaced, the gdb debugger above also needs to be modified to the compiled GDB path.
Run eclipse debugging again, and STL will be displayed normally.
Note that the debugging options configured earlier also need to be modified, because the preferences configuration options take effect later and the previous configuration options are old. The modification is the same as the previous configuration.