ld and sopath and gdb useage

本文详细介绍了程序运行时如何查找所需共享库的具体步骤,包括环境变量LD_LIBRARY_PATH的作用、缓存文件/etc/ld.so.cache的内容及其优先级顺序,并提供了调试过程中设置gdbserver及远程调试的方法,以及32位库在64位Ubuntu系统中的安装路径。



1. so search path:

The necessary shared libraries needed by the program are  searched  for
       in the following order    

  a      Using      the      environment     variable     LD_LIBRARY_PATH

              (LD_AOUT_LIBRARY_PATH for a.out programs).  Except if  the  exe‐
              cutable is a setuid/setgid binary, in which case it is ignored.

  b      From  the  cache file /etc/ld.so.cache which contains a compiled
              list of candidate libraries previously found  in  the  augmented
              library  path.  Libraries  installed  in  hardware  capabilities
              directories (see below) are prefered to other libraries.

   c     In the default path /lib, and then /usr/lib.

2. see all the lib

cat /etc/ld.so.cache

 cat /etc/ld.so.conf (include /etc/ld.so.conf.d/*.conf)



3.gdb

a.

start gdb server

"/data/gdbserver :5039 --attach $p

//12345,tcp port; $p, pid


b. adb to tcp

adb forward tcp:5039 tcp:5039

//local port, remote port


c. connect to gdb server

target remote :5039


d. set so path

solib-search-path /XXX

mount -o remount,rw -t yaffs2 /dev/block/mtdblock1 /system
echo "|/system/bin/dd of=/sdcard/core-%e-%p-%t" >/proc/sys/kernel/core_pattern


4. lib for 32 in 64bit ubuntu

/lib/i386-linux-gnu


(spider) zhanggexu@ubuntu:~/newcode/be900v2/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin$ ./arm-buildroot-linux-gnueabi-gdb GNU gdb (GDB) 10.1 Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> 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-pc-linux-gnu --target=arm-buildroot-linux-gnueabi". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word". (gdb) set sysroot debug_target/ (gdb) set solib-search-path debug_target/usr/lib/ (gdb) file debug_target/usr/sbin/syslog-ng Reading symbols from debug_target/usr/sbin/syslog-ng... (No debugging symbols found in debug_target/usr/sbin/syslog-ng) (gdb) (gdb) core-file core warning: Can't open file /usr/lib/libcrypto.so.1.1.1 during file-backed mapping note processing warning: Can't open file /usr/lib/libssl.so.1.1.1 during file-backed mapping note processing warning: Can't open file /lib/libjson-c.so.5 during file-backed mapping note processing warning: Can't open file /lib/libc-2.32.so during file-backed mapping note processing warning: Can't open file /lib/libpthread-2.32.so during file-backed mapping note processing warning: Can't open file /lib/libdl-2.32.so during file-backed mapping note processing warning: Can't open file /usr/lib/libpcre2-8.so.0.11.2 during file-backed mapping note processing warning: Can't open file /usr/lib/libsecret-storage.so.0.0.0 during file-backed mapping note processing warning: Can't open file /usr/lib/libevtlog-4.7.so.0.0.0 during file-backed mapping note processing warning: Can't open file /usr/lib/libintl.so.8.1.1 during file-backed mapping note processing warning: Can't open file /usr/lib/libglib-2.0.so.0.5800.3 during file-backed mapping note processing warning: Can't open file /usr/lib/libgthread-2.0.so.0.5800.3 during file-backed mapping note processing warning: Can't open file /usr/lib/libgmodule-2.0.so.0.5800.3 during file-backed mapping note processing warning: Can't open file /lib/librt-2.32.so during file-backed mapping note processing warning: Can't open file /lib/libm-2.32.so during file-backed mapping note processing warning: Can't open file /usr/lib/libsyslog-ng-4.7.so.0.0.0 during file-backed mapping note processing warning: Can't open file /usr/lib/libiconv.so.2.4.0 during file-backed mapping note processing warning: Can't open file /lib/ld-2.32.so during file-backed mapping note processing warning: Can't open file /tmp/syslog-ng.persist during file-backed mapping note processing warning: exec file is newer than core file. [New LWP 8050] warning: Could not load shared library symbols for 18 libraries, e.g. /usr/lib/libiconv.so.2. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? Core was generated by `/usr/sbin/syslog-ng --foreground -f /etc/syslog-ng.conf --stderr'. Program terminated with signal SIGABRT, Aborted. #0 0xf777e68c in ?? () (gdb)
最新发布
11-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值