Online Book Reader

Home Category

Running Linux, 5th Edition - Matthias Kalle Dalheimer [398]

By Root 1344 0

} *

(gdb)

If you're interested in examining memory on a more fundamental level, beyond the petty confines of defined types, you can use the x command. x takes a memory address as an argument. If you give it a variable, it uses the value of that variable as the address.

x also takes a count and a type specification as an optional argument. The count is the number of objects of the given type to display. For example, x/100x 0x4200 displays 100 bytes of data, represented in hexadecimal format, at the address 0x4200. Use help x to get a description of the various output formats.

To examine the value of mydisplay->vendor, we can use:

(gdb) x mydisplay->vendor

0x9de70 <_end+35376>: 76 'L'

(gdb) x/6c mydisplay->vendor

0x9de70 <_end+35376>: 76 'L' 105 'i' 110 'n' 117 'u' 120 'x' 0 '\000'

(gdb) x/s mydisplay->vendor

0x9de70 <_end+35376>: "Linux"

(gdb)

The first field of each line gives the absolute address of the data. The second represents the address as some symbol (in this case, _end) plus an offset in bytes. The remaining fields give the actual value of memory at that address, first in decimal, then as an ASCII character. As described earlier, you can force x to print the data in other formats.

Getting Information

The info command provides information about the status of the program being debugged. There are many subcommands under info; use help info to see them all. For example, info program displays the execution status of the program:

(gdb) info program

Using the running image of child process 138.

Program stopped at 0x9e.

It stopped at breakpoint 1.

(gdb)

Another useful command is info locals, which displays the names and values of all local variables in the current function:

(gdb) info locals

inimage = (struct {...} *) 0x2000

outimage = (struct {...} *) 0x8000

(gdb)

This is a rather cursory description of the variables. The print or x commands describe them further.

Similarly, info variables displays a list of all known variables in the program, ordered by source file. Note that many of the variables displayed will be from sources outside your actual program—for example, the names of variables used within the library code. The values for these variables are not displayed because the list is culled more or less directly from the executable's symbol table. Only those local variables in the current stack frame and global (static) variables are actually accessible from gdb. info address gives you information about exactly where a certain variable is stored. For example:

(gdb) info address inimage

Symbol "inimage" is a local variable at frame offset -20.

(gdb)

By frame offset, gdb means that inimage is stored 20 bytes below the top of the stack frame.

You can get information on the current frame using the info frame command, as so:

(gdb) info frame

Stack level 0, frame at 0xbffffaa8:

eip = 0x9e in main (main.c:44); saved eip 0x34

source language c.

Arglist at 0xbffffaa8, args: argc=1, argv=0xbffffabc

Locals at 0xbffffaa8, Previous frame's sp is 0x0

Saved registers:

ebx at 0xbffffaa0, ebp at 0xbffffaa8, esi at 0xbffffaa4, eip at\

0xbffffaac

(gdb)

This kind of information is useful if you're debugging at the assembly-language level with the disass, nexti, and stepi commands (see "Instruction-level debugging," later in this chapter).

Miscellaneous Features

We have barely scratched the surface of what gdb can do. It is an amazing program with a lot of power; we have introduced you only to the most commonly used commands. In this section, we look at other features of gdb and then send you on your way.

If you're interested in learning more about gdb, we encourage you to read the gdb manual page and the Free Software Foundation manual. The manual is also available as an online Info file. (Info files may be read under Emacs or using the info reader; see "Tutorial and Online Help" in Chapter 19 for details.)

Breakpoints and watchpoints

As promised, this section demonstrates further use of breakpoints and watchpoints. Breakpoints are set with the break

Return Main Page Previous Page Next Page

®Online Book Reader