How to use gdb with LD_PRELOAD

后端 未结 5 1391
攒了一身酷
攒了一身酷 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:47

    You can basically do it the same way, just add gdb before the program name:

    LD_PRELOAD=./my.so gdb ./my.program
    

    You can check the environment variables using:

    (gdb) show environment LD_PRELOAD
    

    In the rare case you actually need to change it inside gdb, e.g. when debugging a dlopen(), you ca do that:

    (gdb) set environment LD_PRELOAD ./my.so
    

    Oh, wait, it doesn't work for me with gdb 7.6.2! The library doesn't get loaded, that means none of the answer here are entirely correct, at least with current tools.

提交回复
热议问题