Skip to content

[lldb] Provide lr value in faulting frame on arm64 #138805

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add the sources for an API test case to be written
  • Loading branch information
jasonmolenda committed May 8, 2025
commit b10162deb49ecddca6439665c2b8ea1995fdd81f
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#define DW_CFA_register 0x9
#define ehframe_x22 22
#define ehframe_x23 23
#define ehframe_pc 32

.section __TEXT,__text,regular,pure_instructions

//--------------------------------------
// to_be_interrupted() a frameless function that does a non-ABI
// function call ("is interrupted/traps" simulated) to trap().
// Before it branches to trap(), it puts its return address in
// x23. trap() knows to branch back to $x23 when it has finished.
//--------------------------------------
.globl _to_be_interrupted
.p2align 2
_to_be_interrupted:
.cfi_startproc

// This is a garbage entry to ensure that eh_frame is emitted,
// it isn't used for anything. If there's no eh_frame, lldb
// can do an assembly emulation scan and add a rule for $lr
// which won't expose the issue at hand.
.cfi_escape DW_CFA_register, ehframe_x22, ehframe_x23
mov x24, x0
add x24, x24, #1

adrp x23, L_.return@PAGE ; put return address in x4
add x23, x23, L_.return@PAGEOFF

b _trap ; branch to trap handler, fake async interrupt

L_.return:
mov x0, x24
ret
.cfi_endproc



//--------------------------------------
// trap() trap handler function, sets up stack frame
// with special unwind rule for the pc value of the
// "interrupted" stack frame (it's in x23), then calls
// break_to_debugger().
//--------------------------------------
.globl _trap
.p2align 2
_trap:
.cfi_startproc
.cfi_signal_frame

// The pc value when we were interrupted is in x23
.cfi_escape DW_CFA_register, ehframe_pc, ehframe_x23

// standard prologue save of fp & lr so we can call puts()
sub sp, sp, #32
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16

bl _break_to_debugger

ldp x29, x30, [sp, #16]
add sp, sp, #32

// jump back to $x23 to resume execution of to_be_interrupted
br x23
.cfi_endproc

//--------------------------------------
// break_to_debugger() executes a BRK instruction
//--------------------------------------
.globl _break_to_debugger
.p2align 2
_break_to_debugger:
.cfi_startproc

// standard prologue save of fp & lr so we can call puts()
sub sp, sp, #32
stp x29, x30, [sp, #16]
add x29, sp, #16
.cfi_def_cfa w29, 16
.cfi_offset w30, -8
.cfi_offset w29, -16

brk #0xf000 ;; __builtin_debugtrap aarch64 instruction

ldp x29, x30, [sp, #16]
add sp, sp, #32
ret
.cfi_endproc
6 changes: 6 additions & 0 deletions lldb/test/API/macosx/unwind-frameless-faulted/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int to_be_interrupted(int);
int main() {
int c = 10;
c = to_be_interrupted(c);
return c;
}