1030b9a7cSGreg Lehey# $FreeBSD$
2030b9a7cSGreg Lehey# .gdbinit file for remote serial debugging.
3030b9a7cSGreg Lehey# see gdbinit(9) for further details.
4030b9a7cSGreg Lehey#
5*747ca5f5SGreg Lehey# XXX Do not use this file directly.  It contains parameters which are
6*747ca5f5SGreg Lehey# XXX substituted by the kernel Makefile when you do a 'make gdbinit'.
7*747ca5f5SGreg Lehey# XXX This also removes lines starting with '# XXX'.
8*747ca5f5SGreg Lehey# XXX
9*747ca5f5SGreg Lehey# To debug kernels, do:
10*747ca5f5SGreg Lehey#
11*747ca5f5SGreg Lehey#  cd /usr/src/sys/GENERIC   (or kernel build directory)
12*747ca5f5SGreg Lehey#  make gdbinit
13*747ca5f5SGreg Lehey#  gdb -k kernel.debug
14*747ca5f5SGreg Lehey#
15*747ca5f5SGreg Lehey# Read gdb(4) for more details.
16*747ca5f5SGreg Lehey
17*747ca5f5SGreg Lehey# The following lines (down to "***** End" comment) may need to be changed
18*747ca5f5SGreg Lehey
19*747ca5f5SGreg Lehey# Bit rate for serial link.  Due to problems in the interface,
20*747ca5f5SGreg Lehey# this may not work well above 9600 bps.
21*747ca5f5SGreg Leheyset remotebaud 9600
22*747ca5f5SGreg Lehey
23030b9a7cSGreg Leheyset output-radix 16
24030b9a7cSGreg Leheyset height 70
25030b9a7cSGreg Leheyset width 120
26030b9a7cSGreg Leheyset remotetimeout 1
27030b9a7cSGreg Leheyset complaints 1
28030b9a7cSGreg Leheyset print pretty
29030b9a7cSGreg Leheydir ../../..
30*747ca5f5SGreg Lehey
31*747ca5f5SGreg Lehey# ***** End of things you're likely to need to change.
32*747ca5f5SGreg Lehey
33*747ca5f5SGreg Lehey# Connect to remote target via a serial port.
34*747ca5f5SGreg Leheydefine tr
35*747ca5f5SGreg Lehey# Remote debugging port
36*747ca5f5SGreg Leheytarget remote $arg0
37*747ca5f5SGreg Leheyend
38*747ca5f5SGreg Lehey
39030b9a7cSGreg Leheydocument tr
40*747ca5f5SGreg LeheyDebug a remote system via serial or firewire interface.  For example, specify 'tr /dev/cuaa0' to use first serial port, or 'tr localhost:5556' for default firewire port.  See also tr0, tr1 and trf commands.
41*747ca5f5SGreg Leheyend
42*747ca5f5SGreg Lehey
43*747ca5f5SGreg Lehey# Convenience functions.  These call tr.
44*747ca5f5SGreg Lehey# debug via cuaa0
45*747ca5f5SGreg Leheydefine tr0
46*747ca5f5SGreg Leheytr /dev/cuaa0
47*747ca5f5SGreg Leheyend
48*747ca5f5SGreg Leheydefine tr1
49*747ca5f5SGreg Leheytr /dev/cuaa1
50*747ca5f5SGreg Leheyend
51*747ca5f5SGreg Lehey# Firewire
52*747ca5f5SGreg Leheydefine trf
53*747ca5f5SGreg Leheytr localhost:5556
54*747ca5f5SGreg Leheyend
55*747ca5f5SGreg Lehey
56*747ca5f5SGreg Leheydocument tr0
57*747ca5f5SGreg LeheyDebug a remote system via serial interface /dev/cuaa0.  See also tr, tr1 and trf commands.
58*747ca5f5SGreg Leheyend
59*747ca5f5SGreg Leheydocument tr1
60*747ca5f5SGreg LeheyDebug a remote system via serial interface /dev/cuaa1.  See also tr, tr0 and trf commands.
61*747ca5f5SGreg Leheyend
62*747ca5f5SGreg Leheydocument trf
63*747ca5f5SGreg LeheyDebug a remote system via firewire interface at default port 5556.  See also tr, tr0 and tr1 commands.
64*747ca5f5SGreg Leheyend
65*747ca5f5SGreg Lehey
66*747ca5f5SGreg Lehey# Get symbols from klds.  Unfortunately, there are a number of
67*747ca5f5SGreg Lehey# landmines involved here:
68*747ca5f5SGreg Lehey#
69*747ca5f5SGreg Lehey# When debugging the same machine (via /dev/mem), we can get the
70*747ca5f5SGreg Lehey# script to call kldstat and pass the info on to asf(8).  This won't
71*747ca5f5SGreg Lehey# work for crashes or remote debugging, of course, because we'd get
72*747ca5f5SGreg Lehey# the information for the wrong system.  Instead, we use the macro
73*747ca5f5SGreg Lehey# "kldstat", which extracts the information from the "dump".  The
74*747ca5f5SGreg Lehey# trouble here is that it's a pain to use, since gdb doesn't have the
75*747ca5f5SGreg Lehey# capability to pass data to scripts, so we have to mark it and paste
76*747ca5f5SGreg Lehey# it into the script.  This makes it silly to use this method for
77*747ca5f5SGreg Lehey# debugging the local system.  Instead, we have two scripts:
78*747ca5f5SGreg Lehey#
79*747ca5f5SGreg Lehey# getsyms uses the information in the "dump", and you have to paste it.
80*747ca5f5SGreg Lehey# kldsyms uses the local kld information.
81*747ca5f5SGreg Lehey#
82*747ca5f5SGreg Lehey# Improvements in gdb should make this go away some day.
83*747ca5f5SGreg Lehey#
84*747ca5f5SGreg Leheydefine kldsyms
85*747ca5f5SGreg Lehey# This will be replaced by the path of the real modules directory.
86*747ca5f5SGreg Leheyshell asf -f -k MODPATH
87*747ca5f5SGreg Leheysource .asf
88*747ca5f5SGreg Leheyend
89*747ca5f5SGreg Leheydocument kldsyms
90*747ca5f5SGreg LeheyRead in the symbol tables for the debugging machine.  This only makes sense when debugging /dev/mem; use the 'getsyms' macro for remote debugging.
91*747ca5f5SGreg Leheyend
92*747ca5f5SGreg Lehey
93*747ca5f5SGreg Lehey# Remote system
94*747ca5f5SGreg Leheydefine getsyms
95*747ca5f5SGreg Leheykldstat
96*747ca5f5SGreg Leheyecho Select the list above with the mouse, paste into the screen\n
97*747ca5f5SGreg Leheyecho and then press ^D.  Yes, this is annoying.\n
98*747ca5f5SGreg Lehey# This will be replaced by the path of the real modules directory.
99*747ca5f5SGreg Leheyshell asf -f MODPATH
100*747ca5f5SGreg Leheysource .asf
101*747ca5f5SGreg Leheyend
102*747ca5f5SGreg Lehey
103*747ca5f5SGreg Leheydocument getsyms
104*747ca5f5SGreg LeheyDisplay kldstat information for the target machine and invite user to paste it back in.  This causes the symbols for the KLDs to be loaded.  When doing memory debugging, use the command kldsyms instead.
105030b9a7cSGreg Leheyend
106030b9a7cSGreg Lehey
107030b9a7cSGreg Leheysource gdbinit.kernel
108030b9a7cSGreg Leheysource gdbinit.vinum
109b38d4c01SGreg Leheysource gdbinit.machine
110030b9a7cSGreg Lehey
111*747ca5f5SGreg Leheyecho Ready to go.  Enter 'tr' to connect to the remote target\n
112*747ca5f5SGreg Leheyecho with /dev/cuaa0, 'tr /dev/cuaa1' to connect to a different port\n
113*747ca5f5SGreg Leheyecho or 'trf portno' to connect to the remote target with the firewire\n
114*747ca5f5SGreg Leheyecho interface.  portno defaults to 5556.\n
115*747ca5f5SGreg Leheyecho \n
116*747ca5f5SGreg Leheyecho Type 'getsyms' after connection to load kld symbols.\n
117*747ca5f5SGreg Leheyecho \n
118*747ca5f5SGreg Leheyecho If you're debugging a local system, you can use 'kldsyms' instead\n
119*747ca5f5SGreg Leheyecho to load the kld symbols.  That's a less obnoxious interface.\n
120