Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -5200,7 +5200,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,30 @@
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, "return 5", 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).
result = frame.EvaluateExpression("int (*fptr)() = &func; fptr()")
self.assertTrue(result.GetError().Success())
self.assertEqual(result.GetValueAsSigned(), 5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int func(void) { return 5; }

int main(int argc, const char *argv[]) { return func(); }