Using the interactive debugger: Difference between revisions
(→Weblinks: +link) |
(→Special case: C: decoding options) |
||
Line 37: | Line 37: | ||
In C, strings are in reality arrays of chars. Without any further instructions, the debugger will show you the base address of that array. If you wish to see the array contents, you need to instruct the debugger to ''dereference'' the address, and pull the content up to 20 elements: | In C, strings are in reality arrays of chars. Without any further instructions, the debugger will show you the base address of that array. If you wish to see the array contents, you need to instruct the debugger to ''dereference'' the address, and pull the content up to 20 elements: | ||
EVAL *variable:c 20 | EVAL *variable:c 20 | ||
The appendix <code>:c</code> can be: | |||
* <code>:a</code> for ASCII character string, | |||
* <code>:c</code> for character string, | |||
* <code>:x</code> for decode to hex, | |||
More complex constructs can be dissected likewise. | More complex constructs can be dissected likewise. |
Revision as of 13:33, 5 September 2025
With no prior experience, getting into using the interactive debugger can be quite frustrating. This article should provide a quick start to the uninitiated.
Compile program with debugging information
The debugger is more helpful, the more source information is imbedded into the final program object. For an ILE RPG application, simply
- call up
wrkmbrpdm
with the source file containing the member of the program to be debugged, - type 14 into the line with the application you wish to debug — and do not press enter yet,
- add dbgview(*all) into the command line at the screen bottom,
- and finally press enter to compile the source to the eventual *pgm object.
Switching on debug mode
This is done by issuing the command
strdebug[1]
with appropriate options. Prompt with F4
.
- The pgm option is very helpful to limit the debugging scope to the desired application(s).
- The
updprod(*yes)
is necessary if your program relies on using files from a normal[2] *prod type library.
After pressing enter, you'll be presented with the Display Module Source screen. From here you can scroll through the imbedded code to set or delete so called breakpoints. These are tags in code lines, where the normal program handling is suspended, and the debugger screen (Display Module Source) is called up again.
Running the program in debug mode
If you've set one or more appropriate breakpoints, exit the Display Module Source screen with F3
, and run your program object as intended. Most often you'll call
it from the command line:
call mypgm
The program will now run as usual until the first breakpoint is hit. Then, the Display Module Source screen is displayed again, showing the current line the program's execution was suspended due to the breakpoint. From here, you can
- single-step through the program with
F10
, - inspect variable contents by placing the cursor appropriately, and pressing
F11
, - set watches to variables by placing the cursor appropriately, and pressing
F17
.
Especially outputting variable contents with F11
is extremely helpful.
Special case: C
If you're debugging C programs, and look at a string variable with F11
, you'll get output in the message line akin to the following:
variable = SPP:F441AE89590012B2
In C, strings are in reality arrays of chars. Without any further instructions, the debugger will show you the base address of that array. If you wish to see the array contents, you need to instruct the debugger to dereference the address, and pull the content up to 20 elements:
EVAL *variable:c 20
The appendix :c
can be:
:a
for ASCII character string,:c
for character string,:x
for decode to hex,
More complex constructs can be dissected likewise.
If you're done, press F3
to end your program.
Ending debug mode
Issue the following command:
enddbg
Weblinks
- STRDBG Command | How to Debug RPGLE Program | RPGLE Free Form in AS400 (IBM i) | VCP Technology , Video on YouTube (9:29)[3]
- Related documentation for debugging ILE languages on ibm.com:
- Debugging C program strings with STRDBG, answer from Stephen West for dereferencing pointer variables