Whoriarsty.com

Who runs the world? Tech.

Technology

ISeries Source Debugger: Advanced Debugging Tips

Not long ago, a friend of mine had a problem with a show that had just ended. We were using the source code debugger to find out what was causing your problem. We finally discovered the problem, but in the course of our work, we came across some debugger commands and options that you were not aware of before. Now I’m not going to say that I know everything about the IBM source code debugger, but I’ve been using it for a long time. I was surprised to discover something new, so I thought I would share what I learned with you.

% INDEX Built-in function

The% INDEX function is one of the functions that you were not aware of until recently. It is very useful when manipulating multiple-occurrence data structures. It is even more useful when used in conjunction with the built-in value _QRNU_DSI_xxxx (where xxxx = the name of a multiple-occurrence data structure). The EVAL _QRNU_DSI_xxxx command will return the current occurrence of a multiple-occurrence data structure. This is often a very useful thing to know during program execution, and as far as I know, this is the only way to get it. By using the% INDEX function, you can also change the current occurrence of a multi-occurrence data structure. See below.

d WorkMultDS1 occurs ds (30)

d StringA 10a

d StringB 25a

To find the current occurrence of the data structure without changing it:

Command: EVAL _QRNU_DSI_WorkMultDS1

Outcome: 1 (or whatever the current occurrence of WorkMultDS1 is)

To change the current occurrence:

Command: WorkMultDS1 =% INDEX (12)

Outcome: WorkMultDS1 =% INDEX (12) = 12

After issuing the above command, the interrogated subfields will reflect the values ​​of the twelfth occurrence of the data structure.

% SUBSTR Built-in function

This function is very convenient when working with large strings. Using the EVAL function alone will only display the first 500 characters of a field. As a side note, the easy solution to that problem is to add the type and length to the EVAL function as shown below:

This command will display the first 2000 characters of the Long_String_Name variable in character format:

Command: EVAL Long_String_name: C 2000

This command will display the first 2000 characters of the Long_String_Name variable in hexadecimal format:

Command: EVAL Long_String_name: X 2000

The hex display is important when displaying data that contains packed decimal or binary data. But we are not talking about the EVAL function. The SUBSTR function will do exactly what the name implies; will display a substring or part of a string value. Look at the examples to be continued.

Suppose StringFldA = ‘Now is the time for all good men …’

Command: EVAL% SUBSTR (StringFldA 12 4)

Outcome: % SUBSTR (StringFldA 12 4) = ‘time’

Not surprisingly, you can also use the% SUBSTR function to set the value of a specific part of a string. Sometimes this is a much more useful way to use this feature. An example of this usage is shown below.

Suppose StringFldA = ‘Now is the time for all good men …’

Command: EVAL% SUBSTR (StringFldA 12 4) = ‘bla’

Outcome: % SUBSTR (StringFldA 12 4) = ‘blah’

To see the complete string, use the following command:

Command: EVAL StringFldA

Outcome: StringFldA = ‘Now is the blah for all good men …’

The% SUBSTR function can also be used to set a conditional breakpoint or watchdog condition. As an example, the code shown below will stop execution only when StringFldA positions 12-15 are ‘blah’:

Command: BREAK 100 when% SUBSTR (StringFldA 12 4) = ‘blah’

Or you can observe the change of those same positions using this clock condition:

Command: CLOCK% SUBSTR (StringFldA 12 4)

After issuing the above command, each time the content of positions 12 to 15 changes, the execution of the program stops and you are notified.

EQUATE function

More and more often I come across field names that are really long. Don’t get me wrong here, I think this is great. But I don’t type as well, so a 25-character field name has a much better chance of being misspelled than an old 6-character one (even if the 25-character one is much more understandable). So if you don’t write well (or just don’t like to write, like I do), use the EQUATE debugging function. This function allows you to define an “alias” for a field name, expression, or command. Take the example below.

Command: EQUATE SmName This_is_a_really_long_field_name

Then you can find the value of “This_is_a_really_long_field_name” by entering the command shown below:

Command: EVAL SmName

The EQUATE command can also be used to create a macro … more or less. This can be done by “aliasing” a full debug command.

Command: EQUATE SmCmd EVAL% substr (StringA, 5,5)

Now, by simply typing SmCmd and pressing Enter, you can display the value of positions 5 through 9 of the StringA variable.

So the next time you start testing a program or chasing a bug, remember them and you may save yourself some headaches.

LEAVE A RESPONSE

Your email address will not be published. Required fields are marked *