如何从安装的库中加载gdb加载符号?

时间:2016-03-23 07:48:53

标签: linux debugging gdb debian debug-symbols

已安装

libopal-dbglibopal3.10.10。但是在调试时我无法看到库代码。

objdump --debugging /usr/lib/libopal.so.3.10.10给出:

00000018 0000000000000024 0000001c FDE cie=00000000 pc=00000000006a61c0..00000000006f82b0
  DW_CFA_def_cfa_offset: 16
  DW_CFA_advance_loc: 6 to 00000000006a61c6
  DW_CFA_def_cfa_offset: 24
  DW_CFA_advance_loc: 10 to 00000000006a61d0
  DW_CFA_def_cfa_expression (DW_OP_breg7 (rsp): 8; DW_OP_breg16 (rip): 0; DW_OP_lit15; DW_OP_and; DW_OP_lit11; DW_OP_ge; DW_OP_lit3; DW_OP_shl; DW_OP_plus)
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop
  DW_CFA_nop

...

有趣的是objdump --debugging /usr/lib/debug/usr/lib/libopal.so.3.10.10没有输出任何内容:

/usr/lib/debug/usr/lib/libopal.so.3.10.10:     file format elf64-x86-64

Contents of the .eh_frame section:

00000000 ZERO terminator

调试时,不提供行号:

(gdb) n
Single stepping until exit from function _ZN12RTP_Encoding10WaitForPDUER10PUDPSocketS1_RK13PTimeInterval,
which has no line number information.
0x00007ffff5d73641 in RTP_UDP::WaitForPDU(PUDPSocket&, PUDPSocket&, PTimeInterval const&) () from /usr/lib/libopal.so.3.10.10
(gdb) list
77  in ../sysdeps/unix/syscall-template.S
(gdb) n
Single stepping until exit from function _ZN7RTP_UDP10WaitForPDUER10PUDPSocketS1_RK13PTimeInterval,
which has no line number information.
0x00007ffff5d731e3 in RTP_UDP::Internal_ReadData(RTP_DataFrame&) () from /usr/lib/libopal.so.3.10.10

或者像ptlib中那样(安装了libpt-dbglibpt-1.10.10):

(gdb) 
0x00007ffff52922c0 in PSocket::Select(PSocket::SelectList&, PSocket::SelectList&, PSocket::SelectList&, PTimeInterval const&) () from /usr/lib/libpt.so.2.10.10
(gdb) 
Single stepping until exit from function _ZN7PSocket6SelectERNS_10SelectListES1_S1_RK13PTimeInterval,
which has no line number information.
0x00007ffff52bc0e9 in PSocket::Select(PSocket&, PSocket&, PTimeInterval const&) () from /usr/lib/libpt.so.2.10.10
(gdb) lis
2946    in malloc.c
(gdb) s
Single stepping until exit from function _ZN7PSocket6SelectERS_S0_RK13PTimeInterval,
which has no line number information.
0x00007ffff5d736b7 in RTP_UDP::Internal_WaitForPDU(PUDPSocket&, PUDPSocket&, PTimeInterval const&) () from /usr/lib/libopal.so.3.10.10
(gdb) lis
2946    in malloc.c

1 个答案:

答案 0 :(得分:0)

好的,今天交易了以下黑客:

执行apt-get source libpt-dbg,然后修补debian/rules

--- a/debian/rules  2016-03-23 14:25:56.067355795 +0100
+++ b/debian/rules  2016-03-23 11:53:11.384111449 +0100
@@ -23,7 +23,7 @@
    dh_auto_configure -- --enable-oss --enable-v4l --disable-avc --disable-dc --enable-exceptions

 override_dh_auto_build:
-   dh_auto_build -- optshared docs
+   dh_auto_build -- debugshared docs

 override_dh_strip:
    dh_strip -a --dbg-package=libpt-dbg
@@ -35,7 +35,7 @@

 override_dh_auto_test:
    $(MAKE) PTLIBDIR=$(CURDIR) -C samples/hello_world clean
-   $(MAKE) PTLIBDIR=$(CURDIR) -C samples/hello_world opt
+   $(MAKE) PTLIBDIR=$(CURDIR) -C samples/hello_world debug
    #if (samples/hello_world/obj*/hello 2>/dev/null);then \
    #   echo opt hello_world sample incorrectly compiled static; false ; \
    #else \

同时为补丁添加实际源补丁(导入或更新debian/patches目录):

