From 51effa57818bf937fb7c889b8f567c146bb4eefe Mon Sep 17 00:00:00 2001 From: Jeffrey Tan Date: Wed, 19 Oct 2022 11:58:23 -0700 Subject: [PATCH] Fix exception description in lldb-vscode There is a bug in lldb-vscode that only shows stop reason ("exception") in stopped event without showing the stop description of thrown exception. This causes VSCode UI to only show "Paused on Exception" general message in callstack window UI. This patch fixes the bug so that VSCode callstack will show the detailed exceptioni description, like "signal SIGABRT" or "EXC_BAD_ACCESS..." which aligns with command line lldb experience. I use C++ exception in testcase because the hardware exception description is platform dependent and hard to verify. Differential Revision: https://reviews.llvm.org/D136295 --- .../test/tools/lldb-vscode/lldbvscode_testcase.py | 8 ++++---- lldb/test/API/tools/lldb-vscode/exception/Makefile | 3 +++ .../lldb-vscode/exception/TestVSCode_exception.py | 24 ++++++++++++++++++++++ lldb/test/API/tools/lldb-vscode/exception/main.cpp | 6 ++++++ lldb/tools/lldb-vscode/JSONUtils.cpp | 2 +- 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 lldb/test/API/tools/lldb-vscode/exception/Makefile create mode 100644 lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py create mode 100644 lldb/test/API/tools/lldb-vscode/exception/main.cpp diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py index 8ba8e0e..a91f3b2 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/lldbvscode_testcase.py @@ -93,10 +93,10 @@ class VSCodeTestCaseBase(TestBase): return self.assertTrue(False, "breakpoint not hit") - def verify_exception_breakpoint_hit(self, filter_label): + def verify_stop_exception_info(self, expected_description): '''Wait for the process we are debugging to stop, and verify the stop reason is 'exception' and that the description matches - 'filter_label' + 'expected_description' ''' stopped_events = self.vscode.wait_for_stopped() for stopped_event in stopped_events: @@ -109,7 +109,7 @@ class VSCodeTestCaseBase(TestBase): if 'description' not in body: continue description = body['description'] - if filter_label == description: + if expected_description == description: return True return False @@ -236,7 +236,7 @@ class VSCodeTestCaseBase(TestBase): def continue_to_exception_breakpoint(self, filter_label): self.vscode.request_continue() - self.assertTrue(self.verify_exception_breakpoint_hit(filter_label), + self.assertTrue(self.verify_stop_exception_info(filter_label), 'verify we got "%s"' % (filter_label)) def continue_to_exit(self, exitCode=0): diff --git a/lldb/test/API/tools/lldb-vscode/exception/Makefile b/lldb/test/API/tools/lldb-vscode/exception/Makefile new file mode 100644 index 0000000..99998b2 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp + +include Makefile.rules diff --git a/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py new file mode 100644 index 0000000..2fc0d9c --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/TestVSCode_exception.py @@ -0,0 +1,24 @@ +""" +Test exception behavior in VSCode +""" + + +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +import lldbvscode_testcase + + +class TestVSCode_exception(lldbvscode_testcase.VSCodeTestCaseBase): + + @skipIfWindows + def test_stopped_description(self): + ''' + Test that exception description is shown correctly in stopped + event. + ''' + program = self.getBuildArtifact("a.out") + print("test_stopped_description called", flush=True) + self.build_and_launch(program) + + self.vscode.request_continue() + self.assertTrue(self.verify_stop_exception_info("signal SIGABRT")) diff --git a/lldb/test/API/tools/lldb-vscode/exception/main.cpp b/lldb/test/API/tools/lldb-vscode/exception/main.cpp new file mode 100644 index 0000000..b940d07 --- /dev/null +++ b/lldb/test/API/tools/lldb-vscode/exception/main.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + raise(SIGABRT); + return 0; +} diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp index 4bc965e..baeed2a 100644 --- a/lldb/tools/lldb-vscode/JSONUtils.cpp +++ b/lldb/tools/lldb-vscode/JSONUtils.cpp @@ -930,7 +930,7 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread, // If no description has been set, then set it to the default thread stopped // description. If we have breakpoints that get hit and shouldn't be reported // as breakpoints, then they will set the description above. - if (ObjectContainsKey(body, "description")) { + if (!ObjectContainsKey(body, "description")) { char description[1024]; if (thread.GetStopDescription(description, sizeof(description))) { EmplaceSafeString(body, "description", std::string(description)); -- 2.7.4