[Lldb-commits] [lldb] 9a3f0cd - Fix crash in lldb-vscode when missing function name
Tom Yang via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 3 12:56:59 PDT 2023
Author: Tom Yang
Date: 2023-08-03T12:56:37-07:00
New Revision: 9a3f0cd717f68ccf9e348bce2d76a2372482f4f2
URL: https://github.com/llvm/llvm-project/commit/9a3f0cd717f68ccf9e348bce2d76a2372482f4f2
DIFF: https://github.com/llvm/llvm-project/commit/9a3f0cd717f68ccf9e348bce2d76a2372482f4f2.diff
LOG: Fix crash in lldb-vscode when missing function name
Summary:
In cases where the PC has no function name, lldb-vscode crashes.
`lldb::SBFrame::GetDisplayFunctionName()` returns a `nullptr`, and when we
attempt to construct an `std::string`, it raises an exception.
Test plan:
This can be observed with creating a test file (credit to @clayborg for
the example):
```
int main() {
typedef void (*FooCallback)();
FooCallback foo_callback = (FooCallback)0;
foo_callback(); // Crash at zero!
return 0;
}
```
and attempting to debug the file through VSCode.
I add a test case in D156732 which should cover this.
Differential Revision: https://reviews.llvm.org/D156970
Added:
Modified:
lldb/tools/lldb-vscode/JSONUtils.cpp
Removed:
################################################################################
diff --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 5ece7c01346b73..6acb07296da3be 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -696,7 +696,11 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
int64_t frame_id = MakeVSCodeFrameID(frame);
object.try_emplace("id", frame_id);
- std::string frame_name = frame.GetDisplayFunctionName();
+ // `function_name` can be a nullptr, which throws an error when assigned to an
+ // `std::string`.
+ const char *function_name = frame.GetDisplayFunctionName();
+ std::string frame_name =
+ function_name == nullptr ? std::string() : function_name;
if (frame_name.empty())
frame_name = "<unknown>";
bool is_optimized = frame.GetFunction().GetIsOptimized();
More information about the lldb-commits
mailing list