Index: ptlib-2.10.10~dfsg/Makefile.in
===================================================================
--- ptlib-2.10.10~dfsg.orig/Makefile.in
+++ ptlib-2.10.10~dfsg/Makefile.in
@@ -83,7 +83,7 @@ ifeq (,$(findstring $(OSTYPE),Darwin cyg
   DEBUG_SONAME = $(PTLIB_DEBUG_FILE).@MAJOR_VERSION@.@MINOR_VERSION@@BUILD_TYPE@@BUILD_NUMBER@
 else
   LIB_SONAME   = $(subst .$(LIB_SUFFIX),.@MAJOR_VERSION@.@MINOR_VERSION@@BUILD_TYPE@@BUILD_NUMBER@.$(LIB_SUFFIX),$(PTLIB_FILE))
-  DEBUG_SONAME = $(subst .$(LIB_SUFFIX),.@MAJOR_VERSION@.@MINOR_VERSION@@BUILD_TYPE@@BUILD_NUMBER@._d$(LIB_SUFFIX),$(PTLIB_FILE))
+  DEBUG_SONAME = $(subst .$(LIB_SUFFIX),.@MAJOR_VERSION@.@MINOR_VERSION@@BUILD_TYPE@@BUILD_NUMBER@.$(LIB_SUFFIX),$(PTLIB_FILE))
 endif

 # all these targets are just passed to all subdirectories
Index: ptlib-2.10.10~dfsg/make/unix.mak
===================================================================
--- ptlib-2.10.10~dfsg.orig/make/unix.mak
+++ ptlib-2.10.10~dfsg/make/unix.mak
@@ -596,7 +596,7 @@ endif

 ifndef OBJ_SUFFIX
 ifdef  DEBUG
-OBJ_SUFFIX := _d
+OBJ_SUFFIX :=
 else
 OBJ_SUFFIX :=
 endif # DEBUG
@@ -663,7 +663,7 @@ PT_LIBDIR   = $(PTLIBDIR)/lib_$(PLATFORM_T
 # set name of the PT library
 PTLIB_BASE = pt$(OBJ_SUFFIX)
 PTLIB_FILE = lib$(PTLIB_BASE)$(LIB_TYPE).$(LIB_SUFFIX)
-PTLIB_DEBUG_FILE= lib$(PTLIB_BASE)_d$(LIB_TYPE).$(LIB_SUFFIX)
+PTLIB_DEBUG_FILE= lib$(PTLIB_BASE)$(LIB_TYPE).$(LIB_SUFFIX)
 PT_OBJBASE = obj$(OBJDIR_SUFFIX)
 PT_OBJDIR  = $(PT_LIBDIR)/$(PT_OBJBASE)

然后使用debuild -us -uc -i -I构建包。

接下来是蛋白石(apt-get source libopal-dbg)。修补debian/rules

--- a/debian/rules  2016-03-23 15:55:49.460972494 +0100
+++ b/debian/rules  2016-03-23 15:24:37.685361838 +0100
@@ -23,7 +23,7 @@

 override_dh_auto_build:
    sed -e 's#^Libs: #Libs: -L$(OPAL_LIBDIR) #' opal.pc >samples/opal.pc
-   dh_auto_build -- PKG_CONFIG_PATH=$(CURDIR)/samples VERBOSE=1 opt docs
+   dh_auto_build -- PKG_CONFIG_PATH=$(CURDIR)/samples VERBOSE=1 debug docs

 #override_dh_auto_test:
 #  if (samples/simple/obj*/simpleopal --help >/dev/null);then \

在源补丁dir中添加补丁:

Index: opal-3.10.10~dfsg2/Makefile.in
===================================================================
--- opal-3.10.10~dfsg2.orig/Makefile.in
+++ opal-3.10.10~dfsg2/Makefile.in
@@ -560,7 +560,7 @@ $(OPAL_DEPDIR)/%.dep : %.c
 .PHONY: default_target

 ifeq ($(OPAL_SHARED_LIB),)
-default_target :: opt
+default_target :: debug
 else
 default_target :: Makefile $(OPAL_LIBDIR)/$(LIB_FILENAME_STATIC)
 ifeq ($(OPAL_SHARED_LIB),1)
Index: opal-3.10.10~dfsg2/configure
===================================================================
--- opal-3.10.10~dfsg2.orig/configure
+++ opal-3.10.10~dfsg2/configure
@@ -4919,7 +4919,7 @@ fi
             PTLIB_LIBS=`$PKG_CONFIG ptlib --libs`

             RELEASE_LIBS=`$PKG_CONFIG ptlib --libs`
-            DEBUG_LIBS=`$PKG_CONFIG ptlib --define-variable=suffix=_d --libs`
+            DEBUG_LIBS=`$PKG_CONFIG ptlib --libs`

                     else
             if test "x${PTLIB_VERSION_CHECK}" = "xyes" ; then
@@ -5113,7 +5113,7 @@ fi

             PTLIB_VERSION=`$PKG_CONFIG ptlib --modversion`
             PTLIB_CXXFLAGS=`$PKG_CONFIG ptlib --variable=cxxflags`
-            DEBUG_LIBS=`$PKG_CONFIG ptlib --define-variable=suffix=_d --libs`
+            DEBUG_LIBS=`$PKG_CONFIG ptlib --libs`
             RELEASE_LIBS="$PTLIB_LIBS"
           fi

@@ -5133,7 +5133,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
           { $as_echo "$as_me:${as_lineno-$LINENO}: checking linkable PTLib" >&5
 $as_echo_n "checking linkable PTLib... " >&6; }

-          DEBUG_LIBS=`$PKG_CONFIG ptlib --define-variable=suffix=_d --libs`
+          DEBUG_LIBS=`$PKG_CONFIG ptlib --libs`
           RELEASE_LIBS=`$PKG_CONFIG ptlib --libs`

            suffix=""""""
@@ -5174,7 +5174,7 @@ rm -f core conftest.err conftest.$ac_obj
 $as_echo "opt, shared" >&6; }
           else

-           suffix="_d"""
+           suffix=""""
       if test "x$suffix" = "x" ; then
              LIBS=`$PKG_CONFIG ptlib "" --libs`
            else
@@ -5211,7 +5211,7 @@ rm -f core conftest.err conftest.$ac_obj
               { $as_echo "$as_me:${as_lineno-$LINENO}: result: debug, shared" >&5
 $as_echo "debug, shared" >&6; }
             else
-              DEBUG_LIBS=`$PKG_CONFIG ptlib --static --define-variable=suffix=_d_s --libs`
+              DEBUG_LIBS=`$PKG_CONFIG ptlib --static --define-variable=suffix=_s --libs`
               RELEASE_LIBS=`$PKG_CONFIG ptlib --static --define-variable=suffix=_s --libs`

            suffix="""_s"
@@ -5252,7 +5252,7 @@ rm -f core conftest.err conftest.$ac_obj
 $as_echo "release, static" >&6; }
               else

-           suffix="_d_s"
+           suffix="_s"
       if test "x$suffix" = "x" ; then
              LIBS=`$PKG_CONFIG ptlib --static --libs`
            else
@@ -5362,7 +5362,7 @@ case "$OSTYPE" in
           SHARED_CFLAGS="-KPIC -D__inline=inline"

           if test "xDEBUG" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5396,7 +5396,7 @@ case "$OSTYPE" in


           if test "xRELEASE" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5438,7 +5438,7 @@ case "$OSTYPE" in
           SHARED_CFLAGS="-fPIC"

           if test "xDEBUG" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5472,7 +5472,7 @@ case "$OSTYPE" in


           if test "xRELEASE" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5521,7 +5521,7 @@ case "$OSTYPE" in
           SHARED_CFLAGS=

           if test "xDEBUG" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5555,7 +5555,7 @@ case "$OSTYPE" in


           if test "xRELEASE" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5596,7 +5596,7 @@ case "$OSTYPE" in
           SHARED_CFLAGS="-fPIC"

           if test "xDEBUG" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5630,7 +5630,7 @@ case "$OSTYPE" in


           if test "xRELEASE" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5672,7 +5672,7 @@ case "$OSTYPE" in
           SHARED_CFLAGS="-fPIC"

           if test "xDEBUG" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
@@ -5706,7 +5706,7 @@ case "$OSTYPE" in


           if test "xRELEASE" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
Index: opal-3.10.10~dfsg2/opal.m4
===================================================================
--- opal-3.10.10~dfsg2.orig/opal.m4
+++ opal-3.10.10~dfsg2/opal.m4
@@ -154,7 +154,7 @@ dnl            $LIB_FILENAME_SHARED_PAT
 AC_DEFUN([OPAL_DETERMINE_LIBNAMES],
          [
           if test "x$1" = "xDEBUG" ; then
-            OBJ_SUFFIX="_d"
+            OBJ_SUFFIX=""
           else
             OBJ_SUFFIX=""
           fi
Index: opal-3.10.10~dfsg2/samples/simple/Makefile
===================================================================
--- opal-3.10.10~dfsg2.orig/samples/simple/Makefile
+++ opal-3.10.10~dfsg2/samples/simple/Makefile
@@ -35,7 +35,7 @@ endif

 # Determine which package to use debug or release
 ifeq ($(DEBUG_BUILD), yes)
-DEBUG_SUFFIX=_d
+DEBUG_SUFFIX=
 CFLAGS += -g
 else
 DEBUG_SUFFIX=

使用debuild -us -uc -i -I构建软件包。