[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- ThreadPlanStepRange.cpp -------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-12-15 09:33:19 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStepRange.h"
|
2013-03-13 09:56:41 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
|
|
|
#include "lldb/Breakpoint/BreakpointSite.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Core/Disassembler.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
|
|
|
#include "lldb/Symbol/Symbol.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
|
|
|
#include "lldb/Target/StopInfo.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
2012-03-09 12:10:47 +08:00
|
|
|
#include "lldb/Target/ThreadPlanRunToAddress.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/Stream.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// ThreadPlanStepRange: Step through a stack range, either stepping over or
|
|
|
|
// into based on the value of \a type.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2011-02-08 12:27:50 +08:00
|
|
|
ThreadPlanStepRange::ThreadPlanStepRange(ThreadPlanKind kind, const char *name,
|
|
|
|
Thread &thread,
|
|
|
|
const AddressRange &range,
|
|
|
|
const SymbolContext &addr_context,
|
2014-09-30 07:17:18 +08:00
|
|
|
lldb::RunMode stop_others,
|
|
|
|
bool given_ranges_only)
|
2010-07-10 10:23:31 +08:00
|
|
|
: ThreadPlan(kind, name, thread, eVoteNoOpinion, eVoteNoOpinion),
|
2010-06-09 00:52:24 +08:00
|
|
|
m_addr_context(addr_context), m_address_ranges(),
|
|
|
|
m_stop_others(stop_others), m_stack_id(), m_parent_stack_id(),
|
2013-03-13 09:56:41 +08:00
|
|
|
m_no_more_plans(false), m_first_run_event(true), m_use_fast_step(false),
|
2014-09-30 07:17:18 +08:00
|
|
|
m_given_ranges_only(given_ranges_only) {
|
2013-08-02 05:50:20 +08:00
|
|
|
m_use_fast_step = GetTarget().GetUseFastStepping();
|
2011-10-15 08:24:48 +08:00
|
|
|
AddRange(range);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
|
2014-08-12 07:57:43 +08:00
|
|
|
StackFrameSP parent_stack = m_thread.GetStackFrameAtIndex(1);
|
|
|
|
if (parent_stack)
|
|
|
|
m_parent_stack_id = parent_stack->GetStackID();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanStepRange::~ThreadPlanStepRange() { ClearNextBranchBreakpoint(); }
|
2012-03-09 12:10:47 +08:00
|
|
|
|
|
|
|
void ThreadPlanStepRange::DidPush() {
|
|
|
|
// See if we can find a "next range" breakpoint:
|
|
|
|
SetNextBranchBreakpoint();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
bool ThreadPlanStepRange::ValidatePlan(Stream *error) {
|
|
|
|
if (m_could_not_resolve_hw_bp) {
|
|
|
|
if (error)
|
|
|
|
error->PutCString(
|
|
|
|
"Could not create hardware breakpoint for thread plan.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
Vote ThreadPlanStepRange::ShouldReportStop(Event *event_ptr) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2010-09-04 01:10:42 +08:00
|
|
|
|
|
|
|
const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo;
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ThreadPlanStepRange::ShouldReportStop() returning vote %i\n",
|
|
|
|
vote);
|
2010-09-04 01:10:42 +08:00
|
|
|
return vote;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2011-10-15 08:24:48 +08:00
|
|
|
void ThreadPlanStepRange::AddRange(const AddressRange &new_range) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// For now I'm just adding the ranges. At some point we may want to condense
|
|
|
|
// the ranges if they overlap, though I don't think it is likely to be very
|
|
|
|
// important.
|
2011-10-15 08:24:48 +08:00
|
|
|
m_address_ranges.push_back(new_range);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-07-31 10:19:15 +08:00
|
|
|
// Fill the slot for this address range with an empty DisassemblerSP in the
|
2018-05-01 00:49:04 +08:00
|
|
|
// instruction ranges. I want the indices to match, but I don't want to do
|
|
|
|
// the work to disassemble this range if I don't step into it.
|
2012-03-09 12:10:47 +08:00
|
|
|
m_instruction_ranges.push_back(DisassemblerSP());
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadPlanStepRange::DumpRanges(Stream *s) {
|
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
if (num_ranges == 1) {
|
2012-02-21 08:09:25 +08:00
|
|
|
m_address_ranges[0].Dump(s, m_thread.CalculateTarget().get(),
|
|
|
|
Address::DumpStyleLoadAddress);
|
2011-10-15 08:24:48 +08:00
|
|
|
} else {
|
|
|
|
for (size_t i = 0; i < num_ranges; i++) {
|
2015-07-16 22:21:49 +08:00
|
|
|
s->Printf(" %" PRIu64 ": ", uint64_t(i));
|
2012-02-21 08:09:25 +08:00
|
|
|
m_address_ranges[i].Dump(s, m_thread.CalculateTarget().get(),
|
|
|
|
Address::DumpStyleLoadAddress);
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-10-15 08:24:48 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool ThreadPlanStepRange::InRange() {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2010-06-09 00:52:24 +08:00
|
|
|
bool ret_value = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-10-15 08:24:48 +08:00
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
for (size_t i = 0; i < num_ranges; i++) {
|
2012-02-21 08:09:25 +08:00
|
|
|
ret_value = m_address_ranges[i].ContainsLoadAddress(
|
|
|
|
pc_load_addr, m_thread.CalculateTarget().get());
|
2011-10-15 08:24:48 +08:00
|
|
|
if (ret_value)
|
|
|
|
break;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
if (!ret_value && !m_given_ranges_only) {
|
2010-06-09 00:52:24 +08:00
|
|
|
// See if we've just stepped to another part of the same line number...
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
SymbolContext new_context(
|
|
|
|
frame->GetSymbolContext(eSymbolContextEverything));
|
|
|
|
if (m_addr_context.line_entry.IsValid() &&
|
|
|
|
new_context.line_entry.IsValid()) {
|
2016-05-12 06:46:53 +08:00
|
|
|
if (m_addr_context.line_entry.original_file ==
|
|
|
|
new_context.line_entry.original_file) {
|
2011-09-24 05:08:11 +08:00
|
|
|
if (m_addr_context.line_entry.line == new_context.line_entry.line) {
|
|
|
|
m_addr_context = new_context;
|
2019-05-07 04:01:21 +08:00
|
|
|
const bool include_inlined_functions =
|
|
|
|
GetKind() == eKindStepOverRange;
|
|
|
|
AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange(
|
|
|
|
include_inlined_functions));
|
2011-09-24 05:08:11 +08:00
|
|
|
ret_value = true;
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
2012-09-11 07:42:44 +08:00
|
|
|
m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
|
|
|
|
true, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(
|
|
|
|
log,
|
2011-09-24 05:08:11 +08:00
|
|
|
"Step range plan stepped to another range of same line: %s",
|
|
|
|
s.GetData());
|
|
|
|
}
|
2013-09-27 09:15:46 +08:00
|
|
|
} else if (new_context.line_entry.line == 0) {
|
|
|
|
new_context.line_entry.line = m_addr_context.line_entry.line;
|
|
|
|
m_addr_context = new_context;
|
2019-05-07 04:01:21 +08:00
|
|
|
const bool include_inlined_functions =
|
|
|
|
GetKind() == eKindStepOverRange;
|
|
|
|
AddRange(m_addr_context.line_entry.GetSameLineContiguousAddressRange(
|
|
|
|
include_inlined_functions));
|
2013-09-27 09:15:46 +08:00
|
|
|
ret_value = true;
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
|
|
|
m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
|
|
|
|
true, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Step range plan stepped to a range at linenumber 0 "
|
|
|
|
"stepping through that range: %s",
|
|
|
|
s.GetData());
|
2013-09-27 09:15:46 +08:00
|
|
|
}
|
2012-02-21 08:09:25 +08:00
|
|
|
} else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(
|
|
|
|
m_thread.CalculateTarget().get()) != pc_load_addr) {
|
2011-09-24 05:08:11 +08:00
|
|
|
// Another thing that sometimes happens here is that we step out of
|
2018-05-01 00:49:04 +08:00
|
|
|
// one line into the MIDDLE of another line. So far I mostly see
|
|
|
|
// this due to bugs in the debug information. But we probably don't
|
|
|
|
// want to be in the middle of a line range, so in that case reset
|
|
|
|
// the stepping range to the line we've stepped into the middle of
|
|
|
|
// and continue.
|
2011-09-24 05:08:11 +08:00
|
|
|
m_addr_context = new_context;
|
2011-10-15 08:24:48 +08:00
|
|
|
m_address_ranges.clear();
|
|
|
|
AddRange(m_addr_context.line_entry.range);
|
2011-09-24 05:08:11 +08:00
|
|
|
ret_value = true;
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
2012-09-11 07:42:44 +08:00
|
|
|
m_addr_context.line_entry.Dump(&s, m_thread.CalculateTarget().get(),
|
|
|
|
true, Address::DumpStyleLoadAddress,
|
|
|
|
Address::DumpStyleLoadAddress, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Step range plan stepped to the middle of new "
|
|
|
|
"line(%d): %s, continuing to clear this line.",
|
|
|
|
new_context.line_entry.line, s.GetData());
|
2010-06-09 00:52:24 +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
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (!ret_value && log)
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Step range plan out of range to 0x%" PRIx64, pc_load_addr);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadPlanStepRange::InSymbol() {
|
|
|
|
lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC();
|
2015-12-15 09:33:19 +08:00
|
|
|
if (m_addr_context.function != nullptr) {
|
2012-02-21 08:09:25 +08:00
|
|
|
return m_addr_context.function->GetAddressRange().ContainsLoadAddress(
|
|
|
|
cur_pc, m_thread.CalculateTarget().get());
|
2015-06-26 05:46:34 +08:00
|
|
|
} else if (m_addr_context.symbol && m_addr_context.symbol->ValueIsAddress()) {
|
|
|
|
AddressRange range(m_addr_context.symbol->GetAddressRef(),
|
|
|
|
m_addr_context.symbol->GetByteSize());
|
2012-03-08 05:03:09 +08:00
|
|
|
return range.ContainsLoadAddress(cur_pc, m_thread.CalculateTarget().get());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: This should also handle inlining if we aren't going to do inlining in
|
|
|
|
// the
|
|
|
|
// main stack.
|
|
|
|
//
|
|
|
|
// Ideally we should remember the whole stack frame list, and then compare that
|
|
|
|
// to the current list.
|
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
lldb::FrameComparison ThreadPlanStepRange::CompareCurrentFrameToStartFrame() {
|
|
|
|
FrameComparison frame_order;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-01 08:50:50 +08:00
|
|
|
if (cur_frame_id == m_stack_id) {
|
|
|
|
frame_order = eFrameCompareEqual;
|
|
|
|
} else if (cur_frame_id < m_stack_id) {
|
|
|
|
frame_order = eFrameCompareYounger;
|
2010-06-09 00:52:24 +08:00
|
|
|
} else {
|
2014-08-12 07:57:43 +08:00
|
|
|
StackFrameSP cur_parent_frame = m_thread.GetStackFrameAtIndex(1);
|
|
|
|
StackID cur_parent_id;
|
|
|
|
if (cur_parent_frame)
|
|
|
|
cur_parent_id = cur_parent_frame->GetStackID();
|
2014-08-06 09:49:59 +08:00
|
|
|
if (m_parent_stack_id.IsValid() && cur_parent_id.IsValid() &&
|
|
|
|
m_parent_stack_id == cur_parent_id)
|
|
|
|
frame_order = eFrameCompareSameParent;
|
2010-06-09 00:52:24 +08:00
|
|
|
else
|
2014-08-06 09:49:59 +08:00
|
|
|
frame_order = eFrameCompareOlder;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-03-01 08:50:50 +08:00
|
|
|
return frame_order;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadPlanStepRange::StopOthers() {
|
2019-12-17 09:38:13 +08:00
|
|
|
switch (m_stop_others) {
|
|
|
|
case lldb::eOnlyThisThread:
|
|
|
|
return true;
|
|
|
|
case lldb::eOnlyDuringStepping:
|
|
|
|
// If there is a call in the range of the next branch breakpoint,
|
|
|
|
// then we should always run all threads, since a call can execute
|
|
|
|
// arbitrary code which might for instance take a lock that's held
|
|
|
|
// by another thread.
|
|
|
|
return !m_found_calls;
|
|
|
|
case lldb::eAllThreads:
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-20 22:17:16 +08:00
|
|
|
llvm_unreachable("Unhandled run mode!");
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
InstructionList *ThreadPlanStepRange::GetInstructionsForAddress(
|
|
|
|
lldb::addr_t addr, size_t &range_index, size_t &insn_offset) {
|
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
for (size_t i = 0; i < num_ranges; i++) {
|
|
|
|
if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget())) {
|
|
|
|
// Some joker added a zero size range to the stepping range...
|
|
|
|
if (m_address_ranges[i].GetByteSize() == 0)
|
2015-12-15 09:33:19 +08:00
|
|
|
return nullptr;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
if (!m_instruction_ranges[i]) {
|
|
|
|
// Disassemble the address range given:
|
2015-12-15 09:33:19 +08:00
|
|
|
const char *plugin_name = nullptr;
|
|
|
|
const char *flavor = nullptr;
|
2013-09-13 07:23:35 +08:00
|
|
|
const bool prefer_file_cache = true;
|
2012-03-09 12:10:47 +08:00
|
|
|
m_instruction_ranges[i] = Disassembler::DisassembleRange(
|
2020-03-05 20:03:26 +08:00
|
|
|
GetTarget().GetArchitecture(), plugin_name, flavor, GetTarget(),
|
2013-09-13 07:23:35 +08:00
|
|
|
m_address_ranges[i], prefer_file_cache);
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
if (!m_instruction_ranges[i])
|
2015-12-15 09:33:19 +08:00
|
|
|
return nullptr;
|
2012-03-09 12:10:47 +08:00
|
|
|
else {
|
|
|
|
// Find where we are in the instruction list as well. If we aren't at
|
2018-05-01 00:49:04 +08:00
|
|
|
// an instruction, return nullptr. In this case, we're probably lost,
|
|
|
|
// and shouldn't try to do anything fancy.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
insn_offset =
|
|
|
|
m_instruction_ranges[i]
|
|
|
|
->GetInstructionList()
|
|
|
|
.GetIndexOfInstructionAtLoadAddress(addr, GetTarget());
|
|
|
|
if (insn_offset == UINT32_MAX)
|
2015-12-15 09:33:19 +08:00
|
|
|
return nullptr;
|
2012-03-09 12:10:47 +08:00
|
|
|
else {
|
|
|
|
range_index = i;
|
|
|
|
return &m_instruction_ranges[i]->GetInstructionList();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-12-15 09:33:19 +08:00
|
|
|
return nullptr;
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadPlanStepRange::ClearNextBranchBreakpoint() {
|
|
|
|
if (m_next_branch_bp_sp) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Removing next branch breakpoint: %d.",
|
|
|
|
m_next_branch_bp_sp->GetID());
|
2012-03-09 12:10:47 +08:00
|
|
|
GetTarget().RemoveBreakpointByID(m_next_branch_bp_sp->GetID());
|
|
|
|
m_next_branch_bp_sp.reset();
|
2018-11-15 09:18:15 +08:00
|
|
|
m_could_not_resolve_hw_bp = false;
|
2019-12-17 09:38:13 +08:00
|
|
|
m_found_calls = false;
|
2012-03-09 12:10:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadPlanStepRange::SetNextBranchBreakpoint() {
|
2013-03-13 09:56:41 +08:00
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
return true;
|
|
|
|
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2012-03-09 12:10:47 +08:00
|
|
|
// Stepping through ranges using breakpoints doesn't work yet, but with this
|
2018-05-01 00:49:04 +08:00
|
|
|
// off we fall back to instruction single stepping.
|
2013-01-26 10:19:28 +08:00
|
|
|
if (!m_use_fast_step)
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
|
|
|
|
2019-12-17 09:38:13 +08:00
|
|
|
// clear the m_found_calls, we'll rediscover it for this range.
|
|
|
|
m_found_calls = false;
|
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC();
|
|
|
|
// Find the current address in our address ranges, and fetch the disassembly
|
|
|
|
// if we haven't already:
|
|
|
|
size_t pc_index;
|
|
|
|
size_t range_index;
|
|
|
|
InstructionList *instructions =
|
|
|
|
GetInstructionsForAddress(cur_addr, range_index, pc_index);
|
|
|
|
if (instructions == nullptr)
|
|
|
|
return false;
|
|
|
|
else {
|
|
|
|
Target &target = GetThread().GetProcess()->GetTarget();
|
2019-05-10 04:39:34 +08:00
|
|
|
const bool ignore_calls = GetKind() == eKindStepOverRange;
|
|
|
|
uint32_t branch_index =
|
|
|
|
instructions->GetIndexOfNextBranchInstruction(pc_index, target,
|
2019-12-17 09:38:13 +08:00
|
|
|
ignore_calls,
|
|
|
|
&m_found_calls);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-13 09:56:41 +08:00
|
|
|
Address run_to_address;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-03-13 09:56:41 +08:00
|
|
|
// If we didn't find a branch, run to the end of the range.
|
|
|
|
if (branch_index == UINT32_MAX) {
|
|
|
|
uint32_t last_index = instructions->GetSize() - 1;
|
2015-11-13 11:37:48 +08:00
|
|
|
if (last_index - pc_index > 1) {
|
|
|
|
InstructionSP last_inst =
|
2013-03-13 09:56:41 +08:00
|
|
|
instructions->GetInstructionAtIndex(last_index);
|
|
|
|
size_t last_inst_size = last_inst->GetOpcode().GetByteSize();
|
2015-11-13 11:37:48 +08:00
|
|
|
run_to_address = last_inst->GetAddress();
|
|
|
|
run_to_address.Slide(last_inst_size);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-03-13 09:56:41 +08:00
|
|
|
} else if (branch_index - pc_index > 1) {
|
|
|
|
run_to_address =
|
2015-11-13 11:37:48 +08:00
|
|
|
instructions->GetInstructionAtIndex(branch_index)->GetAddress();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-11-13 11:37:48 +08:00
|
|
|
if (run_to_address.IsValid()) {
|
2013-03-13 09:56:41 +08:00
|
|
|
const bool is_internal = true;
|
|
|
|
m_next_branch_bp_sp =
|
|
|
|
GetTarget().CreateBreakpoint(run_to_address, is_internal, false);
|
|
|
|
if (m_next_branch_bp_sp) {
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
if (m_next_branch_bp_sp->IsHardware() &&
|
|
|
|
!m_next_branch_bp_sp->HasResolvedLocations())
|
|
|
|
m_could_not_resolve_hw_bp = true;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (log) {
|
2013-03-13 09:56:41 +08:00
|
|
|
lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID;
|
|
|
|
BreakpointLocationSP bp_loc =
|
|
|
|
m_next_branch_bp_sp->GetLocationAtIndex(0);
|
|
|
|
if (bp_loc) {
|
|
|
|
BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite();
|
|
|
|
if (bp_site) {
|
|
|
|
bp_site_id = bp_site->GetID();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ThreadPlanStepRange::SetNextBranchBreakpoint - Setting "
|
|
|
|
"breakpoint %d (site %d) to run to address 0x%" PRIx64,
|
|
|
|
m_next_branch_bp_sp->GetID(), bp_site_id,
|
|
|
|
run_to_address.GetLoadAddress(
|
|
|
|
&m_thread.GetProcess()->GetTarget()));
|
2013-03-13 09:56:41 +08:00
|
|
|
}
|
2018-11-15 09:18:15 +08:00
|
|
|
|
2014-03-03 23:39:47 +08:00
|
|
|
m_next_branch_bp_sp->SetThreadID(m_thread.GetID());
|
|
|
|
m_next_branch_bp_sp->SetBreakpointKind("next-branch-location");
|
2018-11-15 09:18:15 +08:00
|
|
|
|
2013-03-13 09:56:41 +08:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool ThreadPlanStepRange::NextRangeBreakpointExplainsStop(
|
|
|
|
lldb::StopInfoSP stop_info_sp) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2013-01-26 10:19:28 +08:00
|
|
|
if (!m_next_branch_bp_sp)
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-03-09 12:10:47 +08:00
|
|
|
break_id_t bp_site_id = stop_info_sp->GetValue();
|
2013-03-13 09:56:41 +08:00
|
|
|
BreakpointSiteSP bp_site_sp =
|
2012-03-09 12:10:47 +08:00
|
|
|
m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id);
|
2013-03-13 09:56:41 +08:00
|
|
|
if (!bp_site_sp)
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
else if (!bp_site_sp->IsBreakpointAtThisSite(m_next_branch_bp_sp->GetID()))
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
else {
|
2010-06-09 00:52:24 +08:00
|
|
|
// If we've hit the next branch breakpoint, then clear it.
|
2013-03-13 09:56:41 +08:00
|
|
|
size_t num_owners = bp_site_sp->GetNumberOfOwners();
|
|
|
|
bool explains_stop = true;
|
|
|
|
// If all the owners are internal, then we are probably just stepping over
|
2018-05-01 00:49:04 +08:00
|
|
|
// this range from multiple threads, or multiple frames, so we want to
|
|
|
|
// continue. If one is not internal, then we should not explain the stop,
|
2013-03-13 09:56:41 +08:00
|
|
|
// and let the user breakpoint handle the stop.
|
|
|
|
for (size_t i = 0; i < num_owners; i++) {
|
2013-10-12 03:48:25 +08:00
|
|
|
if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) {
|
2013-03-13 09:56:41 +08:00
|
|
|
explains_stop = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit "
|
|
|
|
"next range breakpoint which has %" PRIu64
|
|
|
|
" owners - explains stop: %u.",
|
|
|
|
(uint64_t)num_owners, explains_stop);
|
2013-03-13 09:56:41 +08:00
|
|
|
ClearNextBranchBreakpoint();
|
2010-06-09 00:52:24 +08:00
|
|
|
return explains_stop;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadPlanStepRange::WillStop() { return true; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-11-12 03:26:09 +08:00
|
|
|
StateType ThreadPlanStepRange::GetPlanRunState() {
|
2012-03-09 12:10:47 +08:00
|
|
|
if (m_next_branch_bp_sp)
|
|
|
|
return eStateRunning;
|
|
|
|
else
|
|
|
|
return eStateStepping;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadPlanStepRange::MischiefManaged() {
|
2012-09-11 07:42:44 +08:00
|
|
|
// If we have pushed some plans between ShouldStop & MischiefManaged, then
|
|
|
|
// we're not done...
|
|
|
|
// I do this check first because we might have stepped somewhere that will
|
|
|
|
// fool InRange into
|
|
|
|
// thinking it needs to step past the end of that line. This happens, for
|
2018-05-01 00:49:04 +08:00
|
|
|
// instance, when stepping over inlined code that is in the middle of the
|
|
|
|
// current line.
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
if (!m_no_more_plans)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool done = true;
|
|
|
|
if (!IsPlanComplete()) {
|
2012-05-04 05:19:36 +08:00
|
|
|
if (InRange()) {
|
2010-06-09 00:52:24 +08:00
|
|
|
done = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-05-04 05:19:36 +08:00
|
|
|
FrameComparison frame_order = CompareCurrentFrameToStartFrame();
|
2015-12-15 09:33:19 +08:00
|
|
|
done = (frame_order != eFrameCompareOlder) ? m_no_more_plans : true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (done) {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Completed step through range plan.");
|
2013-03-13 09:56:41 +08:00
|
|
|
ClearNextBranchBreakpoint();
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadPlan::MischiefManaged();
|
2013-03-13 09:56:41 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-03-09 12:10:47 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2012-05-04 05:19:36 +08:00
|
|
|
|
|
|
|
bool ThreadPlanStepRange::IsPlanStale() {
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2012-05-04 05:19:36 +08:00
|
|
|
FrameComparison frame_order = CompareCurrentFrameToStartFrame();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-05-04 05:19:36 +08:00
|
|
|
if (frame_order == eFrameCompareOlder) {
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "ThreadPlanStepRange::IsPlanStale returning true, we've "
|
|
|
|
"stepped out.");
|
2012-05-04 05:19:36 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return true;
|
2012-05-04 05:19:36 +08:00
|
|
|
} else if (frame_order == eFrameCompareEqual && InSymbol()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we are not in a place we should step through, we've gotten stale. One
|
|
|
|
// tricky bit here is that some stubs don't push a frame, so we should.
|
2012-05-04 05:19:36 +08:00
|
|
|
// check that we are in the same symbol.
|
|
|
|
if (!InRange()) {
|
2017-02-15 19:42:47 +08:00
|
|
|
// Set plan Complete when we reach next instruction just after the range
|
|
|
|
lldb::addr_t addr = m_thread.GetRegisterContext()->GetPC() - 1;
|
|
|
|
size_t num_ranges = m_address_ranges.size();
|
|
|
|
for (size_t i = 0; i < num_ranges; i++) {
|
|
|
|
bool in_range = m_address_ranges[i].ContainsLoadAddress(
|
|
|
|
addr, m_thread.CalculateTarget().get());
|
|
|
|
if (in_range) {
|
|
|
|
SetPlanComplete();
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 05:19:36 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-05-04 05:19:36 +08:00
|
|
|
return false;
|
|
|
|
}
|