[ <] | [ >] | [ <<] | [ Up] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
If your program is too large to fit completely in your target system's memory, you can sometimes use overlays to work around this problem. GDB provides some support for debugging programs that use overlays.
11.1 How Overlays Work A general explanation of overlays. 11.2 Overlay Commands Managing overlays in GDB. 11.3 Automatic Overlay Debugging GDB can find out which overlays are mapped by asking the inferior. 11.4 Overlay Sample Program A sample program using overlays.
[ <] | [ >] | [ <<] | [ Up] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
Suppose you have a computer whose instruction address space is only 64 kilobytes long, but which has much more memory which can be accessed by other means: special instructions, segment registers, or memory management hardware, for example. Suppose further that you want to adapt a program which is larger than 64 kilobytes to run on this system.
One solution is to identify modules of your program which are relatively independent, and need not call each other directly; call these modules overlays. Separate the overlays from the main program, and place their machine code in the larger memory. Place your main program in instruction memory, but leave at least enough space there to hold the largest overlay as well.
Now, to call a function located in an overlay, you must first copy that overlay's machine code from the large memory into the space set aside for it in the instruction memory, and then jump to its entry point there.
Data Instruction Larger Address Space Address Space Address Space +-----------+ +-----------+ +-----------+ | | | | | | +-----------+ +-----------+ +-----------+<-- overlay 1 | program | | main | .----| overlay 1 | load address | variables | | program | | +-----------+ | and heap | | | | | | +-----------+ | | | +-----------+<-- overlay 2 | | +-----------+ | | | load address +-----------+ | | | .-| overlay 2 | | | | | | | mapped --->+-----------+ | | +-----------+ address | | | | | | | overlay | <-' | | | | area | <---' +-----------+<-- overlay 3 | | <---. | | load address +-----------+ `--| overlay 3 | | | | | +-----------+ | | +-----------+ | | +-----------+ |
[ <] | [ >] | [ <<] | [ Up] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
To use GDB's overlay support, each overlay in your program must correspond to a separate section of the executable file. The section's virtual memory address and load memory address must be the overlay's mapped and load addresses. Identifying overlays with sections allows GDB to determine the appropriate address of a function or variable, depending on whether the overlay is mapped or not.
GDB's overlay commands all start with the word overlay
;
you can abbreviate this as ov
or ovly
. The commands are:
overlay off
Disable GDB's overlay support. When overlay support is disabled, GDB assumes that all functions and variables are always present at their mapped addresses. By default, GDB's overlay support is disabled.
overlay manual
Enable manual overlay debugging. In this mode, GDB
relies on you to tell it which overlays are mapped, and which are not,
using the overlay map-overlay
and overlay unmap-overlay
commands described below.
overlay map-overlay overlay
overlay map overlay
Tell GDB that overlay is now mapped; overlay must be the name of the object file section containing the overlay. When an overlay is mapped, GDB assumes it can find the overlay's functions and variables at their mapped addresses. GDB assumes that any other overlays whose mapped ranges overlap that of overlay are now unmapped.
overlay unmap-overlay overlay
overlay unmap overlay
Tell GDB that overlay is no longer mapped; overlay must be the name of the object file section containing the overlay. When an overlay is unmapped, GDB assumes it can find the overlay's functions and variables at their load addresses.
overlay auto
overlay load-target
overlay load
Re-read the overlay table from the inferior. Normally, GDB re-reads the table GDB automatically each time the inferior stops, so this command should only be necessary if you have changed the overlay mapping yourself using GDB. This command is only useful when using automatic overlay debugging.
overlay list-overlays
overlay list
Display a list of the overlays currently mapped, along with their mapped addresses, load addresses, and sizes.
Normally, when GDB prints a code address, it includes the name of the function the address falls in:
(gdb) print main $3 = {int ()} 0x11a0 <main> |
(gdb) overlay list No sections are mapped. (gdb) print foo $5 = {int (int)} 0x100000 <*foo*> |
(gdb) overlay list Section .ov.foo.text, loaded at 0x100000 - 0x100034, mapped at 0x1016 - 0x104a (gdb) print foo $6 = {int (int)} 0x1016 <foo> |
[ <] | [ >] | [ <<] | [ Up] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
GDB can automatically track which overlays are mapped and which
are not, given some simple co-operation from the overlay manager in the
inferior. If you enable automatic overlay debugging with the
overlay auto
command (see section 11.2 Overlay Commands), GDB
looks in the inferior's memory for certain variables describing the
current state of the overlays.
Here are the variables your overlay manager must define to support GDB's automatic overlay debugging:
_ovly_table
:
struct { /* The overlay's mapped address. */ unsigned long vma; /* The size of the overlay, in bytes. */ unsigned long size; /* The overlay's load address. */ unsigned long lma; /* Non-zero if the overlay is currently mapped; zero otherwise. */ unsigned long mapped; } |
[ <] | [ >] | [ <<] | [ Up] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
When linking a program which uses overlays, you must place the overlays at their load addresses, while relocating them to run at their mapped addresses. To do this, you must write a linker script (see section `Overlay Description' in Using ld: the GNU linker). Unfortunately, since linker scripts are specific to a particular host system, target architecture, and target memory layout, this manual cannot provide portable sample code demonstrating GDB's overlay support.
However, the GDB source distribution does contain an overlaid program, with linker scripts for a few systems, as part of its test suite. The program consists of the following files from `gdb/testsuite/gdb.base':
d10v-elf
and m32r-elf
targets.
You can build the test program using the d10v-elf
GCC
cross-compiler like this:
$ d10v-elf-gcc -g -c overlays.c $ d10v-elf-gcc -g -c ovlymgr.c $ d10v-elf-gcc -g -c foo.c $ d10v-elf-gcc -g -c bar.c $ d10v-elf-gcc -g -c baz.c $ d10v-elf-gcc -g -c grbx.c $ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \ baz.o grbx.o -Wl,-Td10v.ld -o overlays |
[ <<] | [ >>] | [Top] | [Contents] | [Index] | [ ?] |
Please send FSF & GNU inquiries & questions to gnu@gnu.org. There are also other ways to contact the FSF.
These pages are maintained by the GDB developers.
Copyright Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.
This document was generated by GDB Administrator on March, 27 2008 using texi2html