xref: /OK3568_Linux_fs/buildroot/docs/manual/using-buildroot-debugger.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// -*- mode:doc; -*-
2*4882a593Smuzhiyun// vim: set syntax=asciidoc:
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun==== Using +gdb+ in Buildroot
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunBuildroot allows to do cross-debugging, where the debugger runs on the
7*4882a593Smuzhiyunbuild machine and communicates with +gdbserver+ on the target to
8*4882a593Smuzhiyuncontrol the execution of the program.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunTo achieve this:
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun* If you are using an _internal toolchain_ (built by Buildroot), you
13*4882a593Smuzhiyun  must enable +BR2_PACKAGE_HOST_GDB+, +BR2_PACKAGE_GDB+ and
14*4882a593Smuzhiyun  +BR2_PACKAGE_GDB_SERVER+. This ensures that both the cross gdb and
15*4882a593Smuzhiyun  gdbserver get built, and that gdbserver gets installed to your target.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun* If you are using an _external toolchain_, you should enable
18*4882a593Smuzhiyun  +BR2_TOOLCHAIN_EXTERNAL_GDB_SERVER_COPY+, which will copy the
19*4882a593Smuzhiyun  gdbserver included with the external toolchain to the target. If your
20*4882a593Smuzhiyun  external toolchain does not have a cross gdb or gdbserver, it is also
21*4882a593Smuzhiyun  possible to let Buildroot build them, by enabling the same options as
22*4882a593Smuzhiyun  for the _internal toolchain backend_.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunNow, to start debugging a program called +foo+, you should run on the
25*4882a593Smuzhiyuntarget:
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun----------------------------
28*4882a593Smuzhiyungdbserver :2345 foo
29*4882a593Smuzhiyun----------------------------
30*4882a593Smuzhiyun
31*4882a593SmuzhiyunThis will cause +gdbserver+ to listen on TCP port 2345 for a connection
32*4882a593Smuzhiyunfrom the cross gdb.
33*4882a593Smuzhiyun
34*4882a593SmuzhiyunThen, on the host, you should start the cross gdb using the following
35*4882a593Smuzhiyuncommand line:
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun----------------------------
38*4882a593Smuzhiyun<buildroot>/output/host/bin/<tuple>-gdb -ix <buildroot>/output/staging/usr/share/buildroot/gdbinit foo
39*4882a593Smuzhiyun----------------------------
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunOf course, +foo+ must be available in the current directory, built
42*4882a593Smuzhiyunwith debugging symbols. Typically you start this command from the
43*4882a593Smuzhiyundirectory where +foo+ is built (and not from +output/target/+ as the
44*4882a593Smuzhiyunbinaries in that directory are stripped).
45*4882a593Smuzhiyun
46*4882a593SmuzhiyunThe +<buildroot>/output/staging/usr/share/buildroot/gdbinit+ file will tell the
47*4882a593Smuzhiyuncross gdb where to find the libraries of the target.
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunFinally, to connect to the target from the cross gdb:
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun----------------------------
52*4882a593Smuzhiyun(gdb) target remote <target ip address>:2345
53*4882a593Smuzhiyun----------------------------
54