(gdb) show solib-absolute-prefix

Prefix for loading absolute shared library symbol files is

'/opt/mvl/pro/devkit/arm/xscale_be/target'.

(gdb)

You can set or change where GDB searches for shared libraries using the GDB commands set solib- absolute-prefix and set solib-search-path. If you are developing your own shared library modules or have custom library locations on your system, you can use solib-search-path to instruct GDB where to look for your libraries. For more details about these and other GDB commands, consult the online GDB manual referenced at the end of this chapter in Section 15.6.1, 'Suggestions for Additional Reading.'

One final note about ldd. You might have noticed the addresses from Listing 15-8 and 15-9 associated with the libraries. ldd displays the load address for the start of these code segments as they would be if the program were loaded by the Linux dynamic linker/loader. Executed on the target, the addresses in Listing 15-5 make perfect sense, and we can correlate these with the /proc/<pid>/maps listing of the running process on the target. Listing 15-10 displays the memory segments for this target process after it is completely loaded and running.

Listing 15-10. Memory Segments from /proc/<pid>/maps on Target

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

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

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

0002e000-0005e000 rwxp 0002e000 00:00 0          [heap]

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

40017000-40019000 rw-p 40017000 00:00 0

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

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

40020000-4011d000 r-xp 00000000 00:0a 4982651    /lib/tls/libc-2.3.3.so

4011d000-40120000 ---p 000fd000 00:0a 4982651    /lib/tls/libc-2.3.3.so

40120000-40124000 rw-p 000f8000 00:0a 4982651    /lib/tls/libc-2.3.3.so

40124000-40126000 r--p 000fc000 00:0a 4982651    /lib/tls/libc-2.3.3.so

40126000-40128000 rw-p 000fe000 00:0a 4982651    /lib/tls/libc-2.3.3.so

40128000-4012a000 rw-p 40128000 00:00 0

4012a000-40133000 r-xp 00000000 00:0a 4982652    /lib/tls/libnss_files-2.3.3.so

40133000-4013a000 ---p 00009000 00:0a 4982652    /lib/tls/libnss_files-2.3.3.so

4013a000-4013b000 r--p 00008000 00:0a 4982652    /lib/tls/libnss_files-2.3.3.so

4013b000-4013c000 rw-p 00009000 00:0a 4982652    /lib/tls/libnss_files-2.3.3.so

becaa000-becbf000 rwxp becaa000 00:00 0          [stack]

root@coyote:~#

Notice the correlation of the target ldd output from Listing 15-8 to the memory segments displayed in the /proc file system for this process. The start (beginning of .text segment) of the Linux loader is 0x40000000 and the start of libc is at 0x40020000. These are the virtual addresses where these portions of the application have been loaded, and are reported by the target invocation of ldd. However, the load addresses reported by the cross version of ldd in Listing 15-9 (0xdead1000 and 0xdead2000) are there to remind you that these libraries cannot be loaded on your host system (they are ARM architecture binaries), and the load addresses are simply placeholders.

15.4. Debugging Multiple Tasks

Generally the developer is presented with two different debugging scenarios when dealing with multiple threads of execution. Processes can exist in their own address space or can share an address space (and other system resources) with other threads of execution. The former (independent processes not sharing common address space) must be debugged using separate independent debug sessions. Nothing prevents you from using gdbserver on multiple processes on your target system, and using a separate invocation of GDB on your development host to coordinate a debug session for multiple cooperating but independent processes.

15.4.1. Debugging Multiple Processes

When a process being debugged under GDB uses the fork() system call [103] to spawn a new process, GDB can take two courses of action. It can continue to control and debug the parent process, or it can stop debugging the parent process and attach to the newly formed child process. You can control this behavior using the set follow-fork-mode command. The two modes are follow parent and follow child. The default behavior is for GDB to follow the parent. In this case, the child process executes immediately upon a successful fork.

Listing 15-11 reproduces a snippet of a simple program that forks multiple processes from its main() routine.

Listing 15-11. Using fork() to Spawn a Child Process

...

for(i=0; i<MAX_PROCESSES; i++) {

 /* Creating child process */

 pid[i] = fork(); /* Parent gets non-zero PID */

 if (pid[i] == -1) {

  perror('fork failed');

  exit(1);

 }

 if (pid[i] == 0) { /* Indicates child's code path */

  worker_process(); /* The forked process calls this */

 }

}

/* Parent's main control loop */

while (1) {

 ...

}

This simple loop creates MAX_THREADS new processes using the fork() system call. Each newly spawned process executes a body of code defined by the function worker_process(). When run under GDB in the default mode, GDB detects the creation of the new threads of execution (processes) but remains attached to the parent's thread of execution. Listing 15-12 illustrates this GDB session.

Listing 15-12. GDB in follow-fork-mode = parent

(gdb) target remote 192.168.1.141:2001

0x40000790 in ?? ()

(gdb) b main

Breakpoint 1 at 0x8888: file forker.c, line 104.

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

0

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

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