talz
talz

Reputation: 1200

How to show an environment variable (that I did not set) in lldb?

I would like to inspect the defined environment variables in various moments during the run of a program.

settings show target.env-vars only shows me env-vars I've set in lldb, not all the environment variables available to the running process.

How do I read the value of an environment variable that is available to the running process (either because the program was started with that variable or the variable was defined during the run) in lldb?

Upvotes: 0

Views: 480

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

lldb doesn't keep track of the environment actually in the program, but at least on most Unix systems you can access it through the environ global variable, so something like this will work:

(lldb) expr int idx = 0; while (1) { char *str = ((char **)environ)[idx]; if (str == (char *) NULL) break; else printf("%d: %s\n", idx++, str); }

If you do this a lot, then you can put:

command alias print_real_env expr int idx = 0; while (1) { char *str = ((char **)environ)[idx]; if (str == (char *) NULL) break; else printf("%d: %s\n", idx++, str); }

in your ~/.lldbinit file, and then just run print_real_env.

Upvotes: 2

Related Questions