如何在 Intel x86 服务器上构建 IBM PowerLinux 应用程(4)

[root@localhost ~]# gdb attach 25412 GNU gdb (GDB) 7.6.50.20130722-cvs Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+:GNU GPL version 3 or later <> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-linux". … (gdb)

将目录设置到源代码发行版。

(gdb) set directories /home/ProjectToolchainPLCompile/apr-1.5.1
(gdb) where #0 0x00000fff7cb676f8 in ___newselect_nocancel () at ../sysdeps/unix/syscall-template.S:81 #1 0x00000fff7cd38274 in apr_sleep (t=<optimized out>) at time/unix/time.c:246 #2 0x0000000010034220 in ap_wait_or_timeout (status=0xfffeaa1e704, exitcode=0xfffeaa1e700, ret=0xfffeaa1e6e0, p=0x1003d0c6138, s=<optimized out>) at mpm_common.c:195 #3 0x0000000010079238 in server_main_loop (remaining_children_to_start=<optimized out>) at worker.c:1654 #4 worker_run (_pconf=<optimized out>, plog=<optimized out>, s=<optimized out>) at worker.c:1823 #5 0x0000000010033430 in ap_run_mpm (pconf=0x1003d0c6138, plog=0x1003d0f3378, s=0x1003d0ef4c0) at mpm_common.c:96 #6 0x000000001002a5d8 in main (argc=3, argv=0xfffeaa1ee28) at main.c:777

将一个函数移动到 apr_sleep。

(gdb) up #1 0x00000fff7cd38274 in apr_sleep (t=<optimized out>) at time/unix/time.c:246 246 select(0, NULL, NULL, NULL, &tv);

列出 apr_sleep 的源代码。

(gdb) list 241 delay(t/1000); 242 #else 243 struct timeval tv; 244 tv.tv_usec = t % APR_USEC_PER_SEC; 245 tv.tv_sec = t / APR_USEC_PER_SEC; 246 select(0, NULL, NULL, NULL, &tv); 247 #endif 248 } 249 250 #ifdef OS2

与该进程分离。

(gdb) detach Detaching from program:/tmp/usr/local/bin/httpd, process 25412 (gdb) quit

远程调试

toolchain 还包含 gdbserver 程序。它允许开发人员从一个远程 gdb 会话连接到他们的应用程序。请确保在 PowerLinux 服务器上调用 gdbserver 程序时,您使用了来自 toolchain 的 gdb。对我而言,一定要检查它是否在我的路径上。

# type gdbserver gdbserver is hashed (/opt/at7.0-5-rc1/bin/gdbserver)

这是在 PowerLinux 服务器上使用 gdbserver 程序的一个例子。我们将附加到一个正在运行的 httpd 进程:

[root@stgisv241 bin]# gdbserver --attach 9.3.4.240:2345 22589 Attached; pid = 22589 Listening on port 2345

在 x86 服务器上,对本地服务器上的 httpd 二进制程序调用 powerpc64-linux-gdb 程序。请注意,来自 toolchain 的 gdb 版本名为 powerpc64-linux-gdb。使用的 httpd 二进制程序是 PowerLinux 服务器上运行的同一个交叉编译的二进制程序版本。

# pwd /tmp/usr/local/bin [root@stgisv240 bin]# powerpc64-linux-gdb ./httpd GNU gdb (GDB) 7.6.50.20130722-cvs Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+:GNU GPL version 3 or later <> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.Type "show copying" and "show warranty" for details. This GDB was configured as "--host=i686-linux --target=powerpc64-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: <>. Find the GDB manual and other documentation resources online at: <>. For help, type "help". Type "apropos word" to search for commands related to "word". .. Reading symbols from /tmp/usr/local/bin/httpd...done. (gdb)

仍在 x86 gdb 会话上,在 gdb 内调用目标命令,如下面的示例所示。

(gdb) target remote 9.3.4.241:2345 Remote debugging using 9.3.4.241:2345 warning:Could not load shared library symbols for 7 libraries, e.g. /opt/at7.0-5-rc1/lib64/power7/librt.so.1. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? Reading symbols from /tmp/usr/local/apr/lib/libaprutil-1.so.0...done. Loaded symbols for /tmp/usr/local/apr/lib/libaprutil-1.so.0 Reading symbols from /tmp/usr/local/apr/lib/libexpat.so.0...done. Loaded symbols for /tmp/usr/local/apr/lib/libexpat.so.0 Reading symbols from /tmp/usr/local/apr/lib/libapr-1.so.0...done. Loaded symbols for /tmp/usr/local/apr/lib/libapr-1.so.0 …. Reading symbols from /tmp/usr/local/modules/mod_alias.so...done. Loaded symbols for /tmp/usr/local/modules/mod_alias.so warning:Unable to find dynamic linker breakpoint function. GDB will be unable to debug shared library initializers and track explicitly loaded dynamic code. 0x00000fffa8fe76f8 in ??() (gdb)

可以看到一些与 gdb 无法找到库符号相关的警告消息。 gdb 命令 info sharedlibrary 显示了 gdb 未能从中读取符号的库。下面的示例输出显示了 gdb 未能从中读取符号的库。请注意,这些库是系统的一部分,除非它们在编译时打开了符号,否则您无需担忧它们。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/cf58afa05233967f4786f553f252ed15.html