return, return

You can cancel execution of a function call with the return

expression

command. If you give an expression argument, its value

 

is used as the return value from the function value.

When you use return, GDB discards the selected stack frame (and all frames within it). You can think of this as making the discarded frame return prematurely. If you wish to specify a value to be returned, give that value as the argument to return.

This pops the selected stack frame (see “Selecting a frame” (page 73)), and any other frames inside of it, leaving its caller as the innermost remaining frame. That frame becomes selected. The specified value is stored in the registers used for returning values of functions.

The return command does not resume execution; it leaves the program stopped in the state that would exist if the function had just returned. In contrast, the finish command (see “Continuing and stepping” (page 64)) resumes execution until the selected stack frame returns naturally.

11.5 Calling program functions

call expr Evaluate the expression expr without displaying void returned values.

You can use this variant of the print command if you want to execute a function from your program, but without cluttering the output with void returned values. If the result is not void, it is printed and saved in the value history.

For the A29K, a user-controlled variable call_scratch_address specifies the location of a scratch area to be used when GDB calls a function in the target. This is necessary because the usual method of putting the scratch area on the stack does not work in systems that have separate instruction and data spaces.

11.6 Patching programs

By default, GDB opens the file containing the executable code of your program (or the corefile) as read-only. This prevents accidental alteration to machine code; and it also prevents you from intentionally patching your program binary.

If you would like to be able to patch the binary, you can specify that explicitly with the set write command. For example, you might want to turn on internal debugging flags, or even to make emergency repairs.

set write on, If you specify 'set write on', GDB opens executable and core set write off files for both reading and writing; if you specify 'set write

off' (the default), GDB opens them as read-only.

If you have already loaded a file, you must load it again (using the exec-fileor core-filecommand) after changing set write, for your new setting to take effect.

122 Altering Execution

Page 122
Image 122
HP gnu source-level debugger 5992-4701 manual Calling program functions, Patching programs, Return , return