Using the interactive debugger: Difference between revisions

From Try-AS/400
Jump to navigation Jump to search
(→‎Weblinks: Better links)
(→‎Running the program in debug mode: Hint from Stephen West)
Line 28: Line 28:
* inspect variable contents by placing the cursor appropriately, and pressing <code>F11</code>,
* inspect variable contents by placing the cursor appropriately, and pressing <code>F11</code>,
* set watches to variables by placing the cursor appropriately, and pressing <code>F17</code>.
* set watches to variables by placing the cursor appropriately, and pressing <code>F17</code>.
Especially outputting variable contents with <code>F11</code> is extremely helpful.
If you're debugging C programs, and look at a string variable with <code>F11</code>, 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
More complex constructs can be dissected likewise.


If you're done, press <code>F3</code> to end your program.
If you're done, press <code>F3</code> to end your program.

Revision as of 10:46, 4 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.

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

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

Footnotes

  1. This is a restricted command. It can be used only by user profiles
    • being member of the qpgmr group profile,
    • having *allobj authority.
  2. The crtlib command has a parameter type(*prod|*test)
  3. The presenter has a very strong accent, possibly making it very hard to understand what he's saying.