Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
8 changes: 7 additions & 1 deletion lldb/source/Target/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5080,7 +5080,13 @@ Process::RunThreadPlan(ExecutionContext &exe_ctx,
return eExpressionSetupError;
}

StackID ctx_frame_id = selected_frame_sp->GetStackID();
// If the ExecutionContext has a frame, we want to make sure to save/restore
// that frame into exe_ctx. This can happen when we run expressions from a
// non-selected SBFrame, in which case we don't want some thread-plan
// to overwrite the ExecutionContext frame.
StackID ctx_frame_id = exe_ctx.HasFrameScope()
? exe_ctx.GetFrameRef().GetStackID()
: selected_frame_sp->GetStackID();

// N.B. Running the target may unset the currently selected thread and frame.
// We don't want to do that either, so we should arrange to reset them as
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
C_SOURCES := main.c

include Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil


class ExprFromNonZeroFrame(TestBase):
NO_DEBUG_INFO_TESTCASE = True

def test(self):
"""
Tests that we can use SBFrame::EvaluateExpression on a frame
that we're not stopped in, even if thread-plans run as part of
parsing the expression (e.g., when running static initializers).
"""
self.build()

(_, _, thread, _) = lldbutil.run_to_source_breakpoint(
self, "Break here", lldb.SBFileSpec("main.c")
)
frame = thread.GetFrameAtIndex(1)

# Using a function pointer inside the expression ensures we
# emit a ptrauth static initializer on arm64e into the JITted
# expression. The thread-plan that runs for this static
# initializer should save/restore the current execution context
# frame (which in this test is frame #1).
frame.EvaluateExpression("void (*fptr)() = &func; fptr()")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void func() { __builtin_printf("Break here"); }

int main(int argc) {
func();
return 0;
}