forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb-dap] Enabling instruction breakpoint support to lldb-dap. (llvm…
…#105278) Added support for "supportsInstructionBreakpoints" capability and now it this command is triggered when we set instruction breakpoint. We need this support as part of enabling disassembly view debugging. Following features should work as part of this feature enablement: 1. Settings breakpoints in disassembly view: Unsetting the breakpoint is not happening from the disassembly view. Currently we need to unset breakpoint manually from the breakpoint List. Multiple breakpoints are getting set for the same $ 2. Step over, step into, continue in the disassembly view The format for DisassembleRequest and DisassembleResponse at https://raw.githubusercontent.com/microsoft/vscode/master/src/vs/workbench/contrib/debug/common/debugProtocol.d.ts . Ref Images: Set instruction breakpoint in disassembly view: ![image](https://github.com/user-attachments/assets/833bfb34-86f4-40e2-8c20-14b638a612a2) After issuing continue: ![image](https://github.com/user-attachments/assets/884572a3-915e-422b-b8dd-d132e5c00de6) --------- Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com> Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-lv.qualcomm.com>
- Loading branch information
1 parent
09e09ae
commit 403e2ec
Showing
14 changed files
with
577 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CXX_SOURCES := main-copy.cpp | ||
CXXFLAGS_EXTRAS := -O0 -g | ||
include Makefile.rules | ||
|
||
main-copy.cpp: main.cpp | ||
cp -f $< $@ |
97 changes: 97 additions & 0 deletions
97
lldb/test/API/tools/lldb-dap/instruction-breakpoint/TestDAP_instruction_breakpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import dap_server | ||
import shutil | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
import lldbdap_testcase | ||
import os | ||
import lldb | ||
|
||
|
||
class TestDAP_InstructionBreakpointTestCase(lldbdap_testcase.DAPTestCaseBase): | ||
NO_DEBUG_INFO_TESTCASE = True | ||
|
||
def setUp(self): | ||
lldbdap_testcase.DAPTestCaseBase.setUp(self) | ||
|
||
self.main_basename = "main-copy.cpp" | ||
self.main_path = os.path.realpath(self.getBuildArtifact(self.main_basename)) | ||
|
||
def test_instruction_breakpoint(self): | ||
self.build() | ||
self.instruction_breakpoint_test() | ||
|
||
def instruction_breakpoint_test(self): | ||
"""Sample test to ensure SBFrame::Disassemble produces SOME output""" | ||
# Create a target by the debugger. | ||
target = self.createTestTarget() | ||
|
||
main_line = line_number("main.cpp", "breakpoint 1") | ||
|
||
program = self.getBuildArtifact("a.out") | ||
self.build_and_launch(program) | ||
|
||
# Set source breakpoint 1 | ||
response = self.dap_server.request_setBreakpoints(self.main_path, [main_line]) | ||
breakpoints = response["body"]["breakpoints"] | ||
self.assertEquals(len(breakpoints), 1) | ||
breakpoint = breakpoints[0] | ||
self.assertEqual( | ||
breakpoint["line"], main_line, "incorrect breakpoint source line" | ||
) | ||
self.assertTrue(breakpoint["verified"], "breakpoint is not verified") | ||
self.assertEqual( | ||
self.main_basename, breakpoint["source"]["name"], "incorrect source name" | ||
) | ||
self.assertEqual( | ||
self.main_path, breakpoint["source"]["path"], "incorrect source file path" | ||
) | ||
other_breakpoint_id = breakpoint["id"] | ||
|
||
# Continue and then verifiy the breakpoint | ||
self.dap_server.request_continue() | ||
self.verify_breakpoint_hit([other_breakpoint_id]) | ||
|
||
# now we check the stack trace making sure that we got mapped source paths | ||
frames = self.dap_server.request_stackTrace()["body"]["stackFrames"] | ||
intstructionPointerReference = [] | ||
setIntstructionBreakpoints = [] | ||
intstructionPointerReference.append(frames[0]["instructionPointerReference"]) | ||
self.assertEqual( | ||
frames[0]["source"]["name"], self.main_basename, "incorrect source name" | ||
) | ||
self.assertEqual( | ||
frames[0]["source"]["path"], self.main_path, "incorrect source file path" | ||
) | ||
|
||
# Check disassembly view | ||
instruction = self.disassemble(frameIndex=0) | ||
self.assertEqual( | ||
instruction["address"], | ||
intstructionPointerReference[0], | ||
"current breakpoint reference is not in the disaasembly view", | ||
) | ||
|
||
# Get next instruction address to set instruction breakpoint | ||
disassembled_instruction_list = self.dap_server.disassembled_instructions | ||
instruction_addr_list = list(disassembled_instruction_list.keys()) | ||
index = instruction_addr_list.index(intstructionPointerReference[0]) | ||
if len(instruction_addr_list) >= (index + 1): | ||
next_inst_addr = instruction_addr_list[index + 1] | ||
if len(next_inst_addr) > 2: | ||
setIntstructionBreakpoints.append(next_inst_addr) | ||
instruction_breakpoint_response = ( | ||
self.dap_server.request_setInstructionBreakpoints( | ||
setIntstructionBreakpoints | ||
) | ||
) | ||
inst_breakpoints = instruction_breakpoint_response["body"][ | ||
"breakpoints" | ||
] | ||
self.assertEqual( | ||
inst_breakpoints[0]["instructionReference"], | ||
next_inst_addr, | ||
"Instruction breakpoint has not been resolved or failed to relocate the instruction breakpoint", | ||
) | ||
self.dap_server.request_continue() | ||
self.verify_breakpoint_hit([inst_breakpoints[0]["id"]]) |
18 changes: 18 additions & 0 deletions
18
lldb/test/API/tools/lldb-dap/instruction-breakpoint/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
int function(int x) { | ||
|
||
if (x == 0) // breakpoint 1 | ||
return x; | ||
|
||
if ((x % 2) != 0) | ||
return x; | ||
else | ||
return function(x - 1) + x; | ||
} | ||
|
||
int main(int argc, char const *argv[]) { | ||
int n = function(2); | ||
return n; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===-- InstructionBreakpoint.cpp ------------------------------------*- C++ | ||
//-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "InstructionBreakpoint.h" | ||
#include "DAP.h" | ||
|
||
namespace lldb_dap { | ||
|
||
// Instruction Breakpoint | ||
InstructionBreakpoint::InstructionBreakpoint(const llvm::json::Object &obj) | ||
: Breakpoint(obj), instructionAddressReference(LLDB_INVALID_ADDRESS), id(0), | ||
offset(GetSigned(obj, "offset", 0)) { | ||
GetString(obj, "instructionReference") | ||
.getAsInteger(0, instructionAddressReference); | ||
instructionAddressReference += offset; | ||
} | ||
|
||
void InstructionBreakpoint::SetInstructionBreakpoint() { | ||
bp = g_dap.target.BreakpointCreateByAddress(instructionAddressReference); | ||
id = bp.GetID(); | ||
} | ||
} // namespace lldb_dap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===-- InstructionBreakpoint.h --------------------------------------*- C++ | ||
//-*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_TOOLS_LLDB_DAP_INSTRUCTIONBREAKPOINT_H | ||
#define LLDB_TOOLS_LLDB_DAP_INSTRUCTIONBREAKPOINT_H | ||
|
||
#include "Breakpoint.h" | ||
#include "llvm/ADT/StringRef.h" | ||
|
||
namespace lldb_dap { | ||
|
||
// Instruction Breakpoint | ||
struct InstructionBreakpoint : public Breakpoint { | ||
|
||
lldb::addr_t instructionAddressReference; | ||
int32_t id; | ||
int32_t offset; | ||
|
||
InstructionBreakpoint() | ||
: Breakpoint(), instructionAddressReference(LLDB_INVALID_ADDRESS), id(0), | ||
offset(0) {} | ||
InstructionBreakpoint(const llvm::json::Object &obj); | ||
|
||
// Set instruction breakpoint in LLDB as a new breakpoint | ||
void SetInstructionBreakpoint(); | ||
}; | ||
|
||
} // namespace lldb_dap | ||
|
||
#endif |
Oops, something went wrong.