shithub: 9ferno

ref: b502a62da2ec6058923db94f87ecc2d29db2fa77
dir: /man/3/dbg/

View raw version
dbg \- remote kernel debugging
.B "bind -b '#b' /dev"
.B /dev/dbgctl
.B /dev/dbglog
.BI "echo r >/dev/dbgctl"
.I Dbg
allows a native kernel to be debugged remotely,
by means of a simple protocol, typically run on a serial port
.IR eia (3)).
.IR acid (10.1)
debugger uses the protocol for instance; see its
.B -R
.I Dbg
uses the values of several global variables set by the kernel configuration file (see
.IR conf (10.6)),
all of which default values.
The variables and default values are listed below:
int dbgstart = 0;
char	*dbgdata = "#t/eia0";
char	*dbgctl = "#t/eia0ctl";
char	*dbgctlstart = "b19200";
char	*dbgctlstop = "h";
char	*dbgctlflush = "f";
Different values can be set by including similar declarations,
with values as desired, in the
.B code
section of the configuration file.
.I Dbg
uses the values as follows:
.TP \w'\f5dbgctlflushxx\fP'u
.PD 0
.B dbgstart
if non-zero, start the debugger protocol on the
configured connection during driver initialisation (system startup);
otherwise it must be started explicitly by the
.B r
control request (see below)
.B dbgdata
data file for the debugging connection
.B dbgctl
control file for the debugging connection
.B dbgctlstart
control request to initialise link (eg, baud rate)
.B dbgctlstop
control request to hang up link
.B dbgctlflush
control request to write to flush input and output on link
.I Dbg
serves two files that control and monitor its operation.
.B Dbgctl
accepts several textual commands; normally only
.B r
is needed:
.BI d " dbgdata"
set the value of
.B dbgdata
to the value given as an argument
.BI c " dbgctl"
.PD 0
.BI i " dbgctlstart"
.BI h " dbgctlstop"
.BI f " dbgctlflush"
set the value of the corresponding control variable to the value of the first argument
.B r
start running the debugger protocol (not needed if
.B dbgstart
was non-zero at boot)
.B s
stop running the debugger protocol; stop and flush the link
When read,
.B dbgctl
yields a single line showing the status of the device
.RB (` running '
.RB ` stopped ')
and the current values of the debugger control
variables listed above.
.B Dbglog
is a read-only text file containing lines representing debugger events,
one per line.
It is mainly useful for checking the operation of the device, or debugging new
.IR acid (10.1)
.SS Debug protocol
The protocol is subject to change.
The host running the debugger and the target to be debugged
exchange 10-byte messages containing a one byte message type
and 9 bytes of data.
Bytes unused by a given type are set to zero.
Normally the host sends one of the T-messages below and
receives the corresponding R-message, or
.BR Rerr .
(These are unrelated to the T-messages and R-messages of
.IR intro (5).)
Exceptionally, the target sends the first message, an
.B Rerr
to reset the protocol, and thus the debugger is notified if the target
is rebooted during a debugging session and can reset its own state.
Values, including addresses, are sometimes represented textually
in hexadecimal, but are usually in binary as a single byte, or an array of 4 bytes,
high-order byte first (big endian).
The term
.I process
here refers exclusively to those created directly or indirectly by
.IR kproc (10.2),
not to Limbo processes, which are not visible directly through
the protocol (although it is possible to write
.IR acid (10.1)
functions that interact through
.I dbg
with the Inferno data structures representing
the state of the Dis virtual machine).
Many requests read or write the memory or state of the
.IR "current process"
set by the
.B Tproc
message (see below).
Addresses are always 32 bits.
An address below the size of
.B Ureg
(saved register state) for the target is interpreted as an offset within the saved
state for the current process.
Otherwise it refers to an address in kernel virtual memory.
Currently in native Inferno all processes share the same address space.
The message type names used below
are assigned values by declarations in
.BR /include/rdbg.h .
The following messages are currently implemented:
.TP \w'Tstart'u
.PD 0
.B Terr
.BI Rerr " reason\fR[9]\fR"
The last message failed for the given
.IR reason ,
a text string:
.BR reset ,
the target or debug driver was restarted;
.BR count ,
bad count;
.BR unk ,
unknown command;
.BR inval ,
invalid parameter;
.BR pid ,
no such process;
.BR unsup ,
unsupported action;
.BR notstop ,
action requires process to be stopped first.
.BI Tmget " addr\fR[4]\fP n\fR[1]\fP"
.I n
bytes of memory from
.IR addr ;
.I n
must be no greater than 9
.BI Rmget " data\fR[9]\fP"
.I data
requested by
.B Tmget
.BI Tmput " addr\fR[4]\fP n\fR[1]\fP data\fR[4]\fP"
Write the first
.I n
bytes of
.I data
to memory at
.IR addr ,
and flush the data and instruction caches for that region;
.I n
must be no greater than 4
.BI Rmput
Reply to a successful
.B Tmput
.BI Tproc " pid\fR[4]\fP"
Set the current process to the one with integer process ID
.I pid
for subsequent requests.
.BI Rproc " addr\fR[8]\fP"
.I Addr
is the address in hexadecimal text of the
.B Proc
structure for process
.I pid
in the corresponding
.BR Tproc .
.BI Tstatus " pid\fR[4]\fP"
Request the status of process
.I pid
leaving the current process ID unchanged.
.BI Rstatus " status\fR[9]\fP"
Return the textual status of the process
as a text string, currently one of:
.BR Dead ,
.BR Moribund ,
.BR Ready ,
.BR Scheding ,
.BR Running ,
.BR Queueing ,
.BR Wakeme ,
.BR Broken ,
.BR Stopped ,
.BR Rendezvous ,
or if invalid, the state value as a hexadecimal number.
.BI Trnote " pid\fR[4]\fP"
Retrieve the note (trap status) for the given
.I pid
.BI Rrnote " status\fR[9]\fP"
Provide the textual trap
.I status
for the requested process (currently always returns null status)
.BI Tstop " pid\fR[4]\fP"
Tell the kernel to stop running process
.I pid
in debugging state
.B Stopped
when it next appears in the scheduler.
.BI Rstop
Reply to successful
.B Tstop
.BI Tstart
Cancel a previous
.BR Tstop ;
if the process has already stopped, make it ready to run.
.BI Rstart
Reply to successful
.B Tstart
.BI Tcondbreak " val\fR[4]\fP op\fR[4]\fP"
.I op
.BR d ,
remove and delete the breakpoint with ID
.IR val .
All other operations help
create a conditional breakpoint, providing a possibly empty list of operations
representing a conditional expression in Reverse Polish is followed
by a breakpoint request,
each expression element represented by a single
.B Tcondbreak
.I Op
is a single character representing an operation, with
.I val
(integer, address, process ID) as a parameter.
The operator
.B n
should appear first; it assigns the
breakpoint an ID number
.I val
(no greater than 255).
Expression primaries are:
.BI k " val,"
true if process
.I val
is at this breakpoint;
.BI b " val,"
true if program counter is
.IR val ;
.BI p " val,"
.I val
as a 32-bit literal.
Expression operators are:
.B *
(indirect, yielding 32-bit value);
.B &
(bit-wise AND);
.B =
(values equal);
.B !
(values not equal);
.B a
(logical AND);
.B o
(logical OR).
Although the expression is interpreted following Reverse Polish notation,
when transmitted, the
.B b
operation is sent last (to mark the end of the sequence and create the breakpoint),
but is moved to the start of the expression before evaluation.
.BI Rcondbreak
Reply to successful
.BR Tcondbreak .
.BI Tstartstop " pid\fR[4]\fP"
If the process
.I pid
is not stopped, return
.B Rerr
.BR notstop .
Otherwise, if the process is not stopped at
a breakpoint, start it, and wait for it to reach a breakpoint
that evaluates `true'
.BI Rstartstop " id\fR[1]\fP"
Process has stopped at breakpoint with the given
.I id
.BI Twaitstop
Unimplemented. See
.BR Tstartstop .
.BI Rwaitstop
.BI Tkill " pid\fR[4]\fP note\fR[5]\fP"
Kill process
.I pid
with the given textual
.IR note .
.BI Rkill
Reply to successful
.BR Tkill .
.B /os/port/devdbg.c
.B /os/*/*break.c
.B /os/*/trap.c
.IR acid (10.1)
The protocol is not itself error-detecting let alone error-correcting, although that normally does not
matter for debugging even
over a serial line, provided the connection is reasonably sound.