LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1279|回复: 14

gdb调试共享库的问题

[复制链接]
发表于 2004-7-14 10:14:38 | 显示全部楼层 |阅读模式
开发Linux的共享库(so),如何调试?
我使用"gcc -g "编译了一个共享库libtest.so,使用testexec1程序(gcc -g编译)调用成功,但是不能执行调试,如下,请问这是什么原因?

//////////////////////////////////////////////////////////////////////
[root@gyq-c src]# ./testexec1
num = 2030, test(num) = 3030
[root@gyq-c src]# gdb testexec1
GNU gdb Red Hat Linux (6.0post-0.20040223.17rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"..."/home/hqgyq/Projects/testexec1/src/testexec1": not in executable format: 不可识别的文件格式
                                                                                
(gdb)
发表于 2004-7-14 11:17:54 | 显示全部楼层
用file命令看看testexec1是什么文件格式。
 楼主| 发表于 2004-7-14 11:29:35 | 显示全部楼层
[root@gyq-c src]# file testexec1
testexec1: Bourne shell script text executable
[root@gyq-c src]#

为什么会这样?
发表于 2004-7-14 14:41:56 | 显示全部楼层
这就对了,bash shell脚本的格式是文本文件嘛,怎么能用gdb调试呢?
直接用文本编辑器打开就可以了。
ps: 你是怎么用gcc编译出shell脚本的?
 楼主| 发表于 2004-7-14 14:46:53 | 显示全部楼层
gcc能编译出脚本来吗?
我真地不懂。
发表于 2004-7-14 14:48:57 | 显示全部楼层
但是file命令的结果明明是shell脚本呀!
 楼主| 发表于 2004-7-14 15:23:32 | 显示全部楼层
我是用anjuta1.2.2编译的,
??????????
发表于 2004-7-14 16:51:10 | 显示全部楼层
你用文本编辑器把文件打开看看它的文件头是什么?
 楼主| 发表于 2004-7-14 16:58:33 | 显示全部楼层
文件内容是这样的(gcc能编译出这样的文件!!!???):
#! /bin/sh

# compressiondriver - temporary wrapper script for .libs/compressiondriver
# Generated by ltmain.sh - GNU libtool 1.4.3 (1.922.2.111 2002/10/23 02:54:36)
#
# The compressiondriver program cannot be directly executed until all the libtool
# libraries that it depends on are installed.
#
# This wrapper script should never be moved out of the build directory.
# If it is, it will not operate correctly.

# Sed substitution that helps us do robust quoting.  It backslashifies
# metacharacters that are still active within double-quoted strings.
Xsed=/bin/sed' -e 1s/^X//'
sed_quote_subst='s/\([\\`\\"$\\\\]\)/\\\1/g'

# The HP-UX ksh and POSIX shell print the target directory to stdout
# if CDPATH is set.
if test "${CDPATH+set}" = set; then CDPATH=:; export CDPATH; fi

relink_command="(cd /home/hqgyq/Projects/CompressionDriver/src; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=\"/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/hqgyq/bin\"; export PATH; gcc -Wall -g -o \$progdir/\$file main.o  -L/home/hqgyq/Projects/Compression/src /home/hqgyq/Projects/Compression/src/.libs/libcompression.so -Wl,--rpath -Wl,/home/hqgyq/Projects/Compression/src/.libs -Wl,--rpath -Wl,/usr/local/lib)"

# This environment variable determines our operation mode.
if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
  # install mode needs the following variable:
  notinst_deplibs=' /home/hqgyq/Projects/Compression/src/libcompression.la'
else
  # When we are sourced in execute mode, $file and $echo are already set.
  if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
    echo="echo"
    file="$0"
    # Make sure echo works.
    if test "X$1" = X--no-reexec; then
      # Discard the --no-reexec flag, and continue.
      shift
    elif test "X`($echo '\t') 2>/dev/null`" = 'X\t'; then
      # Yippee, $echo works!
      :
    else
      # Restart under the correct shell, and then maybe $echo will work.
      exec /bin/sh "$0" --no-reexec ${1+"$@"}
    fi
  fi

  # Find the directory that this script lives in.
  thisdir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`
  test "x$thisdir" = "x$file" && thisdir=.

  # Follow symbolic links until we get to the real thisdir.
  file=`ls -ld "$file" | /bin/sed -n 's/.*-> //p'`
  while test -n "$file"; do
    destdir=`$echo "X$file" | $Xsed -e 's%/[^/]*$%%'`

    # If there was a directory component, then change thisdir.
    if test "x$destdir" != "x$file"; then
      case "$destdir" in
      [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
      *) thisdir="$thisdir/$destdir" ;;
      esac
    fi

    file=`$echo "X$file" | $Xsed -e 's%^.*/%%'`
    file=`ls -ld "$thisdir/$file" | /bin/sed -n 's/.*-> //p'`
  done

  # Try to get the absolute directory name.
  absdir=`cd "$thisdir" && pwd`
  test -n "$absdir" && thisdir="$absdir"

  program=lt-'compressiondriver'
  progdir="$thisdir/.libs"

  if test ! -f "$progdir/$program" || \
     { file=`ls -1dt "$progdir/$program" "$progdir/../$program" 2>/dev/null | /bin/sed 1q`; \
       test "X$file" != "X$progdir/$program"; }; then

    file="$$-$program"

    if test ! -d "$progdir"; then
      mkdir "$progdir"
    else
      rm -f "$progdir/$file"
    fi

    # relink executable if necessary
    if test -n "$relink_command"; then
      if relink_command_output=`eval $relink_command 2>&1`; then :
      else
        echo "$relink_command_output" >&2
        rm -f "$progdir/$file"
        exit 1
      fi
    fi

    mv -f "$progdir/$file" "$progdir/$program" 2>/dev/null ||
    { rm -f "$progdir/$program";
      mv -f "$progdir/$file" "$progdir/$program"; }
    rm -f "$progdir/$file"
  fi

  if test -f "$progdir/$program"; then
    if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
      # Run the actual program with our arguments.

      # Export the path to the program.
      PATH="$progdirPATH"
      export PATH

      exec $program ${1+"$@"}

      $echo "$0: cannot exec $program ${1+"$@"}"
      exit 1
    fi
  else
    # The program doesn't exist.
    $echo "$0: error: $progdir/$program does not exist" 1>&2
    $echo "This script is just a wrapper for $program." 1>&2
    echo "See the libtool documentation for more information." 1>&2
    exit 1
  fi
fi
发表于 2004-7-14 17:38:50 | 显示全部楼层
呵呵,果然是脚本程序。
估计是集成开发环境调用libtools搞出来的。gcc肯定不会生成这样的文件。
现在知道IDE过于自动化的好处了吧。
试试在命令行上编译吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表