0%

Install cgdb from source and configurate it for c++

cgdb is a lightweight curses (terminal-based) interface to the GNU Debugger (GDB). In addition to the standard gdb console, cgdb provides a split screen view that displays the source code as it executes. The keyboard interface is modeled after vim, so vim users should feel at home using cgdb.

To use vertical window split orientation mode in cgdb, I need cgdb version higher than 0.7, so I decided to install cgdb from source.

Install

pre-requirements

1
sudo apt-get install automake libncurses5-dev flex texinfo libreadline-dev

build from source

1
2
3
4
5
6
7
8
9
# latest sources should be newer than version 0.7.1
git clone https://github.com/cgdb/cgdb.git
cd cgdb
mkdir build
./autogen.sh
cd build
../configure
make -j8
sudo make install

Configuration

Tell gdb to skip standard files

1
2
# To skip all .h files in /usr/include/c++/5/bits
skip -gfi /usr/include/c++/5/bits/*.h
  • Sadly, my gdb version is exactly 7.11 (installed via apt). Following solution is provided by blog above, and it works for me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
define skipstdcxxheaders
python
def skipAllIn(root):
import os
for root, dirs, files in os.walk(root, topdown=False):
for name in files:
path = os.path.join(root, name)
gdb.execute('skip file %s' % path, to_string=True)
# do this for C++ only
if 'c++' in gdb.execute('show language', to_string=True):
skipAllIn('/usr/include/c++')
end
end

define hookpost-run
skipstdcxxheaders
end
define hookpost-start
skipstdcxxheaders
end
define hookpost-attach
skipstdcxxheaders
end
  • To verify whether the configuration works, check with info skip in cgdb.

Troubleshooting

  • These errors are all dependences issues.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# problem
$ ./autogen.sh
...
E: Unable to locate package aclocal
# solution
$ sudo apt-get install automake

# problem
$ ./autogen.sh
...
configure: error: CGDB requires curses.h or ncurses/curses.h to build.
# solution
$ sudo apt-get install libncurses5-dev

# problem
$ ./autogen.sh
...
configure: error: Please install flex before installing
# solution
$ sudo apt-get install flex

# problem
$ ./autogen.sh
...
configure: error: Please install makeinfo before installing
# solution
$ sudo apt-get install texinfo

# problem
$ ./autogen.sh
...
checking version of installed readline library... configure: WARNING: Could not test version of installed readline library.
configure: error: CGDB requires GNU readline 5.1 or greater to link.
If you used --with-readline instead of using the system readline library,
make sure to set the correct readline library on the linker search path
via LD_LIBRARY_PATH or some other facility.
# solution
$ sudo apt-get install libreadline-dev

欢迎关注我的其它发布渠道