|
Several gdb macros useful for kernel debugging are defined in gdb
scripts available from the downloads page.
The scripts containing these macros are sourced in gdb to load their
definitions into gdb. The recommended way of loading these macros is to
source these gdb scripts from a .gdbinit file kept in the
kernel source top level directory. gdb reads .gdbinit file in
the directory where it is executed and runs commands given in the file.
Hardware debugging
kgdb versions 1.7 onwards support hardware breakpoint commands from
gdb, so following commands don't apply to them. Use gdb hardware
watchpoint commands instead.
kgdb supports debugging capabilities available in IA32 hardware.
Three types of IA32 hardware breakpoints are supported by kgdb: data
write watchpoint, instruction execution breakpoint and data access
watchpoint. The difference between hardware breakpoints and
software breakpoints in gdb is that gdb modifies code for
inserting a breakpoint, whereas hardware breakpoints without modifying
the code. Only 4 hardware breakpoints and watchpoints are available.
Each hardware breakpoint can be of one of the three types: execution,
write, access.
- An Execution breakpoint is triggered when code at the breakpoint
address is executed.
- A write breakpoint ( aka watchpoints ) is triggered when memory
location at the breakpoint address is written.
- An access breakpoint is triggered when memory location at the
breakpoint address is either read or written.
As hardware breakpoints are available in limited number, software
breakpoints ( break command in gdb ) should be used instead of
execution hardware breakpoints whenever possible.
A write or access hardware breakpoint can be defined over an address
range of 1 to 4 bytes. The address range length is called length of the
breakpoint. Length of an access or a write breakpoint defines length of
the datatype to be watched. The length is 1 for char ( 1 byte ), 2 for
short ( 2 bytes ) and 3 for int (4 bytes ).
Commands hwebrk, hwwbrk and hwabrk place
an execution, a write and an access breakpoint respectively. Use hwrmbrk
command to remove a hardware breakpoint. These commands take following
arguments.
- breakpointno: 0 to 3
- length: 1 to 3
- address: Memory location in hex ( without 0x ) e.g c015e9bc
Syntax of the three commands is as follows:
hwebrk breakpointno address
hwwbrk breakpointno length address
hwabrk breakpointno length address
hwrmbrk breakpointno
The command exinfo can be used to find which hardware
breakpoint occurred.
A script hwdebugmacros
contains definitions of these macros.
( Examples of using hardware breakpoints to be added )
Process information
psmacros file contains definitions
of process information macros.
The ps macro lists process ids and their names. It is useful
for thread analysis.
The psname macro prints name of the process with given id.
( Examples of using the macros to be added )
Miscellaneous
Several gdb macros useful for kernel debugging are defined in gdb
scripts available from the downloads page.
The scripts containing these macros are sourced in gdb to load their
definitions into gdb. The recommended way of loading these macros is to
source these gdb scripts from a .gdbinit file kept in the
kernel source top level directory. gdb reads .gdbinit file in
the directory where it is executed and runs commands given in the file.
|