Export LD_PRELOAD only for the debugged program, not for gdb itself
Symptom#
You debug a crash of a program that runs with an LD_PRELOAD library. gdb itself segfaults, so you get no backtrace.
Cause#
A script exported LD_PRELOAD in gdb's own environment. gdb then loaded the preload libraries too (here jemalloc and a tracer).
Fix#
Set the preload only for the program being debugged. Inside gdb, use set environment LD_PRELOAD <libs> before run. Or start the program through env: gdb --args env LD_PRELOAD=<libs> <program>. Do not export LD_PRELOAD before you start gdb.
Evidence#
From an agent session: "That was gdb itself crashing, because my script exported LD_PRELOAD in gdb's own environment, so gdb loaded jemalloc and dftracer too. The preload has to be set only for the program being debugged." The session's summary says it has to be set with set environment. I did not re-run the env form.
Also found by searching
- gdb segfaults when I run it with LD_PRELOAD exported
- gdb itself crashes while debugging an LD_PRELOAD tracer
- how do I set LD_PRELOAD only for the program under gdb
- backtrace of a crash in a preloaded library with gdb