Issue |
134811
|
Summary |
SBProcess::GetState() method returns unexpected value
|
Labels |
new issue
|
Assignees |
|
Reporter |
sedymrak
|
I have stumbled upon a situation, when `SBProcess::GetState()` method returns unexpected value.
In order to reproduce the problem, we need two programs:
* debugged-program.c
* main.cpp
The `debugged-program.c` is a simple non-terminating C program:
```
int i = 0;
int main() {
i = 42;
loop:
i++;
goto loop;
return 0;
}
```
The `main.cpp` is a C++ program that uses `liblldb.so`:
```
#include <assert.h>
#include <iostream>
#include <lldb/API/LLDB.h>
int main(const int argc, const char **argv) {
lldb::SBError error = lldb::SBDebugger::InitializeWithErrorHandling();
assert(error.Success());
lldb::SBDebugger debugger = lldb::SBDebugger::Create(false);
assert(debugger.IsValid());
debugger.SetAsync(true);
lldb::SBTarget target = debugger.CreateTarget("debugged-program");
assert(target.IsValid());
lldb::SBLaunchInfo launch_info = target.GetLaunchInfo();
lldb::SBProcess process = target.LaunchSimple(nullptr, nullptr, nullptr);
assert(error.Success() && process.IsValid());
// The following assert fails.
assert(process.GetState() != lldb::eStateStopped);
error = process.Kill();
assert(error.Success());
lldb::SBDebugger::Destroy(debugger);
lldb::SBDebugger::Terminate();
return 0;
}
```
If we compile both programs:
```
/home/me/bin.platform/llvm-project/main.Release.ld/bin/clang -g -o debugged-program debugged-program.c
/home/me/bin.platform/llvm-project/main.Release.ld/bin/clang -g -o main main.cpp \
-I/home/me/bin.platform/llvm-project/main.Release.ld/include \
-L/home/me/bin.platform/llvm-project/main.Release.ld/lib \
-Wl,-rpath,'/home/me/bin.platform/llvm-project/main.Release.ld/lib' \
-llldb -lstdc++
```
and run the `./main` program, this program will fail with the following error:
```
main: main.cpp:21: int main(const int, const char **): Assertion `process.GetState() != lldb::eStateStopped' failed.
Aborted
```
The `assert` fails because the `process.GetState()` _expression_ returns `lldb::eStateStopped)` value.
The value returned by the `SBProcess::GetState()` method is unexpected.
(As far as I understand the meaning of the `SBProcess::GetState()` method and the meaning of the `lldb::StateType` values.)
I admit that the `main` program uses LLDB API in an misguided fashion because:
* it does not defined any breakpoints prior to launching the `debugged-program`
* it does not take advantage of the broadcaster-listener mechanism that would allow the `main` program to wait until the `debugged-program` hits some breakpoint
but I believe that the sequence of LLDB API calls is legal and the `SBProcess::GetState()` method should return some value other than `lldb::eStateStopped` because it is certain that the debugged process is not stopped.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs