How to run gdb with LD_PRELOAD?

后端 未结 1 1145
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 06:55

I have a program using LD_PRELOAD. The program should be run like this, \"LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD a.out\", if without gdb.

Here are what I did w

1条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 07:23

    GDB does not invoke your executable directly. Instead, it does

    bash -c '/nfs_home/chenwj/tools/bin/qemu-i386  -U LD_PRELOAD bzip2_base.i386-m32-gcc44-annotated input.source 1'
    

    This is done so that bash takes care of I/O redirection (which you are not using).

    My guess is that /bin/bash doesn't work when LD_PRELOAD=libdbo.so is in effect, though I don't understand the exact nature of failure.

    One way to work around this problem is to create a wrapper executable, implementing C equivalent of this:

    export LD_PRELOAD=/nfs_home/chenwj/tools/lib/libdbo.so
    exec /nfs_home/chenwj/tools/bin/qemu-i386 "$@"
    

    and debug that executable (without setting LD_PRELOAD). You'll see an extra SIGTRAP when the wrapper execve()s the wrapped qemu-i386, which you should ignore and continue.

    0 讨论(0)
提交回复
热议问题