尝试设置断点时,gdb无法访问附加进程中的内存

时间:2013-12-03 17:56:48

标签: linux debugging gdb

我正在调试postgres进程的用户定义函数(在自定义创建的libafd.so中找到)。

在psql(运行postgres进程)中取出进程的pid:

SELECT pg_backend_pid();
pg_backend_pid 
----------------
      22648
(1 row)

将gdb附加到进程(以root身份运行):

# gdb libafd.so -p 22648

加载了一堆符号,有些失败了:

GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 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 "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /usr/lib/postgresql/9.1/lib/libafd.so...done.
Attaching to program: /usr/lib/postgresql/9.1/lib/libafd.so, process 22648
Reading symbols from /usr/lib/x86_64-linux-gnu/libxml2.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libxml2.so.2
Reading symbols from /lib/x86_64-linux-gnu/libpam.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libpam.so.0
Reading symbols from /lib/x86_64-linux-gnu/libssl.so.1.0.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libssl.so.1.0.0
Reading symbols from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libkrb5.so.3
Reading symbols from /lib/x86_64-linux-gnu/libcom_err.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libcom_err.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2
Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libdl-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libdl.so.2
Reading symbols from /lib/x86_64-linux-gnu/libm.so.6...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libm-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libm.so.6
Reading symbols from /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2
Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libc.so.6
Reading symbols from /lib/x86_64-linux-gnu/libz.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libz.so.1
Reading symbols from /usr/lib/x86_64-linux-gnu/liblzma.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/liblzma.so.5
Reading symbols from /usr/lib/x86_64-linux-gnu/libk5crypto.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libk5crypto.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5support.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libkrb5support.so.0
Reading symbols from /lib/x86_64-linux-gnu/libkeyutils.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libkeyutils.so.1
Reading symbols from /lib/x86_64-linux-gnu/libresolv.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libresolv-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libresolv.so.2
Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libpthread-2.15.so...done.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
done.
Loaded symbols for /lib/x86_64-linux-gnu/libpthread.so.0
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.15.so...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/libsasl2.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libsasl2.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/libgssapi.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libgssapi.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libgnutls.so.26...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libgnutls.so.26
Reading symbols from /lib/x86_64-linux-gnu/libgcrypt.so.11...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libgcrypt.so.11
Reading symbols from /usr/lib/x86_64-linux-gnu/libheimntlm.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libheimntlm.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5.so.26...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libkrb5.so.26
Reading symbols from /usr/lib/x86_64-linux-gnu/libasn1.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libasn1.so.8
Reading symbols from /usr/lib/x86_64-linux-gnu/libhcrypto.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libhcrypto.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libroken.so.18...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libroken.so.18
Reading symbols from /usr/lib/x86_64-linux-gnu/libtasn1.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libtasn1.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libp11-kit.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libp11-kit.so.0
Reading symbols from /lib/x86_64-linux-gnu/libgpg-error.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libgpg-error.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libwind.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libwind.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libheimbase.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libheimbase.so.1
Reading symbols from /usr/lib/x86_64-linux-gnu/libhx509.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libhx509.so.5
Reading symbols from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libsqlite3.so.0
Reading symbols from /lib/x86_64-linux-gnu/libcrypt.so.1...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libcrypt-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libcrypt.so.1
Reading symbols from /lib/x86_64-linux-gnu/libnss_files.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libnss_files-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libnss_files.so.2
Reading symbols from /lib/x86_64-linux-gnu/libnss_compat.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libnss_compat-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libnss_compat.so.2
Reading symbols from /lib/x86_64-linux-gnu/libnsl.so.1...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libnsl-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libnsl.so.1
Reading symbols from /lib/x86_64-linux-gnu/libnss_nis.so.2...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/libnss_nis-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/libnss_nis.so.2
Reading symbols from /usr/lib/postgresql/9.1/lib/libafd.so...done.
Loaded symbols for /usr/lib/postgresql/9.1/lib/libafd.so
Reading symbols from /usr/lib/libgdal.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libgdal.so.1
Reading symbols from /usr/lib/libspatialindex.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libspatialindex.so.1
Reading symbols from /usr/lib/libboost_iostreams.so.1.46.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libboost_iostreams.so.1.46.1
Reading symbols from /usr/lib/libboost_serialization.so.1.46.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libboost_serialization.so.1.46.1
Reading symbols from /usr/lib/libproj.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libproj.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libQtSql.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libQtSql.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libQtCore.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libQtCore.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libstdc++.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libstdc++.so.6
Reading symbols from /lib/x86_64-linux-gnu/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libgcc_s.so.1
Reading symbols from /usr/lib/libarmadillo.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libarmadillo.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/libpoppler.so.19...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libpoppler.so.19
Reading symbols from /usr/lib/libgeos_c.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libgeos_c.so.1
Reading symbols from /usr/lib/libepsilon.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libepsilon.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libodbc.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libodbc.so.1
Reading symbols from /usr/lib/x86_64-linux-gnu/libodbcinst.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libodbcinst.so.1
Reading symbols from /lib/x86_64-linux-gnu/libexpat.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libexpat.so.1
Reading symbols from /usr/lib/libxerces-c.so.28...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libxerces-c.so.28
Reading symbols from /usr/lib/x86_64-linux-gnu/libjasper.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libjasper.so.1
Reading symbols from /usr/lib/libnetcdf.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libnetcdf.so.6
Reading symbols from /usr/lib/libhdf5.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libhdf5.so.6
Reading symbols from /usr/lib/libmfhdfalt.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libmfhdfalt.so.0
Reading symbols from /usr/lib/libdfalt.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libdfalt.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/libgif.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libgif.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libjpeg.so.8...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libjpeg.so.8
Reading symbols from /lib/x86_64-linux-gnu/libpng12.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libpng12.so.0
Reading symbols from /usr/lib/libpq.so.5...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libpq.so.5
Reading symbols from /usr/lib/x86_64-linux-gnu/libdapclient.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libdapclient.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libdap.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libdap.so.11
Reading symbols from /usr/lib/libspatialite.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libspatialite.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
Reading symbols from /lib/x86_64-linux-gnu/libbz2.so.1.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libbz2.so.1.0
Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...Reading symbols from /usr/lib/debug/lib/x86_64-linux-gnu/librt-2.15.so...done.
done.
Loaded symbols for /lib/x86_64-linux-gnu/librt.so.1
Reading symbols from /lib/x86_64-linux-gnu/libglib-2.0.so.0...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libglib-2.0.so.0
Reading symbols from /usr/lib/libblas.so.3gf...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libblas.so.3gf
Reading symbols from /usr/lib/liblapack.so.3gf...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/liblapack.so.3gf
Reading symbols from /usr/lib/x86_64-linux-gnu/liblcms2.so.2...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/liblcms2.so.2
Reading symbols from /usr/lib/x86_64-linux-gnu/libtiff.so.4...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libtiff.so.4
Reading symbols from /usr/lib/x86_64-linux-gnu/libfreetype.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libfreetype.so.6
Reading symbols from /usr/lib/x86_64-linux-gnu/libfontconfig.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libfontconfig.so.1
Reading symbols from /usr/lib/libgeos-3.3.8.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libgeos-3.3.8.so
Reading symbols from /usr/lib/x86_64-linux-gnu/libltdl.so.7...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libltdl.so.7
Reading symbols from /usr/lib/libicuuc.so.48...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libicuuc.so.48
Reading symbols from /usr/lib/libhdf5_hl.so.6...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libhdf5_hl.so.6
Reading symbols from /usr/lib/x86_64-linux-gnu/libfreexl.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libfreexl.so.1
Reading symbols from /usr/lib/x86_64-linux-gnu/libidn.so.11...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libidn.so.11
Reading symbols from /usr/lib/x86_64-linux-gnu/librtmp.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/librtmp.so.0
Reading symbols from /lib/x86_64-linux-gnu/libpcre.so.3...(no debugging symbols found)...done.
Loaded symbols for /lib/x86_64-linux-gnu/libpcre.so.3
Reading symbols from /usr/lib/x86_64-linux-gnu/libgfortran.so.3...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libgfortran.so.3
Reading symbols from /usr/lib/libicudata.so.48...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libicudata.so.48
Reading symbols from /usr/lib/x86_64-linux-gnu/libquadmath.so.0...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/libquadmath.so.0
Reading symbols from /usr/lib/x86_64-linux-gnu/gconv/UTF-16.so...Reading symbols from /usr/lib/debug/usr/lib/x86_64-linux-gnu/gconv/UTF-16.so...done.
done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/gconv/UTF-16.so
Reading symbols from /usr/lib/libicui18n.so.48...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/libicui18n.so.48
Reading symbols from /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlite.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlite.so
Reading symbols from /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlpsql.so...(no debugging symbols found)...done.
Loaded symbols for /usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlpsql.so
0x00002b3b1ed34c22 in __libc_recv (fd=8, buf=0xb0da00, n=8192, 
flags=<optimized out>) at ../sysdeps/unix/sysv/linux/x86_64/recv.c:30
30  ../sysdeps/unix/sysv/linux/x86_64/recv.c: No such file or directory.

