Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: 陳韋任 <chenwj@iis.sinica.edu.tw>
To: gdb@sourceware.org
Subject: Re: How to run gdb with LD_PRELOAD?
Date: Thu, 20 Jan 2011 07:22:00 -0000	[thread overview]
Message-ID: <20110120072229.GA75330@cs.nctu.edu.tw> (raw)
In-Reply-To: <20110116080056.GA61509@cs.nctu.edu.tw>

Hi, all

  I also posted this question on stackoverflow, see the link
below.

  http://stackoverflow.com/questions/4703763/how-to-run-gdb-with-ld-preload

  It turns out that LD_PRELOAD not only affect qemu-i386 but also
the bash invoked by gdb. The shared library dbo.so loaded by
LD_PRELOAD is quite special, I think. What dbo.so 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 dbo.so
__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"
   */  
  dbo.OpenELF(argv[3]);

  // 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
"bzip2_base.i386-m32-gcc44-annotated".

Regards,
chenwj

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


  reply	other threads:[~2011-01-20  7:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-15 14:45 陳韋任
2011-01-15 23:16 ` Michael Snyder
2011-01-16  2:56   ` 陳韋任
2011-01-16  8:01     ` Philippe Waroquiers
2011-01-16  8:04       ` 陳韋任
2011-01-16  0:52 ` Hui Zhu
2011-01-16  2:58   ` 陳韋任
2011-01-16  8:01 ` 陳韋任
2011-01-20  7:22   ` 陳韋任 [this message]
2011-01-20  7:35     ` Pedro Alves
2011-01-20  9:29       ` 陳韋任

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110120072229.GA75330@cs.nctu.edu.tw \
    --to=chenwj@iis.sinica.edu.tw \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox