Issue |
137048
|
Summary |
[lldb] SBProcess.GetSTDENV doesn't not return the debugee error messages
|
Labels |
new issue
|
Assignees |
|
Reporter |
da-viper
|
When using the SBProcess from the SBAPI.
It the messages written to stderr is send through stdout.
example code
```cpp
#include <iostream>
int main() {
std::cout << "INFO: from debugee stdout\n";
std::cerr << "ERROR: from debugee stdcerr\n";
}
```
using the SB_API adapted from example/process_events.py
```py
#!/usr/bin/env python3
# name: process_io.py
# ----------------------------------------------------------------------
# Be sure to add the python path that points to the LLDB shared library.
# On MacOSX csh, tcsh:
# setenv PYTHONPATH /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python
# On MacOSX sh, bash:
# export PYTHONPATH=/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python
# ----------------------------------------------------------------------
import lldb
import sys
def handle_events(process: lldb.SBProcess, listener: lldb.SBListener):
event = lldb.SBEvent()
while listener.WaitForEvent(1, event):
state = lldb.SBProcess.GetStateFromEvent(event)
if state == lldb.eStateExited or state == lldb.eStateDetached:
break
elif state == lldb.eStateStopped:
process.Continue()
def main():
exec = sys.argv[1]
debugger = lldb.SBDebugger.Create()
launch_info = lldb.SBLaunchInfo(sys.argv)
target = debugger.CreateTarget(exec)
if not target:
print(f"target is not valid\n target: {exec}", file=sys.stderr)
return
target_error = lldb.SBError()
process = target.Launch(launch_info, target_error)
print(f"launch: {target_error}")
if process and process.GetProcessID() != lldb.LLDB_INVALID_PROCESS_ID:
handle_events(process, debugger.GetListener())
process_stdout = process.GetSTDOUT(1024)
print(f"Process STDOUT:\n{process_stdout}")
process_stderr = process.GetSTDERR(1024)
print(f"Process STDERR:\n{process_stderr}")
process.Kill()
if __name__ == "__main__":
main()
```
compile and run with
`./process_io.py a.out`
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs