Unable to get thread information

I’m trying a native debug for the Hello World code project. I’m working under MacOS 13.0.1 with gdb installed via homebrew.

My platform.ini has this

[env:native]
platform = native
build_flags = --verbose
build_type = debug

It builds fine and manually starting gdb from the cmd-line I can debug. But when running from the IDE with F5 focused on main.cpp there’s a popup telling

Unable to get thread information: No symbol “undefined” in current context. (from thread-select undefined)

The debugger no longer responds and I have to kill it along with the Python process.
Unfortunately the above message does not help me further. Any takers?

When you manually gdb .pio/native/program on the commandline in the project directory, then do break main and run, does it startup and break properly?

Well, as I said already, it does. I have no idea why pio shows this pop-up.

Oh, from inside PIO it does not. Only from a terminal. As soon as I enter run it pops up the message.

Open a PlatformIO CLI and execute

pio debug --interface=gdb -- -x .pioinit

in it, then again do b main and run, then info threads. Does it show an error?

That just hangs and I have to interrupt. Here no message popped up.

Hm. Sadly I don’t have a Mac so I can’t cross-verify. On Windows + MinGW64 it does

C:\Users\Max\temp\win_gdb>pio debug --interface=gdb -- -x .pioinit
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gdb.exe: warning: Couldn't determine a path for the index cache directory.
Reading symbols from C:\Users\Max\temp\win_gdb\.pio\build\native\program.exe...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = None
PlatformIO: Initializing remote target...
Temporary breakpoint 1 at 0x1400017c0: file src\main.cpp, line 3.
PlatformIO: Initialization completed
(gdb) PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Starting program: C:\Users\Max\temp\win_gdb\.pio\build\native\program.exe
[New Thread 10108.0x1a8]

Thread 1 hit Temporary breakpoint 1, main () at src\main.cpp:3
3       int main() {
(gdb)
(gdb) info threads
  Id   Target Id           Frame
* 1    Thread 10108.0x3060 main () at src\main.cpp:3
  2    Thread 10108.0x1a8  0x00007ffcf2670b14 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\windows\SYSTEM32\ntdll.dll

So I didn’t even need to start the program manually.

Last thing: Does the hangup also happen with the latest core version? CLIpio upgrade --dev and retry the same command.

If it still fails, please open an issue at Issues · platformio/platformio-core · GitHub with the exact project sources and used GCC/GDB versions and Mac version.

Building the index… takes time. I have to get up early tomorrow. So can’t reply now. Will come back later then. Thanks for the moment and cheers.

No change. After issuing the above command it’s

Reading symbols…

Stating program: …

Then it hangs. Once I press Ctrl-C there’s

^C[New Thread 0x2203 of process 38870]
[New Thread 0x2503 of process 38870]
warning: unhandled dyld version (17)

Thread 2 hit Temporary breakpoint 1, main () at src/main.cpp:29
29 cout << "This program is used to compute the value of the following series : " << endl;
(gdb) The program being debugged has been started already.
Start it from the beginning? (y or n) [answered Y; input not from terminal]
Starting program: <…>/PlatformIO/Projects/221123-164320-hello-world/.pio/build/native/program

This is where some input has to be entered (it’s a simple test program). The next Ctrl-C (no way to input something to either program or gdb) lets the program run through the 2nd input to its end. Then (gdb) asks again.

1 Like

Can you post the exact src/main.cpp?

#include <iostream>
#include <cmath>

using namespace std;

int ComputeFactorial(int number) {
  int fact = 0;

  for (int j = 1; j <= number; j++) {
    fact = fact * j;
  }

  return fact;
}

double ComputeSeriesValue(double x, int n) {
  double seriesValue = 0.0;
  double xpow = 1;

  for (int k = 0; k <= n; k++) {
    seriesValue += xpow / ComputeFactorial(k);
    xpow = xpow * x;
  }

  return seriesValue;
}

int main() {
  cout << "This program is used to compute the value of the following series : " << endl;

  cout << "(x^0)/0! + (x^1)/1! + (x^2)/2! + (x^3)/3! + (x^4)/4! + ........ + (x^n)/n! " << endl;

  cout << "Please enter the value of x : " ;
  
  double x;
  cin >> x;

  int n;
  cout << endl << "Please enter an integer value for n : " ;
  cin >> n;
  cout << endl;

  double seriesValue = ComputeSeriesValue(x, n);
  cout << "The value of the series for the values entered is " 
	<< seriesValue << endl;

  return 0;
}

Would not matter if it contained just a printf or so.

Yeah it definitely doesn’t hang for me with that source code, on Linux it does it normally

Reading symbols from /home/max/temp/gdb/.pio/build/native/program...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = None
PlatformIO: Initializing remote target...
Temporary breakpoint 1 at 0x12eb: file src/main.cpp, line 28.
PlatformIO: Initialization completed
(gdb) PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Starting program: /home/max/temp/gdb/.pio/build/native/program 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Temporary breakpoint 1, main () at src/main.cpp:28
28	int main() {
(gdb)
(gdb) info threads
  Id   Target Id                                   Frame 
* 1    Thread 0x7ffff7a473c0 (LWP 17718) "program" main () at src/main.cpp:28

I’d suggest to open an issue at this point per above.

Can you point me to where I should do that? Thanks!

^ That right there is what I meant.

Yes, I made the upgrade last evening. No change. Will now open the issue. Thanks!

Opened issue #4471. Thanks again.

I just closed the issue since I found out that using lldb would be the simplest solution.

Anybody knows solution for this? I’m running into exactly same issue. Trying to debug my native unit tests on Mac with latest VSC(1.83.1) and PIO plugin (Core 6.1.11·Home 3.4.4) using gdb. I signed the tool based on this thread How to debug a native application on MacOS

When running from command line, only after pressing Clt^C it shows info about breakpoint.

Reading symbols from /Users/lubos.horacek/workspace/project/.pio/build/native/program...
PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = None
PlatformIO: Initializing remote target...
Temporary breakpoint 1 at 0x100000e24: file test/test_native/test_first.cpp, line 58.
PlatformIO: Initialization completed
(gdb) PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
Starting program: /Users/lubos.horacek/workspace/project/.pio/build/native/program 
 
^C[New Thread 0x1603 of process 26130]
[New Thread 0x2003 of process 26130]
warning: unhandled dyld version (17)

Thread 2 hit Temporary breakpoint 1, main (argc=1, argv=0x7ff7bfeff500)
    at test/test_native/test_first.cpp:58
58		UNITY_BEGIN();
(gdb) (gdb) 

In VSC it hangs with this output:

Processing native (platform: native)
--------------------------------------------------------------------------------
Building...
Reading symbols from /Users/lubos.horacek/workspace/project/.pio/build/native/program...
Warning: 'set target-async', an alias for the command 'set mi-async', is deprecated.
Use 'set mi-async'.

PlatformIO Unified Debugger -> https://bit.ly/pio-debug
PlatformIO: debug_tool = None
PlatformIO: Initializing remote target...
Temporary breakpoint 1 at 0x100000d74: file test/test_native/test_firstcpp, line 58.
PlatformIO: Initialization completed
PlatformIO: Resume the execution to `debug_init_break = tbreak main`
PlatformIO: More configuration options -> https://bit.ly/pio-debug
[New Thread 0x1703 of process 13434]

Platformio.ini:

[env:native]
platform = native
test_build_src = yes
upload_port = /dev/null
test_filter =
  test_native
debug_test = test_native
build_type = debug

I simply switched to lldb. Worked a charm.