2015-10-24 02:39:37 +08:00
|
|
|
//===-- StopInfo.cpp --------------------------------------------*- C++ -*-===//
|
2010-08-04 09:40:35 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2010-11-19 02:52:36 +08:00
|
|
|
#include "lldb/Breakpoint/Breakpoint.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
2011-10-14 08:42:25 +08:00
|
|
|
#include "lldb/Breakpoint/Watchpoint.h"
|
2011-08-09 10:12:22 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2015-03-04 07:11:11 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
#include "lldb/Expression/UserExpression.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/StopInfo.h"
|
2011-08-09 10:12:22 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
#include "lldb/Target/UnixSignals.h"
|
2017-03-04 04:56:28 +08:00
|
|
|
#include "lldb/Utility/Log.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/StreamString.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfo::StopInfo(Thread &thread, uint64_t value)
|
|
|
|
: m_thread_wp(thread.shared_from_this()),
|
|
|
|
m_stop_id(thread.GetProcess()->GetStopID()),
|
|
|
|
m_resume_id(thread.GetProcess()->GetResumeID()), m_value(value),
|
|
|
|
m_description(), m_override_should_notify(eLazyBoolCalculate),
|
|
|
|
m_override_should_stop(eLazyBoolCalculate), m_extended_info() {}
|
|
|
|
|
|
|
|
bool StopInfo::IsValid() const {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp)
|
|
|
|
return thread_sp->GetProcess()->GetStopID() == m_stop_id;
|
|
|
|
return false;
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void StopInfo::MakeStopInfoValid() {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
m_stop_id = thread_sp->GetProcess()->GetStopID();
|
|
|
|
m_resume_id = thread_sp->GetProcess()->GetResumeID();
|
|
|
|
}
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool StopInfo::HasTargetRunSinceMe() {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
|
|
|
|
if (thread_sp) {
|
|
|
|
lldb::StateType ret_type = thread_sp->GetProcess()->GetPrivateState();
|
|
|
|
if (ret_type == eStateRunning) {
|
|
|
|
return true;
|
|
|
|
} else if (ret_type == eStateStopped) {
|
|
|
|
// This is a little tricky. We want to count "run and stopped again
|
2018-05-01 00:49:04 +08:00
|
|
|
// before you could ask this question as a "TRUE" answer to
|
|
|
|
// HasTargetRunSinceMe. But we don't want to include any running of the
|
|
|
|
// target done for expressions. So we track both resumes, and resumes
|
|
|
|
// caused by expressions, and check if there are any resumes
|
2016-09-07 04:57:50 +08:00
|
|
|
// NOT caused
|
|
|
|
// by expressions.
|
|
|
|
|
|
|
|
uint32_t curr_resume_id = thread_sp->GetProcess()->GetResumeID();
|
|
|
|
uint32_t last_user_expression_id =
|
|
|
|
thread_sp->GetProcess()->GetLastUserExpressionResumeID();
|
|
|
|
if (curr_resume_id == m_resume_id) {
|
|
|
|
return false;
|
|
|
|
} else if (curr_resume_id > last_user_expression_id) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-11-08 11:00:11 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return false;
|
2011-08-09 10:12:22 +08:00
|
|
|
}
|
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoBreakpoint
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
namespace lldb_private {
|
|
|
|
class StopInfoBreakpoint : public StopInfo {
|
2010-08-04 09:40:35 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoBreakpoint(Thread &thread, break_id_t break_id)
|
|
|
|
: StopInfo(thread, break_id), m_should_stop(false),
|
|
|
|
m_should_stop_is_valid(false), m_should_perform_action(true),
|
|
|
|
m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID),
|
|
|
|
m_was_one_shot(false) {
|
|
|
|
StoreBPInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
StopInfoBreakpoint(Thread &thread, break_id_t break_id, bool should_stop)
|
|
|
|
: StopInfo(thread, break_id), m_should_stop(should_stop),
|
|
|
|
m_should_stop_is_valid(true), m_should_perform_action(true),
|
|
|
|
m_address(LLDB_INVALID_ADDRESS), m_break_id(LLDB_INVALID_BREAK_ID),
|
|
|
|
m_was_one_shot(false) {
|
|
|
|
StoreBPInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
~StopInfoBreakpoint() override = default;
|
|
|
|
|
|
|
|
void StoreBPInfo() {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
if (bp_site_sp) {
|
|
|
|
if (bp_site_sp->GetNumberOfOwners() == 1) {
|
|
|
|
BreakpointLocationSP bp_loc_sp = bp_site_sp->GetOwnerAtIndex(0);
|
|
|
|
if (bp_loc_sp) {
|
|
|
|
m_break_id = bp_loc_sp->GetBreakpoint().GetID();
|
|
|
|
m_was_one_shot = bp_loc_sp->GetBreakpoint().IsOneShot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_address = bp_site_sp->GetLoadAddress();
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValidForOperatingSystemThread(Thread &thread) override {
|
|
|
|
ProcessSP process_sp(thread.GetProcess());
|
|
|
|
if (process_sp) {
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
process_sp->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
if (bp_site_sp)
|
|
|
|
return bp_site_sp->ValidForThisThread(&thread);
|
2012-10-06 03:16:31 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
StopReason GetStopReason() const override { return eStopReasonBreakpoint; }
|
|
|
|
|
|
|
|
bool ShouldStopSynchronous(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
if (!m_should_stop_is_valid) {
|
|
|
|
// Only check once if we should stop at a breakpoint
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
if (bp_site_sp) {
|
|
|
|
ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
|
|
|
|
StoppointCallbackContext context(event_ptr, exe_ctx, true);
|
|
|
|
bp_site_sp->BumpHitCounts();
|
|
|
|
m_should_stop = bp_site_sp->ShouldStop(&context);
|
|
|
|
} else {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf(
|
|
|
|
"Process::%s could not find breakpoint site id: %" PRId64 "...",
|
|
|
|
__FUNCTION__, m_value);
|
|
|
|
|
|
|
|
m_should_stop = true;
|
2011-10-28 09:12:19 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
m_should_stop_is_valid = true;
|
|
|
|
}
|
|
|
|
return m_should_stop;
|
2010-10-15 07:45:03 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DoShouldNotify(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
if (bp_site_sp) {
|
|
|
|
bool all_internal = true;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < bp_site_sp->GetNumberOfOwners(); i++) {
|
|
|
|
if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) {
|
|
|
|
all_internal = false;
|
|
|
|
break;
|
|
|
|
}
|
2015-04-08 06:17:41 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return !all_internal;
|
|
|
|
}
|
2015-04-08 06:17:41 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty()) {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
if (bp_site_sp) {
|
|
|
|
StreamString strm;
|
|
|
|
// If we have just hit an internal breakpoint, and it has a kind
|
2018-05-01 00:49:04 +08:00
|
|
|
// description, print that instead of the full breakpoint printing:
|
2016-09-07 04:57:50 +08:00
|
|
|
if (bp_site_sp->IsInternal()) {
|
|
|
|
size_t num_owners = bp_site_sp->GetNumberOfOwners();
|
|
|
|
for (size_t idx = 0; idx < num_owners; idx++) {
|
|
|
|
const char *kind = bp_site_sp->GetOwnerAtIndex(idx)
|
|
|
|
->GetBreakpoint()
|
|
|
|
.GetBreakpointKind();
|
|
|
|
if (kind != nullptr) {
|
|
|
|
m_description.assign(kind);
|
|
|
|
return kind;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
strm.Printf("breakpoint ");
|
|
|
|
bp_site_sp->GetDescription(&strm, eDescriptionLevelBrief);
|
2016-11-17 05:15:24 +08:00
|
|
|
m_description = strm.GetString();
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
StreamString strm;
|
|
|
|
if (m_break_id != LLDB_INVALID_BREAK_ID) {
|
|
|
|
BreakpointSP break_sp =
|
|
|
|
thread_sp->GetProcess()->GetTarget().GetBreakpointByID(
|
|
|
|
m_break_id);
|
|
|
|
if (break_sp) {
|
|
|
|
if (break_sp->IsInternal()) {
|
|
|
|
const char *kind = break_sp->GetBreakpointKind();
|
|
|
|
if (kind)
|
|
|
|
strm.Printf("internal %s breakpoint(%d).", kind, m_break_id);
|
2013-04-30 07:30:46 +08:00
|
|
|
else
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.Printf("internal breakpoint(%d).", m_break_id);
|
|
|
|
} else {
|
|
|
|
strm.Printf("breakpoint %d.", m_break_id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_was_one_shot)
|
|
|
|
strm.Printf("one-shot breakpoint %d", m_break_id);
|
|
|
|
else
|
|
|
|
strm.Printf("breakpoint %d which has been deleted.",
|
|
|
|
m_break_id);
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else if (m_address == LLDB_INVALID_ADDRESS)
|
|
|
|
strm.Printf("breakpoint site %" PRIi64
|
|
|
|
" which has been deleted - unknown address",
|
|
|
|
m_value);
|
|
|
|
else
|
|
|
|
strm.Printf("breakpoint site %" PRIi64
|
|
|
|
" which has been deleted - was at 0x%" PRIx64,
|
|
|
|
m_value, m_address);
|
|
|
|
|
2016-11-17 05:15:24 +08:00
|
|
|
m_description = strm.GetString();
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_description.c_str();
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
protected:
|
|
|
|
bool ShouldStop(Event *event_ptr) override {
|
2018-05-01 00:49:04 +08:00
|
|
|
// This just reports the work done by PerformAction or the synchronous
|
|
|
|
// stop. It should only ever get called after they have had a chance to
|
|
|
|
// run.
|
2016-09-07 04:57:50 +08:00
|
|
|
assert(m_should_stop_is_valid);
|
|
|
|
return m_should_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformAction(Event *event_ptr) override {
|
|
|
|
if (!m_should_perform_action)
|
|
|
|
return;
|
|
|
|
m_should_perform_action = false;
|
2017-02-15 19:42:47 +08:00
|
|
|
bool internal_breakpoint = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
|
|
|
|
if (thread_sp) {
|
|
|
|
Log *log = lldb_private::GetLogIfAnyCategoriesSet(
|
|
|
|
LIBLLDB_LOG_BREAKPOINTS | LIBLLDB_LOG_STEP);
|
|
|
|
|
|
|
|
if (!thread_sp->IsValid()) {
|
|
|
|
// This shouldn't ever happen, but just in case, don't do more harm.
|
|
|
|
if (log) {
|
|
|
|
log->Printf("PerformAction got called with an invalid thread.");
|
|
|
|
}
|
|
|
|
m_should_stop = true;
|
|
|
|
m_should_stop_is_valid = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointSiteSP bp_site_sp(
|
|
|
|
thread_sp->GetProcess()->GetBreakpointSiteList().FindByID(m_value));
|
|
|
|
std::unordered_set<break_id_t> precondition_breakpoints;
|
|
|
|
|
|
|
|
if (bp_site_sp) {
|
|
|
|
// Let's copy the owners list out of the site and store them in a local
|
2018-05-01 00:49:04 +08:00
|
|
|
// list. That way if one of the breakpoint actions changes the site,
|
|
|
|
// then we won't be operating on a bad list.
|
2016-09-07 04:57:50 +08:00
|
|
|
BreakpointLocationCollection site_locations;
|
|
|
|
size_t num_owners = bp_site_sp->CopyOwnersList(site_locations);
|
|
|
|
|
|
|
|
if (num_owners == 0) {
|
|
|
|
m_should_stop = true;
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We go through each location, and test first its precondition -
|
|
|
|
// this overrides everything. Note, we only do this once per
|
|
|
|
// breakpoint - not once per location... Then check the condition.
|
|
|
|
// If the condition says to stop, then we run the callback for that
|
|
|
|
// location. If that callback says to stop as well, then we set
|
|
|
|
// m_should_stop to true; we are going to stop. But we still want to
|
|
|
|
// give all the breakpoints whose conditions say we are going to stop
|
|
|
|
// a chance to run their callbacks. Of course if any callback
|
|
|
|
// restarts the target by putting "continue" in the callback, then
|
2016-09-07 04:57:50 +08:00
|
|
|
// we're going to restart, without running the rest of the callbacks.
|
2018-05-01 00:49:04 +08:00
|
|
|
// And in this case we will end up not stopping even if another
|
|
|
|
// location said we should stop. But that's better than not running
|
|
|
|
// all the callbacks.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
m_should_stop = false;
|
|
|
|
|
|
|
|
// We don't select threads as we go through them testing breakpoint
|
2018-05-01 00:49:04 +08:00
|
|
|
// conditions and running commands. So we need to set the thread for
|
|
|
|
// expression evaluation here:
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadList::ExpressionExecutionThreadPusher thread_pusher(thread_sp);
|
|
|
|
|
|
|
|
ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (process->GetModIDRef().IsLastResumeForUserExpression()) {
|
|
|
|
// If we are in the middle of evaluating an expression, don't run
|
2018-05-01 00:49:04 +08:00
|
|
|
// asynchronous breakpoint commands or expressions. That could
|
|
|
|
// lead to infinite recursion if the command or condition re-calls
|
|
|
|
// the function with this breakpoint.
|
2016-09-07 04:57:50 +08:00
|
|
|
// TODO: We can keep a list of the breakpoints we've seen while
|
|
|
|
// running expressions in the nested
|
|
|
|
// PerformAction calls that can arise when the action runs a
|
2018-05-01 00:49:04 +08:00
|
|
|
// function that hits another breakpoint, and only stop running
|
|
|
|
// commands when we see the same breakpoint hit a second time.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
m_should_stop_is_valid = true;
|
2018-11-30 17:45:52 +08:00
|
|
|
|
|
|
|
// It is possible that the user has a breakpoint at the same site
|
|
|
|
// as the completed plan had (e.g. user has a breakpoint
|
|
|
|
// on a module entry point, and `ThreadPlanCallFunction` ends
|
|
|
|
// also there). We can't find an internal breakpoint in the loop
|
|
|
|
// later because it was already removed on the plan completion.
|
|
|
|
// So check if the plan was completed, and stop if so.
|
|
|
|
if (thread_sp->CompletedPlanOverridesBreakpoint()) {
|
|
|
|
m_should_stop = true;
|
|
|
|
thread_sp->ResetStopInfo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("StopInfoBreakpoint::PerformAction - Hit a "
|
|
|
|
"breakpoint while running an expression,"
|
|
|
|
" not running commands to avoid recursion.");
|
|
|
|
bool ignoring_breakpoints =
|
|
|
|
process->GetIgnoreBreakpointsInExpressions();
|
|
|
|
if (ignoring_breakpoints) {
|
|
|
|
m_should_stop = false;
|
|
|
|
// Internal breakpoints will always stop.
|
|
|
|
for (size_t j = 0; j < num_owners; j++) {
|
|
|
|
lldb::BreakpointLocationSP bp_loc_sp =
|
|
|
|
bp_site_sp->GetOwnerAtIndex(j);
|
|
|
|
if (bp_loc_sp->GetBreakpoint().IsInternal()) {
|
|
|
|
m_should_stop = true;
|
|
|
|
break;
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
m_should_stop = true;
|
|
|
|
}
|
|
|
|
if (log)
|
|
|
|
log->Printf("StopInfoBreakpoint::PerformAction - in expression, "
|
|
|
|
"continuing: %s.",
|
|
|
|
m_should_stop ? "true" : "false");
|
|
|
|
process->GetTarget().GetDebugger().GetAsyncOutputStream()->Printf(
|
|
|
|
"Warning: hit breakpoint while "
|
|
|
|
"running function, skipping commands and conditions to prevent "
|
|
|
|
"recursion.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StoppointCallbackContext context(event_ptr, exe_ctx, false);
|
|
|
|
|
|
|
|
// For safety's sake let's also grab an extra reference to the
|
2018-05-01 00:49:04 +08:00
|
|
|
// breakpoint owners of the locations we're going to examine, since
|
|
|
|
// the locations are going to have to get back to their breakpoints,
|
|
|
|
// and the locations don't keep their owners alive. I'm just
|
|
|
|
// sticking the BreakpointSP's in a vector since I'm only using it to
|
|
|
|
// locally increment their retain counts.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
std::vector<lldb::BreakpointSP> location_owners;
|
|
|
|
|
|
|
|
for (size_t j = 0; j < num_owners; j++) {
|
|
|
|
BreakpointLocationSP loc(site_locations.GetByIndex(j));
|
|
|
|
location_owners.push_back(loc->GetBreakpoint().shared_from_this());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t j = 0; j < num_owners; j++) {
|
|
|
|
lldb::BreakpointLocationSP bp_loc_sp = site_locations.GetByIndex(j);
|
2017-08-04 02:13:24 +08:00
|
|
|
StreamString loc_desc;
|
|
|
|
if (log) {
|
|
|
|
bp_loc_sp->GetDescription(&loc_desc, eDescriptionLevelBrief);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
// If another action disabled this breakpoint or its location, then
|
|
|
|
// don't run the actions.
|
|
|
|
if (!bp_loc_sp->IsEnabled() ||
|
|
|
|
!bp_loc_sp->GetBreakpoint().IsEnabled())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// The breakpoint site may have many locations associated with it,
|
2018-05-01 00:49:04 +08:00
|
|
|
// not all of them valid for this thread. Skip the ones that
|
|
|
|
// aren't:
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!bp_loc_sp->ValidForThisThread(thread_sp.get())) {
|
|
|
|
if (log) {
|
|
|
|
log->Printf("Breakpoint %s hit on thread 0x%llx but it was not "
|
|
|
|
"for this thread, continuing.",
|
2017-08-04 02:13:24 +08:00
|
|
|
loc_desc.GetData(), static_cast<unsigned long long>(
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_sp->GetID()));
|
|
|
|
}
|
|
|
|
continue;
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 02:13:24 +08:00
|
|
|
internal_breakpoint = bp_loc_sp->GetBreakpoint().IsInternal();
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// First run the precondition, but since the precondition is per
|
2018-05-01 00:49:04 +08:00
|
|
|
// breakpoint, only run it once per breakpoint.
|
2016-09-07 04:57:50 +08:00
|
|
|
std::pair<std::unordered_set<break_id_t>::iterator, bool> result =
|
|
|
|
precondition_breakpoints.insert(
|
|
|
|
bp_loc_sp->GetBreakpoint().GetID());
|
|
|
|
if (!result.second)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bool precondition_result =
|
|
|
|
bp_loc_sp->GetBreakpoint().EvaluatePrecondition(context);
|
|
|
|
if (!precondition_result)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Next run the condition for the breakpoint. If that says we
|
2018-05-01 00:49:04 +08:00
|
|
|
// should stop, then we'll run the callback for the breakpoint. If
|
|
|
|
// the callback says we shouldn't stop that will win.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (bp_loc_sp->GetConditionText() != nullptr) {
|
2017-05-12 12:51:55 +08:00
|
|
|
Status condition_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
bool condition_says_stop =
|
|
|
|
bp_loc_sp->ConditionSaysStop(exe_ctx, condition_error);
|
|
|
|
|
|
|
|
if (!condition_error.Success()) {
|
|
|
|
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
|
|
|
|
StreamSP error_sp = debugger.GetAsyncErrorStream();
|
|
|
|
error_sp->Printf("Stopped due to an error evaluating condition "
|
|
|
|
"of breakpoint ");
|
|
|
|
bp_loc_sp->GetDescription(error_sp.get(),
|
|
|
|
eDescriptionLevelBrief);
|
|
|
|
error_sp->Printf(": \"%s\"", bp_loc_sp->GetConditionText());
|
|
|
|
error_sp->EOL();
|
|
|
|
const char *err_str =
|
|
|
|
condition_error.AsCString("<Unknown Error>");
|
|
|
|
if (log)
|
|
|
|
log->Printf("Error evaluating condition: \"%s\"\n", err_str);
|
|
|
|
|
|
|
|
error_sp->PutCString(err_str);
|
|
|
|
error_sp->EOL();
|
|
|
|
error_sp->Flush();
|
|
|
|
} else {
|
|
|
|
if (log) {
|
|
|
|
log->Printf("Condition evaluated for breakpoint %s on thread "
|
|
|
|
"0x%llx conditon_says_stop: %i.",
|
2017-08-04 02:13:24 +08:00
|
|
|
loc_desc.GetData(),
|
|
|
|
static_cast<unsigned long long>(
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_sp->GetID()),
|
|
|
|
condition_says_stop);
|
2013-01-26 10:19:28 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!condition_says_stop) {
|
|
|
|
// We don't want to increment the hit count of breakpoints if
|
2018-05-01 00:49:04 +08:00
|
|
|
// the condition fails. We've already bumped it by the time
|
|
|
|
// we get here, so undo the bump:
|
2016-09-07 04:57:50 +08:00
|
|
|
bp_loc_sp->UndoBumpHitCount();
|
|
|
|
continue;
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
|
|
|
|
2017-08-04 02:13:24 +08:00
|
|
|
// Check the auto-continue bit on the location, do this before the
|
|
|
|
// callback since it may change this, but that would be for the
|
|
|
|
// NEXT hit. Note, you might think you could check auto-continue
|
|
|
|
// before the condition, and not evaluate the condition if it says
|
|
|
|
// to continue. But failing the condition means the breakpoint was
|
|
|
|
// effectively NOT HIT. So these two states are different.
|
|
|
|
bool auto_continue_says_stop = true;
|
|
|
|
if (bp_loc_sp->IsAutoContinue())
|
|
|
|
{
|
|
|
|
if (log)
|
|
|
|
log->Printf("Continuing breakpoint %s as AutoContinue was set.",
|
|
|
|
loc_desc.GetData());
|
|
|
|
// We want this stop reported, so you will know we auto-continued
|
|
|
|
// but only for external breakpoints:
|
|
|
|
if (!internal_breakpoint)
|
|
|
|
thread_sp->SetShouldReportStop(eVoteYes);
|
|
|
|
auto_continue_says_stop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool callback_says_stop = true;
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// FIXME: For now the callbacks have to run in async mode - the
|
|
|
|
// first time we restart we need
|
|
|
|
// to get out of there. So set it here.
|
|
|
|
// When we figure out how to nest breakpoint hits then this will
|
|
|
|
// change.
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Debugger &debugger = thread_sp->CalculateTarget()->GetDebugger();
|
|
|
|
bool old_async = debugger.GetAsyncExecution();
|
|
|
|
debugger.SetAsyncExecution(true);
|
2013-04-30 07:30:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
callback_says_stop = bp_loc_sp->InvokeCallback(&context);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
debugger.SetAsyncExecution(old_async);
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2017-08-04 02:13:24 +08:00
|
|
|
if (callback_says_stop && auto_continue_says_stop)
|
2016-09-07 04:57:50 +08:00
|
|
|
m_should_stop = true;
|
2017-02-15 19:42:47 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// If we are going to stop for this breakpoint, then remove the
|
|
|
|
// breakpoint.
|
|
|
|
if (callback_says_stop && bp_loc_sp &&
|
|
|
|
bp_loc_sp->GetBreakpoint().IsOneShot()) {
|
|
|
|
thread_sp->GetProcess()->GetTarget().RemoveBreakpointByID(
|
|
|
|
bp_loc_sp->GetBreakpoint().GetID());
|
2013-04-30 07:30:46 +08:00
|
|
|
}
|
2018-05-01 00:49:04 +08:00
|
|
|
// Also make sure that the callback hasn't continued the target. If
|
|
|
|
// it did, when we'll set m_should_start to false and get out of
|
2016-09-07 04:57:50 +08:00
|
|
|
// here.
|
|
|
|
if (HasTargetRunSinceMe()) {
|
|
|
|
m_should_stop = false;
|
|
|
|
break;
|
2013-04-30 07:30:46 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-10 08:59:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
// We've figured out what this stop wants to do, so mark it as valid so
|
|
|
|
// we don't compute it again.
|
|
|
|
m_should_stop_is_valid = true;
|
|
|
|
} else {
|
|
|
|
m_should_stop = true;
|
|
|
|
m_should_stop_is_valid = true;
|
|
|
|
Log *log_process(
|
|
|
|
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
if (log_process)
|
|
|
|
log_process->Printf(
|
|
|
|
"Process::%s could not find breakpoint site id: %" PRId64 "...",
|
|
|
|
__FUNCTION__, m_value);
|
|
|
|
}
|
2017-02-15 19:42:47 +08:00
|
|
|
|
|
|
|
if ((m_should_stop == false || internal_breakpoint)
|
|
|
|
&& thread_sp->CompletedPlanOverridesBreakpoint()) {
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Override should_stop decision when we have completed step plan
|
|
|
|
// additionally to the breakpoint
|
2017-02-15 19:42:47 +08:00
|
|
|
m_should_stop = true;
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Here we clean the preset stop info so the next GetStopInfo call will
|
|
|
|
// find the appropriate stop info, which should be the stop info
|
|
|
|
// related to the completed plan
|
2017-02-15 19:42:47 +08:00
|
|
|
thread_sp->ResetStopInfo();
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf("Process::%s returning from action with m_should_stop: %d.",
|
|
|
|
__FUNCTION__, m_should_stop);
|
2010-08-10 08:59:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
|
|
|
private:
|
2016-09-07 04:57:50 +08:00
|
|
|
bool m_should_stop;
|
|
|
|
bool m_should_stop_is_valid;
|
|
|
|
bool m_should_perform_action; // Since we are trying to preserve the "state"
|
|
|
|
// of the system even if we run functions
|
|
|
|
// etc. behind the users backs, we need to make sure we only REALLY perform
|
|
|
|
// the action once.
|
|
|
|
lldb::addr_t m_address; // We use this to capture the breakpoint site address
|
|
|
|
// when we create the StopInfo,
|
|
|
|
// in case somebody deletes it between the time the StopInfo is made and the
|
|
|
|
// description is asked for.
|
|
|
|
lldb::break_id_t m_break_id;
|
|
|
|
bool m_was_one_shot;
|
2010-08-04 09:40:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoWatchpoint
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoWatchpoint : public StopInfo {
|
2010-08-04 09:40:35 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
// Make sure watchpoint is properly disabled and subsequently enabled while
|
|
|
|
// performing watchpoint actions.
|
|
|
|
class WatchpointSentry {
|
|
|
|
public:
|
2016-10-26 04:34:32 +08:00
|
|
|
WatchpointSentry(ProcessSP p_sp, WatchpointSP w_sp) : process_sp(p_sp),
|
|
|
|
watchpoint_sp(w_sp) {
|
|
|
|
if (process_sp && watchpoint_sp) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const bool notify = false;
|
2016-10-26 04:34:32 +08:00
|
|
|
watchpoint_sp->TurnOnEphemeralMode();
|
|
|
|
process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
|
|
|
|
process_sp->AddPreResumeAction(SentryPreResumeAction, this);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-26 04:34:32 +08:00
|
|
|
|
|
|
|
void DoReenable() {
|
|
|
|
if (process_sp && watchpoint_sp) {
|
|
|
|
bool was_disabled = watchpoint_sp->IsDisabledDuringEphemeralMode();
|
|
|
|
watchpoint_sp->TurnOffEphemeralMode();
|
|
|
|
const bool notify = false;
|
|
|
|
if (was_disabled) {
|
|
|
|
process_sp->DisableWatchpoint(watchpoint_sp.get(), notify);
|
|
|
|
} else {
|
|
|
|
process_sp->EnableWatchpoint(watchpoint_sp.get(), notify);
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-10-26 04:34:32 +08:00
|
|
|
|
|
|
|
~WatchpointSentry() {
|
|
|
|
DoReenable();
|
|
|
|
if (process_sp)
|
|
|
|
process_sp->ClearPreResumeAction(SentryPreResumeAction, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool SentryPreResumeAction(void *sentry_void) {
|
|
|
|
WatchpointSentry *sentry = (WatchpointSentry *) sentry_void;
|
|
|
|
sentry->DoReenable();
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
private:
|
2016-10-26 04:34:32 +08:00
|
|
|
ProcessSP process_sp;
|
|
|
|
WatchpointSP watchpoint_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
};
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoWatchpoint(Thread &thread, break_id_t watch_id,
|
|
|
|
lldb::addr_t watch_hit_addr)
|
|
|
|
: StopInfo(thread, watch_id), m_should_stop(false),
|
|
|
|
m_should_stop_is_valid(false), m_watch_hit_addr(watch_hit_addr) {}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoWatchpoint() override = default;
|
|
|
|
|
|
|
|
StopReason GetStopReason() const override { return eStopReasonWatchpoint; }
|
|
|
|
|
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty()) {
|
|
|
|
StreamString strm;
|
|
|
|
strm.Printf("watchpoint %" PRIi64, m_value);
|
2016-11-17 05:15:24 +08:00
|
|
|
m_description = strm.GetString();
|
2012-11-10 10:08:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_description.c_str();
|
|
|
|
}
|
2012-11-10 10:08:14 +08:00
|
|
|
|
|
|
|
protected:
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ShouldStopSynchronous(Event *event_ptr) override {
|
2018-05-01 00:49:04 +08:00
|
|
|
// ShouldStop() method is idempotent and should not affect hit count. See
|
|
|
|
// Process::RunPrivateStateThread()->Process()->HandlePrivateEvent()
|
2016-09-07 04:57:50 +08:00
|
|
|
// -->Process()::ShouldBroadcastEvent()->ThreadList::ShouldStop()->
|
|
|
|
// Thread::ShouldStop()->ThreadPlanBase::ShouldStop()->
|
|
|
|
// StopInfoWatchpoint::ShouldStop() and
|
|
|
|
// Event::DoOnRemoval()->Process::ProcessEventData::DoOnRemoval()->
|
|
|
|
// StopInfoWatchpoint::PerformAction().
|
|
|
|
if (m_should_stop_is_valid)
|
|
|
|
return m_should_stop;
|
|
|
|
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
WatchpointSP wp_sp(
|
|
|
|
thread_sp->CalculateTarget()->GetWatchpointList().FindByID(
|
|
|
|
GetValue()));
|
|
|
|
if (wp_sp) {
|
|
|
|
// Check if we should stop at a watchpoint.
|
|
|
|
ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
|
|
|
|
StoppointCallbackContext context(event_ptr, exe_ctx, true);
|
|
|
|
m_should_stop = wp_sp->ShouldStop(&context);
|
|
|
|
} else {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
log->Printf(
|
|
|
|
"Process::%s could not find watchpoint location id: %" PRId64
|
|
|
|
"...",
|
|
|
|
__FUNCTION__, GetValue());
|
|
|
|
|
|
|
|
m_should_stop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_should_stop_is_valid = true;
|
|
|
|
return m_should_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShouldStop(Event *event_ptr) override {
|
2018-05-01 00:49:04 +08:00
|
|
|
// This just reports the work done by PerformAction or the synchronous
|
|
|
|
// stop. It should only ever get called after they have had a chance to
|
|
|
|
// run.
|
2016-09-07 04:57:50 +08:00
|
|
|
assert(m_should_stop_is_valid);
|
|
|
|
return m_should_stop;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PerformAction(Event *event_ptr) override {
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS);
|
|
|
|
// We're going to calculate if we should stop or not in some way during the
|
2018-05-01 00:49:04 +08:00
|
|
|
// course of this code. Also by default we're going to stop, so set that
|
|
|
|
// here.
|
2016-09-07 04:57:50 +08:00
|
|
|
m_should_stop = true;
|
2016-10-26 04:34:32 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
|
|
|
|
WatchpointSP wp_sp(
|
|
|
|
thread_sp->CalculateTarget()->GetWatchpointList().FindByID(
|
2016-10-26 04:34:32 +08:00
|
|
|
GetValue()));
|
2016-09-07 04:57:50 +08:00
|
|
|
if (wp_sp) {
|
|
|
|
ExecutionContext exe_ctx(thread_sp->GetStackFrameAtIndex(0));
|
2016-10-26 04:34:32 +08:00
|
|
|
ProcessSP process_sp = exe_ctx.GetProcessSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-22 06:47:15 +08:00
|
|
|
{
|
2016-09-07 04:57:50 +08:00
|
|
|
// check if this process is running on an architecture where
|
2018-05-01 00:49:04 +08:00
|
|
|
// watchpoints trigger before the associated instruction runs. if so,
|
|
|
|
// disable the WP, single-step and then re-enable the watchpoint
|
2016-10-26 04:34:32 +08:00
|
|
|
if (process_sp) {
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t num;
|
|
|
|
bool wp_triggers_after;
|
2016-10-26 04:34:32 +08:00
|
|
|
|
|
|
|
if (process_sp->GetWatchpointSupportInfo(num, wp_triggers_after)
|
2016-09-07 04:57:50 +08:00
|
|
|
.Success()) {
|
|
|
|
if (!wp_triggers_after) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// We need to preserve the watch_index before watchpoint is
|
|
|
|
// disable. Since Watchpoint::SetEnabled will clear the watch
|
|
|
|
// index. This will fix TestWatchpointIter failure
|
2016-12-09 21:54:47 +08:00
|
|
|
Watchpoint *wp = wp_sp.get();
|
|
|
|
uint32_t watch_index = wp->GetHardwareIndex();
|
|
|
|
process_sp->DisableWatchpoint(wp, false);
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP stored_stop_info_sp = thread_sp->GetStopInfo();
|
|
|
|
assert(stored_stop_info_sp.get() == this);
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
Status new_plan_status;
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP new_plan_sp(
|
|
|
|
thread_sp->QueueThreadPlanForStepSingleInstruction(
|
2018-11-15 09:18:15 +08:00
|
|
|
false, // step-over
|
|
|
|
false, // abort_other_plans
|
|
|
|
true, // stop_other_threads
|
|
|
|
new_plan_status));
|
|
|
|
if (new_plan_sp && new_plan_status.Success()) {
|
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
|
|
|
new_plan_sp->SetPrivate(true);
|
|
|
|
}
|
2016-10-26 04:34:32 +08:00
|
|
|
process_sp->GetThreadList().SetSelectedThreadByID(
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_sp->GetID());
|
2016-10-26 04:34:32 +08:00
|
|
|
process_sp->ResumeSynchronous(nullptr);
|
|
|
|
process_sp->GetThreadList().SetSelectedThreadByID(
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_sp->GetID());
|
|
|
|
thread_sp->SetStopInfo(stored_stop_info_sp);
|
2016-12-09 21:54:47 +08:00
|
|
|
process_sp->EnableWatchpoint(wp, false);
|
|
|
|
wp->SetHardwareIndex(watch_index);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-30 07:30:46 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2011-09-22 06:47:15 +08:00
|
|
|
|
2016-10-26 04:34:32 +08:00
|
|
|
// This sentry object makes sure the current watchpoint is disabled
|
2018-05-01 00:49:04 +08:00
|
|
|
// while performing watchpoint actions, and it is then enabled after we
|
|
|
|
// are finished.
|
2016-10-26 04:34:32 +08:00
|
|
|
WatchpointSentry sentry(process_sp, wp_sp);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
/*
|
|
|
|
* MIPS: Last 3bits of the watchpoint address are masked by the kernel.
|
|
|
|
* For example:
|
|
|
|
* 'n' is at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is
|
|
|
|
* set at 'm', then
|
|
|
|
* watch exception is generated even when 'n' is read/written. To handle
|
|
|
|
* this case,
|
|
|
|
* server emulates the instruction at PC and finds the base address of
|
|
|
|
* the load/store
|
|
|
|
* instruction and appends it in the description of the stop-info
|
|
|
|
* packet. If watchpoint
|
|
|
|
* is not set on this address by user then this do not stop.
|
|
|
|
*/
|
|
|
|
if (m_watch_hit_addr != LLDB_INVALID_ADDRESS) {
|
|
|
|
WatchpointSP wp_hit_sp =
|
|
|
|
thread_sp->CalculateTarget()->GetWatchpointList().FindByAddress(
|
|
|
|
m_watch_hit_addr);
|
|
|
|
if (!wp_hit_sp) {
|
|
|
|
m_should_stop = false;
|
|
|
|
wp_sp->IncrementFalseAlarmsAndReviseHitCount();
|
|
|
|
}
|
|
|
|
}
|
2011-09-22 06:47:15 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// TODO: This condition should be checked in the synchronous part of the
|
|
|
|
// watchpoint code
|
|
|
|
// (Watchpoint::ShouldStop), so that we avoid pulling an event even if
|
2018-05-01 00:49:04 +08:00
|
|
|
// the watchpoint fails the ignore count condition. It is moved here
|
|
|
|
// temporarily, because for archs with
|
|
|
|
// watchpoint_exceptions_received=before, the code in the previous
|
|
|
|
// lines takes care of moving the inferior to next PC. We have to check
|
|
|
|
// the ignore count condition after this is done, otherwise we will hit
|
|
|
|
// same watchpoint multiple times until we pass ignore condition, but
|
|
|
|
// we won't actually be ignoring them.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (wp_sp->GetHitCount() <= wp_sp->GetIgnoreCount())
|
|
|
|
m_should_stop = false;
|
|
|
|
|
2016-10-26 04:34:32 +08:00
|
|
|
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_should_stop && wp_sp->GetConditionText() != nullptr) {
|
|
|
|
// We need to make sure the user sees any parse errors in their
|
2016-11-08 12:52:16 +08:00
|
|
|
// condition, so we'll hook the constructor errors up to the
|
|
|
|
// debugger's Async I/O.
|
2016-09-07 04:57:50 +08:00
|
|
|
ExpressionResults result_code;
|
|
|
|
EvaluateExpressionOptions expr_options;
|
|
|
|
expr_options.SetUnwindOnError(true);
|
|
|
|
expr_options.SetIgnoreBreakpoints(true);
|
|
|
|
ValueObjectSP result_value_sp;
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
result_code = UserExpression::Evaluate(
|
2016-11-08 12:52:16 +08:00
|
|
|
exe_ctx, expr_options, wp_sp->GetConditionText(),
|
|
|
|
llvm::StringRef(), result_value_sp, error);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (result_code == eExpressionCompleted) {
|
|
|
|
if (result_value_sp) {
|
|
|
|
Scalar scalar_value;
|
|
|
|
if (result_value_sp->ResolveValue(scalar_value)) {
|
|
|
|
if (scalar_value.ULongLong(1) == 0) {
|
|
|
|
// We have been vetoed. This takes precedence over querying
|
2018-05-01 00:49:04 +08:00
|
|
|
// the watchpoint whether it should stop (aka ignore count
|
|
|
|
// and friends). See also StopInfoWatchpoint::ShouldStop()
|
|
|
|
// as well as Process::ProcessEventData::DoOnRemoval().
|
2016-09-07 04:57:50 +08:00
|
|
|
m_should_stop = false;
|
|
|
|
} else
|
|
|
|
m_should_stop = true;
|
|
|
|
if (log)
|
|
|
|
log->Printf(
|
|
|
|
"Condition successfully evaluated, result is %s.\n",
|
|
|
|
m_should_stop ? "true" : "false");
|
|
|
|
} else {
|
2013-04-30 07:30:46 +08:00
|
|
|
m_should_stop = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log)
|
|
|
|
log->Printf(
|
|
|
|
"Failed to get an integer result from the expression.");
|
|
|
|
}
|
2013-04-30 07:30:46 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
StreamSP error_sp = debugger.GetAsyncErrorStream();
|
|
|
|
error_sp->Printf(
|
|
|
|
"Stopped due to an error evaluating condition of watchpoint ");
|
|
|
|
wp_sp->GetDescription(error_sp.get(), eDescriptionLevelBrief);
|
|
|
|
error_sp->Printf(": \"%s\"", wp_sp->GetConditionText());
|
|
|
|
error_sp->EOL();
|
|
|
|
const char *err_str = error.AsCString("<Unknown Error>");
|
|
|
|
if (log)
|
|
|
|
log->Printf("Error evaluating condition: \"%s\"\n", err_str);
|
|
|
|
|
|
|
|
error_sp->PutCString(err_str);
|
|
|
|
error_sp->EOL();
|
|
|
|
error_sp->Flush();
|
|
|
|
// If the condition fails to be parsed or run, we should stop.
|
|
|
|
m_should_stop = true;
|
|
|
|
}
|
2011-09-22 06:47:15 +08:00
|
|
|
}
|
2012-08-22 06:06:34 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// If the condition says to stop, we run the callback to further decide
|
|
|
|
// whether to stop.
|
|
|
|
if (m_should_stop) {
|
2016-10-26 04:34:32 +08:00
|
|
|
// FIXME: For now the callbacks have to run in async mode - the
|
|
|
|
// first time we restart we need
|
|
|
|
// to get out of there. So set it here.
|
|
|
|
// When we figure out how to nest watchpoint hits then this will
|
|
|
|
// change.
|
|
|
|
|
|
|
|
bool old_async = debugger.GetAsyncExecution();
|
|
|
|
debugger.SetAsyncExecution(true);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StoppointCallbackContext context(event_ptr, exe_ctx, false);
|
|
|
|
bool stop_requested = wp_sp->InvokeCallback(&context);
|
2016-10-26 04:34:32 +08:00
|
|
|
|
|
|
|
debugger.SetAsyncExecution(old_async);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Also make sure that the callback hasn't continued the target. If
|
|
|
|
// it did, when we'll set m_should_stop to false and get out of here.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (HasTargetRunSinceMe())
|
|
|
|
m_should_stop = false;
|
|
|
|
|
|
|
|
if (m_should_stop && !stop_requested) {
|
|
|
|
// We have been vetoed by the callback mechanism.
|
|
|
|
m_should_stop = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Finally, if we are going to stop, print out the new & old values:
|
|
|
|
if (m_should_stop) {
|
|
|
|
wp_sp->CaptureWatchedValue(exe_ctx);
|
|
|
|
|
|
|
|
Debugger &debugger = exe_ctx.GetTargetRef().GetDebugger();
|
|
|
|
StreamSP output_sp = debugger.GetAsyncOutputStream();
|
|
|
|
wp_sp->DumpSnapshots(output_sp.get());
|
|
|
|
output_sp->EOL();
|
|
|
|
output_sp->Flush();
|
|
|
|
}
|
2015-10-06 13:25:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
Log *log_process(
|
|
|
|
lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
|
2011-10-18 02:58:00 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log_process)
|
|
|
|
log_process->Printf(
|
|
|
|
"Process::%s could not find watchpoint id: %" PRId64 "...",
|
|
|
|
__FUNCTION__, m_value);
|
|
|
|
}
|
|
|
|
if (log)
|
|
|
|
log->Printf("Process::%s returning from action with m_should_stop: %d.",
|
|
|
|
__FUNCTION__, m_should_stop);
|
2013-04-30 07:30:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_should_stop_is_valid = true;
|
2011-10-18 02:58:00 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
private:
|
2016-09-07 04:57:50 +08:00
|
|
|
bool m_should_stop;
|
|
|
|
bool m_should_stop_is_valid;
|
|
|
|
lldb::addr_t m_watch_hit_addr;
|
2010-08-04 09:40:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoUnixSignal
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoUnixSignal : public StopInfo {
|
2010-08-04 09:40:35 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoUnixSignal(Thread &thread, int signo, const char *description)
|
|
|
|
: StopInfo(thread, signo) {
|
|
|
|
SetDescription(description);
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoUnixSignal() override = default;
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopReason GetStopReason() const override { return eStopReasonSignal; }
|
2013-02-09 09:29:05 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ShouldStopSynchronous(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp)
|
|
|
|
return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ShouldStop(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp)
|
|
|
|
return thread_sp->GetProcess()->GetUnixSignals()->GetShouldStop(m_value);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If should stop returns false, check if we should notify of this event
|
|
|
|
bool DoShouldNotify(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
bool should_notify =
|
|
|
|
thread_sp->GetProcess()->GetUnixSignals()->GetShouldNotify(m_value);
|
|
|
|
if (should_notify) {
|
|
|
|
StreamString strm;
|
|
|
|
strm.Printf(
|
|
|
|
"thread %d received signal: %s", thread_sp->GetIndexID(),
|
|
|
|
thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(
|
|
|
|
m_value));
|
|
|
|
Process::ProcessEventData::AddRestartedReason(event_ptr,
|
|
|
|
strm.GetData());
|
|
|
|
}
|
|
|
|
return should_notify;
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WillResume(lldb::StateType resume_state) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
if (!thread_sp->GetProcess()->GetUnixSignals()->GetShouldSuppress(
|
|
|
|
m_value))
|
|
|
|
thread_sp->SetResumeSignal(m_value);
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty()) {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp) {
|
|
|
|
StreamString strm;
|
|
|
|
const char *signal_name =
|
|
|
|
thread_sp->GetProcess()->GetUnixSignals()->GetSignalAsCString(
|
|
|
|
m_value);
|
|
|
|
if (signal_name)
|
|
|
|
strm.Printf("signal %s", signal_name);
|
|
|
|
else
|
|
|
|
strm.Printf("signal %" PRIi64, m_value);
|
2016-11-17 05:15:24 +08:00
|
|
|
m_description = strm.GetString();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_description.c_str();
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoTrace
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoTrace : public StopInfo {
|
2010-08-04 09:40:35 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoTrace(Thread &thread) : StopInfo(thread, LLDB_INVALID_UID) {}
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoTrace() override = default;
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopReason GetStopReason() const override { return eStopReasonTrace; }
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty())
|
|
|
|
return "trace";
|
|
|
|
else
|
|
|
|
return m_description.c_str();
|
|
|
|
}
|
2011-06-04 09:26:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoException
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoException : public StopInfo {
|
2011-06-04 09:26:29 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoException(Thread &thread, const char *description)
|
|
|
|
: StopInfo(thread, LLDB_INVALID_UID) {
|
|
|
|
if (description)
|
|
|
|
SetDescription(description);
|
|
|
|
}
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoException() override = default;
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopReason GetStopReason() const override { return eStopReasonException; }
|
|
|
|
|
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty())
|
|
|
|
return "exception";
|
|
|
|
else
|
|
|
|
return m_description.c_str();
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoThreadPlan
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoThreadPlan : public StopInfo {
|
2010-08-04 09:40:35 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoThreadPlan(ThreadPlanSP &plan_sp, ValueObjectSP &return_valobj_sp,
|
|
|
|
ExpressionVariableSP &expression_variable_sp)
|
|
|
|
: StopInfo(plan_sp->GetThread(), LLDB_INVALID_UID), m_plan_sp(plan_sp),
|
|
|
|
m_return_valobj_sp(return_valobj_sp),
|
|
|
|
m_expression_variable_sp(expression_variable_sp) {}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoThreadPlan() override = default;
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopReason GetStopReason() const override { return eStopReasonPlanComplete; }
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *GetDescription() override {
|
|
|
|
if (m_description.empty()) {
|
|
|
|
StreamString strm;
|
|
|
|
m_plan_sp->GetDescription(&strm, eDescriptionLevelBrief);
|
2016-11-17 05:15:24 +08:00
|
|
|
m_description = strm.GetString();
|
2011-12-17 09:35:57 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_description.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueObjectSP GetReturnValueObject() { return m_return_valobj_sp; }
|
|
|
|
|
|
|
|
ExpressionVariableSP GetExpressionVariable() {
|
|
|
|
return m_expression_variable_sp;
|
|
|
|
}
|
|
|
|
|
2013-02-09 09:29:05 +08:00
|
|
|
protected:
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ShouldStop(Event *event_ptr) override {
|
|
|
|
if (m_plan_sp)
|
|
|
|
return m_plan_sp->ShouldStop(event_ptr);
|
|
|
|
else
|
|
|
|
return StopInfo::ShouldStop(event_ptr);
|
|
|
|
}
|
2010-08-04 09:40:35 +08:00
|
|
|
|
|
|
|
private:
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP m_plan_sp;
|
|
|
|
ValueObjectSP m_return_valobj_sp;
|
|
|
|
ExpressionVariableSP m_expression_variable_sp;
|
2010-08-04 09:40:35 +08:00
|
|
|
};
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-12-05 10:50:45 +08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// StopInfoExec
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class StopInfoExec : public StopInfo {
|
2012-12-05 08:16:59 +08:00
|
|
|
public:
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoExec(Thread &thread)
|
|
|
|
: StopInfo(thread, LLDB_INVALID_UID), m_performed_action(false) {}
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
~StopInfoExec() override = default;
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2017-12-05 10:50:45 +08:00
|
|
|
bool ShouldStop(Event *event_ptr) override {
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp)
|
|
|
|
return thread_sp->GetProcess()->GetStopOnExec();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopReason GetStopReason() const override { return eStopReasonExec; }
|
|
|
|
|
|
|
|
const char *GetDescription() override { return "exec"; }
|
2015-10-24 02:39:37 +08:00
|
|
|
|
2012-12-05 08:16:59 +08:00
|
|
|
protected:
|
2016-09-07 04:57:50 +08:00
|
|
|
void PerformAction(Event *event_ptr) override {
|
|
|
|
// Only perform the action once
|
|
|
|
if (m_performed_action)
|
|
|
|
return;
|
|
|
|
m_performed_action = true;
|
|
|
|
ThreadSP thread_sp(m_thread_wp.lock());
|
|
|
|
if (thread_sp)
|
|
|
|
thread_sp->GetProcess()->DidExec();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool m_performed_action;
|
2012-12-05 08:16:59 +08:00
|
|
|
};
|
|
|
|
|
2011-08-09 10:12:22 +08:00
|
|
|
} // namespace lldb_private
|
2010-08-04 09:40:35 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithBreakpointSiteID(Thread &thread,
|
|
|
|
break_id_t break_id) {
|
|
|
|
return StopInfoSP(new StopInfoBreakpoint(thread, break_id));
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithBreakpointSiteID(Thread &thread,
|
|
|
|
break_id_t break_id,
|
|
|
|
bool should_stop) {
|
|
|
|
return StopInfoSP(new StopInfoBreakpoint(thread, break_id, should_stop));
|
2010-10-15 07:45:03 +08:00
|
|
|
}
|
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
StopInfoSP
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfo::CreateStopReasonWithWatchpointID(Thread &thread, break_id_t watch_id,
|
|
|
|
lldb::addr_t watch_hit_addr) {
|
|
|
|
return StopInfoSP(new StopInfoWatchpoint(thread, watch_id, watch_hit_addr));
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithSignal(Thread &thread, int signo,
|
|
|
|
const char *description) {
|
|
|
|
return StopInfoSP(new StopInfoUnixSignal(thread, signo, description));
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonToTrace(Thread &thread) {
|
|
|
|
return StopInfoSP(new StopInfoTrace(thread));
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithPlan(
|
|
|
|
ThreadPlanSP &plan_sp, ValueObjectSP return_valobj_sp,
|
|
|
|
ExpressionVariableSP expression_variable_sp) {
|
|
|
|
return StopInfoSP(new StopInfoThreadPlan(plan_sp, return_valobj_sp,
|
|
|
|
expression_variable_sp));
|
2010-08-04 09:40:35 +08:00
|
|
|
}
|
2011-06-04 09:26:29 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithException(Thread &thread,
|
|
|
|
const char *description) {
|
|
|
|
return StopInfoSP(new StopInfoException(thread, description));
|
2011-06-04 09:26:29 +08:00
|
|
|
}
|
2011-12-17 09:35:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP StopInfo::CreateStopReasonWithExec(Thread &thread) {
|
|
|
|
return StopInfoSP(new StopInfoExec(thread));
|
2012-12-05 08:16:59 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ValueObjectSP StopInfo::GetReturnValueObject(StopInfoSP &stop_info_sp) {
|
|
|
|
if (stop_info_sp &&
|
|
|
|
stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
|
|
|
|
StopInfoThreadPlan *plan_stop_info =
|
|
|
|
static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
|
|
|
|
return plan_stop_info->GetReturnValueObject();
|
|
|
|
} else
|
|
|
|
return ValueObjectSP();
|
2011-12-17 09:35:57 +08:00
|
|
|
}
|
2014-07-08 09:07:32 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ExpressionVariableSP StopInfo::GetExpressionVariable(StopInfoSP &stop_info_sp) {
|
|
|
|
if (stop_info_sp &&
|
|
|
|
stop_info_sp->GetStopReason() == eStopReasonPlanComplete) {
|
|
|
|
StopInfoThreadPlan *plan_stop_info =
|
|
|
|
static_cast<StopInfoThreadPlan *>(stop_info_sp.get());
|
|
|
|
return plan_stop_info->GetExpressionVariable();
|
|
|
|
} else
|
|
|
|
return ExpressionVariableSP();
|
2014-07-08 09:07:32 +08:00
|
|
|
}
|
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
|
|
|
|
|
|
|
lldb::ValueObjectSP
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfo::GetCrashingDereference(StopInfoSP &stop_info_sp,
|
|
|
|
lldb::addr_t *crashing_address) {
|
|
|
|
if (!stop_info_sp) {
|
|
|
|
return ValueObjectSP();
|
|
|
|
}
|
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *description = stop_info_sp->GetDescription();
|
|
|
|
if (!description) {
|
|
|
|
return ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadSP thread_sp = stop_info_sp->GetThread();
|
|
|
|
if (!thread_sp) {
|
|
|
|
return ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
StackFrameSP frame_sp = thread_sp->GetSelectedFrame();
|
|
|
|
|
|
|
|
if (!frame_sp) {
|
|
|
|
return ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char address_string[] = "address=";
|
|
|
|
|
|
|
|
const char *address_loc = strstr(description, address_string);
|
|
|
|
if (!address_loc) {
|
|
|
|
return ValueObjectSP();
|
|
|
|
}
|
|
|
|
|
|
|
|
address_loc += (sizeof(address_string) - 1);
|
|
|
|
|
|
|
|
uint64_t address = strtoull(address_loc, 0, 0);
|
|
|
|
if (crashing_address) {
|
|
|
|
*crashing_address = address;
|
|
|
|
}
|
|
|
|
|
|
|
|
return frame_sp->GuessValueForAddress(address);
|
Added the "frame diagnose" command and use its output to make crash info better.
When a process stops due to a crash, we get the crashing instruction and the
crashing memory location (if there is one). From the user's perspective it is
often unclear what the reason for the crash is in a symbolic sense.
To address this, I have added new fuctionality to StackFrame to parse the
disassembly and reconstruct the sequence of dereferneces and offsets that were
applied to a known variable (or fuction retrn value) to obtain the invalid
pointer.
This makes use of enhancements in the disassembler, as well as new information
provided by the DWARF expression infrastructure, and is exposed through a
"frame diagnose" command. It is also used to provide symbolic information, when
available, in the event of a crash.
The algorithm is very rudimentary, and it needs a bunch of work, including
- better parsing for assembly, preferably with help from LLVM
- support for non-Apple platforms
- cleanup of the algorithm core, preferably to make it all work in terms of
Operands instead of register/offset pairs
- improvement of the GetExpressioPath() logic to make prettier expression
paths, and
- better handling of vtables.
I welcome all suggestios, improvements, and testcases.
llvm-svn: 280692
2016-09-06 12:48:36 +08:00
|
|
|
}
|