How to run gdb with LD_PRELOAD?

Thu Jan 20 07:22:00 GMT 2011

Hi, all

  I also posted this question on stackoverflow, see the link

  It turns out that LD_PRELOAD not only affect qemu-i386 but also
the bash invoked by gdb. The shared library loaded by
LD_PRELOAD is quite special, I think. What does is try
to be executed before the real __libc_start_main, does some hacking,
then pass to the real __libc_start_main.

  Here is the code snippet,
// __libc_start_main provided by
__libc_start_main( PARAMS_START_MAIN )
  // copy the original command line argument
  for( i = 1; i <  argc; i++ )
    argv[i] = ubp_av[i];

   *  Here we tend to open "bzip2_base.i386-m32-gcc44-annotated"

  // pass to the real __libc_start_main
  real_libc_start_main( main, argc, ( char** )argv, init, fini,
    rtld_fini, stack_end );

  The reason why "open "/bin/bash" failed: Permission denied
" occured while using gdb is that the bash invoked by gdb is affected
by LD_PRELOAD, too. Thus, bash will try to open something rather than


Wei-Ren Chen (陳韋任)
Parallel Processing Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667

More information about the Gdb mailing list