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

    <tr>
        <th>Summary</th>
        <td>
            [lldb] No TLS data currently exists for this thread
        </td>
    </tr>

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

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

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

<pre>
    I have a small `C` program that uses `pthread` and `thread local storage`.
```c
static __thread long z = 0xdeadbeef;
static __thread long x = 0xdeadbeef;

// create the function to be executed as a thread
void *thread(void *ptr)
{
    …
}

int main(int argc, char **argv)
{
    …
    pthread_create(&thread1, NULL, *thread, (void *) thr);
    pthread_create(&thread2, NULL, *thread, (void *) thr2);
    …
}
```
- I compile with the following options `-g -O0 -pthread`
- when I try to debug it with `lldb` and print the variables I get the following error:
```sh
[amin@lzvmr5 c_example]$ lldb main
(lldb) target create "main"
Current executable set to '/home/amin/bugs/.../c_example/main' (x86_64).
(lldb) b thread
Breakpoint 1: where = main`thread + 12 at main.c:11:22, address = 0x000000000040074c
(lldb) run
Process 3366142 launched: '/home/amin/bugs/.../c_example/main' (x86_64)
Process 3366142 stopped
* thread #2, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x000000000040074c main`thread(ptr=0x0000000000000001) at main.c:11:22
   8    // create the function to be executed as a thread
   9    void *thread(void *ptr)
   10   {
-> 11       int type = (int) ptr;
   12       printf("%p\n", &z);
   13       printf("%p\n", &x);
   14       fprintf(stderr,"Thread - %d\n",type);
(lldb) p z
error: Couldn't materialize: couldn't get the value of variable z: No TLS data currently exists for this thread.
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) p x
error: Couldn't materialize: couldn't get the value of variable x: No TLS data currently exists for this thread.
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
```
I can print the variables if I use `gdb`.
Attached you can find the complete reproducer.

[c_example.zip](https://github.com/llvm/llvm-project/files/8755345/c_example.zip)



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNVktv4zYQ_jXyZWBBoh6WDz44cQKkCLYLND0HlEg9trQpUJTj-Nd3hpJsx8kWSdvDCrYskZxvvnk71-J19QA130vg0G25UuClwS1-oTW6MnwLtuYW-k52tNPa2kguaJ_vBK0MC6B0wRV0VhteSVz2vWDjBWt8Gj7F8N5ZbpsCnp9PYrsKjuBFGwgOAldyKUsvuvmH04efnR7v7B4_UKCAlUheQtnvCtvoHVgNuQR5kEVvpQDeoc2jPU50rxs0ia3HNZZNC601HluO-ItRHeDl3TEvC7x1Ou1tLqk0Owtb3uwQiR65qQqP3UJRc0Oo-MGl_aeQaWn0_fNgGoJ6LB2WQoL99ufjI_1eGEAvJyNQD1lL6qKbz6CyL6Cya9ifemZKiOF1Dg9Q6G3bKAkvja2HgGml9EuDsdYtBc5l3ryC-e8BzM8ZOCG81HKHMNa8UoSFzPsKGjvA4TGlRD7la2soEKRjz03Dc4VZ_QCVtFd6pTHaeNH6inNXjwvJDd9iXONAHfdbk0DxLA982yrpJRuPxUA6h9CPOZk5FuQrDDmqG9PTY2xIEDYcvO2NkchwyFHiBx2R03hygWld6y2G6N4pZ_doaIc_vu_j_UyB3Q-YC4rTIUuf0xg1---o5G-S_wYf_2o1-SdEy8mrRrpSc2inQvfYDYQM-JDafoFnQxJgLl24EEZ23ViiwemKg2ARF-8omH700HejC5KLojQNYwaKY9HWUhCT_2z6xyqwV7WtFBOnNZwMjJwpO74d7Ee4EZWWSQzwYIcNhXbzC7_54bkASuPkWRSQDe998datSJeaTLS5POiukPz0kbcnTZkrt3_f9VB6SRCf6n54LgxI39Sr5l50B2EIw-Wq67Wd_EZtj-g7087NAdNnuFw5lq7noMuT1ktuXS24FpMer3pKGH1K7HAtFo9i5UmuswIrHM-j1NMQ9TmKJuKMRFZcAl0kbQvHYW3qEnCreyUoQShMVmJnUc1R0k5x3pm6zJ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