2010-06-09 00:52:24 +08:00
|
|
|
//===-- BreakpointLocation.cpp ----------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointID.h"
|
|
|
|
#include "lldb/Breakpoint/StoppointCallbackContext.h"
|
2011-06-03 07:58:26 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/Log.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-30 05:13:06 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
|
|
|
#include "lldb/Core/StreamString.h"
|
2015-03-04 07:11:11 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
2016-03-19 08:03:59 +08:00
|
|
|
#include "lldb/Expression/DiagnosticManager.h"
|
2015-09-22 00:56:08 +08:00
|
|
|
#include "lldb/Expression/ExpressionVariable.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
#include "lldb/Expression/UserExpression.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-30 05:13:06 +08:00
|
|
|
#include "lldb/Symbol/CompileUnit.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2015-09-16 05:13:50 +08:00
|
|
|
#include "lldb/Symbol/TypeSystem.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2010-06-16 10:00:15 +08:00
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
BreakpointLocation::BreakpointLocation(break_id_t loc_id, Breakpoint &owner,
|
|
|
|
const Address &addr, lldb::tid_t tid,
|
2016-05-19 13:13:57 +08:00
|
|
|
bool hardware, bool check_for_resolver)
|
2016-09-07 04:57:50 +08:00
|
|
|
: StoppointLocation(loc_id, addr.GetOpcodeLoadAddress(&owner.GetTarget()),
|
|
|
|
hardware),
|
|
|
|
m_being_created(true), m_should_resolve_indirect_functions(false),
|
|
|
|
m_is_reexported(false), m_is_indirect(false), m_address(addr),
|
|
|
|
m_owner(owner), m_options_ap(), m_bp_site_sp(), m_condition_mutex() {
|
|
|
|
if (check_for_resolver) {
|
|
|
|
Symbol *symbol = m_address.CalculateSymbolContextSymbol();
|
|
|
|
if (symbol && symbol->IsIndirect()) {
|
|
|
|
SetShouldResolveIndirectFunctions(true);
|
2014-01-11 07:46:59 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2016-05-19 13:13:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetThreadID(tid);
|
|
|
|
m_being_created = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
BreakpointLocation::~BreakpointLocation() { ClearBreakpointSite(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::addr_t BreakpointLocation::GetLoadAddress() const {
|
|
|
|
return m_address.GetOpcodeLoadAddress(&m_owner.GetTarget());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Address &BreakpointLocation::GetAddress() { return m_address; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Breakpoint &BreakpointLocation::GetBreakpoint() { return m_owner; }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Target &BreakpointLocation::GetTarget() { return m_owner.GetTarget(); }
|
2015-09-16 05:13:50 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::IsEnabled() const {
|
|
|
|
if (!m_owner.IsEnabled())
|
|
|
|
return false;
|
|
|
|
else if (m_options_ap.get() != nullptr)
|
|
|
|
return m_options_ap->IsEnabled();
|
|
|
|
else
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetEnabled(bool enabled) {
|
|
|
|
GetLocationOptions()->SetEnabled(enabled);
|
|
|
|
if (enabled) {
|
|
|
|
ResolveBreakpointSite();
|
|
|
|
} else {
|
|
|
|
ClearBreakpointSite();
|
|
|
|
}
|
|
|
|
SendBreakpointLocationChangedEvent(enabled ? eBreakpointEventTypeEnabled
|
|
|
|
: eBreakpointEventTypeDisabled);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetThreadID(lldb::tid_t thread_id) {
|
|
|
|
if (thread_id != LLDB_INVALID_THREAD_ID)
|
|
|
|
GetLocationOptions()->SetThreadID(thread_id);
|
|
|
|
else {
|
|
|
|
// If we're resetting this to an invalid thread id, then
|
|
|
|
// don't make an options pointer just to do that.
|
|
|
|
if (m_options_ap.get() != nullptr)
|
|
|
|
m_options_ap->SetThreadID(thread_id);
|
|
|
|
}
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::tid_t BreakpointLocation::GetThreadID() {
|
|
|
|
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
|
|
|
|
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID();
|
|
|
|
else
|
|
|
|
return LLDB_INVALID_THREAD_ID;
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetThreadIndex(uint32_t index) {
|
|
|
|
if (index != 0)
|
|
|
|
GetLocationOptions()->GetThreadSpec()->SetIndex(index);
|
|
|
|
else {
|
|
|
|
// If we're resetting this to an invalid thread id, then
|
|
|
|
// don't make an options pointer just to do that.
|
|
|
|
if (m_options_ap.get() != nullptr)
|
|
|
|
m_options_ap->GetThreadSpec()->SetIndex(index);
|
|
|
|
}
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t BreakpointLocation::GetThreadIndex() const {
|
|
|
|
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
|
|
|
|
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetIndex();
|
|
|
|
else
|
|
|
|
return 0;
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetThreadName(const char *thread_name) {
|
|
|
|
if (thread_name != nullptr)
|
|
|
|
GetLocationOptions()->GetThreadSpec()->SetName(thread_name);
|
|
|
|
else {
|
|
|
|
// If we're resetting this to an invalid thread id, then
|
|
|
|
// don't make an options pointer just to do that.
|
|
|
|
if (m_options_ap.get() != nullptr)
|
|
|
|
m_options_ap->GetThreadSpec()->SetName(thread_name);
|
|
|
|
}
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *BreakpointLocation::GetThreadName() const {
|
|
|
|
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
|
|
|
|
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetName();
|
|
|
|
else
|
|
|
|
return nullptr;
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetQueueName(const char *queue_name) {
|
|
|
|
if (queue_name != nullptr)
|
|
|
|
GetLocationOptions()->GetThreadSpec()->SetQueueName(queue_name);
|
|
|
|
else {
|
|
|
|
// If we're resetting this to an invalid thread id, then
|
|
|
|
// don't make an options pointer just to do that.
|
|
|
|
if (m_options_ap.get() != nullptr)
|
|
|
|
m_options_ap->GetThreadSpec()->SetQueueName(queue_name);
|
|
|
|
}
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeThreadChanged);
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *BreakpointLocation::GetQueueName() const {
|
|
|
|
if (GetOptionsNoCreate()->GetThreadSpecNoCreate())
|
|
|
|
return GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetQueueName();
|
|
|
|
else
|
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::InvokeCallback(StoppointCallbackContext *context) {
|
|
|
|
if (m_options_ap.get() != nullptr && m_options_ap->HasCallback())
|
|
|
|
return m_options_ap->InvokeCallback(context, m_owner.GetID(), GetID());
|
|
|
|
else
|
|
|
|
return m_owner.InvokeCallback(context, GetID());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetCallback(BreakpointHitCallback callback,
|
|
|
|
void *baton, bool is_synchronous) {
|
|
|
|
// The default "Baton" class will keep a copy of "baton" and won't free
|
|
|
|
// or delete it when it goes goes out of scope.
|
2016-09-14 01:53:38 +08:00
|
|
|
GetLocationOptions()->SetCallback(
|
|
|
|
callback, std::make_shared<UntypedBaton>(baton), is_synchronous);
|
2016-09-07 04:57:50 +08:00
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetCallback(BreakpointHitCallback callback,
|
|
|
|
const BatonSP &baton_sp,
|
|
|
|
bool is_synchronous) {
|
|
|
|
GetLocationOptions()->SetCallback(callback, baton_sp, is_synchronous);
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeCommandChanged);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::ClearCallback() {
|
|
|
|
GetLocationOptions()->ClearCallback();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetCondition(const char *condition) {
|
|
|
|
GetLocationOptions()->SetCondition(condition);
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeConditionChanged);
|
2010-10-15 07:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *BreakpointLocation::GetConditionText(size_t *hash) const {
|
|
|
|
return GetOptionsNoCreate()->GetConditionText(hash);
|
2013-04-19 15:09:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::ConditionSaysStop(ExecutionContext &exe_ctx,
|
|
|
|
Error &error) {
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(m_condition_mutex);
|
2016-05-19 13:13:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
size_t condition_hash;
|
|
|
|
const char *condition_text = GetConditionText(&condition_hash);
|
2016-05-19 13:13:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!condition_text) {
|
|
|
|
m_user_expression_sp.reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
error.Clear();
|
|
|
|
|
|
|
|
DiagnosticManager diagnostics;
|
|
|
|
|
|
|
|
if (condition_hash != m_condition_hash || !m_user_expression_sp ||
|
|
|
|
!m_user_expression_sp->MatchesContext(exe_ctx)) {
|
|
|
|
LanguageType language = eLanguageTypeUnknown;
|
|
|
|
// See if we can figure out the language from the frame, otherwise use the
|
|
|
|
// default language:
|
|
|
|
CompileUnit *comp_unit = m_address.CalculateSymbolContextCompileUnit();
|
|
|
|
if (comp_unit)
|
|
|
|
language = comp_unit->GetLanguage();
|
|
|
|
|
|
|
|
m_user_expression_sp.reset(GetTarget().GetUserExpressionForLanguage(
|
2016-11-08 12:52:16 +08:00
|
|
|
condition_text, llvm::StringRef(), language, Expression::eResultTypeAny,
|
2016-09-07 04:57:50 +08:00
|
|
|
EvaluateExpressionOptions(), error));
|
|
|
|
if (error.Fail()) {
|
|
|
|
if (log)
|
|
|
|
log->Printf("Error getting condition expression: %s.",
|
|
|
|
error.AsCString());
|
|
|
|
m_user_expression_sp.reset();
|
|
|
|
return true;
|
2013-05-11 05:58:45 +08:00
|
|
|
}
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!m_user_expression_sp->Parse(diagnostics, exe_ctx,
|
|
|
|
eExecutionPolicyOnlyWhenNeeded, true,
|
|
|
|
false)) {
|
|
|
|
error.SetErrorStringWithFormat(
|
|
|
|
"Couldn't parse conditional expression:\n%s",
|
|
|
|
diagnostics.GetString().c_str());
|
|
|
|
m_user_expression_sp.reset();
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-31 02:50:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_condition_hash = condition_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to make sure the user sees any parse errors in their condition, so
|
|
|
|
// we'll hook the
|
|
|
|
// constructor errors up to the debugger's Async I/O.
|
|
|
|
|
|
|
|
ValueObjectSP result_value_sp;
|
|
|
|
|
|
|
|
EvaluateExpressionOptions options;
|
|
|
|
options.SetUnwindOnError(true);
|
|
|
|
options.SetIgnoreBreakpoints(true);
|
|
|
|
options.SetTryAllThreads(true);
|
|
|
|
options.SetResultIsInternal(
|
|
|
|
true); // Don't generate a user variable for condition expressions.
|
|
|
|
|
|
|
|
Error expr_error;
|
|
|
|
|
|
|
|
diagnostics.Clear();
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ExpressionVariableSP result_variable_sp;
|
|
|
|
|
|
|
|
ExpressionResults result_code = m_user_expression_sp->Execute(
|
|
|
|
diagnostics, exe_ctx, options, m_user_expression_sp, result_variable_sp);
|
|
|
|
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (result_code == eExpressionCompleted) {
|
|
|
|
if (!result_variable_sp) {
|
|
|
|
error.SetErrorString("Expression did not return a result");
|
|
|
|
return false;
|
2013-04-19 15:09:15 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
result_value_sp = result_variable_sp->GetValueObject();
|
|
|
|
|
|
|
|
if (result_value_sp) {
|
|
|
|
ret = result_value_sp->IsLogicalTrue(error);
|
|
|
|
if (log) {
|
|
|
|
if (error.Success()) {
|
|
|
|
log->Printf("Condition successfully evaluated, result is %s.\n",
|
|
|
|
ret ? "true" : "false");
|
|
|
|
} else {
|
|
|
|
error.SetErrorString(
|
|
|
|
"Failed to get an integer result from the expression");
|
|
|
|
ret = false;
|
2013-04-19 15:09:15 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
error.SetErrorString("Failed to get any result from the expression");
|
2013-04-19 15:09:15 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
ret = false;
|
|
|
|
error.SetErrorStringWithFormat("Couldn't execute expression:\n%s",
|
|
|
|
diagnostics.GetString().c_str());
|
|
|
|
}
|
2016-03-19 08:03:59 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret;
|
2010-10-15 07:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t BreakpointLocation::GetIgnoreCount() {
|
|
|
|
return GetOptionsNoCreate()->GetIgnoreCount();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::SetIgnoreCount(uint32_t n) {
|
|
|
|
GetLocationOptions()->SetIgnoreCount(n);
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeIgnoreChanged);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::DecrementIgnoreCount() {
|
|
|
|
if (m_options_ap.get() != nullptr) {
|
|
|
|
uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
|
|
|
|
if (loc_ignore != 0)
|
|
|
|
m_options_ap->SetIgnoreCount(loc_ignore - 1);
|
|
|
|
}
|
2012-06-27 06:27:55 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::IgnoreCountShouldStop() {
|
|
|
|
if (m_options_ap.get() != nullptr) {
|
|
|
|
uint32_t loc_ignore = m_options_ap->GetIgnoreCount();
|
|
|
|
if (loc_ignore != 0) {
|
|
|
|
m_owner.DecrementIgnoreCount();
|
|
|
|
DecrementIgnoreCount(); // Have to decrement our owners' ignore count,
|
|
|
|
// since it won't get a
|
|
|
|
// chance to.
|
|
|
|
return false;
|
2012-06-27 06:27:55 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return true;
|
2012-06-27 06:27:55 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const BreakpointOptions *BreakpointLocation::GetOptionsNoCreate() const {
|
|
|
|
if (m_options_ap.get() != nullptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_options_ap.get();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
|
|
|
return m_owner.GetOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
BreakpointOptions *BreakpointLocation::GetLocationOptions() {
|
|
|
|
// If we make the copy we don't copy the callbacks because that is potentially
|
|
|
|
// expensive and we don't want to do that for the simple case where someone is
|
|
|
|
// just disabling the location.
|
|
|
|
if (m_options_ap.get() == nullptr)
|
|
|
|
m_options_ap.reset(
|
|
|
|
BreakpointOptions::CopyOptionsNoCallback(*m_owner.GetOptions()));
|
|
|
|
|
|
|
|
return m_options_ap.get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::ValidForThisThread(Thread *thread) {
|
|
|
|
return thread->MatchesSpec(GetOptionsNoCreate()->GetThreadSpecNoCreate());
|
2010-06-16 10:00:15 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// RETURNS - true if we should stop at this breakpoint, false if we
|
2010-06-16 10:00:15 +08:00
|
|
|
// should continue. Note, we don't check the thread spec for the breakpoint
|
|
|
|
// here, since if the breakpoint is not for this thread, then the event won't
|
|
|
|
// even get reported, so the check is redundant.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::ShouldStop(StoppointCallbackContext *context) {
|
|
|
|
bool should_stop = true;
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
|
|
|
|
|
|
|
|
// Do this first, if a location is disabled, it shouldn't increment its hit
|
|
|
|
// count.
|
|
|
|
if (!IsEnabled())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!IgnoreCountShouldStop())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!m_owner.IgnoreCountShouldStop())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// We only run synchronous callbacks in ShouldStop:
|
|
|
|
context->is_synchronous = true;
|
|
|
|
should_stop = InvokeCallback(context);
|
|
|
|
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
|
|
|
GetDescription(&s, lldb::eDescriptionLevelVerbose);
|
|
|
|
log->Printf("Hit breakpoint location: %s, %s.\n", s.GetData(),
|
|
|
|
should_stop ? "stopping" : "continuing");
|
|
|
|
}
|
|
|
|
|
|
|
|
return should_stop;
|
2015-01-15 09:41:04 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::BumpHitCount() {
|
|
|
|
if (IsEnabled()) {
|
|
|
|
// Step our hit count, and also step the hit count of the owner.
|
|
|
|
IncrementHitCount();
|
|
|
|
m_owner.IncrementHitCount();
|
|
|
|
}
|
2014-10-22 09:54:17 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void BreakpointLocation::UndoBumpHitCount() {
|
|
|
|
if (IsEnabled()) {
|
|
|
|
// Step our hit count, and also step the hit count of the owner.
|
|
|
|
DecrementHitCount();
|
|
|
|
m_owner.DecrementHitCount();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::IsResolved() const {
|
|
|
|
return m_bp_site_sp.get() != nullptr;
|
2010-10-15 07:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::BreakpointSiteSP BreakpointLocation::GetBreakpointSite() const {
|
|
|
|
return m_bp_site_sp;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::ResolveBreakpointSite() {
|
|
|
|
if (m_bp_site_sp)
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Process *process = m_owner.GetTarget().GetProcessSP().get();
|
|
|
|
if (process == nullptr)
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::break_id_t new_id =
|
|
|
|
process->CreateBreakpointSite(shared_from_this(), m_owner.IsHardware());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (new_id == LLDB_INVALID_BREAK_ID) {
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS);
|
|
|
|
if (log)
|
|
|
|
log->Warning("Tried to add breakpoint site at 0x%" PRIx64
|
|
|
|
" but it was already present.\n",
|
|
|
|
m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()));
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::SetBreakpointSite(BreakpointSiteSP &bp_site_sp) {
|
|
|
|
m_bp_site_sp = bp_site_sp;
|
|
|
|
SendBreakpointLocationChangedEvent(eBreakpointEventTypeLocationsResolved);
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool BreakpointLocation::ClearBreakpointSite() {
|
|
|
|
if (m_bp_site_sp.get()) {
|
|
|
|
ProcessSP process_sp(m_owner.GetTarget().GetProcessSP());
|
|
|
|
// If the process exists, get it to remove the owner, it will remove the
|
|
|
|
// physical implementation
|
|
|
|
// of the breakpoint as well if there are no more owners. Otherwise just
|
|
|
|
// remove this owner.
|
|
|
|
if (process_sp)
|
|
|
|
process_sp->RemoveOwnerFromBreakpointSite(GetBreakpoint().GetID(),
|
|
|
|
GetID(), m_bp_site_sp);
|
|
|
|
else
|
|
|
|
m_bp_site_sp->RemoveOwner(GetBreakpoint().GetID(), GetID());
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_bp_site_sp.reset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointLocation::GetDescription(Stream *s,
|
|
|
|
lldb::DescriptionLevel level) {
|
|
|
|
SymbolContext sc;
|
|
|
|
|
|
|
|
// If the description level is "initial" then the breakpoint is printing out
|
|
|
|
// our initial state,
|
|
|
|
// and we should let it decide how it wants to print our label.
|
|
|
|
if (level != eDescriptionLevelInitial) {
|
|
|
|
s->Indent();
|
|
|
|
BreakpointID::GetCanonicalReference(s, m_owner.GetID(), GetID());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level == lldb::eDescriptionLevelBrief)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (level != eDescriptionLevelInitial)
|
|
|
|
s->PutCString(": ");
|
|
|
|
|
|
|
|
if (level == lldb::eDescriptionLevelVerbose)
|
|
|
|
s->IndentMore();
|
|
|
|
|
|
|
|
if (m_address.IsSectionOffset()) {
|
|
|
|
m_address.CalculateSymbolContext(&sc);
|
|
|
|
|
|
|
|
if (level == lldb::eDescriptionLevelFull ||
|
|
|
|
level == eDescriptionLevelInitial) {
|
|
|
|
if (IsReExported())
|
|
|
|
s->PutCString("re-exported target = ");
|
|
|
|
else
|
|
|
|
s->PutCString("where = ");
|
|
|
|
sc.DumpStopContext(s, m_owner.GetTarget().GetProcessSP().get(), m_address,
|
|
|
|
false, true, false, true, true);
|
|
|
|
} else {
|
|
|
|
if (sc.module_sp) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->EOL();
|
2016-09-07 04:57:50 +08:00
|
|
|
s->Indent("module = ");
|
|
|
|
sc.module_sp->GetFileSpec().Dump(s);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (sc.comp_unit != nullptr) {
|
2010-06-09 00:52:24 +08:00
|
|
|
s->EOL();
|
2016-09-07 04:57:50 +08:00
|
|
|
s->Indent("compile unit = ");
|
|
|
|
static_cast<FileSpec *>(sc.comp_unit)->GetFilename().Dump(s);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (sc.function != nullptr) {
|
|
|
|
s->EOL();
|
|
|
|
s->Indent("function = ");
|
|
|
|
s->PutCString(sc.function->GetName().AsCString("<unknown>"));
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (sc.line_entry.line > 0) {
|
|
|
|
s->EOL();
|
|
|
|
s->Indent("location = ");
|
|
|
|
sc.line_entry.DumpStopContext(s, true);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// If we don't have a comp unit, see if we have a symbol we can print.
|
|
|
|
if (sc.symbol) {
|
|
|
|
s->EOL();
|
|
|
|
if (IsReExported())
|
|
|
|
s->Indent("re-exported target = ");
|
|
|
|
else
|
|
|
|
s->Indent("symbol = ");
|
|
|
|
s->PutCString(sc.symbol->GetName().AsCString("<unknown>"));
|
2010-06-18 09:00:58 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (level == lldb::eDescriptionLevelVerbose) {
|
|
|
|
s->EOL();
|
|
|
|
s->Indent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_address.IsSectionOffset() &&
|
|
|
|
(level == eDescriptionLevelFull || level == eDescriptionLevelInitial))
|
|
|
|
s->Printf(", ");
|
|
|
|
s->Printf("address = ");
|
|
|
|
|
|
|
|
ExecutionContextScope *exe_scope = nullptr;
|
|
|
|
Target *target = &m_owner.GetTarget();
|
|
|
|
if (target)
|
|
|
|
exe_scope = target->GetProcessSP().get();
|
|
|
|
if (exe_scope == nullptr)
|
|
|
|
exe_scope = target;
|
|
|
|
|
|
|
|
if (level == eDescriptionLevelInitial)
|
|
|
|
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleFileAddress);
|
|
|
|
else
|
|
|
|
m_address.Dump(s, exe_scope, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleModuleWithFileAddress);
|
|
|
|
|
|
|
|
if (IsIndirect() && m_bp_site_sp) {
|
|
|
|
Address resolved_address;
|
|
|
|
resolved_address.SetLoadAddress(m_bp_site_sp->GetLoadAddress(), target);
|
|
|
|
Symbol *resolved_symbol = resolved_address.CalculateSymbolContextSymbol();
|
|
|
|
if (resolved_symbol) {
|
|
|
|
if (level == eDescriptionLevelFull || level == eDescriptionLevelInitial)
|
|
|
|
s->Printf(", ");
|
|
|
|
else if (level == lldb::eDescriptionLevelVerbose) {
|
|
|
|
s->EOL();
|
|
|
|
s->Indent();
|
|
|
|
}
|
|
|
|
s->Printf("indirect target = %s",
|
|
|
|
resolved_symbol->GetName().GetCString());
|
2012-02-08 13:23:15 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-09-11 05:40:47 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (level == lldb::eDescriptionLevelVerbose) {
|
|
|
|
s->EOL();
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("resolved = %s\n", IsResolved() ? "true" : "false");
|
|
|
|
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("hit count = %-4u\n", GetHitCount());
|
|
|
|
|
|
|
|
if (m_options_ap.get()) {
|
|
|
|
s->Indent();
|
|
|
|
m_options_ap->GetDescription(s, level);
|
|
|
|
s->EOL();
|
|
|
|
}
|
|
|
|
s->IndentLess();
|
|
|
|
} else if (level != eDescriptionLevelInitial) {
|
|
|
|
s->Printf(", %sresolved, hit count = %u ", (IsResolved() ? "" : "un"),
|
|
|
|
GetHitCount());
|
|
|
|
if (m_options_ap.get()) {
|
|
|
|
m_options_ap->GetDescription(s, level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointLocation::Dump(Stream *s) const {
|
|
|
|
if (s == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->Printf(
|
|
|
|
"BreakpointLocation %u: tid = %4.4" PRIx64 " load addr = 0x%8.8" PRIx64
|
|
|
|
" state = %s type = %s breakpoint "
|
|
|
|
"hw_index = %i hit_count = %-4u ignore_count = %-4u",
|
|
|
|
GetID(), GetOptionsNoCreate()->GetThreadSpecNoCreate()->GetTID(),
|
|
|
|
(uint64_t)m_address.GetOpcodeLoadAddress(&m_owner.GetTarget()),
|
|
|
|
(m_options_ap.get() ? m_options_ap->IsEnabled() : m_owner.IsEnabled())
|
|
|
|
? "enabled "
|
|
|
|
: "disabled",
|
|
|
|
IsHardware() ? "hardware" : "software", GetHardwareIndex(), GetHitCount(),
|
|
|
|
GetOptionsNoCreate()->GetIgnoreCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointLocation::SendBreakpointLocationChangedEvent(
|
|
|
|
lldb::BreakpointEventType eventKind) {
|
|
|
|
if (!m_being_created && !m_owner.IsInternal() &&
|
|
|
|
m_owner.GetTarget().EventTypeHasListeners(
|
|
|
|
Target::eBroadcastBitBreakpointChanged)) {
|
|
|
|
Breakpoint::BreakpointEventData *data = new Breakpoint::BreakpointEventData(
|
|
|
|
eventKind, m_owner.shared_from_this());
|
|
|
|
data->GetBreakpointLocationCollection().Add(shared_from_this());
|
|
|
|
m_owner.GetTarget().BroadcastEvent(Target::eBroadcastBitBreakpointChanged,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BreakpointLocation::SwapLocation(BreakpointLocationSP swap_from) {
|
|
|
|
m_address = swap_from->m_address;
|
|
|
|
m_should_resolve_indirect_functions =
|
|
|
|
swap_from->m_should_resolve_indirect_functions;
|
|
|
|
m_is_reexported = swap_from->m_is_reexported;
|
|
|
|
m_is_indirect = swap_from->m_is_indirect;
|
|
|
|
m_user_expression_sp.reset();
|
2014-09-11 05:40:47 +08:00
|
|
|
}
|