<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/134811>134811</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            SBProcess::GetState() method returns unexpected value
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sedymrak
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V0uP47gR_jX0pWBBpp998EHtXm-MzGGQHmSPASWWJWYoUiFL7e38-oCk5Ee3u3c2gwUMP8Ti99W7ysJ7VRvELVs-suXTRPTUWLf1KF9bJ75PSitftwdoxAuCp74tNUroO2tAgFfUC1LWML6DU4MG2Cp_fvzqbIXes3nB5sWvSM8kCBnfMP7AVjm0SI2V4JB6Zzz0Bn_vsCKU8CJ0jxnLC5YXBwPWSXRAFhx2zsq-QqAGoXO21NhGTgSDKIFONjyunWgjbV4wXoDEsq9rlNPhKKuGg1Yok1Vdl5i-NRj0viO9ykH5aGfbaQRjzZTQtcoIUqaG3cg5UK7y4ZUXyhAoYPMnyNn8MfGEZ4E5eQLYOjyHQWzBkxyAtrZLgAAAivHH8EqHtSU7CCTh5MQzyfrpjR4X8842j0btEvJoA1AjCHqPPkhrVWoty8zbgPPOPMbnylS6lwhsvhPeo6OsYfNf3p0p68lhcNH7s8DA-L74emB8_-XL0-MZ4sZZlTWeIDwQrq5C2NOTqhEOGA8RFa5-ufJpBI7Z9_z4i3PWAcb34Ojrs6cUcpd-H4wiJbT6L_6mqIn3_iaM1MrUQ_ImpydzGd9E0Oy5r2K2J5FRKoXyDteYlX-kzc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