aboutsummaryrefslogtreecommitdiff
path: root/lldb/tools
diff options
context:
space:
mode:
authorWalter Erquinigo <a20012251@gmail.com>2023-12-11 15:20:06 -0500
committerGitHub <noreply@github.com>2023-12-11 15:20:06 -0500
commit0ea19bd3333af71dd3aaf7c0a6ef9a0930958c12 (patch)
tree82a22b4ee84e85af8a58a20bba9837662be461c6 /lldb/tools
parent631c6e834cb07b2769e2c8f1e186dd3a3e0777a1 (diff)
downloadllvm-0ea19bd3333af71dd3aaf7c0a6ef9a0930958c12.zip
llvm-0ea19bd3333af71dd3aaf7c0a6ef9a0930958c12.tar.gz
llvm-0ea19bd3333af71dd3aaf7c0a6ef9a0930958c12.tar.bz2
[lldb-dap] Emit declarations along with variables (#74865)
This is an extension to the protocol that emits the declaration information along with the metadata of each variable. This can be used by vscode extensions to implement, for example, a "goToDefinition" action in the debug tab, or for showing the value of a variable right next to where it's declared during a debug session. As this is cheap, I'm not gating this information under any setting.
Diffstat (limited to 'lldb/tools')
-rw-r--r--lldb/tools/lldb-dap/JSONUtils.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/lldb/tools/lldb-dap/JSONUtils.cpp b/lldb/tools/lldb-dap/JSONUtils.cpp
index 62d7fa5..c8e5304 100644
--- a/lldb/tools/lldb-dap/JSONUtils.cpp
+++ b/lldb/tools/lldb-dap/JSONUtils.cpp
@@ -1103,6 +1103,29 @@ std::string CreateUniqueVariableNameForDisplay(lldb::SBValue v,
// can use this optional information to present the
// children in a paged UI and fetch them in chunks."
// }
+// "declaration": {
+// "type": "object | undefined",
+// "description": "Extension to the protocol that indicates the source
+// location where the variable was declared. This value
+// might not be present if no declaration is available.",
+// "properties": {
+// "path": {
+// "type": "string | undefined",
+// "description": "The source file path where the variable was
+// declared."
+// },
+// "line": {
+// "type": "number | undefined",
+// "description": "The 1-indexed source line where the variable was
+// declared."
+// },
+// "column": {
+// "type": "number | undefined",
+// "description": "The 1-indexed source column where the variable was
+// declared."
+// }
+// }
+// }
// },
// "required": [ "name", "value", "variablesReference" ]
// }
@@ -1167,6 +1190,24 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
const char *evaluateName = evaluateStream.GetData();
if (evaluateName && evaluateName[0])
EmplaceSafeString(object, "evaluateName", std::string(evaluateName));
+
+ if (lldb::SBDeclaration decl = v.GetDeclaration(); decl.IsValid()) {
+ llvm::json::Object decl_obj;
+ if (lldb::SBFileSpec file = decl.GetFileSpec(); file.IsValid()) {
+ char path[PATH_MAX] = "";
+ if (file.GetPath(path, sizeof(path)) &&
+ lldb::SBFileSpec::ResolvePath(path, path, PATH_MAX)) {
+ decl_obj.try_emplace("path", std::string(path));
+ }
+ }
+
+ if (int line = decl.GetLine())
+ decl_obj.try_emplace("line", line);
+ if (int column = decl.GetColumn())
+ decl_obj.try_emplace("column", column);
+
+ object.try_emplace("declaration", std::move(decl_obj));
+ }
return llvm::json::Value(std::move(object));
}