GEOS SDK TechDocs
|
|
5.2 Attaching and Detaching
|
5.4 Examining and Modifying Memory
The commands in this group are used to stop at specified breakpoints in an application's code and then step through the code line by line if necessary. These commands are often used with each other to examine critical areas in the application source code.
stop, brk, go, cbrk, spawn
The
stop
,
brk
and
cbrk
commands are used to set breakpoints. The breakpoint commands have many subcommands controlling the actions and attributes of a particular breakpoint.
The
cbrk
command sets breakpoints to be evaluated by the Swat stub;
brk
sets them to be evaluated by Swat. The Swat stub can evaluate the conditions much faster than Swat, but
cbrk
has certain limitations: only a limited number of breakpoints can be set using
cbrk
, and these breakpoints can only compare registers when the breakpoint is hit with a given set of criteria.
stop in <class>::<message> [if <expr>] stop in <procedure> [if <expr>] stop in <address-history-token> [if <expr>] stop at [<file:]<line> [if <expr>] stop <address> [if <expr>]
This is the main command to use when setting breakpoints in C programs. The "stop in" command will set a breakpoint at the beginning of a procedure, immediately after the procedure's stack frame has been set up. The "stop at" command will set a breakpoint at the first instruction of the given source line. If no <file> is specified, the source file for the current stack frame is used. If a condition is specified by means of an "if <expr>" clause, you should enclose the expression in curly braces to prevent any nested commands, such as a "value fetch" command, from being evaluated until the breakpoint is hit.
brk [<sub-command>]
The
brk
(breakpoint) command is used for setting nearly all breakpoints in an application's code. The simplest way to use it is to type
brk
with a single
addr
argument. The address is usually a routine name for a suspect procedure, and when the breakpoint is reached the code-stepping commands can be used to examine it carefully. The
brk
command can also create conditional breakpoints which will only be taken if certain conditions are satisfied. Once set, a breakpoint is given an integer number which can be obtained using the
list
subcommand (see Breakpoints
).
brk <addr> [<command>]
brk
command without any subcommands sets an unconditional breakpoint at the address specified in
addr
. If the
command
argument is passed, the given swat command will be carried out when the breakpoint is hit.
brk delete <break>*
clear
, above.
brk enable <break>*
brk disable <break>*
brk list [<addr>]
addr
is given, it returns the breakpoint numbers of all breakpoints set at the given address.
(geos:0) 4 => brk list Num S Address Patient Command/Condition 1 E loader::kcode::LoaderError all echo Loader death due to [penum LoaderStrings [read-reg ax]] expr 1 2 E kcode::FatalError all why assign kdata::errorFlag 0 expr 1 3 E kcode::WarningNotice all why-warning 4 E kcode::CWARNINGNOTICE all why-warning (geos:0) 5 => stop in Mess1Draw brk5 (geos:0) 6 => brk list Num S Address Patient Command/Condition 1 E loader::kcode::LoaderError all echo Loader death due to [penum LoaderStrings [read-reg ax]] expr 1 2 E kcode::FatalError all why assign kdata::errorFlag 0 expr 1 3 E kcode::WarningNotice all why-warning 4 E kcode::CWARNINGNOTICE all why-warning 5 E <ss1::MESS1_TEXT::Mess1Draw+10 all halt (geos:0) 7 => brk dis brk4 (geos:0) 8 => brk list Num S Address Patient Command/Condition 1 E loader::kcode::LoaderError all echo Loader death due to [penum LoaderStrings [read-reg ax]] expr 1 2 E kcode::FatalError all why assign kdata::errorFlag 0 expr 1 3 E kcode::WarningNotice all why-warning 4 D kcode::CWARNINGNOTICE all why-warning 5 E <ss1::MESS1_TEXT::Mess1Draw+10 all halt (geos:0) 9 =>
go [<address-expressions>]
The go command sets a one-time breakpoint and resumes execution on the target PC. The net effect of this is to let the target go until it hits a given address, then stop.
cbrk [<sub-command>]
The
cbrk
(conditional breakpoint) command is used to set fast conditional breakpoints. This command is very similar to the
brk
command above, except that the condition is evaluated by the Swat stub--this increases the speed of the evaluation. There are, however, certain restrictions on the
cbrk
command: only a limited number of breakpoints can be set (eight), and the scope of the evaluation is limited to comparing word registers (or a single word of memory) to a given set of values.
In the following descriptions,
criteria
stands for a series of one or more arguments of the form:
<register> <op> <value>
criteria
is given the breakpoint becomes a standard, unconditional breakpoint.spawn <patient-name> [<addr>]
The
spawn
command is used to set a temporary breakpoint in a process or thread which has not yet been created. The arguments are
patient-name
addr
This command is used to stop the geode before any of its code can be run, allowing breakpoints to be set in the desired routines. If you could not stop the machine in this manner, the application could hit a buggy routine before a breakpoint could be set in that routine. The
spawn
command can also be used to catch the spawning of new threads which is useful to keep track of the threads being used by an application (see The spawn Command
).
Swat Display 3-5 The spawn Command
(geos:1) 12 => spawn mess1 Mess1Draw Re-using patient math Re-using patient borlandc Re-using patient mess1 Thread 0 created for patient mess1 Interrupt 3: Breakpoint trap Stopped in Mess1Draw, line 211, "C:OMNIGO/Appl/SDK_C/MESS1/MESS1.GOC" Mess1Draw(GStateHandle gstate) /* GState to draw to */ (mess1:0) 13 =>
srcwin, istep, sstep
Once an application is stopped at a breakpoint and you want to examine the code line by line, you can use the commands
istep
(instruction step) and
sstep
(source step). These enter the
instruction step mode
or
source step mode
to examine and execute the application code line by line.
The subcommands for both
istep
and
sstep
are nearly the same and are used for actions including stepping to the next line, skipping the next instruction, or exiting the step mode and continuing the execution of the application. The
istep
and
sstep
commands are very similar except that
istep
is used when stepping through assembly source code (thus stepping through instructions), and
sstep
is used for stepping through C source code.
srcwin <numlines> [view]
The srcwin command will display the source code surrounding the presently executing code any time execution is stopped. The presently executing line will be highlighted. You may set breakpoints with the mouse by clicking on the line numbers which appear to the side. To scroll the srcwin buffer use the arrow keys, the <PgUp> key, and the <PgDn> key.
istep [<default subcommand>]
sstep [<default subcommand>]
These two commands are used to single-step through code, executing one or more instructions at a time. The
default subcommand
argument determines the action taken by Swat when the Return key is pressed. For example, the command
[hello3:0] 7 => istep n
will enter instruction step mode, and subsequently pressing the Return key will have the same effect as pressing
n
. If no default command is given, pressing Return has the same effect as pressing
s
.
The subcommands to the
istep
and
sstep
commands are
n
subcommand was given.
o
differs from
n
in that it executes all instructions in a macro without further interpretation and can only be used with
istep
. If a breakpoint other than for the next instruction is hit, it will take effect as long as the above conditions are met.
n
and
o
but will stop whenever a breakpoint is hit even if the frame is different.
O
will execute all instructions in a macro without further interpretation, and it can only be used with
istep
. If a breakpoint other than one for the next instruction is hit, it will take effect as long as the above conditions are met.
istep/sstep
and return to the command level. These subcommands are used when a point in the code is reached where another command needs to be used--to examine memory, for example.
istep
and continues the execution of the application. When GEOS next stops, Swat will return to the command prompt.
ObjMessage()
and
ObjCallInstanceNoLock()
assembly routines.
GEOS SDK TechDocs
|
|
5.2 Attaching and Detaching
|
5.4 Examining and Modifying Memory