Using the interactive debugger: Difference between revisions

From Try-AS/400
Jump to navigation Jump to search
(→‎Weblinks: *DS4 mode)
 
(5 intermediate revisions by the same user not shown)
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.
=== Special case: C ===
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
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.


If you're done, press <code>F3</code> to end your program.
If you're done, press <code>F3</code> to end your program.
Line 38: Line 54:
* [https://www.youtube.com/watch?v=suwow1bGh1o STRDBG Command | How to Debug RPGLE Program | RPGLE Free Form in AS400 (IBM i) | VCP Technology ], Video on YouTube (9:29)<ref>The presenter has a very strong accent, possibly making it very hard to understand what he's saying.</ref>
* [https://www.youtube.com/watch?v=suwow1bGh1o STRDBG Command | How to Debug RPGLE Program | RPGLE Free Form in AS400 (IBM i) | VCP Technology ], Video on YouTube (9:29)<ref>The presenter has a very strong accent, possibly making it very hard to understand what he's saying.</ref>
* Related documentation for debugging ILE languages on ''ibm.com'':
* Related documentation for debugging ILE languages on ''ibm.com'':
** [https://www.ibm.com/docs/en/i/7.6.0?topic=guide-debugging-programs for C/C++]
** [https://www.ibm.com/docs/en/i/7.6.0?topic=guide-debugging-programs ''Debugging Programs'' for C/C++]
** [https://www.ibm.com/docs/en/i/7.6.0?topic=programs-debugging-program for COBOL]
** [https://www.ibm.com/docs/en/i/7.6.0?topic=programs-debugging-program ''Debugging Programs'' for COBOL]
** [https://www.ibm.com/docs/en/i/7.6.0?topic=handling-debugging-programs for RPG]
** [https://www.ibm.com/docs/en/i/7.6.0?topic=handling-debugging-programs ''Debugging Programs'' for RPG]
* [https://archive.midrange.com/c400-l/202509/msg00002.html Debugging C program strings with STRDBG], answer from Stephen West for dereferencing pointer variables
* [http://www.ibm.com/support/pages/debugger-does-not-display-source-wide-screen-mode Debugger Does Not Display Source in Wide Screen Mode], ibm.com


== Footnotes ==
== Footnotes ==

Latest revision as of 18:30, 6 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

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.