• Keine Ergebnisse gefunden

User'sManual Instant-C" '

Im Dokument Rational if if it If LQ!r~AL m (Seite 46-49)

RUNNING PROGRAMS

5.3 #run command

So that you can test the main function of programs that

will

become separate .EXE or .CMD

files,

we have

provided the #run command. For more details, see the description of the #run command in Chapter 6.

5.4 Debuqqinq Overview

Instant-C has powerful debugging capabilites that

are always available to you. No special libraries,

compiler options, or separate

utilities

are

necessary. The debugging

facilities

offered by

Tnstant-c

fall

into three categories:

Interpretation

Because Instant-C has the interactions of an interpreter, you can perform a numberimpossibleof actions that are

difficult

or

with a compiler. Immediate

execution lets you call a function directly to view

its

value and any

side-effects. Arguments can be varied

each tinte you invoke the function to verify proper operation. Variables can be displayed or modified at any time.

Execution of your program may be

interrupted to allow you to examine

its

progress or to pursue a different path of execution.

Fast Modification

Because

it

is sq fast and easy to change

your programs, debugging techniques

formerly called "brute-force" methods

are now elegant and efficient. For

example,

printf

calls can be inserted in

a function to display the values of certain variables, or to record the

Page 32 """" """ " chapter 5 l-.:'l,',.:'·.i||' '-'I'

!·y líc?!|[: ":,l, ".·\ .,I,-"' - " ?

' User's Manual

lnstant"C"

,,NN,N, ,,,,R,M,

occurance of sorne events. The function

can be tested right away, and once the information is obtained, the debugging

code can be removed in a watter of

seconds. Thus, Instant-c's debugging capabilities can be extended and customized by your own c Language programming.

Debugging commands

Commands are available to specify

functions that are to be traced, to start, continue, or stop execution of

your program, and to examine variables

and the program execution history.

5.5 Interruptinq Your Program

Most debugging

activities

take place after your

program has started running and is interrupted.

Interruptions can be voluntary: a call is made to a traced function (see #trace command), a call

is

made

to the breakpoint function

(i.e.,

_()) function, or a Control-Break interrupt or control-c interrupt is

issued from the keyboard. The keyboard interrupts

are available on MS-DOS and pc-dos systems only.

Involuntary interrupts include division by zero,

stack overflow, call to an undefined function, or taking the difference of dissimilarly typed pointers. A call to the exit function is considered

an interruption so that yÓu can see how your program

terminated.

When an interruption occurs, Instant-C displays a

message describing the interruption. For example, entering

#

i

= 3/0

Results in:

** Execution interrupted: division by zero in

command line

User'sManual fV

Instant-C

running programs

After the message is displayed, you are at interpreter level. You can issue any command,

execute any statement, or (usually) resume execution of your program.

The stack, or history of function calls to the interruption, is preserved, and you can look at

it

with the #back command. At interpreter level, you

can display variables, evaluate expressions, and execute c language statements including calls to functions. The C language you enter to the interpreter is evaluated in the context of the function that was interrupted, so '{ou can examine or

modify local, or automatic, variables declared in that function.

We use the term "active" 'to describe functions that

are on the stack. The interpreter can execute in the context of any active function by using the €Loca1

command. #local specifies the function to use.

calling other functions from the interpreter may

result in another interruption. Interruptions

themselves may be stacked or nested. The back

command shows the level of any stacked

interruptions. The #reset command allows you discard or unstack any or

all

levels. Levels should be

discarded when you no longer need them, to prevent

confusion and to avoid possible stack overflows.

5.6 Debugqer Commands

The debugger commands are

fully

described in

chapter 6, but an overview of each is offered here sc) that you can see how they work together.

The commands

fall

into several categories: those that resuine or abort interrupted executions (#go,

#step, and #reset), those that manage breakpoints

(#trace and #untraee), and those that display values

(#Pc, #pd, #po, #ps, #px, and #local).

Any execution that has been interrupted can be resumed in several ways. Resuming execution is much

Page 34 Chapter 5 {".('Ig,'"\: ),| '9üa

l:t Rc¿!'('rí,,1,

, ..,/, ,, '.· t (

" User'sManual

Instant-C

RUNNING PROGRAMS

like a executing return C language statement from the interpreter. The various ways your can resume your program are:

#go resumes execution at the poínt of

interruption, and proceeds

untíl

your

program returns to the interpreter or

another interruption occurs.

#step resumes execution, but

will

breakpoint

at the end of the next statement. This is the finest level of control, and allows you step through your program or portions of your program, and observe

the flow of control.

#step return

resumes execution, but

will

breakpoint

when the interrupted function returns.

This command is useful in quickly

bypassing functions that are not of direct concern to your debugging. For

example, you have been single stepping a function that calls

printf,

step return

will let printf

execute at

'full

speed'

until it

completes. You can then resume

single stepping

if

appropriate.

#step out resumes execution, but

will

breakpoint

when the current function calls another function or returns. This allows you to follow the execution of your program by stepping from function call to function call or return, without line-by-line detail.

#step in resumes execution, and like #step

will

break at each statement, but

will

not

notify you of calls to other functions.

This makes

it

easier to use a single

command to examine the execution of a function.

#step exec c statement

unlike the other step commands, step

Im Dokument Rational if if it If LQ!r~AL m (Seite 46-49)