Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* How to run gdb with LD_PRELOAD?
@ 2011-01-15 14:45 陳韋任
  2011-01-15 23:16 ` Michael Snyder
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: 陳韋任 @ 2011-01-15 14:45 UTC (permalink / raw)
  To: gdb

Hi, all

  I have a program using LD_PRELOAD. The program should be run like
this, "LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD a.out", if
without gdb.

  Here are what I did while running gdb.

--------------------------------------------------------------------
$ gdb
(gdb) set environment LD_PRELOAD=/path/to/libfoo.so
(gdb) file qemu
(gdb) r -U LD_PRELOAD a.out
--------------------------------------------------------------------

  But gdb gave me the error below,

ERROR: ld.so: object '/nfs_home/chenwj/lib/libdbo.so' from LD_PRELOAD cannot be preloaded: ignored.

  Any suggestion appreciated.  

Regards,
chenwj

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-15 14:45 How to run gdb with LD_PRELOAD? 陳韋任
@ 2011-01-15 23:16 ` Michael Snyder
  2011-01-16  2:56   ` 陳韋任
  2011-01-16  0:52 ` Hui Zhu
  2011-01-16  8:01 ` 陳韋任
  2 siblings, 1 reply; 11+ messages in thread
From: Michael Snyder @ 2011-01-15 23:16 UTC (permalink / raw)
  To: 陳韋任; +Cc: gdb

陳韋任 wrote:
> Hi, all
> 
>   I have a program using LD_PRELOAD. The program should be run like
> this, "LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD a.out", if
> without gdb.
> 
>   Here are what I did while running gdb.
> 
> --------------------------------------------------------------------
> $ gdb
> (gdb) set environment LD_PRELOAD=/path/to/libfoo.so
> (gdb) file qemu
> (gdb) r -U LD_PRELOAD a.out
> --------------------------------------------------------------------
> 
>   But gdb gave me the error below,
> 
> ERROR: ld.so: object '/nfs_home/chenwj/lib/libdbo.so' from LD_PRELOAD cannot be preloaded: ignored.
> 
>   Any suggestion appreciated.  


I would think it should be

(gdb) set environment LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD
(gdb) run


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-15 14:45 How to run gdb with LD_PRELOAD? 陳韋任
  2011-01-15 23:16 ` Michael Snyder
@ 2011-01-16  0:52 ` Hui Zhu
  2011-01-16  2:58   ` 陳韋任
  2011-01-16  8:01 ` 陳韋任
  2 siblings, 1 reply; 11+ messages in thread
From: Hui Zhu @ 2011-01-16  0:52 UTC (permalink / raw)
  To: 陳韋任; +Cc: gdb

http://sourceware.org/gdb/current/onlinedocs/gdb/Environment.html#Environment

On Sat, Jan 15, 2011 at 22:45, 陳韋任 <chenwj@iis.sinica.edu.tw> wrote:
> Hi, all
>
>  I have a program using LD_PRELOAD. The program should be run like
> this, "LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD a.out", if
> without gdb.
>
>  Here are what I did while running gdb.
>
> --------------------------------------------------------------------
> $ gdb
> (gdb) set environment LD_PRELOAD=/path/to/libfoo.so
> (gdb) file qemu
> (gdb) r -U LD_PRELOAD a.out
> --------------------------------------------------------------------
>
>  But gdb gave me the error below,
>
> ERROR: ld.so: object '/nfs_home/chenwj/lib/libdbo.so' from LD_PRELOAD cannot be preloaded: ignored.
>
>  Any suggestion appreciated.
>
> Regards,
> chenwj
>
> --
> Wei-Ren Chen (陳韋任)
> Parallel Processing Lab, Institute of Information Science,
> Academia Sinica, Taiwan (R.O.C.)
> Tel:886-2-2788-3799 #1667
>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-15 23:16 ` Michael Snyder
@ 2011-01-16  2:56   ` 陳韋任
  2011-01-16  8:01     ` Philippe Waroquiers
  0 siblings, 1 reply; 11+ messages in thread
From: 陳韋任 @ 2011-01-16  2:56 UTC (permalink / raw)
  To: Michael Snyder; +Cc: 陳韋任, gdb

Hi, Michael

> (gdb) set environment LD_PRELOAD=/path/to/libfoo.so qemu -U LD_PRELOAD
> (gdb) run

  Thanks for your reply.

  I actually use qemu as an emulator to run a program like "a.out". And the
LD_PRELOAD  is for qemu not the a.out. I did what you said, but gdb gave
me the error below,

ERROR: ld.so: object '/nfs_home/chenwj/tools/bin/qemu-i386' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object '-U' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'LD_PRELOAD' from LD_PRELOAD cannot be preloaded: ignored.
Inconsistency detected by ld.so: rtld.c: 757: init_tls: Assertion `i == _rtld_local._dl_tls_max_dtv_idx' failed!
During startup program exited with code 127.

Regards,
chenwj

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-16  0:52 ` Hui Zhu
@ 2011-01-16  2:58   ` 陳韋任
  0 siblings, 0 replies; 11+ messages in thread
From: 陳韋任 @ 2011-01-16  2:58 UTC (permalink / raw)
  To: Hui Zhu; +Cc: 陳韋任, gdb

Hi, Hui Zhu

  I have saw the link you gave me, but I stll cannot figure out how to
run gdb with LD_PRELOAD. Can you give me an example in my case?

  Thanks!

Regards,
chenwj

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-15 14:45 How to run gdb with LD_PRELOAD? 陳韋任
  2011-01-15 23:16 ` Michael Snyder
  2011-01-16  0:52 ` Hui Zhu
@ 2011-01-16  8:01 ` 陳韋任
  2011-01-20  7:22   ` 陳韋任
  2 siblings, 1 reply; 11+ messages in thread
From: 陳韋任 @ 2011-01-16  8:01 UTC (permalink / raw)
  To: gdb

Hi, all

  A little update to my question.

  Here are what I do while running gdb.
---------------------------------------------------------------------------
(gdb) set environment LD_PRELOAD=/nfs_home/chenwj/tools/lib/libdbo.so
(gdb) file /nfs_home/chenwj/tools/bin/qemu-i386
(gdb) run -U LD_PRELOAD bzip2_base.i386-m32-gcc44-annotated input.source 1
---------------------------------------------------------------------------

  And error below.
---------------------------------------------------------------------------
Starting program: /nfs_home/chenwj/tools/bin/qemu-i386 -U LD_PRELOAD bzip2_base.i386-m32-gcc44-annotated input.source 1
bash: open "/bin/bash" failed: Permission denied
During startup program exited with code 66.
---------------------------------------------------------------------------    

  If I LD_PRELOAD other .so, everything is fine. My guess is there is
something in libdbo.so cause the "Permission denied".

  Any suggestion appreciated.

Regards,
chenwj

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-16  2:56   ` 陳韋任
@ 2011-01-16  8:01     ` Philippe Waroquiers
  2011-01-16  8:04       ` 陳韋任
  0 siblings, 1 reply; 11+ messages in thread
From: Philippe Waroquiers @ 2011-01-16  8:01 UTC (permalink / raw)
  To: 陳韋任; +Cc: 陳韋任, gdb

>  I actually use qemu as an emulator to run a program like "a.out". And the
> LD_PRELOAD  is for qemu not the a.out. I did what you said, but gdb gave
> me the error below,

If it is the a.out that you have to debug, the gdbserver embedded in qemu will allow
to debug it (using "target remote" command of gdb, once ou started qemu with gdbserver)



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-16  8:01     ` Philippe Waroquiers
@ 2011-01-16  8:04       ` 陳韋任
  0 siblings, 0 replies; 11+ messages in thread
From: 陳韋任 @ 2011-01-16  8:04 UTC (permalink / raw)
  To: Philippe Waroquiers; +Cc: 陳韋任, gdb

Hi, Philippe

> If it is the a.out that you have to debug, the gdbserver embedded in qemu will allow
> to debug it (using "target remote" command of gdb, once ou started qemu with gdbserver)

  Thanks for the info. But I actually want to debug the .so. Is this
possible?

Regards,
chenwj

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-16  8:01 ` 陳韋任
@ 2011-01-20  7:22   ` 陳韋任
  2011-01-20  7:35     ` Pedro Alves
  0 siblings, 1 reply; 11+ messages in thread
From: 陳韋任 @ 2011-01-20  7:22 UTC (permalink / raw)
  To: gdb

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-20  7:22   ` 陳韋任
@ 2011-01-20  7:35     ` Pedro Alves
  2011-01-20  9:29       ` 陳韋任
  0 siblings, 1 reply; 11+ messages in thread
From: Pedro Alves @ 2011-01-20  7:35 UTC (permalink / raw)
  To: gdb; +Cc: 陳韋任

See the manual for the documentation of "set exec-wrapper".

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: How to run gdb with LD_PRELOAD?
  2011-01-20  7:35     ` Pedro Alves
@ 2011-01-20  9:29       ` 陳韋任
  0 siblings, 0 replies; 11+ messages in thread
From: 陳韋任 @ 2011-01-20  9:29 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb, 陳韋任

> See the manual for the documentation of "set exec-wrapper".
Thanks! Pedro

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-01-20  9:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-15 14:45 How to run gdb with LD_PRELOAD? 陳韋任
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   ` 陳韋任
2011-01-20  7:35     ` Pedro Alves
2011-01-20  9:29       ` 陳韋任

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox