Skip to content

[lldb-dap] DisassembleRequestHandler: use a better invalid instruction #141463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 27, 2025

Conversation

eronnen
Copy link
Contributor

@eronnen eronnen commented May 26, 2025

DisassembleRequestHandler: use a better invalid instruction value that fits VSCode client

@llvmbot
Copy link
Member

llvmbot commented May 26, 2025

@llvm/pr-subscribers-lldb

Author: Ely Ronnen (eronnen)

Changes

DisassembleRequestHandler: use a better invalid instruction value that fits VSCode client


Full diff: https://github.com/llvm/llvm-project/pull/141463.diff

2 Files Affected:

  • (modified) lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp (+1)
  • (modified) lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp (+9-2)
diff --git a/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
index c9061ef19f17a..1d110eac18126 100644
--- a/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/DisassembleRequestHandler.cpp
@@ -27,6 +27,7 @@ namespace lldb_dap {
 
 static protocol::DisassembledInstruction GetInvalidInstruction() {
   DisassembledInstruction invalid_inst;
+  invalid_inst.address = LLDB_INVALID_ADDRESS;
   invalid_inst.presentationHint =
       DisassembledInstruction::eDisassembledInstructionPresentationHintInvalid;
   return invalid_inst;
diff --git a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
index 8d4fbd18fee7c..2af919265b1c9 100644
--- a/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
+++ b/lldb/tools/lldb-dap/Protocol/ProtocolTypes.cpp
@@ -847,8 +847,15 @@ bool fromJSON(const llvm::json::Value &Params, DisassembledInstruction &DI,
 }
 
 llvm::json::Value toJSON(const DisassembledInstruction &DI) {
-  llvm::json::Object result{{"address", "0x" + llvm::utohexstr(DI.address)},
-                            {"instruction", DI.instruction}};
+  llvm::json::Object result{{"instruction", DI.instruction}};
+  if (DI.address == LLDB_INVALID_ADDRESS) {
+    // VSCode has explicit comparisons to the string "-1" in order to check for
+    // invalid instructions. See
+    // https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/debug/browser/disassemblyView.ts
+    result.insert({"address", "-1"});
+  } else {
+    result.insert({"address", "0x" + llvm::utohexstr(DI.address)});
+  }
 
   if (DI.instructionBytes)
     result.insert({"instructionBytes", *DI.instructionBytes});

{"instruction", DI.instruction}};
llvm::json::Object result{{"instruction", DI.instruction}};
if (DI.address == LLDB_INVALID_ADDRESS) {
// VSCode has explicit comparisons to the string "-1" in order to check for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: VS Code not VSCode.

Suggested change
// VSCode has explicit comparisons to the string "-1" in order to check for
// VS Code has explicit comparisons to the string "-1" in order to check for

@eronnen eronnen merged commit 8821c38 into llvm:main May 27, 2025
5 of 9 checks passed
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
llvm#141463)

DisassembleRequestHandler: use a better invalid instruction value that
fits VSCode client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants