This is an archive of the discontinued LLVM Phabricator instance.

Display PC instead of <unknown> for stack trace in vscode
ClosedPublic

Authored by zhyty on Jul 31 2023, 12:42 PM.

Details

Summary

It isn't useful for users to see "<unknown>" as a stack trace when lldb fails to symbolicate a stack frame. I've replaced "<unknown>" with the value of the program counter instead.

Test Plan:

To test this, I opened a target that lldb fails to symbolicate in
VSCode, and observed in the CALL STACK section that instead of being
shown as "<unknown>", those stack frames are represented by their
program counters.

I also ran lldb-dotest -p TestVSCode and saw that the tests passed.

Diff Detail

Event Timeline

zhyty created this revision.Jul 31 2023, 12:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2023, 12:42 PM
zhyty requested review of this revision.Jul 31 2023, 12:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 31 2023, 12:42 PM

Can you add a testcase for this?

lldb/tools/lldb-vscode/JSONUtils.cpp
707

I do not think this is needed?

710

I do not think os.flush() is needed. llvm::raw_string_ostream should auto flush while running out of scope.

clayborg requested changes to this revision.Aug 1 2023, 12:35 PM

Adding a test case for this is a good idea. In order to get the PC somewhere bad, you can probably make a function pointer that points to data, then try to branch there. The PC will end up somewhere with no function name and should allow us to reproduce this.

Here is a small program that will reproduce this:

int main() {
  typedef void (*FooCallback)();
  FooCallback foo_callback = (FooCallback)0;
  foo_callback(); // Crash at zero!
  return 0;
}

This will crash at 0x00000000 as we tried to call a function there. It makes the "<unknown>" show up in the VS code GUI

lldb/tools/lldb-vscode/JSONUtils.cpp
707

remove this, the "frame_name" is already empty from the initializer on line 761

This revision now requires changes to proceed.Aug 1 2023, 12:35 PM

You can copy this folder to a new test folder and adjust the test to verify:

lldb/test/API/tools/lldb-vscode/stackTrace
zhyty updated this revision to Diff 546738.Aug 3 2023, 12:58 AM
  • added a test case
  • rebased this commit on top of D156970, which fixes a crash preventing me from testing this feature
  • addressed other comments
zhyty marked 3 inline comments as done.Aug 3 2023, 12:59 AM
zhyty updated this revision to Diff 546979.Aug 3 2023, 12:59 PM

remove a.out

clayborg accepted this revision.Aug 3 2023, 1:55 PM

Looks good!

This revision is now accepted and ready to land.Aug 3 2023, 1:55 PM
This revision was automatically updated to reflect the committed changes.