process ID (PID) of our target application from the gdbserver output in Listing 15-3. Our process was assigned PID 197. Given that, we can see the memory segments in use right after process startup, as shown in Listing 15-6.

Listing 15-6. Initial Target Memory Segment Mapping

root@coyote:~# cat /proc/197/maps

00008000-00026000 r-xp 00000000 00:0e 4852444    ./websdemo-stripped

0002d000-0002e000 rw-p 0001d000 00:0e 4852444    ./websdemo-stripped

40000000-40017000 r-xp 00000000 00:0a 4982583    /lib/ld-2.3.3.so

4001e000-40020000 rw-p 00016000 00:0a 4982583    /lib/ld-2.3.3.so

bedf9000-bee0e000 rwxp bedf9000 00:00 0          [stack]

root@coyote:~#

Here we see the target websdemo-stripped application occupying two memory segments. The first is the read-only executable segment at 0x8000, and the second is a read-write data segment at 0x2d000. The third memory segment is the one of interest. It is the Linux dynamic linker's executable code segment. Notice that it starts at address 0x40000000. If we investigate further, we can confirm that GDB is actually sitting at the first line of code for the dynamic linker, before any code from our own application has been executed. Using our cross version of readelf, we can confirm the starting address of the linker as follows:

# xscale_be-readelf -S ld-2.3.3.so | grep .text

[ 9] .text    PROGBITS    00000790 000790 012c6c 00  AX  0   0 16

From this data, we conclude that the address GDB reports on startup is the first instruction from ld- 2.3.3.so, the Linux dynamic linker/loader. You can use this technique to get rough ideas of where your code is if you don't have symbolic debug information for a process or shared library.

Remember that we are executing this cross readelf command on our development host. Therefore, the ld-2.3.3.so file, itself an XScale binary object, must be accessible to your development host. Most typically, this file resides on your development host, and is a component of your embedded Linux distribution installed on your host.

15.3.1. Shared Library Events in GDB

GDB can alert you to shared library events. This can be useful for understanding your application's behavior or the behavior of the Linux loader, or for setting breakpoints in shared library routines you want to debug or step through. Listing 15-7 illustrates this technique. Normally, the complete path to the library is displayed. This listing has been edited for better readability.

Listing 15-7. Stopping GDB on Shared Library Events

$ xscale_be-gdb -q websdemo

(gdb) target remote 192.168.1.141:2001

Remote debugging using 192.168.1.141:2001

0x40000790 in ?? ()

(gdb) i shared <<<Display loaded shared libs

No shared libraries loaded at this time.

(gdb) b main <<<Break at main

Breakpoint 1 at 0x12b80: file main.c, line 72.

(gdb) c

Continuing.

Breakpoint 1, main (argc=0x1, argv=0xbec7fdc4) at main.c:72

72               int localvar = 9;

(gdb) i shared

From To Syms Read Shared Object Library

0x40033300  0x4010260c  Yes         /opt/mvl/.../lib/tls/libc.so.6

0x40000790  0x400133fc  Yes         /opt/mvl/.../lib/ld-linux.so.3

(gdb) set stop-on-solib-events 1

(gdb) c

Continuing.

Stopped due to shared library event

(gdb) i shared

From To Syms Read Shared Object Library

0x40033300  0x4010260c  Yes         /opt/mvl/.../lib/tls/libc.so.6

0x40000790  0x400133fc  Yes         /opt/mvl/.../lib/ld-linux.so.3

0x4012bad8  0x40132104  Yes         /opt/mvl/.../libnss_files.so.2

(gdb)

When the debug session is first started, of course, no shared libraries are loaded. You can see this with the first i shared command. This command displays the shared libraries that are currently loaded. Setting a breakpoint at our application's main() function, we see that two shared libraries are now loaded. These are the Linux dynamic linker/loader and the standard C library component libc.

From here, we issue the set stop-on-solib-event command and continue program execution. When the application tries to execute a function from another shared library, that library is loaded. In case you are wondering, the gethostbyname() function is encountered and causes the next shared object load.

This example illustrates an important cross-development concept. The binary application (ELF image) running on the target contains information on the libraries it needs to resolve its external references. We can view this information easily using the ldd command introduced in Chapter 11, 'BusyBox,' and detailed in Chapter 13. Listing 15-8 shows the output of ldd invoked from the target board.

Listing 15-8. ldd Executed on Target Board

root@coyote:/workspace# ldd websdemo

         libc.so.6 => /lib/tls/libc.so.6 (0x40020000)

         /lib/ld-linux.so.3    (0x40000000)

root@coyote:/workspace#

Notice that the paths to the shared libraries on the target are absolute paths starting at /lib on the root file system. But GDB running on your host development workstation cannot use these paths to find the libraries. You should realize that to do so would result in your host GDB loading libraries from the wrong architecture. Your host is likely x86, whereas, in this example, the target is ARM XScale.

If you invoke your cross version of ldd, you will see the paths that were preconfigured into your toolchain. Your toolchain must have knowledge of where these files exist on your host development system.[101] Listing 15-9 illustrates this. Again, we have edited the listing for readability; long paths have been abbreviated.

Listing 15-9. ldd Executed on Development Host

$ xscale_be-ldd websdemo

   libc.so.6 => /opt/mvl/.../xscale_be/target/lib/libc.so.6 (0xdead1000)

   ld-linux.so.3 => /opt/mvl/.../xscale_be/target/lib/ld-linux.so.3 (0xdead2000)

$

Your cross toolchain should be preconfigured with these library locations. Not only does your host GDB need to know where they are located, but, of course, your compiler and linker also need this knowledge.[102] GDB can tell you where it is configured to look for these libraries using the show solib-absolute-prefix command:

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату