[Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Samuel Quiring
Greetings,

I invoke my program as follows:

 LD_PRELOAD=./libfakec.so ./my_app –e

The LD_PRELOAD environment variable tells the loader that libfakec.so should be 
loaded BEFORE every other library including the C runtime, libc.so (see 
http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick, for 
example).  I am substituting some of my own routines for standard library 
calls.  My app is working like I want, but the question is how to run the app 
under valgrind?  I tried this:

valgrind LD_PRELOAD=./libfakec.so ./my_app –e

But valgrind gave and error saying that LD_PRELOAD=./libfakec.so ./my_app –e 
is not a valid path.  In theory, I could put the LD_PRELOAD before the valgrind 
invocation:

LD_PRELOAD=./libfakec.so  valgrind  ./my_app –e

But then valgrind would also be using my special library routines and I am 
pretty sure that will not work.

Is there a way around this?  I am running on CentOS 6.5.

-Sam

PS: I tried to figure out how to search the archives of this mailing list for 
LD_PRELOAD, but I could not see a way.
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] valgrind with shell scripts

2014-01-14 Thread Samuel Quiring
Greetings,

Normally I invoke my app using a shell script:

 ./run.sh  –e  run log

If I invoke this script using valgrind:

 valgrind ./run.sh –e  run log

Will valgrind evaluate the shell script or my app or both?

-Sam


--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with shell scripts

2014-01-14 Thread Dan Kegel
On Tue, Jan 14, 2014 at 7:18 AM, Samuel Quiring
samuel_quir...@symantec.com wrote:
  valgrind ./run.sh –e  run log

 Will valgrind evaluate the shell script or my app or both?

Just the shell script.  Try --trace-children=yes .

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with shell scripts

2014-01-14 Thread David Faure
On Tuesday 14 January 2014 07:18:05 Samuel Quiring wrote:
 Greetings,
 
 Normally I invoke my app using a shell script:
 
  ./run.sh  –e  run log

[I don't understand the run log part of it, but let's ignore that]

 If I invoke this script using valgrind:
 
  valgrind ./run.sh –e  run log
 
 Will valgrind evaluate the shell script or my app or both?

The shell script. Better modify the shell script itself to call valgrind :)

But you can also use the above command with --trace-children=yes
and then it will trace all children, including your app.

-- 
David Faure, fa...@kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5


--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


[Valgrind-users] Best valgrind options for finding corrupt memory

2014-01-14 Thread Samuel Quiring
Greetings,

I suspect my program is corrupting (overwriting) memory, e.g., malloc'ing 16 
bytes for a string that is 17 bytes when you count the nul, then copying 17 
bytes into the 16 byte area.  What are the best valgrind options for detecting 
memory corruption?

-Sam

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] Best valgrind options for finding corrupt memory

2014-01-14 Thread David Faure
On Tuesday 14 January 2014 08:03:14 Samuel Quiring wrote:
 Greetings,
 
 I suspect my program is corrupting (overwriting) memory, e.g., malloc'ing 16
 bytes for a string that is 17 bytes when you count the nul, then copying 17
 bytes into the 16 byte area.  What are the best valgrind options for
 detecting memory corruption?

The default options :-)

(memcheck tool)

-- 
David Faure, fa...@kde.org, http://www.davidfaure.fr
Working on KDE, in particular KDE Frameworks 5


--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with shell scripts

2014-01-14 Thread Fred Smith
Or modify the shellscript to add valgrind and its args to the statement that 
invokes your final program.

Fred Smith
Senior Applications Programmer/Analyst
Computrition, Inc.
175 Middlesex Turnpike
Bedford, MA 01730
ph: 781-275-4488 x5013
fax: 781-357-4100


-Original Message-
From: Dan Kegel [mailto:d...@kegel.com] 
Sent: Tuesday, January 14, 2014 10:36 AM
To: Samuel Quiring
Cc: valgrind-users@lists.sourceforge.net
Subject: Re: [Valgrind-users] valgrind with shell scripts

On Tue, Jan 14, 2014 at 7:18 AM, Samuel Quiring
samuel_quir...@symantec.com wrote:
  valgrind ./run.sh -e  run log

 Will valgrind evaluate the shell script or my app or both?

Just the shell script.  Try --trace-children=yes .

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to which they are addressed. If 
you have received this email in error please notify the system manager. Please 
note that any views or opinions presented in this email are solely those of the 
author and do not necessarily represent those of the company. Finally, the 
recipient should check this email and any attachments for the presence of 
viruses. The company accepts no liability for any damage caused by any virus 
transmitted by this email

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with shell scripts

2014-01-14 Thread Patrick J. LoPresti
On Tue, Jan 14, 2014 at 7:18 AM, Samuel Quiring
samuel_quir...@symantec.com wrote:

 Will valgrind evaluate the shell script or my app or both?

The script, and as others have said, --trace-children=yes will do
what you want. However...

...you can also change your script to exec your app. That is better
style anyway (fewer processes, allows parent process to retrieve
proper exit status, etc.), if your script does not have any work to do
after your app terminates.

 - Pat

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Philippe Waroquiers
On Tue, 2014-01-14 at 07:14 -0800, Samuel Quiring wrote:

 LD_PRELOAD=./libfakec.so  valgrind  ./my_app –e
 
 
 But then valgrind would also be using my special library routines and
 I am pretty sure that will not work.
 
 
 Is there a way around this?  I am running on CentOS 6.5.


I guess that your second question, related to running a shell script
and its children under Valgrind is related to setting LD_PRELOAD
in the run.sh.
I am not sure that this will solve the possible problem.

Here are some elements:

There are 2 stages for starting your program under valgrind.
The stage 1 is the valgrind launcher (this is the valgrind
executable).
This is a normal executable, dynamically linked, and depends
on some standard shared libs as shown by
ldd valgrind
linux-gate.so.1 =  (0x007ab000)
libc.so.6 = /lib/libc.so.6 (0x00214000)
/lib/ld-linux.so.2 (0x001f2000)

valgrind (stage 1) will then launch the stage 2, which is
the specific tool as requested on the command line (e.g. memcheck)
and for the needed platform (e.g. x86).
So, it will e.g. launch memcheck-x86-linux, which is not a dynamic
executable:
ldd memcheck-x86-linux 
not a dynamic executable

As long as your LD_PRELOAD does not change the behaviour of
the libraries used by valgrind stage 1, then valgrind stage 1
should work properly.
If your LD_PRELOAD replaces things part of e.g. libc, you might
have problems in valgrind stage 1.


If you cannot make all that work, there might be ways to solve that:

* maybe statically link the valgrind stage 1 ?
* otherwise, modify the function setup_client_env in 
coregrind/m_initimg/initimg-linux.c
  so as to add your specific LD_PRELOAD string only for the client.
  (but I suspect that will however then not work with
--trace-children=yes, as then the LD_PRELOAD will be used
   by the valgrind stage 1 used to launch the tool on a forked/exec-ed
   children.

Hope this helps, give some feedback about what has worked (or not).

We might maybe need to add a valgrind option
   --client-ld-preload=.. 
to avoid such problem ?
Or alternatively, statically link valgrind (but that means that
valgrind can then only be built if all libs for static linking
are available).



Philippe



--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] Best valgrind options for finding corrupt memory

2014-01-14 Thread gene.fortan...@freescale.com
Hi,

Yes defaults. Starting at 4:52 of this YouTube video you will see this fellow 
determine that his code also has the strlen problem with malloc:
http://www.youtube.com/watch?v=fvTsFjDuag8


Bye,
Gene Fortanely | Freescale Semiconductor


-Original Message-
From: David Faure [mailto:fa...@kde.org] 
Sent: Tuesday, January 14, 2014 10:05 AM
To: valgrind-users@lists.sourceforge.net
Cc: Samuel Quiring
Subject: Re: [Valgrind-users] Best valgrind options for finding corrupt memory

On Tuesday 14 January 2014 08:03:14 Samuel Quiring wrote:
 Greetings,
 
 I suspect my program is corrupting (overwriting) memory, e.g., 
 malloc'ing 16 bytes for a string that is 17 bytes when you count the 
 nul, then copying 17 bytes into the 16 byte area.  What are the best 
 valgrind options for detecting memory corruption?

The default options :-)

(memcheck tool)

--
David Faure, fa...@kde.org, http://www.davidfaure.fr Working on KDE, in 
particular KDE Frameworks 5


--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users



--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] Best valgrind options for finding corrupt memory

2014-01-14 Thread Philippe Waroquiers
On Tue, 2014-01-14 at 17:04 +0100, David Faure wrote:
 On Tuesday 14 January 2014 08:03:14 Samuel Quiring wrote:
  Greetings,
  
  I suspect my program is corrupting (overwriting) memory, e.g., malloc'ing 16
  bytes for a string that is 17 bytes when you count the nul, then copying 17
  bytes into the 16 byte area.  What are the best valgrind options for
  detecting memory corruption?
 
 The default options :-)
 
 (memcheck tool)
 
memcheck default options are effectively ok by default.

But there are some options that you can change if you want to increase
the probability to find a memory corruption or get more info about 
such a bug.

Typically, you might use one or more of the following:

--redzone-size=number   set minimum size of redzones added before/after
  heap blocks (in bytes). [16]

--read-var-info=yes|noread debug info on stack and global variables
  and use it to print better error messages in
  tools that make use of it (Memcheck, Helgrind,
  DRD) [no]
--freelist-vol=number  volume of freed blocks queue [2000]
--freelist-big-blocks=number   releases first blocks with size= [100]
--keep-stacktraces=alloc|free|alloc-and-free|alloc-then-free|none
stack trace(s) to keep for malloc'd/free'd areas   [alloc-then-free]

The above will impact (increase or decrease) memory and/or cpu used by valgrind.


Philippe



--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Mike Shal
On Tue, Jan 14, 2014 at 10:14 AM, Samuel Quiring 
samuel_quir...@symantec.com wrote:

 Greetings,

 I invoke my program as follows:

  LD_PRELOAD=./libfakec.so ./my_app –e

 The LD_PRELOAD environment variable tells the loader that libfakec.so
 should be loaded BEFORE every other library including the C runtime,
 libc.so (see
 http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick,
 for example).  I am substituting some of my own routines for standard
 library calls.  My app is working like I want, but the question is how to
 run the app under valgrind?  I tried this:

 valgrind LD_PRELOAD=./libfakec.so ./my_app –e

 But valgrind gave and error saying that LD_PRELOAD=./libfakec.so ./my_app
 –e is not a valid path.  In theory, I could put the LD_PRELOAD before the
 valgrind invocation:

 LD_PRELOAD=./libfakec.so  valgrind  ./my_app –e

 But then valgrind would also be using my special library routines and I am
 pretty sure that will not work.


Maybe you can do it with a shell-script wrapper? Eg:

run-me.sh:
#! /bin/sh
LD_PRELOAD=./libfakec.so ./myapp -e

Then run:

valgrind --trace-children=yes ./run-me.sh

-Mike
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Philippe Waroquiers
On Tue, 2014-01-14 at 11:29 -0500, Mike Shal wrote:
 O
 
 Maybe you can do it with a shell-script wrapper? Eg:
 
 
 run-me.sh:
 
 #! /bin/sh
 
 LD_PRELOAD=./libfakec.so ./myapp -e
 
 
 Then run:
 
 valgrind --trace-children=yes ./run-me.sh

I do not think so, as the trace-children=yes will cause the valgrind
launcher to be relaunched to launch myapp. And this valgrind child
will then use the problematic LD_PRELOAD library.

Philippe




--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Mike Shal
On Tue, Jan 14, 2014 at 11:37 AM, Philippe Waroquiers 
philippe.waroqui...@skynet.be wrote:

 On Tue, 2014-01-14 at 11:29 -0500, Mike Shal wrote:
  O
 
  Maybe you can do it with a shell-script wrapper? Eg:
 
 
  run-me.sh:
 
  #! /bin/sh
 
  LD_PRELOAD=./libfakec.so ./myapp -e
 
 
  Then run:
 
  valgrind --trace-children=yes ./run-me.sh

 I do not think so, as the trace-children=yes will cause the valgrind
 launcher to be relaunched to launch myapp. And this valgrind child
 will then use the problematic LD_PRELOAD library.


Oh, hmm. I had just tried a simple LD_PRELOAD test with wrapping fopen()
and open(). I added a constructor function to the library to see where it
gets initialized, and it does indeed get added to valgrind with
--trace-children=yes. So, scratch that.

We might maybe need to add a valgrind option
--client-ld-preload=..
 to avoid such problem ?


Or maybe a more general --client-environment? That way it's not specific to
LD_PRELOAD.

-Mike
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Samuel Quiring
| Maybe you can do it with a shell-script wrapper? Eg:
|
| run-me.sh:
| #! /bin/sh
| LD_PRELOAD=./libfakec.so ./myapp -e
|
| Then run:
|
| valgrind --trace-children=yes ./run-me.sh

This has been my approach.  Now I am suspicious that  - -trace-children=yes is 
not working like I hoped.  I get the EXACT SAME output whether I have  - 
-trace–children=yes or do not have that option.  So I think there must be more 
to getting  - -trace-children=yes to behave like I want.

Here is the output.  Every number is the same whether or not I have - 
-trace-children=yes.

==13527== HEAP SUMMARY:
==13527== in use at exit: 19,116 bytes in 584 blocks
==13527==   total heap usage: 766 allocs, 182 frees, 29,553 bytes allocated
==13527==
==13527== LEAK SUMMARY:
==13527==definitely lost: 0 bytes in 0 blocks
==13527==indirectly lost: 0 bytes in 0 blocks
==13527==  possibly lost: 0 bytes in 0 blocks
==13527==still reachable: 19,116 bytes in 584 blocks
==13527== suppressed: 0 bytes in 0 blocks



From: Mike Shal mar...@gmail.commailto:mar...@gmail.com
Date: Tue, Jan 14 9:29 AM
To: Samuel Quiring 
samuel_quir...@symantec.commailto:samuel_quir...@symantec.com
Cc: 
valgrind-users@lists.sourceforge.netmailto:valgrind-users@lists.sourceforge.net
 
valgrind-users@lists.sourceforge.netmailto:valgrind-users@lists.sourceforge.net
Subject: Re: [Valgrind-users] valgrind with LD_PRELOAD

On Tue, Jan 14, 2014 at 10:14 AM, Samuel Quiring 
samuel_quir...@symantec.commailto:samuel_quir...@symantec.com wrote:
Greetings,

I invoke my program as follows:

 LD_PRELOAD=./libfakec.so ./my_app –e

The LD_PRELOAD environment variable tells the loader that libfakec.so should be 
loaded BEFORE every other library including the C runtime, libc.so (see 
http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick, for 
example).  I am substituting some of my own routines for standard library 
calls.  My app is working like I want, but the question is how to run the app 
under valgrind?  I tried this:

valgrind LD_PRELOAD=./libfakec.so ./my_app –e

But valgrind gave and error saying that LD_PRELOAD=./libfakec.so ./my_app –e 
is not a valid path.  In theory, I could put the LD_PRELOAD before the valgrind 
invocation:

LD_PRELOAD=./libfakec.so  valgrind  ./my_app –e

But then valgrind would also be using my special library routines and I am 
pretty sure that will not work.


Maybe you can do it with a shell-script wrapper? Eg:

run-me.sh:
#! /bin/sh
LD_PRELOAD=./libfakec.so ./myapp -e

Then run:

valgrind --trace-children=yes ./run-me.sh

-Mike
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Philippe Waroquiers
On Tue, 2014-01-14 at 08:57 -0800, Samuel Quiring wrote:
 | Maybe you can do it with a shell-script wrapper? Eg:
 |
 | run-me.sh:
 
 | #! /bin/sh
 
 | LD_PRELOAD=./libfakec.so ./myapp -e
 |
 | Then run:
 |
 | valgrind --trace-children=yes ./run-me.sh
 
 
 
 This has been my approach.  Now I am suspicious that  -
As explained in another mail, it is highly suspected that this
will not help to solve your problem.

  -trace-children=yes is not working like I hoped.  I get the EXACT
 SAME output whether I have  - -trace–children=yes or do not have that
 option.  So I think there must be more to getting  -
 -trace-children=yes to behave like I want.
 
 
 Here is the output.  Every number is the same whether or not I have -
 -trace-children=yes.
 
 
 ==13527== HEAP SUMMARY:
 ==13527== in use at exit: 19,116 bytes in 584 blocks
 ==13527==   total heap usage: 766 allocs, 182 frees, 29,553 bytes
 allocated
 ==13527== 
 ==13527== LEAK SUMMARY:
 ==13527==definitely lost: 0 bytes in 0 blocks
 ==13527==indirectly lost: 0 bytes in 0 blocks
 ==13527==  possibly lost: 0 bytes in 0 blocks
 ==13527==still reachable: 19,116 bytes in 584 blocks
 ==13527== suppressed: 0 bytes in 0 blocks
The above must be the output of valgrind for the shell. The shell
behaviour does not change for --trace-children=yes/no.
But when giving --trace-children=yes, you should get additional input
before.
E.g. this is what I get:

==3589== Command: ./run.sh
...
==3590== Command: 
/home/philippe/valgrind/trunk_untouched/memcheck/tests/trivialleak
...
==3590== HEAP SUMMARY:
==3590== in use at exit: 1,000 bytes in 1,000 blocks
==3590==   total heap usage: 1,000 allocs, 0 frees, 1,000 bytes allocated
...
==3589== HEAP SUMMARY:
==3589== in use at exit: 19,960 bytes in 572 blocks
==3589==   total heap usage: 725 allocs, 153 frees, 26,630 bytes allocated
...

So, with trace children, you see lines for different pids (and a heap summary
result for each process which exits)

Philippe




--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users


Re: [Valgrind-users] valgrind with LD_PRELOAD

2014-01-14 Thread Magnus Reftel
On 14 January 2014 16:14, Samuel Quiring samuel_quir...@symantec.com wrote:
 Greetings,

 I invoke my program as follows:

  LD_PRELOAD=./libfakec.so ./my_app –e

 The LD_PRELOAD environment variable tells the loader that libfakec.so should
 be loaded BEFORE every other library including the C runtime, libc.so (see
 http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick, for
 example).  I am substituting some of my own routines for standard library
 calls.  My app is working like I want, but the question is how to run the
 app under valgrind?

What I did when I was in a similar situation was to have an
initialization function ( marked __attribute__((constructor)) ) which
checked the name of the executable to determine whether to use my
versions of the functions or the libc ones. In my functions, I then
had an if which either did the special things which was the reason for
the LD_PRELOAD, or just delegated to the libc implementation of the
function depending on whether the executable was the target one.

But yes, the suggestions from Philippe Waroquiers and Mike Shal about
passing variables would have made life a lot easier.

BR
Magnus Reftel

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users