From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 353 invoked by alias); 20 Jan 2011 07:22:42 -0000 Received: (qmail 343 invoked by uid 22791); 20 Jan 2011 07:22:40 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,TW_NW,TW_QE,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from csmailer.cs.nctu.edu.tw (HELO csmailer.cs.nctu.edu.tw) (140.113.235.130) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 20 Jan 2011 07:22:33 +0000 Received: from csmailer.cs.nctu.edu.tw (localhost [127.0.0.1]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 3D5A1266 for ; Thu, 20 Jan 2011 15:24:59 +0800 (CST) Received: from alumni.cs.nctu.edu.tw (alumni.cs.nctu.edu.tw [140.113.235.116]) by csmailer.cs.nctu.edu.tw (Postfix) with ESMTP id 366A5265 for ; Thu, 20 Jan 2011 15:24:59 +0800 (CST) Received: (from chenwj@localhost) by alumni.cs.nctu.edu.tw (8.14.4/8.14.4/Submit) id p0K7MT0s077845 for gdb@sourceware.org; Thu, 20 Jan 2011 15:22:29 +0800 (CST) (envelope-from chenwj) Date: Thu, 20 Jan 2011 07:22:00 -0000 From: =?utf-8?B?6Zmz6Z+L5Lu7?= To: gdb@sourceware.org Subject: Re: How to run gdb with LD_PRELOAD? Message-ID: <20110120072229.GA75330@cs.nctu.edu.tw> Mail-Followup-To: gdb@sourceware.org References: <20110115144525.GD44658@cs.nctu.edu.tw> <20110116080056.GA61509@cs.nctu.edu.tw> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20110116080056.GA61509@cs.nctu.edu.tw> User-Agent: Mutt/1.5.21 (2010-09-15) Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2011-01/txt/msg00077.txt.bz2 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 =3D 1; i < argc; i++ ) argv[i] =3D ubp_av[i]; /* * Here we tend to open "bzip2_base.i386-m32-gcc44-annotated" */=20=20 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 --=20 Wei-Ren Chen (=E9=99=B3=E9=9F=8B=E4=BB=BB) Parallel Processing Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667