RPG Debug – Display Pointer Data

  • Home
  • /
  • Blog
  • /
  • RPG Debug – Display Pointer Data

July 21, 2017

RPG Debug – Display Pointer Data

By NickLitten

July 21, 2017

pointer, address, based, debug, IBM i, RPG, RPGLE

Pointing at Pointers and laughing aka “How to Display Pointer Data”

RPG has all kinds of different data types. In the olden days of RPG, we only really thought in terms of character variables and numeric variables (signed numeric and packed numeric).  But as the language has advanced and adopted new technologies, methods of talking to the web and kept up with enormous increases in data sizes and hardware technology – lots of new variables have become available to us: variable length fields, timestamps, date fields, binary, graphics, blobs, clobs and of course – POINTERS.

So what is a Pointer?

I like to think that a pointer is like an address to a house – it’s not the house itself –  it is just pointing at something and leading you to it. So, you cant DEBUG an address and expect to the the contents of the house. You need to follow it to the house first. Once you understand that, you might ask how to Display Pointer Data while debugging.

Debugging programs that use pointers manes you need to format your requests for “looking at the pointer data” in a a slightly different way.

I just found this excellent section in the ILE RPG PROGRAMMERS GUIDE which says:

Displaying Data Addressed by Pointers

If you want to see what a pointer is pointing to, you can use the EVAL command with the :c or 😡 suffix. For example, if pointer field PTR1 is pointing to 10 bytes of character data,

EVAL PTR1:c 10

will show the contents of those 10 bytes.

You can also show the contents in hexadecimal using:

EVAL PTR1:x 10

This would be especially useful when the data that the pointer addresses is not stored in printable form, such as packed or binary data.

If you have a variable FLD1 based on basing pointer PTR1 that is itself based on a pointer PTR2, you will not be able to evaluate FLD1 using a simple EVAL command in the debugger.

Instead, you must explicitly give the debugger the chain of basing pointers:

===> EVAL PTR2->PTR1->FLD1

For example, if you have the following definitions:

debug RPG Pointers
dcl-s pPointers pointer; dcl-ds pointers based(ppointers);   p1 pointer;   p2 pointer; end-ds; dcl-s data1 char(10) based(p1); dcl-s data2 char(10) based(p2);

you can use these commands in the debugger to display or change the values of DATA1 and DATA2:

===> eval pPointers->p1->data1

===> eval pPointers->p2->data2 = 'new value'

To determine the expression to specify in the debugger, you start from the end of the expression with the value that you want to evaluate: data1

Then you move to the left and add the name that appears in the BASED keyword for the definition of data1, which is p1: p1->data1

Then you move to the left again and add the name that appears in the BASED keyword for the definition of p1, which is pPointers: pPointers->p1->data1

The expression is complete when the pointer that you have specified was not defined with the BASED keyword. In this case, pPointers is not defined as based, so the debug expression is now complete.

===> eval pPointers->p1->data1
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>