Files
llvm/lldb/source/Target/ThreadPlanCallFunction.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

486 lines
17 KiB
C++
Raw Normal View History

//===-- ThreadPlanCallFunction.cpp ----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "lldb/Target/ThreadPlanCallFunction.h"
#include "lldb/Breakpoint/Breakpoint.h"
#include "lldb/Breakpoint/BreakpointLocation.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/DumpRegisterValue.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/Core/Module.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Target/ABI.h"
#include "lldb/Target/LanguageRuntime.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Target.h"
#include "lldb/Target/Thread.h"
#include "lldb/Target/ThreadPlanRunToAddress.h"
#include "lldb/Utility/LLDBLog.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Stream.h"
#include <memory>
using namespace lldb;
using namespace lldb_private;
// ThreadPlanCallFunction: Plan to call a single function
bool ThreadPlanCallFunction::ConstructorSetup(
Thread &thread, ABI *&abi, lldb::addr_t &start_load_addr,
lldb::addr_t &function_load_addr) {
SetIsControllingPlan(true);
SetOkayToDiscard(false);
SetPrivate(true);
ProcessSP process_sp(thread.GetProcess());
if (!process_sp)
return false;
abi = process_sp->GetABI().get();
if (!abi)
return false;
Log *log = GetLog(LLDBLog::Step);
SetBreakpoints();
m_function_sp = thread.GetRegisterContext()->GetSP() - abi->GetRedZoneSize();
// If we can't read memory at the point of the process where we are planning
// to put our function, we're not going to get any further...
Status error;
process_sp->ReadUnsignedIntegerFromMemory(m_function_sp, 4, 0, error);
if (!error.Success()) {
m_constructor_errors.Printf(
"Trying to put the stack in unreadable memory at: 0x%" PRIx64 ".",
m_function_sp);
LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
m_constructor_errors.GetData());
return false;
}
llvm::Expected<Address> start_address = GetTarget().GetEntryPointAddress();
if (!start_address) {
m_constructor_errors.Printf(
"%s", llvm::toString(start_address.takeError()).c_str());
LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
m_constructor_errors.GetData());
return false;
}
m_start_addr = *start_address;
start_load_addr = m_start_addr.GetLoadAddress(&GetTarget());
// Checkpoint the thread state so we can restore it later.
if (log && log->GetVerbose())
ReportRegisterState("About to checkpoint thread before function call. "
"Original register state was:");
if (!thread.CheckpointThreadState(m_stored_thread_state)) {
m_constructor_errors.Printf("Setting up ThreadPlanCallFunction, failed to "
"checkpoint thread state.");
LLDB_LOGF(log, "ThreadPlanCallFunction(%p): %s.", static_cast<void *>(this),
m_constructor_errors.GetData());
return false;
}
function_load_addr = m_function_addr.GetLoadAddress(&GetTarget());
return true;
}
ThreadPlanCallFunction::ThreadPlanCallFunction(
Thread &thread, const Address &function, const CompilerType &return_type,
llvm::ArrayRef<addr_t> args, const EvaluateExpressionOptions &options)
: ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
eVoteNoOpinion, eVoteNoOpinion),
m_valid(false), m_stop_other_threads(options.GetStopOthers()),
m_unwind_on_error(options.DoesUnwindOnError()),
m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
m_debug_execution(options.GetDebug()),
m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
m_start_addr(), m_function_sp(0), m_subplan_sp(),
m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr),
m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(),
m_return_valobj_sp(), m_takedown_done(false),
m_should_clear_objc_exception_bp(false),
m_should_clear_cxx_exception_bp(false),
m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(return_type) {
lldb::addr_t start_load_addr = LLDB_INVALID_ADDRESS;
lldb::addr_t function_load_addr = LLDB_INVALID_ADDRESS;
ABI *abi = nullptr;
if (!ConstructorSetup(thread, abi, start_load_addr, function_load_addr))
return;
if (!abi->PrepareTrivialCall(thread, m_function_sp, function_load_addr,
start_load_addr, args))
return;
ReportRegisterState("Function call was set up. Register state was:");
m_valid = true;
}
ThreadPlanCallFunction::ThreadPlanCallFunction(
Thread &thread, const Address &function,
const EvaluateExpressionOptions &options)
: ThreadPlan(ThreadPlan::eKindCallFunction, "Call function plan", thread,
eVoteNoOpinion, eVoteNoOpinion),
m_valid(false), m_stop_other_threads(options.GetStopOthers()),
m_unwind_on_error(options.DoesUnwindOnError()),
m_ignore_breakpoints(options.DoesIgnoreBreakpoints()),
m_debug_execution(options.GetDebug()),
m_trap_exceptions(options.GetTrapExceptions()), m_function_addr(function),
m_start_addr(), m_function_sp(0), m_subplan_sp(),
m_cxx_language_runtime(nullptr), m_objc_language_runtime(nullptr),
m_stored_thread_state(), m_real_stop_info_sp(), m_constructor_errors(),
m_return_valobj_sp(), m_takedown_done(false),
m_should_clear_objc_exception_bp(false),
m_should_clear_cxx_exception_bp(false),
m_stop_address(LLDB_INVALID_ADDRESS), m_return_type(CompilerType()) {}
ThreadPlanCallFunction::~ThreadPlanCallFunction() {
DoTakedown(PlanSucceeded());
}
void ThreadPlanCallFunction::ReportRegisterState(const char *message) {
Log *log = GetLog(LLDBLog::Step);
if (log && log->GetVerbose()) {
StreamString strm;
RegisterContext *reg_ctx = GetThread().GetRegisterContext().get();
log->PutCString(message);
RegisterValue reg_value;
for (uint32_t reg_idx = 0, num_registers = reg_ctx->GetRegisterCount();
reg_idx < num_registers; ++reg_idx) {
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoAtIndex(reg_idx);
if (reg_ctx->ReadRegister(reg_info, reg_value)) {
DumpRegisterValue(reg_value, strm, *reg_info, true, false,
eFormatDefault);
strm.EOL();
}
}
log->PutString(strm.GetString());
}
}
void ThreadPlanCallFunction::DoTakedown(bool success) {
Log *log = GetLog(LLDBLog::Step);
Thread &thread = GetThread();
if (!m_valid) {
// If ConstructorSetup was succesfull but PrepareTrivialCall was not,
// we will have a saved register state and potentially modified registers.
// Restore those.
if (m_stored_thread_state.register_backup_sp)
if (!thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state))
LLDB_LOGF(
log,
"ThreadPlanCallFunction(%p): Failed to restore register state from "
"invalid plan that contained a saved register state.",
static_cast<void *>(this));
// Don't call DoTakedown if we were never valid to begin with.
LLDB_LOGF(log,
"ThreadPlanCallFunction(%p): Log called on "
"ThreadPlanCallFunction that was never valid.",
static_cast<void *>(this));
return;
}
if (!m_takedown_done) {
if (success) {
SetReturnValue();
}
LLDB_LOGF(log,
"ThreadPlanCallFunction(%p): DoTakedown called for thread "
"0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
m_takedown_done = true;
m_stop_address =
thread.GetStackFrameAtIndex(0)->GetRegisterContext()->GetPC();
m_real_stop_info_sp = GetPrivateStopInfo();
if (!thread.RestoreRegisterStateFromCheckpoint(m_stored_thread_state)) {
LLDB_LOGF(log,
"ThreadPlanCallFunction(%p): DoTakedown failed to restore "
"register state",
static_cast<void *>(this));
}
SetPlanComplete(success);
ClearBreakpoints();
if (log && log->GetVerbose())
ReportRegisterState("Restoring thread state after function call. "
"Restored register state:");
} else {
LLDB_LOGF(log,
"ThreadPlanCallFunction(%p): DoTakedown called as no-op for "
"thread 0x%4.4" PRIx64 ", m_valid: %d complete: %d.\n",
static_cast<void *>(this), m_tid, m_valid, IsPlanComplete());
}
}
void ThreadPlanCallFunction::DidPop() { DoTakedown(PlanSucceeded()); }
void ThreadPlanCallFunction::GetDescription(Stream *s, DescriptionLevel level) {
if (level == eDescriptionLevelBrief) {
s->Printf("Function call thread plan");
} else {
s->Printf("Thread plan to call 0x%" PRIx64,
m_function_addr.GetLoadAddress(&GetTarget()));
}
}
bool ThreadPlanCallFunction::ValidatePlan(Stream *error) {
if (!m_valid) {
if (error) {
if (m_constructor_errors.GetSize() > 0)
error->PutCString(m_constructor_errors.GetString());
else
error->PutCString("Unknown error");
}
return false;
}
return true;
}
Vote ThreadPlanCallFunction::ShouldReportStop(Event *event_ptr) {
if (m_takedown_done || IsPlanComplete())
return eVoteYes;
else
return ThreadPlan::ShouldReportStop(event_ptr);
}
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 ThreadPlanCallFunction::DoPlanExplainsStop(Event *event_ptr) {
Log *log(GetLog(LLDBLog::Step | LLDBLog::Process));
m_real_stop_info_sp = GetPrivateStopInfo();
// If our subplan knows why we stopped, even if it's done (which would
// forward the question to us) we answer yes.
if (m_subplan_sp && m_subplan_sp->PlanExplainsStop(event_ptr)) {
SetPlanComplete();
return true;
}
// Check if the breakpoint is one of ours.
StopReason stop_reason;
if (!m_real_stop_info_sp)
stop_reason = eStopReasonNone;
else
stop_reason = m_real_stop_info_sp->GetStopReason();
LLDB_LOG(log,
"ThreadPlanCallFunction::PlanExplainsStop: Got stop reason - {0}.",
Thread::StopReasonAsString(stop_reason));
if (stop_reason == eStopReasonBreakpoint && BreakpointsExplainStop())
return true;
// One more quirk here. If this event was from Halt interrupting the target,
// then we should not consider ourselves complete. Return true to
// acknowledge the stop.
if (Process::ProcessEventData::GetInterruptedFromEvent(event_ptr)) {
LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: The event is an "
"Interrupt, returning true.");
return true;
}
// We control breakpoints separately from other "stop reasons." So first,
// check the case where we stopped for an internal breakpoint, in that case,
// continue on. If it is not an internal breakpoint, consult
// m_ignore_breakpoints.
if (stop_reason == eStopReasonBreakpoint) {
uint64_t break_site_id = m_real_stop_info_sp->GetValue();
BreakpointSiteSP bp_site_sp;
bp_site_sp = m_process.GetBreakpointSiteList().FindByID(break_site_id);
if (bp_site_sp) {
[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
uint32_t num_owners = bp_site_sp->GetNumberOfConstituents();
bool is_internal = true;
for (uint32_t i = 0; i < num_owners; i++) {
[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
Breakpoint &bp = bp_site_sp->GetConstituentAtIndex(i)->GetBreakpoint();
LLDB_LOGF(log,
"ThreadPlanCallFunction::PlanExplainsStop: hit "
"breakpoint %d while calling function",
bp.GetID());
if (!bp.IsInternal()) {
is_internal = false;
break;
}
}
if (is_internal) {
LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop hit an "
"internal breakpoint, not stopping.");
return false;
}
}
if (m_ignore_breakpoints) {
LLDB_LOGF(log,
"ThreadPlanCallFunction::PlanExplainsStop: we are ignoring "
"breakpoints, overriding breakpoint stop info ShouldStop, "
"returning true");
m_real_stop_info_sp->OverrideShouldStop(false);
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
return true;
} else {
LLDB_LOGF(log, "ThreadPlanCallFunction::PlanExplainsStop: we are not "
"ignoring breakpoints, overriding breakpoint stop info "
"ShouldStop, returning true");
m_real_stop_info_sp->OverrideShouldStop(true);
return false;
}
} else if (!m_unwind_on_error) {
// If we don't want to discard this plan, than any stop we don't understand
// should be propagated up the stack.
return false;
} else {
// If the subplan is running, any crashes are attributable to us. If we
// want to discard the plan, then we say we explain the stop but if we are
// going to be discarded, let whoever is above us explain the stop. But
// don't discard the plan if the stop would restart itself (for instance if
// it is a signal that is set not to stop. Check that here first. We just
// say we explain the stop but aren't done and everything will continue on
// from there.
if (m_real_stop_info_sp &&
m_real_stop_info_sp->ShouldStopSynchronous(event_ptr)) {
SetPlanComplete(false);
return m_subplan_sp ? m_unwind_on_error : false;
} else
return true;
}
}
bool ThreadPlanCallFunction::ShouldStop(Event *event_ptr) {
// We do some computation in DoPlanExplainsStop that may or may not set the
// plan as complete. We need to do that here to make sure our state is
// correct.
DoPlanExplainsStop(event_ptr);
if (IsPlanComplete()) {
ReportRegisterState("Function completed. Register state was:");
return true;
} else {
return false;
}
}
bool ThreadPlanCallFunction::StopOthers() { return m_stop_other_threads; }
StateType ThreadPlanCallFunction::GetPlanRunState() { return eStateRunning; }
void ThreadPlanCallFunction::DidPush() {
//#define SINGLE_STEP_EXPRESSIONS
// Now set the thread state to "no reason" so we don't run with whatever
// signal was outstanding... Wait till the plan is pushed so we aren't
// changing the stop info till we're about to run.
GetThread().SetStopInfoToNothing();
#ifndef SINGLE_STEP_EXPRESSIONS
Thread &thread = GetThread();
m_subplan_sp = std::make_shared<ThreadPlanRunToAddress>(thread, m_start_addr,
m_stop_other_threads);
thread.QueueThreadPlan(m_subplan_sp, false);
m_subplan_sp->SetPrivate(true);
#endif
}
bool ThreadPlanCallFunction::WillStop() { return true; }
bool ThreadPlanCallFunction::MischiefManaged() {
Log *log = GetLog(LLDBLog::Step);
if (IsPlanComplete()) {
LLDB_LOGF(log, "ThreadPlanCallFunction(%p): Completed call function plan.",
static_cast<void *>(this));
ThreadPlan::MischiefManaged();
return true;
} else {
return false;
}
}
void ThreadPlanCallFunction::SetBreakpoints() {
if (m_trap_exceptions) {
m_cxx_language_runtime =
m_process.GetLanguageRuntime(eLanguageTypeC_plus_plus);
m_objc_language_runtime = m_process.GetLanguageRuntime(eLanguageTypeObjC);
if (m_cxx_language_runtime) {
m_should_clear_cxx_exception_bp =
!m_cxx_language_runtime->ExceptionBreakpointsAreSet();
m_cxx_language_runtime->SetExceptionBreakpoints();
}
if (m_objc_language_runtime) {
m_should_clear_objc_exception_bp =
!m_objc_language_runtime->ExceptionBreakpointsAreSet();
m_objc_language_runtime->SetExceptionBreakpoints();
}
}
}
void ThreadPlanCallFunction::ClearBreakpoints() {
if (m_trap_exceptions) {
if (m_cxx_language_runtime && m_should_clear_cxx_exception_bp)
m_cxx_language_runtime->ClearExceptionBreakpoints();
if (m_objc_language_runtime && m_should_clear_objc_exception_bp)
m_objc_language_runtime->ClearExceptionBreakpoints();
}
}
bool ThreadPlanCallFunction::BreakpointsExplainStop() {
StopInfoSP stop_info_sp = GetPrivateStopInfo();
if (m_trap_exceptions) {
if ((m_cxx_language_runtime &&
m_cxx_language_runtime->ExceptionBreakpointsExplainStop(
stop_info_sp)) ||
(m_objc_language_runtime &&
m_objc_language_runtime->ExceptionBreakpointsExplainStop(
stop_info_sp))) {
Log *log = GetLog(LLDBLog::Step);
LLDB_LOGF(log, "ThreadPlanCallFunction::BreakpointsExplainStop - Hit an "
"exception breakpoint, setting plan complete.");
SetPlanComplete(false);
// If the user has set the ObjC language breakpoint, it would normally
// get priority over our internal catcher breakpoint, but in this case we
// can't let that happen, so force the ShouldStop here.
stop_info_sp->OverrideShouldStop(true);
return true;
}
}
return false;
}
void ThreadPlanCallFunction::SetStopOthers(bool new_value) {
m_subplan_sp->SetStopOthers(new_value);
}
void ThreadPlanCallFunction::RestoreThreadState() {
GetThread().RestoreThreadStateFromCheckpoint(m_stored_thread_state);
}
void ThreadPlanCallFunction::SetReturnValue() {
const ABI *abi = m_process.GetABI().get();
if (abi && m_return_type.IsValid()) {
const bool persistent = false;
m_return_valobj_sp =
abi->GetReturnValueObject(GetThread(), m_return_type, persistent);
}
}