Hi all,

I'm trying to read the value of an environment variable that a process was
launched with but to which lldb attached to after it launched.
SBEnvironment looked interesting but I tried using
```
script
print(lldb.debugger.GetSelectedTarget().GetEnvironment().Get("PRINT_ME")
```
and that prints 'None'.

I am able to get the value using
```
script addr = lldb.debugger.GetSelectedTarget().EvaluateExpression("(char
*)getenv(\"PRINT_ME\")").GetValueAsUnsigned()
script err = lldb.SBError()
script
print(lldb.debugger.GetSelectedTarget().GetProcess().ReadCStringFromMemory(addr,
1024, err))
```
but that seems like overkill for reading an environment variable. Is there
a better way to do this that I'm missing?

I'm using the following program to quickly test things:
```
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
int main() {
  raise(SIGSTOP);
  printf("%s\n", getenv("PRINT_ME"));
}
```
_______________________________________________
lldb-dev mailing list
lldb-dev@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev

Reply via email to