vadimcn / codelldb

A native debugger extension for VSCode based on LLDB
https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb
MIT License
2.42k stars 237 forks source link

Focus on a thread while debugging. #1058

Closed mehlian closed 3 months ago

mehlian commented 5 months ago

Discussed in https://github.com/vadimcn/codelldb/discussions/848

Originally posted by **ldelossa** January 24, 2023 Is it possible to make VSCode stop jumping to the first thread when debugging a multi-threaded program? I'm trying to watch the sequence of calls in thread-2's frame but every time I step, VSCode jumps back to thread-1's frame. This is despite using the "step into" button for the frame itself. Here is a screenshare of what I mean. No matter what, it jumps back to thread-1's stack. This makes debugging pretty tough. https://user-images.githubusercontent.com/5642902/214208182-4f571076-3f46-452f-8d11-eb14a6ae6f3a.mp4

I have a similar problem when debugging an Android app - when a breakpoint is hit or a "step" is performed, the main thread is focused in vscode and I need to manually switch threads to continue debugging (main thread stop reason = jit-debug-register, second thread stop reason = breakpoint 1.1).

There is no problem when using lldb without vscode.

Edit: After further investigation it looks like issue is with lldb (I'm not sure). Two threads are returning stop signal and first one is selected in vs code

Process 4330 stopped
* thread #1, name = 'company.testapp', stop reason = jit-debug-register
    frame #0: 0x00000077a199f03c libart.so`__jit_debug_register_code
libart.so`__jit_debug_register_code:
->  0x77a199f03c <+0>: ret

libart.so`__dex_debug_register_code:
    0x77a199f040 <+0>: ret

libart.so`std::__1::map<art::DexFile const*, art::JITCodeEntry*, std::__1::less<art::DexFile const*>, std::__1::allocator<std::__1::pair<art::DexFile const* const, art::JITCodeEntry*>>>::~map:
    0x77a199f044 <+0>: ldr    x0, [x0, #0x8]
    0x77a199f048 <+4>: b      0x77a17bbda0              ; std::__1::__tree<art::Histogram<unsigned long>*, art::CompareHistorgramByTimeSpentDeclining, std::__1::allocator<art::Histogram<unsigned long>*>>::destroy(std::__1::__tree_node<art::Histogram<unsigned long>*, void*>*)
  thread #17, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x00000077371109c8 libgameinuse.so`update(memory=0x0000007738264be0, platform=0x0000007738264b40, input=0x0000007738264b70, time=0x0000007738264b60) at game.cpp:366:9
   363          
   364          memory->inputValue = Math::clamp01(memory->inputValue + 0.1f);
   365      }
-> 366      if (input->arrowDown)
   367      {
   368          memory->inputValue = Math::clamp01(memory->inputValue - 0.1f);
   369      }
(lldb) c
Process 4330 resuming
Process 4330 stopped
* thread #17, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x00000077371109c8 libgameinuse.so`update(memory=0x0000007738264be0, platform=0x0000007738264b40, input=0x0000007738264b70, time=0x0000007738264b60) at game.cpp:366:9
   363          
   364          memory->inputValue = Math::clamp01(memory->inputValue + 0.1f);
   365      }
-> 366      if (input->arrowDown)
   367      {
   368          memory->inputValue = Math::clamp01(memory->inputValue - 0.1f);
   369      }
(lldb) c
Process 4330 resuming
Process 4330 stopped
* thread #1, name = 'company.testapp', stop reason = jit-debug-register
    frame #0: 0x00000077a199f03c libart.so`__jit_debug_register_code
libart.so`__jit_debug_register_code:
->  0x77a199f03c <+0>: ret

libart.so`__dex_debug_register_code:
    0x77a199f040 <+0>: ret

libart.so`std::__1::map<art::DexFile const*, art::JITCodeEntry*, std::__1::less<art::DexFile const*>, std::__1::allocator<std::__1::pair<art::DexFile const* const, art::JITCodeEntry*>>>::~map:
    0x77a199f044 <+0>: ldr    x0, [x0, #0x8]
    0x77a199f048 <+4>: b      0x77a17bbda0              ; std::__1::__tree<art::Histogram<unsigned long>*, art::CompareHistorgramByTimeSpentDeclining, std::__1::allocator<art::Histogram<unsigned long>*>>::destroy(std::__1::__tree_node<art::Histogram<unsigned long>*, void*>*)
  thread #17, name = 'main', stop reason = breakpoint 1.1
    frame #0: 0x00000077371109c8 libgameinuse.so`update(memory=0x0000007738264be0, platform=0x0000007738264b40, input=0x0000007738264b70, time=0x0000007738264b60) at game.cpp:366:9
   363          
   364          memory->inputValue = Math::clamp01(memory->inputValue + 0.1f);
   365      }
-> 366      if (input->arrowDown)
   367      {
   368          memory->inputValue = Math::clamp01(memory->inputValue - 0.1f);
   369      }
(lldb) c
Process 4330 resuming
mehlian commented 3 months ago

Fixed my problem by using this setting in lldb: settings set plugin.jit-loader.gdb.enable off

Now jit breakpoint signal is ignored and only mine breakpoints are honored.

Here is more detail about this: https://llvm.org/docs/DebuggingJITedCode.html