-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldb][riscv] Fix setting breakpoint for undecoded instruction (#90075)
This patch adds an interface GetLastInstrSize to get information about the size of last tried to be decoded instruction and uses it to set software breakpoint if the memory can be decoded as instruction. RISC-V architecture instruction format specifies the length of instruction in first bits, so we can set a breakpoint for these cases. This is needed as RISCV have a lot of extensions, that are not supported by `EmulateInstructionRISCV`.
- Loading branch information
Showing
8 changed files
with
137 additions
and
29 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
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,3 @@ | ||
C_SOURCES := main.c | ||
|
||
include Makefile.rules |
44 changes: 44 additions & 0 deletions
44
lldb/test/API/riscv/break-undecoded/TestBreakpointIllegal.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,44 @@ | ||
""" | ||
Test that we can set up software breakpoint even if we failed to decode and execute instruction | ||
""" | ||
|
||
import lldb | ||
from lldbsuite.test.decorators import * | ||
from lldbsuite.test.lldbtest import * | ||
from lldbsuite.test import lldbutil | ||
|
||
|
||
class TestBreakpointIllegal(TestBase): | ||
@skipIf(archs=no_match(["rv64gc"])) | ||
def test_4(self): | ||
self.build() | ||
(target, process, cur_thread, bkpt) = lldbutil.run_to_source_breakpoint( | ||
self, "main", lldb.SBFileSpec("main.c") | ||
) | ||
self.runCmd("thread step-inst") | ||
# we need to step more, as some compilers do not set appropriate debug info. | ||
while cur_thread.GetStopDescription(256) == "instruction step into": | ||
self.runCmd("thread step-inst") | ||
# The stop reason of the thread should be illegal opcode. | ||
self.expect( | ||
"thread list", | ||
STOPPED_DUE_TO_SIGNAL, | ||
substrs=["stopped", "stop reason = signal SIGILL: illegal opcode"], | ||
) | ||
|
||
@skipIf(archs=no_match(["rv64gc"])) | ||
def test_2(self): | ||
self.build(dictionary={"C_SOURCES": "compressed.c", "EXE": "compressed.x"}) | ||
(target, process, cur_thread, bkpt) = lldbutil.run_to_source_breakpoint( | ||
self, "main", lldb.SBFileSpec("compressed.c"), exe_name="compressed.x" | ||
) | ||
self.runCmd("thread step-inst") | ||
# we need to step more, as some compilers do not set appropriate debug info. | ||
while cur_thread.GetStopDescription(256) == "instruction step into": | ||
self.runCmd("thread step-inst") | ||
# The stop reason of the thread should be illegal opcode. | ||
self.expect( | ||
"thread list", | ||
STOPPED_DUE_TO_SIGNAL, | ||
substrs=["stopped", "stop reason = signal SIGILL: illegal opcode"], | ||
) |
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,7 @@ | ||
int main() { | ||
// This instruction is not valid, but we have an ability to set | ||
// software breakpoint. | ||
// This results in illegal instruction during execution, not fail to set | ||
// breakpoint | ||
asm volatile(".2byte 0xaf"); | ||
} |
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,7 @@ | ||
int main() { | ||
// This instruction is not valid, but we have an ability to set | ||
// software breakpoint. | ||
// This results in illegal instruction during execution, not fail to set | ||
// breakpoint | ||
asm volatile(".4byte 0xc58573" : :); | ||
} |