Bug 411203 - valgrind should have a mean to pass environment variable to target program
Summary: valgrind should have a mean to pass environment variable to target program
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-23 12:02 UTC by Yann Droneaud
Modified: 2024-05-16 20:29 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yann Droneaud 2019-08-23 12:02:19 UTC
Under glibc based operating system, I sometimes have to specify option to the dynamic loader ld.so using environment variables.

strace has -E option to do so.

It useful because sometime environment variables might have unwanted effect on the wrapper program: LD_LIBRARY_PATH could make the wrapper use libraries that it shouldn't. In fact any LD_ environment variable is a potential issue for the tracer.

strace -E is also great because it allows removing environment variables. 

Unfortunately, AFAICT, valgrind doesn't have (yet) support for altering the tracee environment variables.
Comment 1 Yann Droneaud 2019-08-23 12:12:05 UTC
It shouldn't be difficult to implement, but it's a bit tricky as valgrind launcher already communicate with each tool through environment variables.
So environment variable to be added/removed from tracee environment have to be encoded in environment variables passed to valgrind's tool.
I've to find how (and where) to implement this.
Comment 2 Julian Seward 2019-12-28 17:00:23 UTC
(In reply to Yann Droneaud from comment #0)

> Unfortunately, AFAICT, valgrind doesn't have (yet) support for altering the
> tracee environment variables.

Why do you say that?  AFAIK, V passes the env vars to the program it is running.
Comment 3 Yann Droneaud 2020-01-06 11:04:00 UTC
(In reply to Julian Seward from comment #2)
> (In reply to Yann Droneaud from comment #0)
> 
> > Unfortunately, AFAICT, valgrind doesn't have (yet) support for altering the
> > tracee environment variables.
> 
> Why do you say that?  AFAIK, V passes the env vars to the program it is
> running.

It's not possible to add/remove variables to the tracee's environment only.

For example, if I want to enable LD_VERBOSE=1 (only) for test-program to be traced, doing "LD_PROFILE=1 valgrind test-program" will affect valgrind too.

strace has the -E option that enable to set environment variables only for the program to be traced. See http://man7.org/linux/man-pages/man1/strace.1.html#OPTIONS
Comment 4 Paul Floyd 2023-01-19 14:47:02 UTC
Valgrind certainly can change the guest environment.

For a start Valgrind is responsible for synthesizing the guest stack which includes argv, envp, and auxv.

As necessary it will either add or modify LD_PRELOAD and GLIBC_TUNABLES (on Linux, LD_32_PRELOAD and DYLD_INSERT_LIBRARIES on other platforms). In addition the launcher will add or modify VALGRIND_LIB.
Comment 5 Frank Ch. Eigler 2024-05-16 20:10:27 UTC
Another case where this sort of feature would be useful relates to debuginfod.  We may need a way of passing $DEBUGINFOD_URLS only to valgrind or only to the target process (depending on what it is we're trying to debug).

Consider a command line option scheme kind of like docker's or /bin/env's:

valgrind -e ENV1= -e ENV2=foo   /bin/target

which could mean "drop ENV1 from, and override ENV2=foo in, valgrind's environment"
Comment 6 Paul Floyd 2024-05-16 20:29:54 UTC
It would probably be easiest to do this in valgrind itself. It already does this to insert LD_PRELOADs for the core and tool vgpreaload libs.