Method 2: Using the TOC and map file
Method 2 demonstrates accessing global data using the TOC and the map file. This method requires that the system is stopped in the KDB kernel debugger within a procedure of the kernel extension to be debugged. The address of the data for the demokext_j variable is calculated.
Before you can locate the address of global data using the address of the TOC and the map file, the system must be stopped in the KDB kernel debugger within a routine of the kernel extension you want to debug. To do this, set a breakpoint within the kernel extension. For more information about setting a breakpoint, see Setting breakpoints.
When the KDB kernel debugger is invoked, general purpose register number 2 points to the address of the TOC. From the map file, the offset from the start of the table of contents (TOC) to the desired TOC entry can be calculated. Knowing this offset, and knowing the address at which the TOC starts, allows the address of the TOC entry for the desired global variable to be calculated. Then, the address of the TOC entry for the desired variable can be examined to determine the address of the data.
For example, assume that the KDB kernel
debugger was invoked because of a breakpoint at line 67 of the demokext routine, and that the value for general purpose
register number 2 is 0x01304754.
To find the address of the demokext_j variable, complete the following:
To view and modify global data, do the following:
- At the
KDB(0)prompt, set a break at line 67 of the demokext routine by typing the following:b demokext+e0Note: Breaking at this location ensures that the KDB kernel debugger is invoked while within the demokext routines. - Obtain the value of General Purpose Register 2. You need that to determine the address of the TOC.
- Exit the KDB kernel debugger by typing
gon the command line. - Bring the demo program to the foreground and choose a selection.
Choosing a selection causes the demokext routine
to be called for configuration. Because a break was set, this causes
the KDB kernel debugger to be invoked. Note: The prompt changes to a dollar sign (
$). - Bring the demo program to the foreground by typing the following:
fgNote: The prompt changes to./demo. - Enter a value of
1to select the option to increment the counters within the demokext kernel extension. This causes a break at line 67 of the demokext kernel extension and the prompt changes toKDB(0). - Display the general purpose registers
by typing the following:
The data displayed should be similar to the following:dr
Using the map, the offset to the TOC entry for the demokext_j variable from the start of the TOC wasr0 : 0130411C r1 : 2FF3B210 r2 : 01304754 r3 : 01304744 r4 : 0047B180 r5 : 0047B230 r6 : 000005FB r7 : 000DD300 r8 : 000005FB r9 : 000DD300 r10 : 00000000 r11 : 00000000 r12 : 013042F4 r13 : DEADBEEF r14 : 00000001 r15 : 2FF22D80 r16 : 2FF22D88 r17 : 00000000 r18 : DEADBEEF r19 : DEADBEEF r20 : DEADBEEF r21 : DEADBEEF r22 : DEADBEEF r23 : DEADBEEF r24 : 2FF3B6E0 r25 : 2FF3B400 r26 : 10000574 r27 : 22222484 r28 : E3001E30 r29 : E6001800 r30 : 01304744 r31 : 013046480x00000008. Adding this offset to the value displayed for r2 indicates that the TOC entry of interest is at:0x0130475C.Note: The KDB kernel debugger can be used to perform the addition. In this case, the subcommand to use is hcal @r2+8. For more information about the hcal subcommand, see hcal and dcal subcommands. - Display the TOC entry for the demokext_j variable by typing the following:
This entry contains the address of the data for the demokext_j variable. The data displayed should be similar to the following:dw 0130475C
The value for the first word displayed is the address of the data for the demokext_j variable.TOC+000008: 01304744 000BCB34 00242E94 001E0518 .0GD...4.$...... - Display the data for the demokext_j variable
by typing the following:
The displayed data should indicate that the value for the demokext_j variable is still 0x0000064. This was set earlier because the breakpoint set was in the demokext routine prior to incrementing the demokext_j variable. The data displayed should be similar to the following:dw 01304744demokext_j+000000: 00000064 01304040 01304754 00000000 ...d.0@@.0GT.... - Clear all breakpoints with the following command:
ca - Exit the kernel debugger by typing
gon the command line.Note: When you exit, the demo program is in the foreground and a prompt for the next option is displayed. The kernel extension is going to run and increment the demokext_j variable. Next time it should have a value of0x00000065. - Type the Ctrl+Z key sequence to stop the demo program. At this
point, the prompt changes to a dollar sign (
$). - Place the demo program in the background by typing the following:
bg