检查我有兴趣在gdb中调试的函数:

(gdb) info functions libafd_traj_quality
All functions matching regular expression "libafd_traj_quality":

File ../libAFD/libafd.cpp:
Datum libafd_traj_quality(FunctionCallInfo);
const Pg_finfo_record *pg_finfo_libafd_traj_quality();
Datum libafd_traj_quality(FunctionCallInfo);
const Pg_finfo_record *pg_finfo_libafd_traj_quality();
(gdb) 

尝试设置断点并获取错误:

(gdb) b libafd_traj_quality
Cannot access memory at address 0x26c01f
(gdb)

如何在我的函数上设置断点???

其他信息:

# cat /proc/22648/maps  | grep libafd
2b3b2556e000-2b3b25a82000 r-xp 00000000 08:01 5379086                    /usr/lib/postgresql/9.1/lib/libafd.so
2b3b25a82000-2b3b25c82000 ---p 00514000 08:01 5379086                    /usr/lib/postgresql/9.1/lib/libafd.so
2b3b25c82000-2b3b25c88000 r--p 00514000 08:01 5379086                    /usr/lib/postgresql/9.1/lib/libafd.so
2b3b25c88000-2b3b25c9a000 rw-p 0051a000 08:01 5379086                    /usr/lib/postgresql/9.1/lib/libafd.so

# nm -as /usr/lib/postgresql/9.1/lib/libafd.so | grep libafd_traj_quality
00000000003d4788 r _ZZ28pg_finfo_libafd_traj_qualityE8my_finfo
000000000026c01f T libafd_traj_quality
000000000026c012 T pg_finfo_libafd_traj_quality

非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

我认为问题可能是你告诉gdb调试共享库,通常你给它一个exectuable的名字。但是,由于您正在调试已经运行的进程,因此您甚至不应该这样做。尝试附加到过程中,无需指定文件,只需指定PID。