[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 08:23:27 +01:00
|
|
|
//===-- ThreadPlanStepOut.cpp ---------------------------------------------===//
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// 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
|
2010-06-08 16:52:24 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2015-12-15 01:33:19 +00:00
|
|
|
#include "lldb/Target/ThreadPlanStepOut.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
2011-12-17 01:35:57 +00:00
|
|
|
#include "lldb/Core/Value.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
#include "lldb/Symbol/Block.h"
|
|
|
|
|
#include "lldb/Symbol/Function.h"
|
2016-01-08 21:40:11 +00:00
|
|
|
#include "lldb/Symbol/Symbol.h"
|
<rdar://problem/11757916>
Make breakpoint setting by file and line much more efficient by only looking for inlined breakpoint locations if we are setting a breakpoint in anything but a source implementation file. Implementing this complex for a many reasons. Turns out that parsing compile units lazily had some issues with respect to how we need to do things with DWARF in .o files. So the fixes in the checkin for this makes these changes:
- Add a new setting called "target.inline-breakpoint-strategy" which can be set to "never", "always", or "headers". "never" will never try and set any inlined breakpoints (fastest). "always" always looks for inlined breakpoint locations (slowest, but most accurate). "headers", which is the default setting, will only look for inlined breakpoint locations if the breakpoint is set in what are consudered to be header files, which is realy defined as "not in an implementation source file".
- modify the breakpoint setting by file and line to check the current "target.inline-breakpoint-strategy" setting and act accordingly
- Modify compile units to be able to get their language and other info lazily. This allows us to create compile units from the debug map and not have to fill all of the details in, and then lazily discover this information as we go on debuggging. This is needed to avoid parsing all .o files when setting breakpoints in implementation only files (no inlines). Otherwise we would need to parse the .o file, the object file (mach-o in our case) and the symbol file (DWARF in the object file) just to see what the compile unit was.
- modify the "SymbolFileDWARFDebugMap" to subclass lldb_private::Module so that the virtual "GetObjectFile()" and "GetSymbolVendor()" functions can be intercepted when the .o file contenst are later lazilly needed. Prior to this fix, when we first instantiated the "SymbolFileDWARFDebugMap" class, we would also make modules, object files and symbol files for every .o file in the debug map because we needed to fix up the sections in the .o files with information that is in the executable debug map. Now we lazily do this in the DebugMapModule::GetObjectFile()
Cleaned up header includes a bit as well.
llvm-svn: 162860
2012-08-29 21:13:06 +00:00
|
|
|
#include "lldb/Symbol/Type.h"
|
2015-03-03 19:23:09 +00:00
|
|
|
#include "lldb/Target/ABI.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2010-08-04 01:40:35 +00:00
|
|
|
#include "lldb/Target/StopInfo.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
#include "lldb/Target/Target.h"
|
2011-10-15 00:57:28 +00:00
|
|
|
#include "lldb/Target/ThreadPlanStepOverRange.h"
|
2014-03-13 02:47:14 +00:00
|
|
|
#include "lldb/Target/ThreadPlanStepThrough.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2017-03-03 20:56:28 +00:00
|
|
|
#include "lldb/Utility/Log.h"
|
2024-10-24 20:20:48 -07:00
|
|
|
#include "lldb/ValueObject/ValueObjectConstResult.h"
|
2010-06-08 16:52:24 +00:00
|
|
|
|
2019-02-11 23:13:08 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2014-03-13 02:47:14 +00:00
|
|
|
uint32_t ThreadPlanStepOut::s_default_flag_values = 0;
|
|
|
|
|
|
2025-04-17 11:33:07 -07:00
|
|
|
/// Computes the target frame this plan should step out to.
|
|
|
|
|
static StackFrameSP
|
|
|
|
|
ComputeTargetFrame(Thread &thread, uint32_t start_frame_idx,
|
|
|
|
|
std::vector<StackFrameSP> &skipped_frames) {
|
|
|
|
|
uint32_t frame_idx = start_frame_idx + 1;
|
|
|
|
|
StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);
|
|
|
|
|
if (!return_frame_sp)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
while (return_frame_sp->IsArtificial() || return_frame_sp->IsHidden()) {
|
|
|
|
|
skipped_frames.push_back(return_frame_sp);
|
|
|
|
|
|
|
|
|
|
frame_idx++;
|
|
|
|
|
return_frame_sp = thread.GetStackFrameAtIndex(frame_idx);
|
|
|
|
|
|
|
|
|
|
// We never expect to see an artificial frame without a regular ancestor.
|
|
|
|
|
// Defensively refuse to step out.
|
|
|
|
|
if (!return_frame_sp) {
|
|
|
|
|
LLDB_LOG(GetLog(LLDBLog::Step),
|
|
|
|
|
"Can't step out of frame with artificial ancestors");
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return return_frame_sp;
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
// ThreadPlanStepOut: Step out of the current frame
|
|
|
|
|
ThreadPlanStepOut::ThreadPlanStepOut(
|
|
|
|
|
Thread &thread, SymbolContext *context, bool first_insn, bool stop_others,
|
2021-02-17 15:09:50 -08:00
|
|
|
Vote report_stop_vote, Vote report_run_vote, uint32_t frame_idx,
|
2016-01-08 21:40:11 +00:00
|
|
|
LazyBool step_out_avoids_code_without_debug_info,
|
2016-08-23 17:55:21 +00:00
|
|
|
bool continue_to_next_branch, bool gather_return_value)
|
2021-02-17 15:09:50 -08:00
|
|
|
: ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, report_stop_vote,
|
|
|
|
|
report_run_vote),
|
2010-06-08 16:52:24 +00:00
|
|
|
ThreadPlanShouldStopHere(this), m_step_from_insn(LLDB_INVALID_ADDRESS),
|
2010-07-16 12:32:33 +00:00
|
|
|
m_return_bp_id(LLDB_INVALID_BREAK_ID),
|
2010-06-08 16:52:24 +00:00
|
|
|
m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
|
2016-08-23 17:55:21 +00:00
|
|
|
m_immediate_step_from_function(nullptr),
|
|
|
|
|
m_calculate_return_value(gather_return_value) {
|
2014-03-13 02:47:14 +00:00
|
|
|
SetFlagsToDefault();
|
|
|
|
|
SetupAvoidNoDebug(step_out_avoids_code_without_debug_info);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-03-10 14:03:53 -07:00
|
|
|
m_step_from_insn = thread.GetRegisterContext()->GetPC(0);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2025-04-17 11:33:07 -07:00
|
|
|
StackFrameSP return_frame_sp =
|
|
|
|
|
ComputeTargetFrame(thread, frame_idx, m_stepped_past_frames);
|
2020-03-10 14:03:53 -07:00
|
|
|
StackFrameSP immediate_return_from_sp(thread.GetStackFrameAtIndex(frame_idx));
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2025-04-17 12:53:25 -07:00
|
|
|
SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
|
|
|
|
|
continue_to_next_branch);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 14:13:28 -07:00
|
|
|
ThreadPlanStepOut::ThreadPlanStepOut(Thread &thread, bool stop_others,
|
|
|
|
|
Vote report_stop_vote,
|
|
|
|
|
Vote report_run_vote, uint32_t frame_idx,
|
|
|
|
|
bool continue_to_next_branch,
|
|
|
|
|
bool gather_return_value)
|
|
|
|
|
: ThreadPlan(ThreadPlan::eKindStepOut, "Step out", thread, report_stop_vote,
|
|
|
|
|
report_run_vote),
|
|
|
|
|
ThreadPlanShouldStopHere(this), m_return_bp_id(LLDB_INVALID_BREAK_ID),
|
|
|
|
|
m_return_addr(LLDB_INVALID_ADDRESS), m_stop_others(stop_others),
|
|
|
|
|
m_immediate_step_from_function(nullptr),
|
|
|
|
|
m_calculate_return_value(gather_return_value) {
|
|
|
|
|
SetFlagsToDefault();
|
|
|
|
|
m_step_from_insn = thread.GetRegisterContext()->GetPC(0);
|
|
|
|
|
|
|
|
|
|
StackFrameSP return_frame_sp = thread.GetStackFrameAtIndex(frame_idx + 1);
|
|
|
|
|
StackFrameSP immediate_return_from_sp =
|
|
|
|
|
thread.GetStackFrameAtIndex(frame_idx);
|
|
|
|
|
|
|
|
|
|
SetupReturnAddress(return_frame_sp, immediate_return_from_sp, frame_idx,
|
|
|
|
|
continue_to_next_branch);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-17 12:53:25 -07:00
|
|
|
void ThreadPlanStepOut::SetupReturnAddress(
|
|
|
|
|
StackFrameSP return_frame_sp, StackFrameSP immediate_return_from_sp,
|
|
|
|
|
uint32_t frame_idx, bool continue_to_next_branch) {
|
2012-03-13 16:34:56 +00:00
|
|
|
if (!return_frame_sp || !immediate_return_from_sp)
|
|
|
|
|
return; // we can't do anything here. ValidatePlan() will return false.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-03-01 00:50:50 +00:00
|
|
|
m_step_out_to_id = return_frame_sp->GetStackID();
|
|
|
|
|
m_immediate_step_from_id = immediate_return_from_sp->GetStackID();
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// If the frame directly below the one we are returning to is inlined, we
|
|
|
|
|
// have to be a little more careful. It is non-trivial to determine the real
|
|
|
|
|
// "return code address" for an inlined frame, so we have to work our way to
|
|
|
|
|
// that frame and then step out.
|
2018-10-05 23:23:15 +00:00
|
|
|
if (immediate_return_from_sp->IsInlined()) {
|
2011-10-15 00:57:28 +00:00
|
|
|
if (frame_idx > 0) {
|
|
|
|
|
// First queue a plan that gets us to this inlined frame, and when we get
|
2018-04-30 16:49:04 +00:00
|
|
|
// there we'll queue a second plan that walks us out of this frame.
|
2019-02-11 23:13:08 +00:00
|
|
|
m_step_out_to_inline_plan_sp = std::make_shared<ThreadPlanStepOut>(
|
2025-04-17 12:53:25 -07:00
|
|
|
GetThread(), nullptr, false, m_stop_others, eVoteNoOpinion,
|
|
|
|
|
eVoteNoOpinion, frame_idx - 1, eLazyBoolNo, continue_to_next_branch);
|
2014-03-13 02:47:14 +00:00
|
|
|
static_cast<ThreadPlanStepOut *>(m_step_out_to_inline_plan_sp.get())
|
|
|
|
|
->SetShouldStopHereCallbacks(nullptr, nullptr);
|
2014-09-29 23:17:18 +00:00
|
|
|
m_step_out_to_inline_plan_sp->SetPrivate(true);
|
2011-10-15 00:57:28 +00:00
|
|
|
} else {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If we're already at the inlined frame we're stepping through, then
|
|
|
|
|
// just do that now.
|
2011-10-15 00:57:28 +00:00
|
|
|
QueueInlinedStepPlan(false);
|
|
|
|
|
}
|
2018-10-05 23:23:15 +00:00
|
|
|
} else {
|
2011-10-15 00:57:28 +00:00
|
|
|
// Find the return address and set a breakpoint there:
|
|
|
|
|
// FIXME - can we do this more securely if we know first_insn?
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-08 21:40:11 +00:00
|
|
|
Address return_address(return_frame_sp->GetFrameCodeAddress());
|
|
|
|
|
if (continue_to_next_branch) {
|
|
|
|
|
SymbolContext return_address_sc;
|
|
|
|
|
AddressRange range;
|
|
|
|
|
Address return_address_decr_pc = return_address;
|
|
|
|
|
if (return_address_decr_pc.GetOffset() > 0)
|
|
|
|
|
return_address_decr_pc.Slide(-1);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2016-01-08 21:40:11 +00:00
|
|
|
return_address_decr_pc.CalculateSymbolContext(
|
|
|
|
|
&return_address_sc, lldb::eSymbolContextLineEntry);
|
2012-07-31 22:19:25 +00:00
|
|
|
if (return_address_sc.line_entry.IsValid()) {
|
2019-05-06 20:01:21 +00:00
|
|
|
const bool include_inlined_functions = false;
|
|
|
|
|
range = return_address_sc.line_entry.GetSameLineContiguousAddressRange(
|
|
|
|
|
include_inlined_functions);
|
2015-12-15 01:33:19 +00:00
|
|
|
if (range.GetByteSize() > 0) {
|
2020-03-10 14:03:53 -07:00
|
|
|
return_address = m_process.AdvanceAddressToNextBranchInstruction(
|
|
|
|
|
return_address, range);
|
2011-12-17 01:35:57 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-10 14:03:53 -07:00
|
|
|
m_return_addr = return_address.GetLoadAddress(&m_process.GetTarget());
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
if (m_return_addr == LLDB_INVALID_ADDRESS)
|
2016-09-06 20:57:50 +00:00
|
|
|
return;
|
|
|
|
|
|
2019-12-20 11:00:11 -08:00
|
|
|
// Perform some additional validation on the return address.
|
|
|
|
|
uint32_t permissions = 0;
|
2025-04-17 11:33:07 -07:00
|
|
|
Log *log = GetLog(LLDBLog::Step);
|
2020-03-10 14:03:53 -07:00
|
|
|
if (!m_process.GetLoadAddressPermissions(m_return_addr, permissions)) {
|
2020-02-10 13:40:17 -06:00
|
|
|
LLDB_LOGF(log, "ThreadPlanStepOut(%p): Return address (0x%" PRIx64
|
|
|
|
|
") permissions not found.", static_cast<void *>(this),
|
|
|
|
|
m_return_addr);
|
2019-12-20 11:00:11 -08:00
|
|
|
} else if (!(permissions & ePermissionsExecutable)) {
|
|
|
|
|
m_constructor_errors.Printf("Return address (0x%" PRIx64
|
|
|
|
|
") did not point to executable memory.",
|
|
|
|
|
m_return_addr);
|
|
|
|
|
LLDB_LOGF(log, "ThreadPlanStepOut(%p): %s", static_cast<void *>(this),
|
|
|
|
|
m_constructor_errors.GetData());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-10 14:03:53 -07:00
|
|
|
Breakpoint *return_bp =
|
|
|
|
|
GetTarget().CreateBreakpoint(m_return_addr, true, false).get();
|
2018-11-15 01:18:15 +00:00
|
|
|
|
2015-12-15 01:33:19 +00:00
|
|
|
if (return_bp != nullptr) {
|
2018-11-15 01:18:15 +00:00
|
|
|
if (return_bp->IsHardware() && !return_bp->HasResolvedLocations())
|
|
|
|
|
m_could_not_resolve_hw_bp = true;
|
2020-03-10 14:03:53 -07:00
|
|
|
return_bp->SetThreadID(m_tid);
|
2012-02-21 00:09:25 +00:00
|
|
|
m_return_bp_id = return_bp->GetID();
|
2013-01-26 02:19:28 +00:00
|
|
|
return_bp->SetBreakpointKind("step-out");
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2011-10-15 00:57:28 +00:00
|
|
|
|
2014-03-13 02:47:14 +00:00
|
|
|
if (immediate_return_from_sp) {
|
|
|
|
|
const SymbolContext &sc =
|
|
|
|
|
immediate_return_from_sp->GetSymbolContext(eSymbolContextFunction);
|
|
|
|
|
if (sc.function) {
|
|
|
|
|
m_immediate_step_from_function = sc.function;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-13 02:47:14 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-13 02:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
void ThreadPlanStepOut::SetupAvoidNoDebug(
|
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
2014-03-13 02:47:14 +00:00
|
|
|
bool avoid_nodebug = true;
|
|
|
|
|
switch (step_out_avoids_code_without_debug_info) {
|
|
|
|
|
case eLazyBoolYes:
|
|
|
|
|
avoid_nodebug = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2014-03-13 02:47:14 +00:00
|
|
|
case eLazyBoolNo:
|
|
|
|
|
avoid_nodebug = false;
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2014-03-13 02:47:14 +00:00
|
|
|
case eLazyBoolCalculate:
|
2020-03-10 14:03:53 -07:00
|
|
|
avoid_nodebug = GetThread().GetStepOutAvoidsNoDebug();
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2014-03-13 02:47:14 +00:00
|
|
|
if (avoid_nodebug)
|
|
|
|
|
GetFlags().Set(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
|
2011-10-15 00:57:28 +00:00
|
|
|
else
|
|
|
|
|
GetFlags().Clear(ThreadPlanShouldStopHere::eStepOutAvoidNoDebug);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadPlanStepOut::DidPush() {
|
2020-03-10 14:03:53 -07:00
|
|
|
Thread &thread = GetThread();
|
2010-06-08 16:52:24 +00:00
|
|
|
if (m_step_out_to_inline_plan_sp)
|
2020-03-10 14:03:53 -07:00
|
|
|
thread.QueueThreadPlan(m_step_out_to_inline_plan_sp, false);
|
2010-06-08 16:52:24 +00:00
|
|
|
else if (m_step_through_inline_plan_sp)
|
2020-03-10 14:03:53 -07:00
|
|
|
thread.QueueThreadPlan(m_step_through_inline_plan_sp, false);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThreadPlanStepOut::~ThreadPlanStepOut() {
|
2014-09-29 23:17:18 +00:00
|
|
|
if (m_return_bp_id != LLDB_INVALID_BREAK_ID)
|
2020-03-18 12:05:08 -07:00
|
|
|
GetTarget().RemoveBreakpointByID(m_return_bp_id);
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ThreadPlanStepOut::GetDescription(Stream *s,
|
|
|
|
|
lldb::DescriptionLevel level) {
|
|
|
|
|
if (level == lldb::eDescriptionLevelBrief)
|
|
|
|
|
s->Printf("step out");
|
|
|
|
|
else {
|
2014-03-13 02:47:14 +00:00
|
|
|
if (m_step_out_to_inline_plan_sp)
|
|
|
|
|
s->Printf("Stepping out to inlined frame so we can walk through it.");
|
2011-10-15 00:57:28 +00:00
|
|
|
else if (m_step_through_inline_plan_sp)
|
|
|
|
|
s->Printf("Stepping out by stepping through inlined function.");
|
2016-09-06 20:57:50 +00:00
|
|
|
else {
|
2014-09-29 23:17:18 +00:00
|
|
|
s->Printf("Stepping out from ");
|
|
|
|
|
Address tmp_address;
|
2011-10-15 00:57:28 +00:00
|
|
|
if (tmp_address.SetLoadAddress(m_step_from_insn, &GetTarget())) {
|
2020-03-18 12:05:08 -07:00
|
|
|
tmp_address.Dump(s, &m_process, Address::DumpStyleResolvedDescription,
|
2014-09-29 23:17:18 +00:00
|
|
|
Address::DumpStyleLoadAddress);
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2011-10-15 00:57:28 +00:00
|
|
|
s->Printf("address 0x%" PRIx64 "", (uint64_t)m_step_from_insn);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
// FIXME: find some useful way to present the m_return_id, since there may
|
|
|
|
|
// be multiple copies of the
|
|
|
|
|
// same function on the stack.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
s->Printf(" returning to frame at ");
|
|
|
|
|
if (tmp_address.SetLoadAddress(m_return_addr, &GetTarget())) {
|
2020-03-18 12:05:08 -07:00
|
|
|
tmp_address.Dump(s, &m_process, Address::DumpStyleResolvedDescription,
|
2014-09-29 23:17:18 +00:00
|
|
|
Address::DumpStyleLoadAddress);
|
2012-07-31 22:19:25 +00:00
|
|
|
} else {
|
|
|
|
|
s->Printf("address 0x%" PRIx64 "", (uint64_t)m_return_addr);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-09-29 23:17:18 +00:00
|
|
|
if (level == eDescriptionLevelVerbose)
|
2012-07-31 22:19:25 +00:00
|
|
|
s->Printf(" using breakpoint site %d", m_return_bp_id);
|
2011-10-15 00:57:28 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2018-10-05 23:23:15 +00:00
|
|
|
|
2020-03-18 12:05:08 -07:00
|
|
|
if (m_stepped_past_frames.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2018-10-05 23:23:15 +00:00
|
|
|
s->Printf("\n");
|
|
|
|
|
for (StackFrameSP frame_sp : m_stepped_past_frames) {
|
|
|
|
|
s->Printf("Stepped out past: ");
|
|
|
|
|
frame_sp->DumpUsingSettingsFormat(s);
|
|
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 00:35:16 +00:00
|
|
|
bool ThreadPlanStepOut::ValidatePlan(Stream *error) {
|
2014-03-13 02:47:14 +00:00
|
|
|
if (m_step_out_to_inline_plan_sp)
|
2015-12-15 01:33:19 +00:00
|
|
|
return m_step_out_to_inline_plan_sp->ValidatePlan(error);
|
2018-11-15 01:18:15 +00:00
|
|
|
|
|
|
|
|
if (m_step_through_inline_plan_sp)
|
2012-02-21 00:09:25 +00:00
|
|
|
return m_step_through_inline_plan_sp->ValidatePlan(error);
|
2018-11-15 01:18:15 +00:00
|
|
|
|
|
|
|
|
if (m_could_not_resolve_hw_bp) {
|
|
|
|
|
if (error)
|
|
|
|
|
error->PutCString(
|
|
|
|
|
"Could not create hardware breakpoint for thread plan.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_return_bp_id == LLDB_INVALID_BREAK_ID) {
|
2019-12-20 11:00:11 -08:00
|
|
|
if (error) {
|
2010-08-04 01:40:35 +00:00
|
|
|
error->PutCString("Could not create return address breakpoint.");
|
2019-12-20 11:00:11 -08:00
|
|
|
if (m_constructor_errors.GetSize() > 0) {
|
|
|
|
|
error->PutCString(" ");
|
|
|
|
|
error->PutCString(m_constructor_errors.GetString());
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-08-04 01:40:35 +00:00
|
|
|
return false;
|
2018-11-15 01:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ThreadPlanStepOut::DoPlanExplainsStop(Event *event_ptr) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If the step out plan is done, then we just need to step through the
|
|
|
|
|
// inlined frame.
|
2014-03-13 02:47:14 +00:00
|
|
|
if (m_step_out_to_inline_plan_sp) {
|
|
|
|
|
return m_step_out_to_inline_plan_sp->MischiefManaged();
|
2011-10-15 00:57:28 +00:00
|
|
|
} else if (m_step_through_inline_plan_sp) {
|
2014-03-13 02:47:14 +00:00
|
|
|
if (m_step_through_inline_plan_sp->MischiefManaged()) {
|
|
|
|
|
CalculateReturnValue();
|
|
|
|
|
SetPlanComplete();
|
|
|
|
|
return true;
|
|
|
|
|
} else
|
|
|
|
|
return false;
|
|
|
|
|
} else if (m_step_out_further_plan_sp) {
|
2015-12-15 01:33:19 +00:00
|
|
|
return m_step_out_further_plan_sp->MischiefManaged();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:47:14 +00:00
|
|
|
// We don't explain signals or breakpoints (breakpoints that handle stepping
|
2018-04-30 16:49:04 +00:00
|
|
|
// in or out will be handled by a child plan.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2013-06-04 01:40:51 +00:00
|
|
|
StopInfoSP stop_info_sp = GetPrivateStopInfo();
|
2010-10-20 00:39:53 +00:00
|
|
|
if (stop_info_sp) {
|
|
|
|
|
StopReason reason = stop_info_sp->GetStopReason();
|
2015-07-23 19:55:02 +00:00
|
|
|
if (reason == eStopReasonBreakpoint) {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If this is OUR breakpoint, we're fine, otherwise we don't know why
|
|
|
|
|
// this happened...
|
2012-02-21 00:09:25 +00:00
|
|
|
BreakpointSiteSP site_sp(
|
2020-03-10 14:03:53 -07:00
|
|
|
m_process.GetBreakpointSiteList().FindByID(stop_info_sp->GetValue()));
|
2014-03-13 02:47:14 +00:00
|
|
|
if (site_sp && site_sp->IsBreakpointAtThisSite(m_return_bp_id)) {
|
|
|
|
|
bool done;
|
|
|
|
|
|
2020-03-10 14:03:53 -07:00
|
|
|
StackID frame_zero_id =
|
|
|
|
|
GetThread().GetStackFrameAtIndex(0)->GetStackID();
|
2014-03-13 02:47:14 +00:00
|
|
|
|
|
|
|
|
if (m_step_out_to_id == frame_zero_id)
|
|
|
|
|
done = true;
|
|
|
|
|
else if (m_step_out_to_id < frame_zero_id) {
|
|
|
|
|
// Either we stepped past the breakpoint, or the stack ID calculation
|
|
|
|
|
// was incorrect and we should probably stop.
|
|
|
|
|
done = true;
|
|
|
|
|
} else {
|
|
|
|
|
done = (m_immediate_step_from_id < frame_zero_id);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:47:14 +00:00
|
|
|
if (done) {
|
2018-11-15 01:18:15 +00:00
|
|
|
if (InvokeShouldStopHereCallback(eFrameCompareOlder, m_status)) {
|
2011-12-17 01:35:57 +00:00
|
|
|
CalculateReturnValue();
|
2011-10-15 00:57:28 +00:00
|
|
|
SetPlanComplete();
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-10-15 00:57:28 +00:00
|
|
|
}
|
2010-06-08 16:52:24 +00:00
|
|
|
|
|
|
|
|
// If there was only one owner, then we're done. But if we also hit
|
2018-04-30 16:49:04 +00:00
|
|
|
// some user breakpoint on our way out, we should mark ourselves as
|
|
|
|
|
// done, but also not claim to explain the stop, since it is more
|
|
|
|
|
// important to report the user breakpoint than the step out
|
|
|
|
|
// completion.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
[lldb] [mostly NFC] Large WP foundation: WatchpointResources (#68845)
This patch is rearranging code a bit to add WatchpointResources to
Process. A WatchpointResource is meant to represent a hardware
watchpoint register in the inferior process. It has an address, a size,
a type, and a list of Watchpoints that are using this
WatchpointResource.
This current patch doesn't add any of the features of
WatchpointResources that make them interesting -- a user asking to watch
a 24 byte object could watch this with three 8 byte WatchpointResources.
Or a Watchpoint on 1 byte at 0x1002 and a second watchpoint on 1 byte at
0x1003, these must both be served by a single WatchpointResource on that
doubleword at 0x1000 on a 64-bit target, if two hardware watchpoint
registers were used to track these separately, one of them may not be
hit. Or if you have one Watchpoint on a variable with a condition set,
and another Watchpoint on that same variable with a command defined or
different condition, or ignorecount, both of those Watchpoints need to
evaluate their criteria/commands when their WatchpointResource has been
hit.
There's a bit of code movement to rearrange things in the direction I'll
need for implementing this feature, so I want to start with reviewing &
landing this mostly NFC patch and we can focus on the algorithmic
choices about how WatchpointResources are shared and handled as they're
triggeed, separately.
This patch also stops printing "Watchpoint <n> hit: old value: <x>, new
vlaue: <y>" for Read watchpoints. I could make an argument for print
"Watchpoint <n> hit: current value <x>" but the current output doesn't
make any sense, and the user can print the value if they are
particularly interested. Read watchpoints are used primarily to
understand what code is reading a variable.
This patch adds more fallbacks for how to print the objects being
watched if we have types, instead of assuming they are all integral
values, so a struct will print its elements. As large watchpoints are
added, we'll be doing a lot more of those.
To track the WatchpointSP in the WatchpointResources, I changed the
internal API which took a WatchpointSP and devolved it to a Watchpoint*,
which meant touching several different Process files. I removed the
watchpoint code in ProcessKDP which only reported that watchpoints
aren't supported, the base class does that already.
I haven't yet changed how we receive a watchpoint to identify the
WatchpointResource responsible for the trigger, and identify all
Watchpoints that are using this Resource to evaluate their conditions
etc. This is the same work that a BreakpointSite needs to do when it has
been tiggered, where multiple Breakpoints may be at the same address.
There is not yet any printing of the Resources that a Watchpoint is
implemented in terms of ("watchpoint list", or
SBWatchpoint::GetDescription).
"watchpoint set var" and "watchpoint set expression" take a size
argument which was previously 1, 2, 4, or 8 (an enum). I've changed this
to an unsigned int. Most hardware implementations can only watch 1, 2,
4, 8 byte ranges, but with Resources we'll allow a user to ask for
different sized watchpoints and set them in hardware-expressble terms
soon.
I've annotated areas where I know there is work still needed with
LWP_TODO that I'll be working on once this is landed.
I've tested this on aarch64 macOS, aarch64 Linux, and Intel macOS.
https://discourse.llvm.org/t/rfc-large-watchpoint-support-in-lldb/72116
(cherry picked from commit fc6b72523f3d73b921690a713e97a433c96066c6)
2023-11-27 13:28:59 -08:00
|
|
|
if (site_sp->GetNumberOfConstituents() == 1)
|
2011-10-15 00:57:28 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-10-15 00:57:28 +00:00
|
|
|
return false;
|
2010-06-08 16:52:24 +00:00
|
|
|
} else if (IsUsuallyUnexplainedStopReason(reason))
|
2011-10-15 00:57:28 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
else
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-10-15 00:57:28 +00:00
|
|
|
return true;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-11 19:26:09 +00:00
|
|
|
bool ThreadPlanStepOut::ShouldStop(Event *event_ptr) {
|
|
|
|
|
if (IsPlanComplete())
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
|
|
|
|
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 00:35:16 +00:00
|
|
|
bool done = false;
|
2014-03-13 02:47:14 +00:00
|
|
|
if (m_step_out_to_inline_plan_sp) {
|
|
|
|
|
if (m_step_out_to_inline_plan_sp->MischiefManaged()) {
|
|
|
|
|
// Now step through the inlined stack we are in:
|
|
|
|
|
if (QueueInlinedStepPlan(true)) {
|
|
|
|
|
// If we can't queue a plan to do this, then just call ourselves done.
|
|
|
|
|
m_step_out_to_inline_plan_sp.reset();
|
|
|
|
|
SetPlanComplete(false);
|
2011-10-15 00:57:28 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else
|
2010-06-08 16:52:24 +00:00
|
|
|
done = true;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else
|
2010-06-08 16:52:24 +00:00
|
|
|
return m_step_out_to_inline_plan_sp->ShouldStop(event_ptr);
|
|
|
|
|
} else if (m_step_through_inline_plan_sp) {
|
|
|
|
|
if (m_step_through_inline_plan_sp->MischiefManaged())
|
|
|
|
|
done = true;
|
|
|
|
|
else
|
|
|
|
|
return m_step_through_inline_plan_sp->ShouldStop(event_ptr);
|
|
|
|
|
} else if (m_step_out_further_plan_sp) {
|
2025-10-08 16:30:24 -07:00
|
|
|
if (m_step_out_further_plan_sp->MischiefManaged()) {
|
2012-02-21 00:09:25 +00:00
|
|
|
m_step_out_further_plan_sp.reset();
|
2025-10-08 16:30:24 -07:00
|
|
|
done = true;
|
|
|
|
|
} else
|
2012-02-21 00:09:25 +00:00
|
|
|
return m_step_out_further_plan_sp->ShouldStop(event_ptr);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-13 02:47:14 +00:00
|
|
|
if (!done) {
|
[lldb] Update ThreadPlanStepOut to handle new breakpoint behavior (#126838)
I will be changing breakpoint hitting behavior soon, where currently
lldb reports a breakpoint as being hit when a thread is *at* a
BreakpointSite, but possibly has not executed the breakpoint instruction
and trapped yet, to having lldb only report a breakpoint hit when the
breakpoint instruction has actually been executed.
One corner case bug with this change is that when you are stopped at a
breakpoint (that has been hit) on the last instruction of a function,
and you do `finish`, a ThreadPlanStepOut is pushed to the thread's plan
stack to put a breakpoint on the return address and resume execution.
And when the thread is asked to resume, it sees that it is at a
BreakpointSite that has been hit, and pushes a
ThreadPlanStepOverBreakpoint on the thread. The StepOverBreakpoint
plan sees that the thread's state is eStateRunning (not eStateStepping),
so it marks itself as "auto continue" -- so once the breakpoint has
been stepped over, we will execution on the thread.
With current lldb stepping behavior ("a thread *at* a BreakpointSite is
said to have stopped with a breakpoint-hit stop reason, even if the
breakpoint hasn't been executed yet"),
`ThreadPlanStepOverBreakpoint::DoPlanExplainsStop` has a special bit of
code which detects when the thread stops with a eStopReasonBreakpoint.
It first checks if the pc is the same as when we started -- did our
"step instruction" not actually step? -- says the stop reason is
explained. Otherwise it sets auto-continue to false (because we've hit
an *unexpected* breakpoint, and we have advanced past our original pc,
and returns false - the stop reason is not explained.
So we do the "finish", lldb instruction steps, we stop *at* the
return-address breakpoint and lldb sets the thread's stop reason to
breakpoint-hit. ThreadPlanStepOverBreakpoint sees an
eStopReasonBreakpoint, sets its auto-continue to false, and says we
stopped for osme reason other than this plan. (and it will also report
`IsPlanStale()==true` so it will remove itself) Meanwhile the
ThreadPlanStepOut sees that it has stopped in the StackID it wanted to
run to, and return success.
This all changes when stopping at a breakpoint site doesn't report
breakpoint-hit until we actually execute the instruction. Now the
ThraedPlanStepOverBreakpoint looks at the thread's stop reason, it's
eStopReasonTrace (we've instruction stepped), and so it leaves its
auto-continue to `true`. ThreadPlanStepOut sees that it has reached its
goal StackID, removes its breakpoint, and says it is done.
Thread::ShouldStop thinks the auto-continue == yes vote from
ThreadPlanStepOverBreakpoint wins, and we lose control of the process.
This patch changes ThreadPlanStepOut to require that *both* (1) we are
at the StackID of the caller function, where we wanted to end up, and
(2) we have actually hit the breakpoint that we inserted.
This in effect means that now lldb instruction-steps over the breakpoint
in the callee function, stops at the return address of the caller
function. StepOverBreakpoint has completed. StepOut is still running,
and we continue the thread again. We immediatley hit the breakpoint
(that we're sitting at), and now ThreadPlanStepOut marks itself as
completed, and we return control to the user.
Jim suggests that ThreadPlanStepOverBreakpoint is a bit unusual because
it's not something pushed on the stack by a higher-order thread plan
that "owns" it, it is inserted by the Thread as it is about to resume,
if we're at a BreakpointSite. It has no connection to the thread plans
above it, but tries to set the auto-continue mode based on the state of
the thread when it is inserted (and tries to detect an unexpected
breakpoint and unset that auto-continue it previously decided on,
because it now realizes it should not influence execution control any
more). Instead maybe the
ThreadPlanStepOverBreakpoint should be inserted as a child plan of
whatever the lowest plan is on the stack at the point it is added.
I added an API test that will catch this bug in the new thread
breakpoint algorithm.
2025-02-12 13:48:01 -08:00
|
|
|
StopInfoSP stop_info_sp = GetPrivateStopInfo();
|
2025-02-12 14:00:41 -08:00
|
|
|
if (stop_info_sp && stop_info_sp->GetStopReason() == eStopReasonBreakpoint) {
|
[lldb] Update ThreadPlanStepOut to handle new breakpoint behavior (#126838)
I will be changing breakpoint hitting behavior soon, where currently
lldb reports a breakpoint as being hit when a thread is *at* a
BreakpointSite, but possibly has not executed the breakpoint instruction
and trapped yet, to having lldb only report a breakpoint hit when the
breakpoint instruction has actually been executed.
One corner case bug with this change is that when you are stopped at a
breakpoint (that has been hit) on the last instruction of a function,
and you do `finish`, a ThreadPlanStepOut is pushed to the thread's plan
stack to put a breakpoint on the return address and resume execution.
And when the thread is asked to resume, it sees that it is at a
BreakpointSite that has been hit, and pushes a
ThreadPlanStepOverBreakpoint on the thread. The StepOverBreakpoint
plan sees that the thread's state is eStateRunning (not eStateStepping),
so it marks itself as "auto continue" -- so once the breakpoint has
been stepped over, we will execution on the thread.
With current lldb stepping behavior ("a thread *at* a BreakpointSite is
said to have stopped with a breakpoint-hit stop reason, even if the
breakpoint hasn't been executed yet"),
`ThreadPlanStepOverBreakpoint::DoPlanExplainsStop` has a special bit of
code which detects when the thread stops with a eStopReasonBreakpoint.
It first checks if the pc is the same as when we started -- did our
"step instruction" not actually step? -- says the stop reason is
explained. Otherwise it sets auto-continue to false (because we've hit
an *unexpected* breakpoint, and we have advanced past our original pc,
and returns false - the stop reason is not explained.
So we do the "finish", lldb instruction steps, we stop *at* the
return-address breakpoint and lldb sets the thread's stop reason to
breakpoint-hit. ThreadPlanStepOverBreakpoint sees an
eStopReasonBreakpoint, sets its auto-continue to false, and says we
stopped for osme reason other than this plan. (and it will also report
`IsPlanStale()==true` so it will remove itself) Meanwhile the
ThreadPlanStepOut sees that it has stopped in the StackID it wanted to
run to, and return success.
This all changes when stopping at a breakpoint site doesn't report
breakpoint-hit until we actually execute the instruction. Now the
ThraedPlanStepOverBreakpoint looks at the thread's stop reason, it's
eStopReasonTrace (we've instruction stepped), and so it leaves its
auto-continue to `true`. ThreadPlanStepOut sees that it has reached its
goal StackID, removes its breakpoint, and says it is done.
Thread::ShouldStop thinks the auto-continue == yes vote from
ThreadPlanStepOverBreakpoint wins, and we lose control of the process.
This patch changes ThreadPlanStepOut to require that *both* (1) we are
at the StackID of the caller function, where we wanted to end up, and
(2) we have actually hit the breakpoint that we inserted.
This in effect means that now lldb instruction-steps over the breakpoint
in the callee function, stops at the return address of the caller
function. StepOverBreakpoint has completed. StepOut is still running,
and we continue the thread again. We immediatley hit the breakpoint
(that we're sitting at), and now ThreadPlanStepOut marks itself as
completed, and we return control to the user.
Jim suggests that ThreadPlanStepOverBreakpoint is a bit unusual because
it's not something pushed on the stack by a higher-order thread plan
that "owns" it, it is inserted by the Thread as it is about to resume,
if we're at a BreakpointSite. It has no connection to the thread plans
above it, but tries to set the auto-continue mode based on the state of
the thread when it is inserted (and tries to detect an unexpected
breakpoint and unset that auto-continue it previously decided on,
because it now realizes it should not influence execution control any
more). Instead maybe the
ThreadPlanStepOverBreakpoint should be inserted as a child plan of
whatever the lowest plan is on the stack at the point it is added.
I added an API test that will catch this bug in the new thread
breakpoint algorithm.
2025-02-12 13:48:01 -08:00
|
|
|
StackID frame_zero_id = GetThread().GetStackFrameAtIndex(0)->GetStackID();
|
|
|
|
|
done = !(frame_zero_id < m_step_out_to_id);
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-30 16:49:04 +00:00
|
|
|
// The normal step out computations think we are done, so all we need to do
|
|
|
|
|
// is consult the ShouldStopHere, and we are done.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-03-01 00:50:50 +00:00
|
|
|
if (done) {
|
2018-11-15 01:18:15 +00:00
|
|
|
if (InvokeShouldStopHereCallback(eFrameCompareOlder, m_status)) {
|
2010-06-08 16:52:24 +00:00
|
|
|
CalculateReturnValue();
|
|
|
|
|
SetPlanComplete();
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2010-06-08 16:52:24 +00:00
|
|
|
m_step_out_further_plan_sp =
|
2018-11-15 01:18:15 +00:00
|
|
|
QueueStepOutFromHerePlan(m_flags, eFrameCompareOlder, m_status);
|
2014-03-13 02:47:14 +00:00
|
|
|
done = false;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
return done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ThreadPlanStepOut::StopOthers() { return m_stop_others; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
StateType ThreadPlanStepOut::GetPlanRunState() { return eStateRunning; }
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
bool ThreadPlanStepOut::DoWillResume(StateType resume_state,
|
2012-02-21 00:09:25 +00:00
|
|
|
bool current_plan) {
|
|
|
|
|
if (m_step_out_to_inline_plan_sp || m_step_through_inline_plan_sp)
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
if (m_return_bp_id == LLDB_INVALID_BREAK_ID)
|
2010-08-04 01:40:35 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 00:35:16 +00:00
|
|
|
if (current_plan) {
|
2020-03-10 14:03:53 -07:00
|
|
|
Breakpoint *return_bp = GetTarget().GetBreakpointByID(m_return_bp_id).get();
|
2015-12-15 01:33:19 +00:00
|
|
|
if (return_bp != nullptr)
|
2011-10-15 00:57:28 +00:00
|
|
|
return_bp->SetEnabled(true);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2014-03-13 02:47:14 +00:00
|
|
|
return true;
|
2010-06-08 16:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ThreadPlanStepOut::WillStop() {
|
2011-10-15 00:57:28 +00:00
|
|
|
if (m_return_bp_id != LLDB_INVALID_BREAK_ID) {
|
2020-03-10 14:03:53 -07:00
|
|
|
Breakpoint *return_bp = GetTarget().GetBreakpointByID(m_return_bp_id).get();
|
2011-10-15 00:57:28 +00:00
|
|
|
if (return_bp != nullptr)
|
2010-06-08 16:52:24 +00:00
|
|
|
return_bp->SetEnabled(false);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
bool ThreadPlanStepOut::MischiefManaged() {
|
|
|
|
|
if (IsPlanComplete()) {
|
|
|
|
|
// Did I reach my breakpoint? If so I'm done.
|
2016-09-06 20:57:50 +00:00
|
|
|
//
|
2011-10-15 00:57:28 +00:00
|
|
|
// I also check the stack depth, since if we've blown past the breakpoint
|
2010-06-08 16:52:24 +00:00
|
|
|
// for some
|
2011-10-15 00:57:28 +00:00
|
|
|
// reason and we're now stopping for some other reason altogether, then
|
2018-04-30 16:49:04 +00:00
|
|
|
// we're done with this step out operation.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Step);
|
2011-10-15 00:57:28 +00:00
|
|
|
if (log)
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Completed step out plan.");
|
2011-10-15 00:57:28 +00:00
|
|
|
if (m_return_bp_id != LLDB_INVALID_BREAK_ID) {
|
2020-03-10 14:03:53 -07:00
|
|
|
GetTarget().RemoveBreakpointByID(m_return_bp_id);
|
2011-10-15 00:57:28 +00:00
|
|
|
m_return_bp_id = LLDB_INVALID_BREAK_ID;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
ThreadPlan::MischiefManaged();
|
2011-10-15 00:57:28 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
} else {
|
2011-10-15 00:57:28 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-10-15 00:57:28 +00:00
|
|
|
}
|
2011-12-17 01:35:57 +00:00
|
|
|
|
|
|
|
|
bool ThreadPlanStepOut::QueueInlinedStepPlan(bool queue_now) {
|
|
|
|
|
// Now figure out the range of this inlined block, and set up a "step through
|
2018-04-30 16:49:04 +00:00
|
|
|
// range" plan for that. If we've been provided with a context, then use the
|
|
|
|
|
// block in that context.
|
2020-03-10 14:03:53 -07:00
|
|
|
Thread &thread = GetThread();
|
|
|
|
|
StackFrameSP immediate_return_from_sp(thread.GetStackFrameAtIndex(0));
|
2015-12-15 01:33:19 +00:00
|
|
|
if (!immediate_return_from_sp)
|
2010-06-08 16:52:24 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2022-01-31 15:57:48 +01:00
|
|
|
Log *log = GetLog(LLDBLog::Step);
|
2011-12-17 01:35:57 +00:00
|
|
|
if (log) {
|
2011-10-15 00:57:28 +00:00
|
|
|
StreamString s;
|
2015-09-24 03:54:50 +00:00
|
|
|
immediate_return_from_sp->Dump(&s, true, false);
|
2019-07-24 17:56:10 +00:00
|
|
|
LLDB_LOGF(log, "Queuing inlined frame to step past: %s.", s.GetData());
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-24 03:54:50 +00:00
|
|
|
Block *from_block = immediate_return_from_sp->GetFrameBlock();
|
2011-10-15 00:57:28 +00:00
|
|
|
if (from_block) {
|
2015-09-24 03:54:50 +00:00
|
|
|
Block *inlined_block = from_block->GetContainingInlinedBlock();
|
2011-10-15 00:57:28 +00:00
|
|
|
if (inlined_block) {
|
2015-09-24 03:54:50 +00:00
|
|
|
size_t num_ranges = inlined_block->GetNumRanges();
|
|
|
|
|
AddressRange inline_range;
|
|
|
|
|
if (inlined_block->GetRangeAtIndex(0, inline_range)) {
|
|
|
|
|
SymbolContext inlined_sc;
|
2012-02-21 00:09:25 +00:00
|
|
|
inlined_block->CalculateSymbolContext(&inlined_sc);
|
|
|
|
|
inlined_sc.target_sp = GetTarget().shared_from_this();
|
2011-10-15 00:57:28 +00:00
|
|
|
RunMode run_mode =
|
2012-02-21 00:09:25 +00:00
|
|
|
m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads;
|
2015-09-24 03:54:50 +00:00
|
|
|
const LazyBool avoid_no_debug = eLazyBoolNo;
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2019-02-11 23:13:08 +00:00
|
|
|
m_step_through_inline_plan_sp =
|
|
|
|
|
std::make_shared<ThreadPlanStepOverRange>(
|
2020-03-10 14:03:53 -07:00
|
|
|
thread, inline_range, inlined_sc, run_mode, avoid_no_debug);
|
2014-09-29 23:17:18 +00:00
|
|
|
ThreadPlanStepOverRange *step_through_inline_plan_ptr =
|
2015-09-24 03:54:50 +00:00
|
|
|
static_cast<ThreadPlanStepOverRange *>(
|
|
|
|
|
m_step_through_inline_plan_sp.get());
|
|
|
|
|
m_step_through_inline_plan_sp->SetPrivate(true);
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
step_through_inline_plan_ptr->SetOkayToDiscard(true);
|
|
|
|
|
StreamString errors;
|
2015-09-24 03:54:50 +00:00
|
|
|
if (!step_through_inline_plan_ptr->ValidatePlan(&errors)) {
|
|
|
|
|
// FIXME: Log this failure.
|
|
|
|
|
delete step_through_inline_plan_ptr;
|
|
|
|
|
return false;
|
2011-12-17 01:35:57 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
for (size_t i = 1; i < num_ranges; i++) {
|
|
|
|
|
if (inlined_block->GetRangeAtIndex(i, inline_range))
|
|
|
|
|
step_through_inline_plan_ptr->AddRange(inline_range);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-15 00:57:28 +00:00
|
|
|
if (queue_now)
|
2020-03-10 14:03:53 -07:00
|
|
|
thread.QueueThreadPlan(m_step_through_inline_plan_sp, false);
|
2010-06-08 16:52:24 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-12-17 01:35:57 +00:00
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2010-06-08 16:52:24 +00:00
|
|
|
return false;
|
2011-12-17 01:35:57 +00:00
|
|
|
}
|
2012-05-03 21:19:36 +00:00
|
|
|
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 00:35:16 +00:00
|
|
|
void ThreadPlanStepOut::CalculateReturnValue() {
|
2011-12-17 01:35:57 +00:00
|
|
|
if (m_return_valobj_sp)
|
2016-09-06 20:57:50 +00:00
|
|
|
return;
|
|
|
|
|
|
2016-08-23 17:55:21 +00:00
|
|
|
if (!m_calculate_return_value)
|
2016-09-06 20:57:50 +00:00
|
|
|
return;
|
|
|
|
|
|
2011-12-17 01:35:57 +00:00
|
|
|
if (m_immediate_step_from_function != nullptr) {
|
2015-09-24 03:54:50 +00:00
|
|
|
CompilerType return_compiler_type =
|
2011-12-17 01:35:57 +00:00
|
|
|
m_immediate_step_from_function->GetCompilerType()
|
2016-01-08 21:40:11 +00:00
|
|
|
.GetFunctionReturnType();
|
2015-09-24 03:54:50 +00:00
|
|
|
if (return_compiler_type) {
|
2020-03-10 14:03:53 -07:00
|
|
|
lldb::ABISP abi_sp = m_process.GetABI();
|
2011-12-17 01:35:57 +00:00
|
|
|
if (abi_sp)
|
2011-10-15 00:57:28 +00:00
|
|
|
m_return_valobj_sp =
|
2020-03-10 14:03:53 -07:00
|
|
|
abi_sp->GetReturnValueObject(GetThread(), return_compiler_type);
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-03 21:19:36 +00:00
|
|
|
bool ThreadPlanStepOut::IsPlanStale() {
|
2018-04-30 16:49:04 +00:00
|
|
|
// If we are still lower on the stack than the frame we are returning to,
|
|
|
|
|
// then there's something for us to do. Otherwise, we're stale.
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2020-03-10 14:03:53 -07:00
|
|
|
StackID frame_zero_id = GetThread().GetStackFrameAtIndex(0)->GetStackID();
|
2015-12-15 01:33:19 +00:00
|
|
|
return !(frame_zero_id < m_step_out_to_id);
|
2012-05-03 21:19:36 +00:00
|
|
|
}
|