How to use gdb with LD_PRELOAD

后端 未结 5 1390
攒了一身酷
攒了一身酷 2020-12-23 16:24

I run a program with LD_PRELOADing a specific library. Like this.

LD_PRELOAD=./my.so ./my_program

How do I run this program with gdb<

5条回答
  •  悲哀的现实
    2020-12-23 16:49

    Posting because we ran into a case where set environment didn't work:

    From GDB documentation:

    set exec-wrapper wrapper
    show exec-wrapper
    unset exec-wrapper
    

    When ‘exec-wrapper’ is set, the specified wrapper is used to launch programs for debugging. gdb starts your program with a shell command of the form exec wrapper program. Quoting is added to program and its arguments, but not to wrapper, so you should add quotes if appropriate for your shell. The wrapper runs until it executes your program, and then gdb takes control.

    You can use any program that eventually calls execve with its arguments as a wrapper. Several standard Unix utilities do this, e.g. env and nohup. Any Unix shell script ending with exec "$@" will also work.

    For example, you can use env to pass an environment variable to the debugged program, without setting the variable in your shell's environment:

             (gdb) set exec-wrapper env 'LD_PRELOAD=libtest.so'
             (gdb) run
    

提交回复
热议问题