Disclaimer : All the postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.

bosdebug command of AIX is a very useful command to help with debugging of AIX Kernel, Device drivers and other Kernel extensions in ‘KDB’.

In this article I’ll explain on one of the very useful options of ‘bosdebug’ which could be used while debugging in KDB  to display data-structures of the source-code in a formatted manner.

Most of the Kernel/Kernel extension code i have seen have a complex tree of structures defined one within another. In my example, i’ll take the below structure defined for a dummy Kernel Extension :

On an AIX machine where the dummy kernel extension is loaded, if we want to check the values of this variable, we could do this :

Check if the symbol ‘info’ is in memory :

Use the  “display double word data”  command dd to dump the contents of symbol ‘info’ on terminal :

To make sense of the above hexadecimal dumped data we need to mark out sections based on the size of each data-type and possible padding.

Example, deciphering the first 16 bytes of data ( 1st line of dumped hex ) :

info+000000: 0001 000000012345 0000000000000002  ……#E……..
type|          id|        priority

type‘ of ‘struct prim‘ being the first short variable will need 2 bytes and the 2nd member ‘id‘ being of type ‘int‘ (size 4 bytes) would result in 2 bytes of padding between ‘type‘ and ‘id‘. Value of ‘type‘ being ‘0x0001‘ and that of ‘id‘ being ‘0x00012345‘.
priority‘ being a ‘long‘ data-type in a 64-bit binary will occupy 8 bytes.

Admittedly, a tedious process to identify the values of structure members !

For simple data-structures (for some experts, even with the structure used in this example) it could be enough to use this crude method. But as the complexity of the data-structures increases it becomes even more difficult and tedious to decipher the dumped data.

Why break your head when KDB in AIX provides such a wonderful command called “pr 🙂

pr       print             print a formatted structure at an address

“pr” command requires the definition of the symbol to be loaded into memory,  for which “-l” option of the “bosdebug” command comes very handy. This is an excerpt from the man page of the ‘bosdebug‘ command :

Following the steps mentioned in the man page i built an object “sym” which contains the symbol of “struct info” and transferred  it to the AIX partition where my Kernel Extension was loaded. Then i used the “bosdebug -l” command to load the debug symbols into memory.

After that, I could easily use the ‘pr’ command in KDB to print the formatted view of structure members :

Armed with definition of the symbol ‘info‘, KDB did the required work to identify the values of the members in structure based on their respective data-types.

With this convenience at hand, kernel developers are spared of the anxious time spent staring hard at computer screens and taking note of each byte line-by-line 😉

Happy debugging !




What do you think ?

Set your Twitter account name in your settings to use the TwitterBar Section.
%d bloggers like this: