1115926Sgrog# $FreeBSD$
2115926Sgrog# .gdbinit file for remote serial debugging.
3115926Sgrog#
4123951Sgrog# XXX Do not use this file directly.  It contains parameters which are
5123951Sgrog# XXX substituted by the kernel Makefile when you do a 'make gdbinit'.
6123951Sgrog# XXX This also removes lines starting with '# XXX'.
7123951Sgrog# XXX
8123951Sgrog# To debug kernels, do:
9123951Sgrog#
10158820Smaxim#  cd /usr/obj/usr/src/sys/GENERIC   (or kernel build directory)
11123951Sgrog#  make gdbinit
12158820Smaxim#  gdb kernel.debug
13123951Sgrog#
14123951Sgrog# Read gdb(4) for more details.
15123951Sgrog
16123951Sgrog# The following lines (down to "***** End" comment) may need to be changed
17123951Sgrog
18123951Sgrog# Bit rate for serial link.  Due to problems in the interface,
19123951Sgrog# this may not work well above 9600 bps.
20123951Sgrogset remotebaud 9600		
21123951Sgrog
22115926Sgrogset output-radix 16
23115926Sgrogset height 70
24115926Sgrogset width 120
25123951Sgrogset remotetimeout 1
26123951Sgrogset complaints 1
27123951Sgrogset print pretty
28123951Sgrogdir ../../..
29115926Sgrog
30123951Sgrog# ***** End of things you're likely to need to change.
31123951Sgrog
32123951Sgrog# Connect to remote target via a serial port.
33115926Sgrogdefine tr
34115926Sgrog# Remote debugging port
35123951Sgrogtarget remote $arg0
36115926Sgrogend
37115926Sgrog
38123951Sgrogdocument tr
39244040SeadlerDebug a remote system via serial or firewire interface.  For example, specify 'tr /dev/cuau0' to use first serial port, or 'tr localhost:5556' for default firewire port.  See also tr0, tr1 and trf commands.
40123951Sgrogend
41123951Sgrog
42123951Sgrog# Convenience functions.  These call tr.
43244040Seadler# debug via cuau0
44123951Sgrogdefine tr0
45244040Seadlertr /dev/cuau0
46123951Sgrogend
47123951Sgrogdefine tr1
48244040Seadlertr /dev/cuau1
49123951Sgrogend
50123951Sgrog# Firewire
51123951Sgrogdefine trf
52123951Sgrogtr localhost:5556
53123951Sgrogend
54123951Sgrog
55123951Sgrogdocument tr0
56244040SeadlerDebug a remote system via serial interface /dev/cuau0.  See also tr, tr1 and trf commands.
57123951Sgrogend
58123951Sgrogdocument tr1
59244040SeadlerDebug a remote system via serial interface /dev/cuau1.  See also tr, tr0 and trf commands.
60123951Sgrogend
61123951Sgrogdocument trf
62123951SgrogDebug a remote system via firewire interface at default port 5556.  See also tr, tr0 and tr1 commands.
63123951Sgrogend
64123951Sgrog
65123951Sgrog# Get symbols from klds.  Unfortunately, there are a number of
66123951Sgrog# landmines involved here:
67123951Sgrog#
68123951Sgrog# When debugging the same machine (via /dev/mem), we can get the
69123951Sgrog# script to call kldstat and pass the info on to asf(8).  This won't
70123951Sgrog# work for crashes or remote debugging, of course, because we'd get
71123951Sgrog# the information for the wrong system.  Instead, we use the macro
72123951Sgrog# "kldstat", which extracts the information from the "dump".  The
73123951Sgrog# trouble here is that it's a pain to use, since gdb doesn't have the
74123951Sgrog# capability to pass data to scripts, so we have to mark it and paste
75123951Sgrog# it into the script.  This makes it silly to use this method for
76123951Sgrog# debugging the local system.  Instead, we have two scripts:
77123951Sgrog#
78123951Sgrog# getsyms uses the information in the "dump", and you have to paste it.
79123951Sgrog# kldsyms uses the local kld information.
80123951Sgrog# 
81123951Sgrog# Improvements in gdb should make this go away some day.
82123951Sgrog#
83123951Sgrogdefine kldsyms
84123951Sgrog# This will be replaced by the path of the real modules directory.
85122033Sgreenshell asf -f -k MODPATH
86115926Sgrogsource .asf
87115926Sgrogend
88123951Sgrogdocument kldsyms
89123951SgrogRead in the symbol tables for the debugging machine.  This only makes sense when debugging /dev/mem; use the 'getsyms' macro for remote debugging.
90123951Sgrogend
91115926Sgrog
92123951Sgrog# Remote system
93123951Sgrogdefine getsyms
94123951Sgrogkldstat
95123951Sgrogecho Select the list above with the mouse, paste into the screen\n
96123951Sgrogecho and then press ^D.  Yes, this is annoying.\n
97123951Sgrog# This will be replaced by the path of the real modules directory.
98123951Sgrogshell asf -f MODPATH
99123951Sgrogsource .asf
100123951Sgrogend
101115926Sgrog
102123951Sgrogdocument getsyms
103123951SgrogDisplay 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.
104115926Sgrogend
105115926Sgrog
106115926Sgrogsource gdbinit.kernel
107115928Sgrogsource gdbinit.machine
108115926Sgrog
109123951Sgrogecho Ready to go.  Enter 'tr' to connect to the remote target\n
110244040Seadlerecho with /dev/cuau0, 'tr /dev/cuau1' to connect to a different port\n
111123951Sgrogecho or 'trf portno' to connect to the remote target with the firewire\n
112123951Sgrogecho interface.  portno defaults to 5556.\n
113123951Sgrogecho \n
114123951Sgrogecho Type 'getsyms' after connection to load kld symbols.\n
115123951Sgrogecho \n
116123951Sgrogecho If you're debugging a local system, you can use 'kldsyms' instead\n
117123951Sgrogecho to load the kld symbols.  That's a less obnoxious interface.\n
118