2010-06-09 00:52:24 +08:00
|
|
|
//===-- Thread.cpp ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/Thread.h"
|
|
|
|
#include "Plugins/Process/Utility/UnwindLLDB.h"
|
|
|
|
#include "Plugins/Process/Utility/UnwindMacOSXFrameBackchain.h"
|
2010-06-16 10:00:15 +08:00
|
|
|
#include "lldb/Breakpoint/BreakpointLocation.h"
|
2010-10-04 09:05:56 +08:00
|
|
|
#include "lldb/Core/Debugger.h"
|
2015-02-05 06:00:53 +08:00
|
|
|
#include "lldb/Core/FormatEntity.h"
|
2015-08-07 05:54:29 +08:00
|
|
|
#include "lldb/Core/Module.h"
|
2015-09-03 09:40:51 +08:00
|
|
|
#include "lldb/Core/ValueObject.h"
|
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process,
lldb_private::Thread, lldb_private::StackFrameList and the
lldb_private::StackFrame classes. We had some command line
commands that had duplicate versions of the process status
output ("thread list" and "process status" for example).
Removed the "file" command and placed it where it should
have been: "target create". Made an alias for "file" to
"target create" so we stay compatible with GDB commands.
We can now have multple usable targets in lldb at the
same time. This is nice for comparing two runs of a program
or debugging more than one binary at the same time. The
new command is "target select <target-idx>" and also to see
a list of the current targets you can use the new "target list"
command. The flow in a debug session can be:
(lldb) target create /path/to/exe/a.out
(lldb) breakpoint set --name main
(lldb) run
... hit breakpoint
(lldb) target create /bin/ls
(lldb) run /tmp
Process 36001 exited with status = 0 (0x00000000)
(lldb) target list
Current targets:
target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
* target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) target select 0
Current targets:
* target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped )
target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited )
(lldb) bt
* thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1
frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16
frame #1: 0x0000000100000b64 a.out`start + 52
Above we created a target for "a.out" and ran and hit a
breakpoint at "main". Then we created a new target for /bin/ls
and ran it. Then we listed the targest and selected our original
"a.out" program, so we showed two concurent debug sessions
going on at the same time.
llvm-svn: 129695
2011-04-18 16:33:37 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-01-24 05:52:47 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueFileSpecList.h"
|
2015-03-04 09:58:01 +08:00
|
|
|
#include "lldb/Interpreter/OptionValueProperties.h"
|
|
|
|
#include "lldb/Interpreter/Property.h"
|
2012-09-27 09:15:29 +08:00
|
|
|
#include "lldb/Symbol/Function.h"
|
2015-03-04 03:23:09 +08:00
|
|
|
#include "lldb/Target/ABI.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/DynamicLoader.h"
|
|
|
|
#include "lldb/Target/ExecutionContext.h"
|
2019-06-02 14:03:05 +08:00
|
|
|
#include "lldb/Target/LanguageRuntime.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/Process.h"
|
|
|
|
#include "lldb/Target/RegisterContext.h"
|
2018-11-29 06:01:52 +08:00
|
|
|
#include "lldb/Target/StackFrameRecognizer.h"
|
2010-08-04 09:40:35 +08:00
|
|
|
#include "lldb/Target/StopInfo.h"
|
2014-05-14 06:02:48 +08:00
|
|
|
#include "lldb/Target/SystemRuntime.h"
|
2010-07-24 00:45:51 +08:00
|
|
|
#include "lldb/Target/Target.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadPlan.h"
|
|
|
|
#include "lldb/Target/ThreadPlanBase.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/ThreadPlanCallFunction.h"
|
2014-09-30 07:17:18 +08:00
|
|
|
#include "lldb/Target/ThreadPlanPython.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/ThreadPlanRunToAddress.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepInRange.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStepInstruction.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOut.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOverRange.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStepThrough.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStepUntil.h"
|
2010-06-16 10:00:15 +08:00
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
2010-08-12 10:14:28 +08:00
|
|
|
#include "lldb/Target/Unwind.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/RegularExpression.h"
|
2018-08-07 19:07:21 +08:00
|
|
|
#include "lldb/Utility/State.h"
|
2017-02-03 05:39:50 +08:00
|
|
|
#include "lldb/Utility/Stream.h"
|
|
|
|
#include "lldb/Utility/StreamString.h"
|
2017-05-29 16:25:46 +08:00
|
|
|
#include "lldb/lldb-enumerations.h"
|
2011-08-22 10:49:39 +08:00
|
|
|
|
2019-02-12 07:13:08 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const ThreadPropertiesSP &Thread::GetGlobalProperties() {
|
|
|
|
// NOTE: intentional leak so we don't crash if global destructor chain gets
|
|
|
|
// called as other threads still use the result of this function
|
2016-10-19 23:12:45 +08:00
|
|
|
static ThreadPropertiesSP *g_settings_sp_ptr =
|
|
|
|
new ThreadPropertiesSP(new ThreadProperties(true));
|
2016-09-07 04:57:50 +08:00
|
|
|
return *g_settings_sp_ptr;
|
|
|
|
}
|
|
|
|
|
2018-09-27 02:50:19 +08:00
|
|
|
static constexpr PropertyDefinition g_properties[] = {
|
2016-09-07 04:57:50 +08:00
|
|
|
{"step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, nullptr,
|
2018-09-27 02:50:19 +08:00
|
|
|
{},
|
2016-09-07 04:57:50 +08:00
|
|
|
"If true, step-in will not stop in functions with no debug information."},
|
|
|
|
{"step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, nullptr,
|
2018-09-27 02:50:19 +08:00
|
|
|
{}, "If true, when step-in/step-out/step-over leave the current frame, "
|
|
|
|
"they will continue to step out till they come to a function with "
|
|
|
|
"debug information. Passing a frame argument to step-out will "
|
|
|
|
"override this option."},
|
|
|
|
{"step-avoid-regexp", OptionValue::eTypeRegex, true, 0, "^std::", {},
|
2016-09-07 04:57:50 +08:00
|
|
|
"A regular expression defining functions step-in won't stop in."},
|
|
|
|
{"step-avoid-libraries", OptionValue::eTypeFileSpecList, true, 0, nullptr,
|
2018-09-27 02:50:19 +08:00
|
|
|
{}, "A list of libraries that source stepping won't stop in."},
|
|
|
|
{"trace-thread", OptionValue::eTypeBoolean, false, false, nullptr, {},
|
2016-09-07 04:57:50 +08:00
|
|
|
"If true, this thread will single-step and log execution."},
|
2018-09-26 05:01:54 +08:00
|
|
|
{"max-backtrace-depth", OptionValue::eTypeUInt64, false, 300000, nullptr,
|
2018-09-27 15:11:58 +08:00
|
|
|
{}, "Maximum number of frames to backtrace."}};
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
enum {
|
2016-09-07 04:57:50 +08:00
|
|
|
ePropertyStepInAvoidsNoDebug,
|
|
|
|
ePropertyStepOutAvoidsNoDebug,
|
|
|
|
ePropertyStepAvoidRegex,
|
|
|
|
ePropertyStepAvoidLibraries,
|
2018-09-26 05:01:54 +08:00
|
|
|
ePropertyEnableThreadTrace,
|
|
|
|
ePropertyMaxBacktraceDepth
|
2012-08-23 01:17:09 +08:00
|
|
|
};
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
class ThreadOptionValueProperties : public OptionValueProperties {
|
2012-08-23 01:17:09 +08:00
|
|
|
public:
|
2019-03-07 05:22:25 +08:00
|
|
|
ThreadOptionValueProperties(ConstString name)
|
2016-09-07 04:57:50 +08:00
|
|
|
: OptionValueProperties(name) {}
|
|
|
|
|
|
|
|
// This constructor is used when creating ThreadOptionValueProperties when it
|
|
|
|
// is part of a new lldb_private::Thread instance. It will copy all current
|
|
|
|
// global property values as needed
|
|
|
|
ThreadOptionValueProperties(ThreadProperties *global_properties)
|
|
|
|
: OptionValueProperties(*global_properties->GetValueProperties()) {}
|
|
|
|
|
|
|
|
const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
|
|
|
|
bool will_modify,
|
|
|
|
uint32_t idx) const override {
|
|
|
|
// When getting the value for a key from the thread options, we will always
|
2018-05-01 00:49:04 +08:00
|
|
|
// try and grab the setting from the current thread if there is one. Else
|
|
|
|
// we just use the one from this instance.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (exe_ctx) {
|
|
|
|
Thread *thread = exe_ctx->GetThreadPtr();
|
|
|
|
if (thread) {
|
|
|
|
ThreadOptionValueProperties *instance_properties =
|
|
|
|
static_cast<ThreadOptionValueProperties *>(
|
|
|
|
thread->GetValueProperties().get());
|
|
|
|
if (this != instance_properties)
|
|
|
|
return instance_properties->ProtectedGetPropertyAtIndex(idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ProtectedGetPropertyAtIndex(idx);
|
|
|
|
}
|
2012-08-23 01:17:09 +08:00
|
|
|
};
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadProperties::ThreadProperties(bool is_global) : Properties() {
|
|
|
|
if (is_global) {
|
2019-02-12 07:13:08 +08:00
|
|
|
m_collection_sp =
|
|
|
|
std::make_shared<ThreadOptionValueProperties>(ConstString("thread"));
|
2016-09-07 04:57:50 +08:00
|
|
|
m_collection_sp->Initialize(g_properties);
|
|
|
|
} else
|
2019-02-12 07:13:08 +08:00
|
|
|
m_collection_sp = std::make_shared<ThreadOptionValueProperties>(
|
|
|
|
Thread::GetGlobalProperties().get());
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
ThreadProperties::~ThreadProperties() = default;
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
const RegularExpression *ThreadProperties::GetSymbolsToAvoidRegexp() {
|
|
|
|
const uint32_t idx = ePropertyStepAvoidRegex;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex(nullptr, idx);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2019-04-24 04:17:04 +08:00
|
|
|
FileSpecList ThreadProperties::GetLibrariesToAvoid() const {
|
2016-09-07 04:57:50 +08:00
|
|
|
const uint32_t idx = ePropertyStepAvoidLibraries;
|
2019-04-24 04:17:04 +08:00
|
|
|
const OptionValueFileSpecList *option_value =
|
2016-09-07 04:57:50 +08:00
|
|
|
m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
|
|
|
|
false, idx);
|
|
|
|
assert(option_value);
|
|
|
|
return option_value->GetCurrentValue();
|
2014-01-24 05:52:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ThreadProperties::GetTraceEnabledState() const {
|
|
|
|
const uint32_t idx = ePropertyEnableThreadTrace;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_properties[idx].default_uint_value != 0);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ThreadProperties::GetStepInAvoidsNoDebug() const {
|
|
|
|
const uint32_t idx = ePropertyStepInAvoidsNoDebug;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_properties[idx].default_uint_value != 0);
|
2014-03-13 10:47:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool ThreadProperties::GetStepOutAvoidsNoDebug() const {
|
|
|
|
const uint32_t idx = ePropertyStepOutAvoidsNoDebug;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
|
|
|
nullptr, idx, g_properties[idx].default_uint_value != 0);
|
2018-09-26 05:01:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ThreadProperties::GetMaxBacktraceDepth() const {
|
|
|
|
const uint32_t idx = ePropertyMaxBacktraceDepth;
|
|
|
|
return m_collection_sp->GetPropertyAtIndexAsUInt64(
|
|
|
|
nullptr, idx, g_properties[idx].default_uint_value != 0);
|
2014-03-13 10:47:14 +08:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
// Thread Event Data
|
2012-08-23 01:17:09 +08:00
|
|
|
|
2019-03-07 05:22:25 +08:00
|
|
|
ConstString Thread::ThreadEventData::GetFlavorString() {
|
2016-09-07 04:57:50 +08:00
|
|
|
static ConstString g_flavor("Thread::ThreadEventData");
|
|
|
|
return g_flavor;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::ThreadEventData::ThreadEventData(const lldb::ThreadSP thread_sp)
|
|
|
|
: m_thread_sp(thread_sp), m_stack_id() {}
|
2012-10-11 02:32:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::ThreadEventData::ThreadEventData(const lldb::ThreadSP thread_sp,
|
|
|
|
const StackID &stack_id)
|
|
|
|
: m_thread_sp(thread_sp), m_stack_id(stack_id) {}
|
2012-10-11 02:32:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::ThreadEventData::ThreadEventData() : m_thread_sp(), m_stack_id() {}
|
2012-10-11 02:32:14 +08:00
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
Thread::ThreadEventData::~ThreadEventData() = default;
|
2012-10-11 02:32:14 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::ThreadEventData::Dump(Stream *s) const {}
|
2012-10-11 02:32:14 +08:00
|
|
|
|
|
|
|
const Thread::ThreadEventData *
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::ThreadEventData::GetEventDataFromEvent(const Event *event_ptr) {
|
|
|
|
if (event_ptr) {
|
|
|
|
const EventData *event_data = event_ptr->GetData();
|
|
|
|
if (event_data &&
|
|
|
|
event_data->GetFlavor() == ThreadEventData::GetFlavorString())
|
|
|
|
return static_cast<const ThreadEventData *>(event_ptr->GetData());
|
|
|
|
}
|
|
|
|
return nullptr;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadSP Thread::ThreadEventData::GetThreadFromEvent(const Event *event_ptr) {
|
|
|
|
ThreadSP thread_sp;
|
|
|
|
const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
|
|
|
|
if (event_data)
|
|
|
|
thread_sp = event_data->GetThread();
|
|
|
|
return thread_sp;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StackID Thread::ThreadEventData::GetStackIDFromEvent(const Event *event_ptr) {
|
|
|
|
StackID stack_id;
|
|
|
|
const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
|
|
|
|
if (event_data)
|
|
|
|
stack_id = event_data->GetStackID();
|
|
|
|
return stack_id;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::ThreadEventData::GetStackFrameFromEvent(const Event *event_ptr) {
|
|
|
|
const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
|
|
|
|
StackFrameSP frame_sp;
|
|
|
|
if (event_data) {
|
|
|
|
ThreadSP thread_sp = event_data->GetThread();
|
|
|
|
if (thread_sp) {
|
|
|
|
frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID(
|
|
|
|
event_data->GetStackID());
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return frame_sp;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Thread class
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ConstString &Thread::GetStaticBroadcasterClass() {
|
|
|
|
static ConstString class_name("lldb.thread");
|
|
|
|
return class_name;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id)
|
2016-09-07 04:57:50 +08:00
|
|
|
: ThreadProperties(false), UserID(tid),
|
2016-05-18 09:59:10 +08:00
|
|
|
Broadcaster(process.GetTarget().GetDebugger().GetBroadcasterManager(),
|
|
|
|
Thread::GetStaticBroadcasterClass().AsCString()),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_process_wp(process.shared_from_this()), m_stop_info_sp(),
|
|
|
|
m_stop_info_stop_id(0), m_stop_info_override_stop_id(0),
|
|
|
|
m_index_id(use_invalid_index_id ? LLDB_INVALID_INDEX32
|
|
|
|
: process.GetNextThreadIndexID(tid)),
|
|
|
|
m_reg_context_sp(), m_state(eStateUnloaded), m_state_mutex(),
|
|
|
|
m_plan_stack(), m_completed_plan_stack(), m_frame_mutex(),
|
|
|
|
m_curr_frames_sp(), m_prev_frames_sp(),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_resume_signal(LLDB_INVALID_SIGNAL_NUMBER),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_resume_state(eStateRunning), m_temporary_resume_state(eStateRunning),
|
2019-02-13 14:25:41 +08:00
|
|
|
m_unwinder_up(), m_destroy_called(false),
|
2016-05-18 09:59:10 +08:00
|
|
|
m_override_should_notify(eLazyBoolCalculate),
|
2016-09-07 04:57:50 +08:00
|
|
|
m_extended_info_fetched(false), m_extended_info() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "%p Thread::Thread(tid = 0x%4.4" PRIx64 ")",
|
|
|
|
static_cast<void *>(this), GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
CheckInWithManager();
|
2018-11-15 09:18:15 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
QueueFundamentalPlan(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread::~Thread() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")",
|
|
|
|
static_cast<void *>(this), GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
/// If you hit this assert, it means your derived class forgot to call
|
|
|
|
/// DoDestroy in its destructor.
|
|
|
|
assert(m_destroy_called);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::DestroyThread() {
|
|
|
|
// Tell any plans on the plan stacks that the thread is being destroyed since
|
2018-05-01 00:49:04 +08:00
|
|
|
// any plans that have a thread go away in the middle of might need to do
|
|
|
|
// cleanup, or in some cases NOT do cleanup...
|
2016-09-07 04:57:50 +08:00
|
|
|
for (auto plan : m_plan_stack)
|
|
|
|
plan->ThreadDestroyed();
|
|
|
|
|
|
|
|
for (auto plan : m_discarded_plan_stack)
|
|
|
|
plan->ThreadDestroyed();
|
|
|
|
|
|
|
|
for (auto plan : m_completed_plan_stack)
|
|
|
|
plan->ThreadDestroyed();
|
|
|
|
|
|
|
|
m_destroy_called = true;
|
|
|
|
m_plan_stack.clear();
|
|
|
|
m_discarded_plan_stack.clear();
|
|
|
|
m_completed_plan_stack.clear();
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Push a ThreadPlanNull on the plan stack. That way we can continue
|
|
|
|
// assuming that the plan stack is never empty, but if somebody errantly asks
|
|
|
|
// questions of a destroyed thread without checking first whether it is
|
|
|
|
// destroyed, they won't crash.
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP null_plan_sp(new ThreadPlanNull(*this));
|
|
|
|
m_plan_stack.push_back(null_plan_sp);
|
|
|
|
|
|
|
|
m_stop_info_sp.reset();
|
|
|
|
m_reg_context_sp.reset();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_unwinder_up.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
|
|
|
|
m_curr_frames_sp.reset();
|
|
|
|
m_prev_frames_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) {
|
|
|
|
if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged))
|
|
|
|
BroadcastEvent(eBroadcastBitSelectedFrameChanged,
|
|
|
|
new ThreadEventData(this->shared_from_this(), new_frame_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::StackFrameSP Thread::GetSelectedFrame() {
|
|
|
|
StackFrameListSP stack_frame_list_sp(GetStackFrameList());
|
|
|
|
StackFrameSP frame_sp = stack_frame_list_sp->GetFrameAtIndex(
|
|
|
|
stack_frame_list_sp->GetSelectedFrameIndex());
|
|
|
|
FunctionOptimizationWarning(frame_sp.get());
|
|
|
|
return frame_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Thread::SetSelectedFrame(lldb_private::StackFrame *frame,
|
|
|
|
bool broadcast) {
|
|
|
|
uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
|
|
|
|
if (broadcast)
|
|
|
|
BroadcastSelectedFrameChange(frame->GetStackID());
|
|
|
|
FunctionOptimizationWarning(frame);
|
|
|
|
return ret_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast) {
|
|
|
|
StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex(frame_idx));
|
|
|
|
if (frame_sp) {
|
|
|
|
GetStackFrameList()->SetSelectedFrame(frame_sp.get());
|
|
|
|
if (broadcast)
|
|
|
|
BroadcastSelectedFrameChange(frame_sp->GetStackID());
|
|
|
|
FunctionOptimizationWarning(frame_sp.get());
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::SetSelectedFrameByIndexNoisily(uint32_t frame_idx,
|
|
|
|
Stream &output_stream) {
|
|
|
|
const bool broadcast = true;
|
|
|
|
bool success = SetSelectedFrameByIndex(frame_idx, broadcast);
|
|
|
|
if (success) {
|
|
|
|
StackFrameSP frame_sp = GetSelectedFrame();
|
|
|
|
if (frame_sp) {
|
|
|
|
bool already_shown = false;
|
|
|
|
SymbolContext frame_sc(
|
|
|
|
frame_sp->GetSymbolContext(eSymbolContextLineEntry));
|
|
|
|
if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() &&
|
|
|
|
frame_sc.line_entry.file && frame_sc.line_entry.line != 0) {
|
|
|
|
already_shown = Host::OpenFileInExternalEditor(
|
|
|
|
frame_sc.line_entry.file, frame_sc.line_entry.line);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool show_frame_info = true;
|
|
|
|
bool show_source = !already_shown;
|
|
|
|
FunctionOptimizationWarning(frame_sp.get());
|
|
|
|
return frame_sp->GetStatus(output_stream, show_frame_info, show_source);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::FunctionOptimizationWarning(StackFrame *frame) {
|
|
|
|
if (frame && frame->HasDebugInformation() &&
|
|
|
|
GetProcess()->GetWarningsOptimization()) {
|
|
|
|
SymbolContext sc =
|
|
|
|
frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextModule);
|
|
|
|
GetProcess()->PrintWarningOptimization(sc);
|
|
|
|
}
|
2010-11-18 10:47:07 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::StopInfoSP Thread::GetStopInfo() {
|
|
|
|
if (m_destroy_called)
|
|
|
|
return m_stop_info_sp;
|
|
|
|
|
2017-02-15 19:42:47 +08:00
|
|
|
ThreadPlanSP completed_plan_sp(GetCompletedPlan());
|
2016-09-07 04:57:50 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX;
|
2017-02-15 19:42:47 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Here we select the stop info according to priorirty: - m_stop_info_sp (if
|
|
|
|
// not trace) - preset value - completed plan stop info - new value with plan
|
|
|
|
// from completed plan stack - m_stop_info_sp (trace stop reason is OK now) -
|
|
|
|
// ask GetPrivateStopInfo to set stop info
|
2017-02-15 19:42:47 +08:00
|
|
|
|
|
|
|
bool have_valid_stop_info = m_stop_info_sp &&
|
|
|
|
m_stop_info_sp ->IsValid() &&
|
|
|
|
m_stop_info_stop_id == stop_id;
|
|
|
|
bool have_valid_completed_plan = completed_plan_sp && completed_plan_sp->PlanSucceeded();
|
2018-11-15 09:18:15 +08:00
|
|
|
bool plan_failed = completed_plan_sp && !completed_plan_sp->PlanSucceeded();
|
2017-02-15 19:42:47 +08:00
|
|
|
bool plan_overrides_trace =
|
|
|
|
have_valid_stop_info && have_valid_completed_plan
|
|
|
|
&& (m_stop_info_sp->GetStopReason() == eStopReasonTrace);
|
2017-05-29 16:25:46 +08:00
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
if (have_valid_stop_info && !plan_overrides_trace && !plan_failed) {
|
2017-02-15 19:42:47 +08:00
|
|
|
return m_stop_info_sp;
|
2018-11-15 09:18:15 +08:00
|
|
|
} else if (completed_plan_sp) {
|
2017-02-15 19:42:47 +08:00
|
|
|
return StopInfo::CreateStopReasonWithPlan(
|
|
|
|
completed_plan_sp, GetReturnValueObject(), GetExpressionVariable());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2017-02-15 19:42:47 +08:00
|
|
|
GetPrivateStopInfo();
|
|
|
|
return m_stop_info_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::StopInfoSP Thread::GetPrivateStopInfo() {
|
|
|
|
if (m_destroy_called)
|
|
|
|
return m_stop_info_sp;
|
|
|
|
|
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp) {
|
|
|
|
const uint32_t process_stop_id = process_sp->GetStopID();
|
|
|
|
if (m_stop_info_stop_id != process_stop_id) {
|
|
|
|
if (m_stop_info_sp) {
|
|
|
|
if (m_stop_info_sp->IsValid() || IsStillAtLastBreakpointHit() ||
|
|
|
|
GetCurrentPlan()->IsVirtualStep())
|
|
|
|
SetStopInfo(m_stop_info_sp);
|
|
|
|
else
|
|
|
|
m_stop_info_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_stop_info_sp) {
|
|
|
|
if (!CalculateStopInfo())
|
|
|
|
SetStopInfo(StopInfoSP());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// The stop info can be manually set by calling Thread::SetStopInfo() prior
|
|
|
|
// to this function ever getting called, so we can't rely on
|
|
|
|
// "m_stop_info_stop_id != process_stop_id" as the condition for the if
|
|
|
|
// statement below, we must also check the stop info to see if we need to
|
|
|
|
// override it. See the header documentation in
|
|
|
|
// Process::GetStopInfoOverrideCallback() for more information on the stop
|
|
|
|
// info override callback.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_stop_info_override_stop_id != process_stop_id) {
|
|
|
|
m_stop_info_override_stop_id = process_stop_id;
|
|
|
|
if (m_stop_info_sp) {
|
2018-06-27 15:01:07 +08:00
|
|
|
if (const Architecture *arch =
|
2017-10-26 05:05:31 +08:00
|
|
|
process_sp->GetTarget().GetArchitecturePlugin())
|
|
|
|
arch->OverrideStopInfo(*this);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return m_stop_info_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::StopReason Thread::GetStopReason() {
|
|
|
|
lldb::StopInfoSP stop_info_sp(GetStopInfo());
|
|
|
|
if (stop_info_sp)
|
|
|
|
return stop_info_sp->GetStopReason();
|
|
|
|
return eStopReasonNone;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::StopInfoIsUpToDate() const {
|
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp)
|
|
|
|
return m_stop_info_stop_id == process_sp->GetStopID();
|
|
|
|
else
|
|
|
|
return true; // Process is no longer around so stop info is always up to
|
|
|
|
// date...
|
|
|
|
}
|
|
|
|
|
2017-02-15 19:42:47 +08:00
|
|
|
void Thread::ResetStopInfo() {
|
|
|
|
if (m_stop_info_sp) {
|
|
|
|
m_stop_info_sp.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::SetStopInfo(const lldb::StopInfoSP &stop_info_sp) {
|
|
|
|
m_stop_info_sp = stop_info_sp;
|
|
|
|
if (m_stop_info_sp) {
|
|
|
|
m_stop_info_sp->MakeStopInfoValid();
|
|
|
|
// If we are overriding the ShouldReportStop, do that here:
|
|
|
|
if (m_override_should_notify != eLazyBoolCalculate)
|
|
|
|
m_stop_info_sp->OverrideShouldNotify(m_override_should_notify ==
|
|
|
|
eLazyBoolYes);
|
|
|
|
}
|
|
|
|
|
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp)
|
|
|
|
m_stop_info_stop_id = process_sp->GetStopID();
|
|
|
|
else
|
|
|
|
m_stop_info_stop_id = UINT32_MAX;
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)",
|
|
|
|
static_cast<void *>(this), GetID(),
|
|
|
|
stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>",
|
|
|
|
m_stop_info_stop_id);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::SetShouldReportStop(Vote vote) {
|
|
|
|
if (vote == eVoteNoOpinion)
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo);
|
|
|
|
if (m_stop_info_sp)
|
|
|
|
m_stop_info_sp->OverrideShouldNotify(m_override_should_notify ==
|
|
|
|
eLazyBoolYes);
|
|
|
|
}
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::SetStopInfoToNothing() {
|
|
|
|
// Note, we can't just NULL out the private reason, or the native thread
|
2018-05-01 00:49:04 +08:00
|
|
|
// implementation will try to go calculate it again. For now, just set it to
|
|
|
|
// a Unix Signal with an invalid signal number.
|
2016-09-07 04:57:50 +08:00
|
|
|
SetStopInfo(
|
|
|
|
StopInfo::CreateStopReasonWithSignal(*this, LLDB_INVALID_SIGNAL_NUMBER));
|
2015-08-06 11:27:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::ThreadStoppedForAReason(void) {
|
|
|
|
return (bool)GetPrivateStopInfo();
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::CheckpointThreadState(ThreadStateCheckpoint &saved_state) {
|
|
|
|
saved_state.register_backup_sp.reset();
|
|
|
|
lldb::StackFrameSP frame_sp(GetStackFrameAtIndex(0));
|
|
|
|
if (frame_sp) {
|
|
|
|
lldb::RegisterCheckpointSP reg_checkpoint_sp(
|
|
|
|
new RegisterCheckpoint(RegisterCheckpoint::Reason::eExpression));
|
|
|
|
if (reg_checkpoint_sp) {
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(frame_sp->GetRegisterContext());
|
|
|
|
if (reg_ctx_sp && reg_ctx_sp->ReadAllRegisterValues(*reg_checkpoint_sp))
|
|
|
|
saved_state.register_backup_sp = reg_checkpoint_sp;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
if (!saved_state.register_backup_sp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
saved_state.stop_info_sp = GetStopInfo();
|
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp)
|
|
|
|
saved_state.orig_stop_id = process_sp->GetStopID();
|
|
|
|
saved_state.current_inlined_depth = GetCurrentInlinedDepth();
|
2017-02-15 19:42:47 +08:00
|
|
|
saved_state.m_completed_plan_stack = m_completed_plan_stack;
|
2017-05-29 16:25:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::RestoreRegisterStateFromCheckpoint(
|
|
|
|
ThreadStateCheckpoint &saved_state) {
|
|
|
|
if (saved_state.register_backup_sp) {
|
|
|
|
lldb::StackFrameSP frame_sp(GetStackFrameAtIndex(0));
|
|
|
|
if (frame_sp) {
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(frame_sp->GetRegisterContext());
|
|
|
|
if (reg_ctx_sp) {
|
|
|
|
bool ret =
|
|
|
|
reg_ctx_sp->WriteAllRegisterValues(*saved_state.register_backup_sp);
|
2013-02-01 05:46:01 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Clear out all stack frames as our world just changed.
|
|
|
|
ClearStackFrames();
|
|
|
|
reg_ctx_sp->InvalidateIfNeeded(true);
|
2019-02-13 14:25:41 +08:00
|
|
|
if (m_unwinder_up)
|
|
|
|
m_unwinder_up->Clear();
|
2016-09-07 04:57:50 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::RestoreThreadStateFromCheckpoint(
|
|
|
|
ThreadStateCheckpoint &saved_state) {
|
|
|
|
if (saved_state.stop_info_sp)
|
|
|
|
saved_state.stop_info_sp->MakeStopInfoValid();
|
|
|
|
SetStopInfo(saved_state.stop_info_sp);
|
|
|
|
GetStackFrameList()->SetCurrentInlinedDepth(
|
|
|
|
saved_state.current_inlined_depth);
|
2017-02-15 19:42:47 +08:00
|
|
|
m_completed_plan_stack = saved_state.m_completed_plan_stack;
|
2016-09-07 04:57:50 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
StateType Thread::GetState() const {
|
|
|
|
// If any other threads access this we will need a mutex for it
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
|
|
|
|
return m_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::SetState(StateType state) {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
|
|
|
|
m_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::WillStop() {
|
|
|
|
ThreadPlan *current_plan = GetCurrentPlan();
|
|
|
|
|
|
|
|
// FIXME: I may decide to disallow threads with no plans. In which
|
|
|
|
// case this should go to an assert.
|
|
|
|
|
|
|
|
if (!current_plan)
|
|
|
|
return;
|
|
|
|
|
|
|
|
current_plan->WillStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::SetupForResume() {
|
|
|
|
if (GetResumeState() != eStateSuspended) {
|
|
|
|
// If we're at a breakpoint push the step-over breakpoint plan. Do this
|
2018-05-01 00:49:04 +08:00
|
|
|
// before telling the current plan it will resume, since we might change
|
|
|
|
// what the current plan is.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
|
|
|
|
if (reg_ctx_sp) {
|
|
|
|
const addr_t thread_pc = reg_ctx_sp->GetPC();
|
|
|
|
BreakpointSiteSP bp_site_sp =
|
|
|
|
GetProcess()->GetBreakpointSiteList().FindByAddress(thread_pc);
|
|
|
|
if (bp_site_sp) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Note, don't assume there's a ThreadPlanStepOverBreakpoint, the
|
|
|
|
// target may not require anything special to step over a breakpoint.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
ThreadPlan *cur_plan = GetCurrentPlan();
|
|
|
|
|
|
|
|
bool push_step_over_bp_plan = false;
|
|
|
|
if (cur_plan->GetKind() == ThreadPlan::eKindStepOverBreakpoint) {
|
|
|
|
ThreadPlanStepOverBreakpoint *bp_plan =
|
|
|
|
(ThreadPlanStepOverBreakpoint *)cur_plan;
|
|
|
|
if (bp_plan->GetBreakpointLoadAddress() != thread_pc)
|
|
|
|
push_step_over_bp_plan = true;
|
|
|
|
} else
|
|
|
|
push_step_over_bp_plan = true;
|
|
|
|
|
|
|
|
if (push_step_over_bp_plan) {
|
|
|
|
ThreadPlanSP step_bp_plan_sp(new ThreadPlanStepOverBreakpoint(*this));
|
|
|
|
if (step_bp_plan_sp) {
|
|
|
|
step_bp_plan_sp->SetPrivate(true);
|
|
|
|
|
|
|
|
if (GetCurrentPlan()->RunState() != eStateStepping) {
|
|
|
|
ThreadPlanStepOverBreakpoint *step_bp_plan =
|
|
|
|
static_cast<ThreadPlanStepOverBreakpoint *>(
|
|
|
|
step_bp_plan_sp.get());
|
|
|
|
step_bp_plan->SetAutoContinue(true);
|
|
|
|
}
|
|
|
|
QueueThreadPlan(step_bp_plan_sp, false);
|
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::ShouldResume(StateType resume_state) {
|
|
|
|
// At this point clear the completed plan stack.
|
|
|
|
m_completed_plan_stack.clear();
|
|
|
|
m_discarded_plan_stack.clear();
|
|
|
|
m_override_should_notify = eLazyBoolCalculate;
|
2015-08-06 11:27:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StateType prev_resume_state = GetTemporaryResumeState();
|
2013-07-30 08:23:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SetTemporaryResumeState(resume_state);
|
|
|
|
|
|
|
|
lldb::ThreadSP backing_thread_sp(GetBackingThread());
|
|
|
|
if (backing_thread_sp)
|
|
|
|
backing_thread_sp->SetTemporaryResumeState(resume_state);
|
|
|
|
|
|
|
|
// Make sure m_stop_info_sp is valid. Don't do this for threads we suspended
|
|
|
|
// in the previous run.
|
|
|
|
if (prev_resume_state != eStateSuspended)
|
|
|
|
GetPrivateStopInfo();
|
|
|
|
|
|
|
|
// This is a little dubious, but we are trying to limit how often we actually
|
2018-05-01 00:49:04 +08:00
|
|
|
// fetch stop info from the target, 'cause that slows down single stepping.
|
|
|
|
// So assume that if we got to the point where we're about to resume, and we
|
|
|
|
// haven't yet had to fetch the stop reason, then it doesn't need to know
|
2016-09-07 04:57:50 +08:00
|
|
|
// about the fact that we are resuming...
|
|
|
|
const uint32_t process_stop_id = GetProcess()->GetStopID();
|
|
|
|
if (m_stop_info_stop_id == process_stop_id &&
|
|
|
|
(m_stop_info_sp && m_stop_info_sp->IsValid())) {
|
|
|
|
StopInfo *stop_info = GetPrivateStopInfo().get();
|
|
|
|
if (stop_info)
|
|
|
|
stop_info->WillResume(resume_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell all the plans that we are about to resume in case they need to clear
|
2018-05-01 00:49:04 +08:00
|
|
|
// any state. We distinguish between the plan on the top of the stack and the
|
|
|
|
// lower plans in case a plan needs to do any special business before it
|
|
|
|
// runs.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
bool need_to_resume = false;
|
|
|
|
ThreadPlan *plan_ptr = GetCurrentPlan();
|
|
|
|
if (plan_ptr) {
|
|
|
|
need_to_resume = plan_ptr->WillResume(resume_state, true);
|
|
|
|
|
|
|
|
while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
|
|
|
|
plan_ptr->WillResume(resume_state, false);
|
2013-05-08 02:35:34 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
// If the WillResume for the plan says we are faking a resume, then it will
|
2018-05-01 00:49:04 +08:00
|
|
|
// have set an appropriate stop info. In that case, don't reset it here.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (need_to_resume && resume_state != eStateSuspended) {
|
|
|
|
m_stop_info_sp.reset();
|
2013-05-09 09:55:29 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need_to_resume) {
|
|
|
|
ClearStackFrames();
|
|
|
|
// Let Thread subclasses do any special work they need to prior to resuming
|
|
|
|
WillResume(resume_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return need_to_resume;
|
2013-05-09 09:55:29 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::DidResume() { SetResumeSignal(LLDB_INVALID_SIGNAL_NUMBER); }
|
2013-07-30 08:23:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::DidStop() { SetState(eStateStopped); }
|
2013-05-14 23:20:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::ShouldStop(Event *event_ptr) {
|
|
|
|
ThreadPlan *current_plan = GetCurrentPlan();
|
|
|
|
|
|
|
|
bool should_stop = true;
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
|
|
|
|
if (GetResumeState() == eStateSuspended) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
|
|
|
|
", should_stop = 0 (ignore since thread was suspended)",
|
|
|
|
__FUNCTION__, GetID(), GetProtocolID());
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetTemporaryResumeState() == eStateSuspended) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
|
|
|
|
", should_stop = 0 (ignore since thread was suspended)",
|
|
|
|
__FUNCTION__, GetID(), GetProtocolID());
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Based on the current thread plan and process stop info, check if this
|
2018-05-01 00:49:04 +08:00
|
|
|
// thread caused the process to stop. NOTE: this must take place before the
|
|
|
|
// plan is moved from the current plan stack to the completed plan stack.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!ThreadStoppedForAReason()) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
|
|
|
|
", pc = 0x%16.16" PRIx64
|
|
|
|
", should_stop = 0 (ignore since no stop reason)",
|
|
|
|
__FUNCTION__, GetID(), GetProtocolID(),
|
|
|
|
GetRegisterContext() ? GetRegisterContext()->GetPC()
|
|
|
|
: LLDB_INVALID_ADDRESS);
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64
|
|
|
|
", pc = 0x%16.16" PRIx64,
|
|
|
|
__FUNCTION__, static_cast<void *>(this), GetID(), GetProtocolID(),
|
|
|
|
GetRegisterContext() ? GetRegisterContext()->GetPC()
|
|
|
|
: LLDB_INVALID_ADDRESS);
|
|
|
|
LLDB_LOGF(log, "^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
|
2016-09-07 04:57:50 +08:00
|
|
|
StreamString s;
|
|
|
|
s.IndentMore();
|
|
|
|
DumpThreadPlans(&s);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Plan stack initial state:\n%s", s.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// The top most plan always gets to do the trace log...
|
|
|
|
current_plan->DoTraceLog();
|
|
|
|
|
|
|
|
// First query the stop info's ShouldStopSynchronous. This handles
|
2018-05-01 00:49:04 +08:00
|
|
|
// "synchronous" stop reasons, for example the breakpoint command on internal
|
|
|
|
// breakpoints. If a synchronous stop reason says we should not stop, then
|
|
|
|
// we don't have to do any more work on this stop.
|
2016-09-07 04:57:50 +08:00
|
|
|
StopInfoSP private_stop_info(GetPrivateStopInfo());
|
|
|
|
if (private_stop_info &&
|
|
|
|
!private_stop_info->ShouldStopSynchronous(event_ptr)) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "StopInfo::ShouldStop async callback says we should not "
|
|
|
|
"stop, returning ShouldStop of false.");
|
2016-09-07 04:57:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If we've already been restarted, don't query the plans since the state
|
|
|
|
// they would examine is not current.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Before the plans see the state of the world, calculate the current inlined
|
|
|
|
// depth.
|
|
|
|
GetStackFrameList()->CalculateCurrentInlinedDepth();
|
|
|
|
|
|
|
|
// If the base plan doesn't understand why we stopped, then we have to find a
|
2018-05-01 00:49:04 +08:00
|
|
|
// plan that does. If that plan is still working, then we don't need to do
|
|
|
|
// any more work. If the plan that explains the stop is done, then we should
|
|
|
|
// pop all the plans below it, and pop it, and then let the plans above it
|
|
|
|
// decide whether they still need to do more work.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
bool done_processing_current_plan = false;
|
|
|
|
|
|
|
|
if (!current_plan->PlanExplainsStop(event_ptr)) {
|
|
|
|
if (current_plan->TracerExplainsStop()) {
|
|
|
|
done_processing_current_plan = true;
|
|
|
|
should_stop = false;
|
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// If the current plan doesn't explain the stop, then find one that does
|
|
|
|
// and let it handle the situation.
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlan *plan_ptr = current_plan;
|
|
|
|
while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
|
|
|
|
if (plan_ptr->PlanExplainsStop(event_ptr)) {
|
|
|
|
should_stop = plan_ptr->ShouldStop(event_ptr);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// plan_ptr explains the stop, next check whether plan_ptr is done,
|
|
|
|
// if so, then we should take it and all the plans below it off the
|
|
|
|
// stack.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (plan_ptr->MischiefManaged()) {
|
|
|
|
// We're going to pop the plans up to and including the plan that
|
|
|
|
// explains the stop.
|
|
|
|
ThreadPlan *prev_plan_ptr = GetPreviousPlan(plan_ptr);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (should_stop)
|
|
|
|
current_plan->WillStop();
|
|
|
|
PopPlan();
|
|
|
|
} while ((current_plan = GetCurrentPlan()) != prev_plan_ptr);
|
2018-05-01 00:49:04 +08:00
|
|
|
// Now, if the responsible plan was not "Okay to discard" then
|
|
|
|
// we're done, otherwise we forward this to the next plan in the
|
|
|
|
// stack below.
|
2016-09-07 04:57:50 +08:00
|
|
|
done_processing_current_plan =
|
|
|
|
(plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard());
|
|
|
|
} else
|
|
|
|
done_processing_current_plan = true;
|
|
|
|
|
|
|
|
break;
|
2013-05-08 02:35:34 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done_processing_current_plan) {
|
|
|
|
bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
|
|
|
|
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Plan %s explains stop, auto-continue %i.",
|
|
|
|
current_plan->GetName(), over_ride_stop);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
// We're starting from the base plan, so just let it decide;
|
|
|
|
if (PlanIsBasePlan(current_plan)) {
|
|
|
|
should_stop = current_plan->ShouldStop(event_ptr);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Base plan says should stop: %i.", should_stop);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2018-05-01 00:49:04 +08:00
|
|
|
// Otherwise, don't let the base plan override what the other plans say
|
|
|
|
// to do, since presumably if there were other plans they would know what
|
|
|
|
// to do...
|
2019-05-24 08:44:33 +08:00
|
|
|
while (true) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (PlanIsBasePlan(current_plan))
|
|
|
|
break;
|
|
|
|
|
|
|
|
should_stop = current_plan->ShouldStop(event_ptr);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Plan %s should stop: %d.", current_plan->GetName(),
|
|
|
|
should_stop);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (current_plan->MischiefManaged()) {
|
|
|
|
if (should_stop)
|
|
|
|
current_plan->WillStop();
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If a Master Plan wants to stop, and wants to stick on the stack,
|
|
|
|
// we let it. Otherwise, see if the plan's parent wants to stop.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (should_stop && current_plan->IsMasterPlan() &&
|
|
|
|
!current_plan->OkayToDiscard()) {
|
|
|
|
PopPlan();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
PopPlan();
|
2014-12-10 07:31:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
current_plan = GetCurrentPlan();
|
|
|
|
if (current_plan == nullptr) {
|
|
|
|
break;
|
2014-12-10 07:31:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
2014-12-10 07:31:02 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-08-09 08:32:52 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (over_ride_stop)
|
|
|
|
should_stop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// One other potential problem is that we set up a master plan, then stop in
|
2018-05-01 00:49:04 +08:00
|
|
|
// before it is complete - for instance by hitting a breakpoint during a
|
|
|
|
// step-over - then do some step/finish/etc operations that wind up past the
|
|
|
|
// end point condition of the initial plan. We don't want to strand the
|
|
|
|
// original plan on the stack, This code clears stale plans off the stack.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
if (should_stop) {
|
|
|
|
ThreadPlan *plan_ptr = GetCurrentPlan();
|
2017-02-15 19:42:47 +08:00
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Discard the stale plans and all plans below them in the stack, plus move
|
|
|
|
// the completed plans to the completed plan stack
|
2016-09-07 04:57:50 +08:00
|
|
|
while (!PlanIsBasePlan(plan_ptr)) {
|
|
|
|
bool stale = plan_ptr->IsPlanStale();
|
|
|
|
ThreadPlan *examined_plan = plan_ptr;
|
|
|
|
plan_ptr = GetPreviousPlan(examined_plan);
|
|
|
|
|
|
|
|
if (stale) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(
|
|
|
|
log,
|
|
|
|
"Plan %s being discarded in cleanup, it says it is already done.",
|
|
|
|
examined_plan->GetName());
|
2017-02-15 19:42:47 +08:00
|
|
|
while (GetCurrentPlan() != examined_plan) {
|
|
|
|
DiscardPlan();
|
|
|
|
}
|
|
|
|
if (examined_plan->IsPlanComplete()) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// plan is complete but does not explain the stop (example: step to a
|
|
|
|
// line with breakpoint), let us move the plan to
|
|
|
|
// completed_plan_stack anyway
|
2017-02-15 19:42:47 +08:00
|
|
|
PopPlan();
|
|
|
|
} else
|
|
|
|
DiscardPlan();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
|
|
|
s.IndentMore();
|
|
|
|
DumpThreadPlans(&s);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Plan stack final state:\n%s", s.GetData());
|
|
|
|
LLDB_LOGF(log, "vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv",
|
|
|
|
should_stop);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return should_stop;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Vote Thread::ShouldReportStop(Event *event_ptr) {
|
|
|
|
StateType thread_state = GetResumeState();
|
|
|
|
StateType temp_thread_state = GetTemporaryResumeState();
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
|
|
|
|
if (thread_state == eStateSuspended || thread_state == eStateInvalid) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
|
|
|
|
": returning vote %i (state was suspended or invalid)",
|
|
|
|
GetID(), eVoteNoOpinion);
|
2016-09-07 04:57:50 +08:00
|
|
|
return eVoteNoOpinion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (temp_thread_state == eStateSuspended ||
|
|
|
|
temp_thread_state == eStateInvalid) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
|
|
|
|
": returning vote %i (temporary state was suspended or invalid)",
|
|
|
|
GetID(), eVoteNoOpinion);
|
2016-09-07 04:57:50 +08:00
|
|
|
return eVoteNoOpinion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ThreadStoppedForAReason()) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
|
|
|
|
": returning vote %i (thread didn't stop for a reason.)",
|
|
|
|
GetID(), eVoteNoOpinion);
|
2016-09-07 04:57:50 +08:00
|
|
|
return eVoteNoOpinion;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_completed_plan_stack.size() > 0) {
|
|
|
|
// Don't use GetCompletedPlan here, since that suppresses private plans.
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
|
|
|
|
": returning vote for complete stack's back plan",
|
|
|
|
GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_completed_plan_stack.back()->ShouldReportStop(event_ptr);
|
|
|
|
} else {
|
|
|
|
Vote thread_vote = eVoteNoOpinion;
|
|
|
|
ThreadPlan *plan_ptr = GetCurrentPlan();
|
2019-05-24 08:44:33 +08:00
|
|
|
while (true) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (plan_ptr->PlanExplainsStop(event_ptr)) {
|
|
|
|
thread_vote = plan_ptr->ShouldReportStop(event_ptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (PlanIsBasePlan(plan_ptr))
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
plan_ptr = GetPreviousPlan(plan_ptr);
|
|
|
|
}
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Thread::ShouldReportStop() tid = 0x%4.4" PRIx64
|
|
|
|
": returning vote %i for current plan",
|
|
|
|
GetID(), thread_vote);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
return thread_vote;
|
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Vote Thread::ShouldReportRun(Event *event_ptr) {
|
|
|
|
StateType thread_state = GetResumeState();
|
|
|
|
|
|
|
|
if (thread_state == eStateSuspended || thread_state == eStateInvalid) {
|
|
|
|
return eVoteNoOpinion;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
if (m_completed_plan_stack.size() > 0) {
|
|
|
|
// Don't use GetCompletedPlan here, since that suppresses private plans.
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Current Plan for thread %d(%p) (0x%4.4" PRIx64
|
|
|
|
", %s): %s being asked whether we should report run.",
|
|
|
|
GetIndexID(), static_cast<void *>(this), GetID(),
|
|
|
|
StateAsCString(GetTemporaryResumeState()),
|
|
|
|
m_completed_plan_stack.back()->GetName());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
return m_completed_plan_stack.back()->ShouldReportRun(event_ptr);
|
|
|
|
} else {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Current Plan for thread %d(%p) (0x%4.4" PRIx64
|
|
|
|
", %s): %s being asked whether we should report run.",
|
|
|
|
GetIndexID(), static_cast<void *>(this), GetID(),
|
|
|
|
StateAsCString(GetTemporaryResumeState()),
|
|
|
|
GetCurrentPlan()->GetName());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
return GetCurrentPlan()->ShouldReportRun(event_ptr);
|
|
|
|
}
|
2015-07-18 07:42:28 +08:00
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::MatchesSpec(const ThreadSpec *spec) {
|
|
|
|
return (spec == nullptr) ? true : spec->ThreadPassesBasicTests(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::PushPlan(ThreadPlanSP &thread_plan_sp) {
|
|
|
|
if (thread_plan_sp) {
|
|
|
|
// If the thread plan doesn't already have a tracer, give it its parent's
|
|
|
|
// tracer:
|
2018-12-21 09:09:15 +08:00
|
|
|
if (!thread_plan_sp->GetThreadPlanTracer()) {
|
|
|
|
assert(!m_plan_stack.empty());
|
2016-09-07 04:57:50 +08:00
|
|
|
thread_plan_sp->SetThreadPlanTracer(
|
|
|
|
m_plan_stack.back()->GetThreadPlanTracer());
|
2018-12-21 09:09:15 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
m_plan_stack.push_back(thread_plan_sp);
|
|
|
|
|
|
|
|
thread_plan_sp->DidPush();
|
|
|
|
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
|
|
|
thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelFull);
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
static_cast<void *>(this), s.GetData(),
|
|
|
|
thread_plan_sp->GetThread().GetID());
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 08:35:16 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::PopPlan() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
|
|
|
|
if (m_plan_stack.size() <= 1)
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
ThreadPlanSP &plan = m_plan_stack.back();
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
plan->GetName(), plan->GetThread().GetID());
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 08:35:16 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
m_completed_plan_stack.push_back(plan);
|
|
|
|
plan->WillPop();
|
|
|
|
m_plan_stack.pop_back();
|
|
|
|
}
|
Figure out the reply to "PlanExplainsStop" once when we stop and then use the cached
value. This fixes problems, for instance, with the StepRange plans, where they know that
they explained the stop because they were at their "run to here" breakpoint, then deleted
that breakpoint, so when they got asked again, doh! I had done this for a couple of plans
in an ad hoc fashion, this just formalizes it.
Also add a "ResumeRequested" in Process so that the code in the completion handlers can
tell the ShouldStop logic they want to resume rather than just directly resuming. That allows
us to handle resuming in a more controlled fashion.
Also, SetPublicState can take a "restarted" flag, so that it doesn't drop the run lock when
the target was immediately restarted.
--This line, and those below , will be ignored--
M test/lang/objc/objc-dynamic-value/TestObjCDynamicValue.py
M include/lldb/Target/ThreadList.h
M include/lldb/Target/ThreadPlanStepOut.h
M include/lldb/Target/Thread.h
M include/lldb/Target/ThreadPlanBase.h
M include/lldb/Target/ThreadPlanStepThrough.h
M include/lldb/Target/ThreadPlanStepInstruction.h
M include/lldb/Target/ThreadPlanStepInRange.h
M include/lldb/Target/ThreadPlanStepOverBreakpoint.h
M include/lldb/Target/ThreadPlanStepUntil.h
M include/lldb/Target/StopInfo.h
M include/lldb/Target/Process.h
M include/lldb/Target/ThreadPlanRunToAddress.h
M include/lldb/Target/ThreadPlan.h
M include/lldb/Target/ThreadPlanCallFunction.h
M include/lldb/Target/ThreadPlanStepOverRange.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.h
M source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleThreadPlanStepThroughObjCTrampoline.cpp
M source/Target/StopInfo.cpp
M source/Target/Process.cpp
M source/Target/ThreadPlanRunToAddress.cpp
M source/Target/ThreadPlan.cpp
M source/Target/ThreadPlanCallFunction.cpp
M source/Target/ThreadPlanStepOverRange.cpp
M source/Target/ThreadList.cpp
M source/Target/ThreadPlanStepOut.cpp
M source/Target/Thread.cpp
M source/Target/ThreadPlanBase.cpp
M source/Target/ThreadPlanStepThrough.cpp
M source/Target/ThreadPlanStepInstruction.cpp
M source/Target/ThreadPlanStepInRange.cpp
M source/Target/ThreadPlanStepOverBreakpoint.cpp
M source/Target/ThreadPlanStepUntil.cpp
M lldb.xcodeproj/xcshareddata/xcschemes/Run Testsuite.xcscheme
llvm-svn: 181381
2013-05-08 08:35:16 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::DiscardPlan() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
if (m_plan_stack.size() > 1) {
|
|
|
|
ThreadPlanSP &plan = m_plan_stack.back();
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log, "Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
plan->GetName(), plan->GetThread().GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
m_discarded_plan_stack.push_back(plan);
|
|
|
|
plan->WillPop();
|
|
|
|
m_plan_stack.pop_back();
|
|
|
|
}
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlan *Thread::GetCurrentPlan() {
|
2018-05-01 00:49:04 +08:00
|
|
|
// There will always be at least the base plan. If somebody is mucking with
|
|
|
|
// a thread with an empty plan stack, we should assert right away.
|
2016-09-07 04:57:50 +08:00
|
|
|
return m_plan_stack.empty() ? nullptr : m_plan_stack.back().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::GetCompletedPlan() {
|
|
|
|
ThreadPlanSP empty_plan_sp;
|
|
|
|
if (!m_completed_plan_stack.empty()) {
|
|
|
|
for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) {
|
|
|
|
ThreadPlanSP completed_plan_sp;
|
|
|
|
completed_plan_sp = m_completed_plan_stack[i];
|
|
|
|
if (!completed_plan_sp->GetPrivate())
|
|
|
|
return completed_plan_sp;
|
2013-11-14 07:28:31 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return empty_plan_sp;
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ValueObjectSP Thread::GetReturnValueObject() {
|
|
|
|
if (!m_completed_plan_stack.empty()) {
|
|
|
|
for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) {
|
|
|
|
ValueObjectSP return_valobj_sp;
|
|
|
|
return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject();
|
|
|
|
if (return_valobj_sp)
|
|
|
|
return return_valobj_sp;
|
2013-11-14 07:28:31 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return ValueObjectSP();
|
2012-11-27 07:52:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ExpressionVariableSP Thread::GetExpressionVariable() {
|
|
|
|
if (!m_completed_plan_stack.empty()) {
|
|
|
|
for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) {
|
|
|
|
ExpressionVariableSP expression_variable_sp;
|
|
|
|
expression_variable_sp =
|
|
|
|
m_completed_plan_stack[i]->GetExpressionVariable();
|
|
|
|
if (expression_variable_sp)
|
|
|
|
return expression_variable_sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ExpressionVariableSP();
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::IsThreadPlanDone(ThreadPlan *plan) {
|
|
|
|
if (!m_completed_plan_stack.empty()) {
|
|
|
|
for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) {
|
|
|
|
if (m_completed_plan_stack[i].get() == plan)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::WasThreadPlanDiscarded(ThreadPlan *plan) {
|
|
|
|
if (!m_discarded_plan_stack.empty()) {
|
|
|
|
for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) {
|
|
|
|
if (m_discarded_plan_stack[i].get() == plan)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2017-02-15 19:42:47 +08:00
|
|
|
bool Thread::CompletedPlanOverridesBreakpoint() {
|
|
|
|
return (!m_completed_plan_stack.empty()) ;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlan *Thread::GetPreviousPlan(ThreadPlan *current_plan) {
|
|
|
|
if (current_plan == nullptr)
|
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int stack_size = m_completed_plan_stack.size();
|
|
|
|
for (int i = stack_size - 1; i > 0; i--) {
|
|
|
|
if (current_plan == m_completed_plan_stack[i].get())
|
|
|
|
return m_completed_plan_stack[i - 1].get();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) {
|
|
|
|
return GetCurrentPlan();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
stack_size = m_plan_stack.size();
|
|
|
|
for (int i = stack_size - 1; i > 0; i--) {
|
|
|
|
if (current_plan == m_plan_stack[i].get())
|
|
|
|
return m_plan_stack[i - 1].get();
|
|
|
|
}
|
|
|
|
return nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
Status Thread::QueueThreadPlan(ThreadPlanSP &thread_plan_sp,
|
|
|
|
bool abort_other_plans) {
|
|
|
|
Status status;
|
|
|
|
StreamString s;
|
|
|
|
if (!thread_plan_sp->ValidatePlan(&s)) {
|
|
|
|
DiscardThreadPlansUpToPlan(thread_plan_sp);
|
|
|
|
thread_plan_sp.reset();
|
|
|
|
status.SetErrorString(s.GetString());
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (abort_other_plans)
|
|
|
|
DiscardThreadPlans(true);
|
|
|
|
|
|
|
|
PushPlan(thread_plan_sp);
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
// This seems a little funny, but I don't want to have to split up the
|
|
|
|
// constructor and the DidPush in the scripted plan, that seems annoying.
|
|
|
|
// That means the constructor has to be in DidPush. So I have to validate the
|
|
|
|
// plan AFTER pushing it, and then take it off again...
|
|
|
|
if (!thread_plan_sp->ValidatePlan(&s)) {
|
|
|
|
DiscardThreadPlansUpToPlan(thread_plan_sp);
|
|
|
|
thread_plan_sp.reset();
|
|
|
|
status.SetErrorString(s.GetString());
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::EnableTracer(bool value, bool single_stepping) {
|
|
|
|
int stack_size = m_plan_stack.size();
|
|
|
|
for (int i = 0; i < stack_size; i++) {
|
|
|
|
if (m_plan_stack[i]->GetThreadPlanTracer()) {
|
|
|
|
m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
|
|
|
|
m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
|
2012-02-01 07:09:20 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-20 08:27:58 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::SetTracer(lldb::ThreadPlanTracerSP &tracer_sp) {
|
|
|
|
int stack_size = m_plan_stack.size();
|
|
|
|
for (int i = 0; i < stack_size; i++)
|
|
|
|
m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
|
|
|
|
}
|
2012-09-01 09:02:41 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::DiscardUserThreadPlansUpToIndex(uint32_t thread_index) {
|
|
|
|
// Count the user thread plans from the back end to get the number of the one
|
2018-05-01 00:49:04 +08:00
|
|
|
// we want to discard:
|
2013-05-02 05:54:04 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t idx = 0;
|
|
|
|
ThreadPlan *up_to_plan_ptr = nullptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
for (ThreadPlanSP plan_sp : m_plan_stack) {
|
|
|
|
if (plan_sp->GetPrivate())
|
|
|
|
continue;
|
|
|
|
if (idx == thread_index) {
|
|
|
|
up_to_plan_ptr = plan_sp.get();
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up_to_plan_ptr == nullptr)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DiscardThreadPlansUpToPlan(up_to_plan_ptr);
|
|
|
|
return true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp) {
|
|
|
|
DiscardThreadPlansUpToPlan(up_to_plan_sp.get());
|
2013-05-11 01:19:04 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr) {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Discarding thread plans for thread tid = 0x%4.4" PRIx64
|
|
|
|
", up to %p",
|
|
|
|
GetID(), static_cast<void *>(up_to_plan_ptr));
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
int stack_size = m_plan_stack.size();
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// If the input plan is nullptr, discard all plans. Otherwise make sure this
|
2018-05-01 00:49:04 +08:00
|
|
|
// plan is in the stack, and if so discard up to and including it.
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (up_to_plan_ptr == nullptr) {
|
|
|
|
for (int i = stack_size - 1; i > 0; i--)
|
|
|
|
DiscardPlan();
|
|
|
|
} else {
|
|
|
|
bool found_it = false;
|
|
|
|
for (int i = stack_size - 1; i > 0; i--) {
|
|
|
|
if (m_plan_stack[i].get() == up_to_plan_ptr)
|
|
|
|
found_it = true;
|
|
|
|
}
|
|
|
|
if (found_it) {
|
|
|
|
bool last_one = false;
|
|
|
|
for (int i = stack_size - 1; i > 0 && !last_one; i--) {
|
|
|
|
if (GetCurrentPlan() == up_to_plan_ptr)
|
|
|
|
last_one = true;
|
|
|
|
DiscardPlan();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::DiscardThreadPlans(bool force) {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
if (log) {
|
2019-07-25 01:56:10 +08:00
|
|
|
LLDB_LOGF(log,
|
|
|
|
"Discarding thread plans for thread (tid = 0x%4.4" PRIx64
|
|
|
|
", force %d)",
|
|
|
|
GetID(), force);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (force) {
|
|
|
|
int stack_size = m_plan_stack.size();
|
|
|
|
for (int i = stack_size - 1; i > 0; i--) {
|
|
|
|
DiscardPlan();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-24 08:44:33 +08:00
|
|
|
while (true) {
|
2016-09-07 04:57:50 +08:00
|
|
|
int master_plan_idx;
|
|
|
|
bool discard = true;
|
|
|
|
|
|
|
|
// Find the first master plan, see if it wants discarding, and if yes
|
|
|
|
// discard up to it.
|
|
|
|
for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0;
|
|
|
|
master_plan_idx--) {
|
|
|
|
if (m_plan_stack[master_plan_idx]->IsMasterPlan()) {
|
|
|
|
discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (discard) {
|
|
|
|
// First pop all the dependent plans:
|
|
|
|
for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) {
|
|
|
|
// FIXME: Do we need a finalize here, or is the rule that
|
|
|
|
// "PrepareForStop"
|
|
|
|
// for the plan leaves it in a state that it is safe to pop the plan
|
|
|
|
// with no more notice?
|
|
|
|
DiscardPlan();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now discard the master plan itself.
|
|
|
|
// The bottom-most plan never gets discarded. "OkayToDiscard" for it
|
2018-05-01 00:49:04 +08:00
|
|
|
// means discard it's dependent plans, but not it...
|
2016-09-07 04:57:50 +08:00
|
|
|
if (master_plan_idx > 0) {
|
|
|
|
DiscardPlan();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If the master plan doesn't want to get discarded, then we're done.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::PlanIsBasePlan(ThreadPlan *plan_ptr) {
|
|
|
|
if (plan_ptr->IsBasePlan())
|
|
|
|
return true;
|
|
|
|
else if (m_plan_stack.size() == 0)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return m_plan_stack[0].get() == plan_ptr;
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::UnwindInnermostExpression() {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
int stack_size = m_plan_stack.size();
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// If the input plan is nullptr, discard all plans. Otherwise make sure this
|
2018-05-01 00:49:04 +08:00
|
|
|
// plan is in the stack, and if so discard up to and including it.
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
for (int i = stack_size - 1; i > 0; i--) {
|
|
|
|
if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) {
|
|
|
|
DiscardThreadPlansUpToPlan(m_plan_stack[i].get());
|
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
error.SetErrorString("No expressions currently active on this thread");
|
|
|
|
return error;
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::QueueFundamentalPlan(bool abort_other_plans) {
|
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanBase(*this));
|
|
|
|
QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepSingleInstruction(
|
2018-11-15 09:18:15 +08:00
|
|
|
bool step_over, bool abort_other_plans, bool stop_other_threads,
|
|
|
|
Status &status) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanStepInstruction(
|
|
|
|
*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepOverRange(
|
|
|
|
bool abort_other_plans, const AddressRange &range,
|
|
|
|
const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
|
2018-11-15 09:18:15 +08:00
|
|
|
Status &status, LazyBool step_out_avoids_code_withoug_debug_info) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp;
|
2019-02-12 07:13:08 +08:00
|
|
|
thread_plan_sp = std::make_shared<ThreadPlanStepOverRange>(
|
2016-09-07 04:57:50 +08:00
|
|
|
*this, range, addr_context, stop_other_threads,
|
2019-02-12 07:13:08 +08:00
|
|
|
step_out_avoids_code_withoug_debug_info);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
Fixed a few bugs in the "step in" thread plan logic.
Added a "step-in-target" flag to "thread step-in" so if you have something like:
Process 28464 stopped
* thread #1: tid = 0x1c03, function: main , stop reason = breakpoint 1.1
frame #0: 0x0000000100000e08 a.out`main at main.c:62
61
-> 62 int A6 = complex (a(4), b(5), c(6)); // Stop here to step targetting b and hitting breakpoint.
63
and you want to get into "complex" skipping a, b and c, you can do:
(lldb) step -t complex
Process 28464 stopped
* thread #1: tid = 0x1c03, function: complex , stop reason = step in
frame #0: 0x0000000100000d0d a.out`complex at main.c:44
41
42 int complex (int first, int second, int third)
43 {
-> 44 return first + second + third; // Step in targetting complex should stop here
45 }
46
47 int main (int argc, char const *argv[])
llvm-svn: 170008
2012-12-13 03:58:40 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Call the QueueThreadPlanForStepOverRange method which takes an address
|
|
|
|
// range.
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepOverRange(
|
|
|
|
bool abort_other_plans, const LineEntry &line_entry,
|
|
|
|
const SymbolContext &addr_context, lldb::RunMode stop_other_threads,
|
2018-11-15 09:18:15 +08:00
|
|
|
Status &status, LazyBool step_out_avoids_code_withoug_debug_info) {
|
2019-05-07 04:01:21 +08:00
|
|
|
const bool include_inlined_functions = true;
|
|
|
|
auto address_range =
|
|
|
|
line_entry.GetSameLineContiguousAddressRange(include_inlined_functions);
|
2016-09-07 04:57:50 +08:00
|
|
|
return QueueThreadPlanForStepOverRange(
|
2019-05-07 04:01:21 +08:00
|
|
|
abort_other_plans, address_range, addr_context, stop_other_threads,
|
|
|
|
status, step_out_avoids_code_withoug_debug_info);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepInRange(
|
|
|
|
bool abort_other_plans, const AddressRange &range,
|
|
|
|
const SymbolContext &addr_context, const char *step_in_target,
|
2018-11-15 09:18:15 +08:00
|
|
|
lldb::RunMode stop_other_threads, Status &status,
|
2016-09-07 04:57:50 +08:00
|
|
|
LazyBool step_in_avoids_code_without_debug_info,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
|
|
|
ThreadPlanSP thread_plan_sp(
|
|
|
|
new ThreadPlanStepInRange(*this, range, addr_context, stop_other_threads,
|
|
|
|
step_in_avoids_code_without_debug_info,
|
|
|
|
step_out_avoids_code_without_debug_info));
|
|
|
|
ThreadPlanStepInRange *plan =
|
|
|
|
static_cast<ThreadPlanStepInRange *>(thread_plan_sp.get());
|
|
|
|
|
|
|
|
if (step_in_target)
|
|
|
|
plan->SetStepInTarget(step_in_target);
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-12-15 08:40:30 +08:00
|
|
|
// Call the QueueThreadPlanForStepInRange method which takes an address range.
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepInRange(
|
|
|
|
bool abort_other_plans, const LineEntry &line_entry,
|
|
|
|
const SymbolContext &addr_context, const char *step_in_target,
|
2018-11-15 09:18:15 +08:00
|
|
|
lldb::RunMode stop_other_threads, Status &status,
|
2016-09-07 04:57:50 +08:00
|
|
|
LazyBool step_in_avoids_code_without_debug_info,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
2019-05-07 04:01:21 +08:00
|
|
|
const bool include_inlined_functions = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
return QueueThreadPlanForStepInRange(
|
2019-05-07 04:01:21 +08:00
|
|
|
abort_other_plans,
|
|
|
|
line_entry.GetSameLineContiguousAddressRange(include_inlined_functions),
|
2018-11-15 09:18:15 +08:00
|
|
|
addr_context, step_in_target, stop_other_threads, status,
|
2016-09-07 04:57:50 +08:00
|
|
|
step_in_avoids_code_without_debug_info,
|
|
|
|
step_out_avoids_code_without_debug_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepOut(
|
|
|
|
bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
|
|
|
|
bool stop_other_threads, Vote stop_vote, Vote run_vote, uint32_t frame_idx,
|
2018-11-15 09:18:15 +08:00
|
|
|
Status &status, LazyBool step_out_avoids_code_without_debug_info) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
|
|
|
|
*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote,
|
|
|
|
frame_idx, step_out_avoids_code_without_debug_info));
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
|
|
|
return thread_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepOutNoShouldStop(
|
|
|
|
bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
|
|
|
|
bool stop_other_threads, Vote stop_vote, Vote run_vote, uint32_t frame_idx,
|
2018-11-15 09:18:15 +08:00
|
|
|
Status &status, bool continue_to_next_branch) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const bool calculate_return_value =
|
|
|
|
false; // No need to calculate the return value here.
|
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
|
|
|
|
*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote,
|
|
|
|
frame_idx, eLazyBoolNo, continue_to_next_branch, calculate_return_value));
|
|
|
|
|
|
|
|
ThreadPlanStepOut *new_plan =
|
|
|
|
static_cast<ThreadPlanStepOut *>(thread_plan_sp.get());
|
|
|
|
new_plan->ClearShouldStopHereCallbacks();
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
|
|
|
return thread_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepThrough(StackID &return_stack_id,
|
|
|
|
bool abort_other_plans,
|
2018-11-15 09:18:15 +08:00
|
|
|
bool stop_other_threads,
|
|
|
|
Status &status) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(
|
|
|
|
new ThreadPlanStepThrough(*this, return_stack_id, stop_other_threads));
|
|
|
|
if (!thread_plan_sp || !thread_plan_sp->ValidatePlan(nullptr))
|
|
|
|
return ThreadPlanSP();
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForRunToAddress(bool abort_other_plans,
|
|
|
|
Address &target_addr,
|
2018-11-15 09:18:15 +08:00
|
|
|
bool stop_other_threads,
|
|
|
|
Status &status) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(
|
|
|
|
new ThreadPlanRunToAddress(*this, target_addr, stop_other_threads));
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepUntil(
|
|
|
|
bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses,
|
|
|
|
bool stop_other_threads, uint32_t frame_idx, Status &status) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanStepUntil(
|
|
|
|
*this, address_list, num_addresses, stop_other_threads, frame_idx));
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ThreadPlanSP Thread::QueueThreadPlanForStepScripted(
|
2018-11-15 09:18:15 +08:00
|
|
|
bool abort_other_plans, const char *class_name, bool stop_other_threads,
|
|
|
|
Status &status) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanPython(*this, class_name));
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
|
|
|
return thread_plan_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
uint32_t Thread::GetIndexID() const { return m_index_id; }
|
|
|
|
|
|
|
|
static void PrintPlanElement(Stream *s, const ThreadPlanSP &plan,
|
|
|
|
lldb::DescriptionLevel desc_level,
|
|
|
|
int32_t elem_idx) {
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("Element %d: ", elem_idx);
|
|
|
|
plan->GetDescription(s, desc_level);
|
|
|
|
s->EOL();
|
|
|
|
s->IndentLess();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintPlanStack(Stream *s,
|
|
|
|
const std::vector<lldb::ThreadPlanSP> &plan_stack,
|
|
|
|
lldb::DescriptionLevel desc_level,
|
|
|
|
bool include_internal) {
|
|
|
|
int32_t print_idx = 0;
|
|
|
|
for (ThreadPlanSP plan_sp : plan_stack) {
|
|
|
|
if (include_internal || !plan_sp->GetPrivate()) {
|
|
|
|
PrintPlanElement(s, plan_sp, desc_level, print_idx++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::DumpThreadPlans(Stream *s, lldb::DescriptionLevel desc_level,
|
|
|
|
bool include_internal,
|
|
|
|
bool ignore_boring_threads) const {
|
|
|
|
uint32_t stack_size;
|
|
|
|
|
|
|
|
if (ignore_boring_threads) {
|
|
|
|
uint32_t stack_size = m_plan_stack.size();
|
|
|
|
uint32_t completed_stack_size = m_completed_plan_stack.size();
|
|
|
|
uint32_t discarded_stack_size = m_discarded_plan_stack.size();
|
|
|
|
if (stack_size == 1 && completed_stack_size == 0 &&
|
|
|
|
discarded_stack_size == 0) {
|
|
|
|
s->Printf("thread #%u: tid = 0x%4.4" PRIx64 "\n", GetIndexID(), GetID());
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("No active thread plans\n");
|
|
|
|
s->IndentLess();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("thread #%u: tid = 0x%4.4" PRIx64 ":\n", GetIndexID(), GetID());
|
|
|
|
s->IndentMore();
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("Active plan stack:\n");
|
|
|
|
PrintPlanStack(s, m_plan_stack, desc_level, include_internal);
|
|
|
|
|
|
|
|
stack_size = m_completed_plan_stack.size();
|
|
|
|
if (stack_size > 0) {
|
2014-09-30 07:17:18 +08:00
|
|
|
s->Indent();
|
2016-09-07 04:57:50 +08:00
|
|
|
s->Printf("Completed Plan Stack:\n");
|
|
|
|
PrintPlanStack(s, m_completed_plan_stack, desc_level, include_internal);
|
|
|
|
}
|
2014-09-30 07:17:18 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
stack_size = m_discarded_plan_stack.size();
|
|
|
|
if (stack_size > 0) {
|
|
|
|
s->Indent();
|
|
|
|
s->Printf("Discarded Plan Stack:\n");
|
|
|
|
PrintPlanStack(s, m_discarded_plan_stack, desc_level, include_internal);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
s->IndentLess();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
TargetSP Thread::CalculateTarget() {
|
|
|
|
TargetSP target_sp;
|
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp)
|
|
|
|
target_sp = process_sp->CalculateTarget();
|
|
|
|
return target_sp;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ProcessSP Thread::CalculateProcess() { return GetProcess(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
ThreadSP Thread::CalculateThread() { return shared_from_this(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StackFrameSP Thread::CalculateStackFrame() { return StackFrameSP(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::CalculateExecutionContext(ExecutionContext &exe_ctx) {
|
|
|
|
exe_ctx.SetContext(shared_from_this());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StackFrameListSP Thread::GetStackFrameList() {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
|
2019-02-12 07:48:59 +08:00
|
|
|
|
|
|
|
if (!m_curr_frames_sp)
|
2019-02-12 09:04:57 +08:00
|
|
|
m_curr_frames_sp =
|
2019-02-12 07:13:08 +08:00
|
|
|
std::make_shared<StackFrameList>(*this, m_prev_frames_sp, true);
|
2019-02-12 07:48:59 +08:00
|
|
|
|
2019-02-12 09:04:57 +08:00
|
|
|
return m_curr_frames_sp;
|
2010-08-25 08:35:26 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void Thread::ClearStackFrames() {
|
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
|
2012-03-29 09:41:38 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Unwind *unwinder = GetUnwinder();
|
|
|
|
if (unwinder)
|
|
|
|
unwinder->Clear();
|
2013-05-02 05:54:04 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
// Only store away the old "reference" StackFrameList if we got all its
|
|
|
|
// frames:
|
|
|
|
// FIXME: At some point we can try to splice in the frames we have fetched
|
|
|
|
// into
|
|
|
|
// the new frame as we make it, but let's not try that now.
|
|
|
|
if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
|
|
|
|
m_prev_frames_sp.swap(m_curr_frames_sp);
|
|
|
|
m_curr_frames_sp.reset();
|
2014-06-13 10:37:02 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
m_extended_info.reset();
|
|
|
|
m_extended_info_fetched = false;
|
2010-08-12 10:14:28 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::StackFrameSP Thread::GetFrameWithConcreteFrameIndex(uint32_t unwind_idx) {
|
|
|
|
return GetStackFrameList()->GetFrameWithConcreteFrameIndex(unwind_idx);
|
2011-01-07 06:15:06 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::ReturnFromFrameWithIndex(uint32_t frame_idx,
|
|
|
|
lldb::ValueObjectSP return_value_sp,
|
|
|
|
bool broadcast) {
|
2016-09-07 04:57:50 +08:00
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(frame_idx);
|
2017-05-12 12:51:55 +08:00
|
|
|
Status return_error;
|
2012-09-12 08:40:39 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!frame_sp) {
|
|
|
|
return_error.SetErrorStringWithFormat(
|
|
|
|
"Could not find frame with index %d in thread 0x%" PRIx64 ".",
|
|
|
|
frame_idx, GetID());
|
|
|
|
}
|
2012-09-27 09:15:29 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
return ReturnFromFrame(frame_sp, return_value_sp, broadcast);
|
2012-09-12 08:40:39 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::ReturnFromFrame(lldb::StackFrameSP frame_sp,
|
|
|
|
lldb::ValueObjectSP return_value_sp,
|
|
|
|
bool broadcast) {
|
|
|
|
Status return_error;
|
2013-09-12 10:20:34 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!frame_sp) {
|
|
|
|
return_error.SetErrorString("Can't return to a null frame.");
|
|
|
|
return return_error;
|
|
|
|
}
|
2013-09-12 10:20:34 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread *thread = frame_sp->GetThread().get();
|
|
|
|
uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1;
|
|
|
|
StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx);
|
|
|
|
if (!older_frame_sp) {
|
|
|
|
return_error.SetErrorString("No older frame to return to.");
|
|
|
|
return return_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (return_value_sp) {
|
|
|
|
lldb::ABISP abi = thread->GetProcess()->GetABI();
|
|
|
|
if (!abi) {
|
|
|
|
return_error.SetErrorString("Could not find ABI to set return value.");
|
|
|
|
return return_error;
|
|
|
|
}
|
|
|
|
SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);
|
|
|
|
|
|
|
|
// FIXME: ValueObject::Cast doesn't currently work correctly, at least not
|
|
|
|
// for scalars.
|
|
|
|
// Turn that back on when that works.
|
2019-05-24 08:44:33 +08:00
|
|
|
if (/* DISABLES CODE */ (false) && sc.function != nullptr) {
|
2016-09-07 04:57:50 +08:00
|
|
|
Type *function_type = sc.function->GetType();
|
|
|
|
if (function_type) {
|
|
|
|
CompilerType return_type =
|
|
|
|
sc.function->GetCompilerType().GetFunctionReturnType();
|
|
|
|
if (return_type) {
|
|
|
|
StreamString s;
|
|
|
|
return_type.DumpTypeDescription(&s);
|
|
|
|
ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type);
|
|
|
|
if (cast_value_sp) {
|
|
|
|
cast_value_sp->SetFormat(eFormatHex);
|
|
|
|
return_value_sp = cast_value_sp;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp);
|
|
|
|
if (!return_error.Success())
|
|
|
|
return return_error;
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// Now write the return registers for the chosen frame: Note, we can't use
|
|
|
|
// ReadAllRegisterValues->WriteAllRegisterValues, since the read & write cook
|
|
|
|
// their data
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0);
|
|
|
|
if (youngest_frame_sp) {
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(youngest_frame_sp->GetRegisterContext());
|
|
|
|
if (reg_ctx_sp) {
|
|
|
|
bool copy_success = reg_ctx_sp->CopyFromRegisterContext(
|
|
|
|
older_frame_sp->GetRegisterContext());
|
|
|
|
if (copy_success) {
|
|
|
|
thread->DiscardThreadPlans(true);
|
|
|
|
thread->ClearStackFrames();
|
|
|
|
if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged))
|
|
|
|
BroadcastEvent(eBroadcastBitStackChanged,
|
|
|
|
new ThreadEventData(this->shared_from_this()));
|
|
|
|
} else {
|
|
|
|
return_error.SetErrorString("Could not reset register values.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return_error.SetErrorString("Frame has no register context.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return_error.SetErrorString("Returned past top frame.");
|
|
|
|
}
|
|
|
|
return return_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DumpAddressList(Stream &s, const std::vector<Address> &list,
|
|
|
|
ExecutionContextScope *exe_scope) {
|
|
|
|
for (size_t n = 0; n < list.size(); n++) {
|
|
|
|
s << "\t";
|
|
|
|
list[n].Dump(&s, exe_scope, Address::DumpStyleResolvedDescription,
|
|
|
|
Address::DumpStyleSectionNameOffset);
|
|
|
|
s << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::JumpToLine(const FileSpec &file, uint32_t line,
|
|
|
|
bool can_leave_function, std::string *warnings) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ExecutionContext exe_ctx(GetStackFrameAtIndex(0));
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
TargetSP target_sp = exe_ctx.GetTargetSP();
|
|
|
|
RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
|
|
|
|
StackFrame *frame = exe_ctx.GetFramePtr();
|
|
|
|
const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction);
|
|
|
|
|
|
|
|
// Find candidate locations.
|
|
|
|
std::vector<Address> candidates, within_function, outside_function;
|
|
|
|
target->GetImages().FindAddressesForLine(target_sp, file, line, sc.function,
|
|
|
|
within_function, outside_function);
|
|
|
|
|
2018-05-01 00:49:04 +08:00
|
|
|
// If possible, we try and stay within the current function. Within a
|
|
|
|
// function, we accept multiple locations (optimized code may do this,
|
|
|
|
// there's no solution here so we do the best we can). However if we're
|
|
|
|
// trying to leave the function, we don't know how to pick the right
|
|
|
|
// location, so if there's more than one then we bail.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (!within_function.empty())
|
|
|
|
candidates = within_function;
|
|
|
|
else if (outside_function.size() == 1 && can_leave_function)
|
|
|
|
candidates = outside_function;
|
|
|
|
|
|
|
|
// Check if we got anything.
|
|
|
|
if (candidates.empty()) {
|
|
|
|
if (outside_function.empty()) {
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Cannot locate an address for %s:%i.",
|
|
|
|
file.GetFilename().AsCString(), line);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else if (outside_function.size() == 1) {
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("%s:%i is outside the current function.",
|
|
|
|
file.GetFilename().AsCString(), line);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
|
|
|
StreamString sstr;
|
|
|
|
DumpAddressList(sstr, outside_function, target);
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("%s:%i has multiple candidate locations:\n%s",
|
|
|
|
file.GetFilename().AsCString(), line, sstr.GetData());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accept the first location, warn about any others.
|
|
|
|
Address dest = candidates[0];
|
|
|
|
if (warnings && candidates.size() > 1) {
|
|
|
|
StreamString sstr;
|
|
|
|
sstr.Printf("%s:%i appears multiple times in this function, selecting the "
|
|
|
|
"first location:\n",
|
|
|
|
file.GetFilename().AsCString(), line);
|
|
|
|
DumpAddressList(sstr, candidates, target);
|
|
|
|
*warnings = sstr.GetString();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reg_ctx->SetPC(dest))
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status("Cannot change PC to target address.");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
return Status();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-09 04:36:40 +08:00
|
|
|
void Thread::DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx,
|
|
|
|
bool stop_format) {
|
2016-09-07 04:57:50 +08:00
|
|
|
ExecutionContext exe_ctx(shared_from_this());
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
if (process == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
StackFrameSP frame_sp;
|
|
|
|
SymbolContext frame_sc;
|
|
|
|
if (frame_idx != LLDB_INVALID_FRAME_ID) {
|
|
|
|
frame_sp = GetStackFrameAtIndex(frame_idx);
|
|
|
|
if (frame_sp) {
|
|
|
|
exe_ctx.SetFrameSP(frame_sp);
|
|
|
|
frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-09 04:36:40 +08:00
|
|
|
const FormatEntity::Entry *thread_format;
|
|
|
|
if (stop_format)
|
|
|
|
thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadStopFormat();
|
|
|
|
else
|
|
|
|
thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
assert(thread_format);
|
|
|
|
|
|
|
|
FormatEntity::Format(*thread_format, strm, frame_sp ? &frame_sc : nullptr,
|
|
|
|
&exe_ctx, nullptr, nullptr, false, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::SettingsInitialize() {}
|
|
|
|
|
|
|
|
void Thread::SettingsTerminate() {}
|
|
|
|
|
|
|
|
lldb::addr_t Thread::GetThreadPointer() { return LLDB_INVALID_ADDRESS; }
|
|
|
|
|
|
|
|
addr_t Thread::GetThreadLocalData(const ModuleSP module,
|
|
|
|
lldb::addr_t tls_file_addr) {
|
2018-05-01 00:49:04 +08:00
|
|
|
// The default implementation is to ask the dynamic loader for it. This can
|
|
|
|
// be overridden for specific platforms.
|
2016-09-07 04:57:50 +08:00
|
|
|
DynamicLoader *loader = GetProcess()->GetDynamicLoader();
|
|
|
|
if (loader)
|
|
|
|
return loader->GetThreadLocalData(module, shared_from_this(),
|
|
|
|
tls_file_addr);
|
|
|
|
else
|
Added support for reading thread-local storage variables, as defined using the __thread modifier.
To make this work this patch extends LLDB to:
- Explicitly track the link_map address for each module. This is effectively the module handle, not sure why it wasn't already being stored off anywhere. As an extension later, it would be nice if someone were to add support for printing this as part of the modules list.
- Allow reading the per-thread data pointer via ptrace. I have added support for Linux here. I'll be happy to add support for FreeBSD once this is reviewed. OS X does not appear to have __thread variables, so maybe we don't need it there. Windows support should eventually be workable along the same lines.
- Make DWARF expressions track which module they originated from.
- Add support for the DW_OP_GNU_push_tls_address DWARF opcode, as generated by gcc and recent versions of clang. Earlier versions of clang (such as 3.2, which is default on Ubuntu right now) do not generate TLS debug info correctly so can not be supported here.
- Understand the format of the pthread DTV block. This is where it gets tricky. We have three basic options here:
1) Call "dlinfo" or "__tls_get_addr" on the inferior and ask it directly. However this won't work on core dumps, and generally speaking it's not a good idea for the debugger to call functions itself, as it has the potential to not work depending on the state of the target.
2) Use libthread_db. This is what GDB does. However this option requires having a version of libthread_db on the host cross-compiled for each potential target. This places a large burden on the user, and would make it very hard to cross-debug from Windows to Linux, for example. Trying to build a library intended exclusively for one OS on a different one is not pleasant. GDB sidesteps the problem and asks the user to figure it out.
3) Parse the DTV structure ourselves. On initial inspection this seems to be a bad option, as the DTV structure (the format used by the runtime to manage TLS data) is not in fact a kernel data structure, it is implemented entirely in useerland in libc. Therefore the layout of it's fields are version and OS dependent, and are not standardized.
However, it turns out not to be such a problem. All OSes use basically the same algorithm (a per-module lookup table) as detailed in Ulrich Drepper's TLS ELF ABI document, so we can easily write code to decode it ourselves. The only question therefore is the exact field layouts required. Happily, the implementors of libpthread expose the structure of the DTV via metadata exported as symbols from the .so itself, designed exactly for this kind of thing. So this patch simply reads that metadata in, and re-implements libthread_db's algorithm itself. We thereby get cross-platform TLS lookup without either requiring third-party libraries, while still being independent of the version of libpthread being used.
Test case included.
llvm-svn: 192922
2013-10-18 05:14:00 +08:00
|
|
|
return LLDB_INVALID_ADDRESS;
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::SafeToCallFunctions() {
|
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (process) {
|
|
|
|
SystemRuntime *runtime = process->GetSystemRuntime();
|
|
|
|
if (runtime) {
|
|
|
|
return runtime->SafeToCallFunctionsOnThisThread(shared_from_this());
|
2014-05-14 06:02:48 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
return true;
|
2014-05-14 06:02:48 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP
|
2016-09-07 04:57:50 +08:00
|
|
|
Thread::GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr) {
|
|
|
|
return GetStackFrameList()->GetStackFrameSPForStackFramePtr(stack_frame_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Thread::StopReasonAsCString(lldb::StopReason reason) {
|
|
|
|
switch (reason) {
|
|
|
|
case eStopReasonInvalid:
|
|
|
|
return "invalid";
|
|
|
|
case eStopReasonNone:
|
|
|
|
return "none";
|
|
|
|
case eStopReasonTrace:
|
|
|
|
return "trace";
|
|
|
|
case eStopReasonBreakpoint:
|
|
|
|
return "breakpoint";
|
|
|
|
case eStopReasonWatchpoint:
|
|
|
|
return "watchpoint";
|
|
|
|
case eStopReasonSignal:
|
|
|
|
return "signal";
|
|
|
|
case eStopReasonException:
|
|
|
|
return "exception";
|
|
|
|
case eStopReasonExec:
|
|
|
|
return "exec";
|
|
|
|
case eStopReasonPlanComplete:
|
|
|
|
return "plan complete";
|
|
|
|
case eStopReasonThreadExiting:
|
|
|
|
return "thread exiting";
|
|
|
|
case eStopReasonInstrumentation:
|
|
|
|
return "instrumentation break";
|
|
|
|
}
|
|
|
|
|
|
|
|
static char unknown_state_string[64];
|
|
|
|
snprintf(unknown_state_string, sizeof(unknown_state_string),
|
|
|
|
"StopReason = %i", reason);
|
|
|
|
return unknown_state_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Thread::RunModeAsCString(lldb::RunMode mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case eOnlyThisThread:
|
|
|
|
return "only this thread";
|
|
|
|
case eAllThreads:
|
|
|
|
return "all threads";
|
|
|
|
case eOnlyDuringStepping:
|
|
|
|
return "only during stepping";
|
|
|
|
}
|
|
|
|
|
|
|
|
static char unknown_state_string[64];
|
|
|
|
snprintf(unknown_state_string, sizeof(unknown_state_string), "RunMode = %i",
|
|
|
|
mode);
|
|
|
|
return unknown_state_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Thread::GetStatus(Stream &strm, uint32_t start_frame,
|
2016-11-09 04:36:40 +08:00
|
|
|
uint32_t num_frames, uint32_t num_frames_with_source,
|
2017-06-13 00:25:24 +08:00
|
|
|
bool stop_format, bool only_stacks) {
|
|
|
|
|
|
|
|
if (!only_stacks) {
|
|
|
|
ExecutionContext exe_ctx(shared_from_this());
|
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
|
|
|
strm.Indent();
|
|
|
|
bool is_selected = false;
|
|
|
|
if (process) {
|
|
|
|
if (process->GetThreadList().GetSelectedThread().get() == this)
|
|
|
|
is_selected = true;
|
|
|
|
}
|
|
|
|
strm.Printf("%c ", is_selected ? '*' : ' ');
|
|
|
|
if (target && target->GetDebugger().GetUseExternalEditor()) {
|
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
|
|
|
|
if (frame_sp) {
|
|
|
|
SymbolContext frame_sc(
|
|
|
|
frame_sp->GetSymbolContext(eSymbolContextLineEntry));
|
|
|
|
if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) {
|
|
|
|
Host::OpenFileInExternalEditor(frame_sc.line_entry.file,
|
|
|
|
frame_sc.line_entry.line);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-13 00:25:24 +08:00
|
|
|
DumpUsingSettingsFormat(strm, start_frame, stop_format);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-06-13 00:25:24 +08:00
|
|
|
size_t num_frames_shown = 0;
|
2016-09-07 04:57:50 +08:00
|
|
|
if (num_frames > 0) {
|
|
|
|
strm.IndentMore();
|
|
|
|
|
|
|
|
const bool show_frame_info = true;
|
2017-06-13 00:25:24 +08:00
|
|
|
const bool show_frame_unique = only_stacks;
|
2016-09-07 04:57:50 +08:00
|
|
|
const char *selected_frame_marker = nullptr;
|
2017-06-13 00:25:24 +08:00
|
|
|
if (num_frames == 1 || only_stacks ||
|
2016-09-07 04:57:50 +08:00
|
|
|
(GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID()))
|
|
|
|
strm.IndentMore();
|
|
|
|
else
|
|
|
|
selected_frame_marker = "* ";
|
2010-11-12 03:26:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
num_frames_shown = GetStackFrameList()->GetStatus(
|
|
|
|
strm, start_frame, num_frames, show_frame_info, num_frames_with_source,
|
2017-06-13 00:25:24 +08:00
|
|
|
show_frame_unique, selected_frame_marker);
|
2016-09-07 04:57:50 +08:00
|
|
|
if (num_frames == 1)
|
|
|
|
strm.IndentLess();
|
|
|
|
strm.IndentLess();
|
|
|
|
}
|
|
|
|
return num_frames_shown;
|
2010-11-12 03:26:09 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool Thread::GetDescription(Stream &strm, lldb::DescriptionLevel level,
|
|
|
|
bool print_json_thread, bool print_json_stopinfo) {
|
2016-11-09 04:36:40 +08:00
|
|
|
const bool stop_format = false;
|
|
|
|
DumpUsingSettingsFormat(strm, 0, stop_format);
|
2016-09-07 04:57:50 +08:00
|
|
|
strm.Printf("\n");
|
2010-11-12 03:26:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
StructuredData::ObjectSP thread_info = GetExtendedInfo();
|
2010-11-12 03:26:09 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (print_json_thread || print_json_stopinfo) {
|
|
|
|
if (thread_info && print_json_thread) {
|
|
|
|
thread_info->Dump(strm);
|
|
|
|
strm.Printf("\n");
|
2012-02-21 08:09:25 +08:00
|
|
|
}
|
2015-04-09 05:19:12 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
if (print_json_stopinfo && m_stop_info_sp) {
|
|
|
|
StructuredData::ObjectSP stop_info = m_stop_info_sp->GetExtendedInfo();
|
|
|
|
if (stop_info) {
|
|
|
|
stop_info->Dump(strm);
|
|
|
|
strm.Printf("\n");
|
|
|
|
}
|
2014-06-13 10:37:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (thread_info) {
|
|
|
|
StructuredData::ObjectSP activity =
|
|
|
|
thread_info->GetObjectForDotSeparatedPath("activity");
|
|
|
|
StructuredData::ObjectSP breadcrumb =
|
|
|
|
thread_info->GetObjectForDotSeparatedPath("breadcrumb");
|
|
|
|
StructuredData::ObjectSP messages =
|
|
|
|
thread_info->GetObjectForDotSeparatedPath("trace_messages");
|
|
|
|
|
|
|
|
bool printed_activity = false;
|
2017-05-29 16:25:46 +08:00
|
|
|
if (activity && activity->GetType() == eStructuredDataTypeDictionary) {
|
2016-09-07 04:57:50 +08:00
|
|
|
StructuredData::Dictionary *activity_dict = activity->GetAsDictionary();
|
|
|
|
StructuredData::ObjectSP id = activity_dict->GetValueForKey("id");
|
|
|
|
StructuredData::ObjectSP name = activity_dict->GetValueForKey("name");
|
2017-05-29 16:25:46 +08:00
|
|
|
if (name && name->GetType() == eStructuredDataTypeString && id &&
|
|
|
|
id->GetType() == eStructuredDataTypeInteger) {
|
2017-05-12 13:49:54 +08:00
|
|
|
strm.Format(" Activity '{0}', {1:x}\n",
|
|
|
|
name->GetAsString()->GetValue(),
|
2016-09-07 04:57:50 +08:00
|
|
|
id->GetAsInteger()->GetValue());
|
|
|
|
}
|
|
|
|
printed_activity = true;
|
|
|
|
}
|
|
|
|
bool printed_breadcrumb = false;
|
2017-05-29 16:25:46 +08:00
|
|
|
if (breadcrumb && breadcrumb->GetType() == eStructuredDataTypeDictionary) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (printed_activity)
|
|
|
|
strm.Printf("\n");
|
|
|
|
StructuredData::Dictionary *breadcrumb_dict =
|
|
|
|
breadcrumb->GetAsDictionary();
|
|
|
|
StructuredData::ObjectSP breadcrumb_text =
|
|
|
|
breadcrumb_dict->GetValueForKey("name");
|
|
|
|
if (breadcrumb_text &&
|
2017-05-29 16:25:46 +08:00
|
|
|
breadcrumb_text->GetType() == eStructuredDataTypeString) {
|
2017-05-12 13:49:54 +08:00
|
|
|
strm.Format(" Current Breadcrumb: {0}\n",
|
|
|
|
breadcrumb_text->GetAsString()->GetValue());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
printed_breadcrumb = true;
|
|
|
|
}
|
2017-05-29 16:25:46 +08:00
|
|
|
if (messages && messages->GetType() == eStructuredDataTypeArray) {
|
2016-09-07 04:57:50 +08:00
|
|
|
if (printed_breadcrumb)
|
|
|
|
strm.Printf("\n");
|
|
|
|
StructuredData::Array *messages_array = messages->GetAsArray();
|
|
|
|
const size_t msg_count = messages_array->GetSize();
|
|
|
|
if (msg_count > 0) {
|
|
|
|
strm.Printf(" %zu trace messages:\n", msg_count);
|
|
|
|
for (size_t i = 0; i < msg_count; i++) {
|
|
|
|
StructuredData::ObjectSP message = messages_array->GetItemAtIndex(i);
|
2017-05-29 16:25:46 +08:00
|
|
|
if (message && message->GetType() == eStructuredDataTypeDictionary) {
|
2016-09-07 04:57:50 +08:00
|
|
|
StructuredData::Dictionary *message_dict =
|
|
|
|
message->GetAsDictionary();
|
|
|
|
StructuredData::ObjectSP message_text =
|
|
|
|
message_dict->GetValueForKey("message");
|
|
|
|
if (message_text &&
|
2017-05-29 16:25:46 +08:00
|
|
|
message_text->GetType() == eStructuredDataTypeString) {
|
2017-05-12 13:49:54 +08:00
|
|
|
strm.Format(" {0}\n", message_text->GetAsString()->GetValue());
|
2013-04-03 04:32:37 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-16 08:09:33 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Thread::GetStackFrameStatus(Stream &strm, uint32_t first_frame,
|
|
|
|
uint32_t num_frames, bool show_frame_info,
|
|
|
|
uint32_t num_frames_with_source) {
|
|
|
|
return GetStackFrameList()->GetStatus(
|
|
|
|
strm, first_frame, num_frames, show_frame_info, num_frames_with_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
Unwind *Thread::GetUnwinder() {
|
2019-02-13 14:25:41 +08:00
|
|
|
if (!m_unwinder_up) {
|
2016-09-07 04:57:50 +08:00
|
|
|
const ArchSpec target_arch(CalculateTarget()->GetArchitecture());
|
|
|
|
const llvm::Triple::ArchType machine = target_arch.GetMachine();
|
|
|
|
switch (machine) {
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
case llvm::Triple::aarch64:
|
|
|
|
case llvm::Triple::thumb:
|
|
|
|
case llvm::Triple::mips:
|
|
|
|
case llvm::Triple::mipsel:
|
|
|
|
case llvm::Triple::mips64:
|
|
|
|
case llvm::Triple::mips64el:
|
|
|
|
case llvm::Triple::ppc:
|
|
|
|
case llvm::Triple::ppc64:
|
2017-10-06 03:44:05 +08:00
|
|
|
case llvm::Triple::ppc64le:
|
2016-09-07 04:57:50 +08:00
|
|
|
case llvm::Triple::systemz:
|
|
|
|
case llvm::Triple::hexagon:
|
2019-02-13 14:25:41 +08:00
|
|
|
m_unwinder_up.reset(new UnwindLLDB(*this));
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
|
2019-02-13 14:25:41 +08:00
|
|
|
m_unwinder_up.reset(new UnwindMacOSXFrameBackchain(*this));
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-13 14:25:41 +08:00
|
|
|
return m_unwinder_up.get();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::Flush() {
|
|
|
|
ClearStackFrames();
|
|
|
|
m_reg_context_sp.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::IsStillAtLastBreakpointHit() {
|
|
|
|
// If we are currently stopped at a breakpoint, always return that stopinfo
|
2018-05-01 00:49:04 +08:00
|
|
|
// and don't reset it. This allows threads to maintain their breakpoint
|
|
|
|
// stopinfo, such as when thread-stepping in multithreaded programs.
|
2016-09-07 04:57:50 +08:00
|
|
|
if (m_stop_info_sp) {
|
|
|
|
StopReason stop_reason = m_stop_info_sp->GetStopReason();
|
|
|
|
if (stop_reason == lldb::eStopReasonBreakpoint) {
|
|
|
|
uint64_t value = m_stop_info_sp->GetValue();
|
|
|
|
lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
|
|
|
|
if (reg_ctx_sp) {
|
|
|
|
lldb::addr_t pc = reg_ctx_sp->GetPC();
|
|
|
|
BreakpointSiteSP bp_site_sp =
|
|
|
|
GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
|
|
|
|
if (bp_site_sp && static_cast<break_id_t>(value) == bp_site_sp->GetID())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::StepIn(bool source_step,
|
|
|
|
LazyBool step_in_avoids_code_without_debug_info,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info)
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
{
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (StateIsStoppedState(process->GetState(), true)) {
|
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(0);
|
|
|
|
ThreadPlanSP new_plan_sp;
|
|
|
|
const lldb::RunMode run_mode = eOnlyThisThread;
|
|
|
|
const bool abort_other_plans = false;
|
|
|
|
|
|
|
|
if (source_step && frame_sp && frame_sp->HasDebugInformation()) {
|
|
|
|
SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
|
|
|
|
new_plan_sp = QueueThreadPlanForStepInRange(
|
2018-11-15 09:18:15 +08:00
|
|
|
abort_other_plans, sc.line_entry, sc, nullptr, run_mode, error,
|
2016-09-07 04:57:50 +08:00
|
|
|
step_in_avoids_code_without_debug_info,
|
|
|
|
step_out_avoids_code_without_debug_info);
|
|
|
|
} else {
|
|
|
|
new_plan_sp = QueueThreadPlanForStepSingleInstruction(
|
2018-11-15 09:18:15 +08:00
|
|
|
false, abort_other_plans, run_mode, error);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
|
|
|
|
|
|
|
// Why do we need to set the current thread by ID here???
|
|
|
|
process->GetThreadList().SetSelectedThreadByID(GetID());
|
|
|
|
error = process->Resume();
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("process not stopped");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::StepOver(bool source_step,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (StateIsStoppedState(process->GetState(), true)) {
|
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(0);
|
|
|
|
ThreadPlanSP new_plan_sp;
|
|
|
|
|
|
|
|
const lldb::RunMode run_mode = eOnlyThisThread;
|
|
|
|
const bool abort_other_plans = false;
|
|
|
|
|
|
|
|
if (source_step && frame_sp && frame_sp->HasDebugInformation()) {
|
|
|
|
SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
|
|
|
|
new_plan_sp = QueueThreadPlanForStepOverRange(
|
2018-11-15 09:18:15 +08:00
|
|
|
abort_other_plans, sc.line_entry, sc, run_mode, error,
|
2016-09-07 04:57:50 +08:00
|
|
|
step_out_avoids_code_without_debug_info);
|
|
|
|
} else {
|
|
|
|
new_plan_sp = QueueThreadPlanForStepSingleInstruction(
|
2018-11-15 09:18:15 +08:00
|
|
|
true, abort_other_plans, run_mode, error);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
|
|
|
|
|
|
|
// Why do we need to set the current thread by ID here???
|
|
|
|
process->GetThreadList().SetSelectedThreadByID(GetID());
|
|
|
|
error = process->Resume();
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("process not stopped");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::StepOut() {
|
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (StateIsStoppedState(process->GetState(), true)) {
|
|
|
|
const bool first_instruction = false;
|
|
|
|
const bool stop_other_threads = false;
|
|
|
|
const bool abort_other_plans = false;
|
|
|
|
|
|
|
|
ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut(
|
|
|
|
abort_other_plans, nullptr, first_instruction, stop_other_threads,
|
2018-11-15 09:18:15 +08:00
|
|
|
eVoteYes, eVoteNoOpinion, 0, error));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
|
|
|
|
|
|
|
// Why do we need to set the current thread by ID here???
|
|
|
|
process->GetThreadList().SetSelectedThreadByID(GetID());
|
|
|
|
error = process->Resume();
|
|
|
|
} else {
|
|
|
|
error.SetErrorString("process not stopped");
|
|
|
|
}
|
|
|
|
return error;
|
2014-03-13 10:47:14 +08:00
|
|
|
}
|
2018-11-29 06:01:52 +08:00
|
|
|
|
|
|
|
ValueObjectSP Thread::GetCurrentException() {
|
2018-12-20 10:01:59 +08:00
|
|
|
if (auto frame_sp = GetStackFrameAtIndex(0))
|
|
|
|
if (auto recognized_frame = frame_sp->GetRecognizedFrame())
|
|
|
|
if (auto e = recognized_frame->GetExceptionObject())
|
|
|
|
return e;
|
|
|
|
|
2019-05-15 09:46:45 +08:00
|
|
|
// NOTE: Even though this behavior is generalized, only ObjC is actually
|
|
|
|
// supported at the moment.
|
2019-05-30 02:08:22 +08:00
|
|
|
for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) {
|
|
|
|
if (auto e = runtime->GetExceptionObjectForThread(shared_from_this()))
|
|
|
|
return e;
|
2019-05-15 09:46:45 +08:00
|
|
|
}
|
2018-11-29 06:01:52 +08:00
|
|
|
|
2018-12-20 10:01:59 +08:00
|
|
|
return ValueObjectSP();
|
2018-11-29 06:01:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ThreadSP Thread::GetCurrentExceptionBacktrace() {
|
2018-12-20 10:01:59 +08:00
|
|
|
ValueObjectSP exception = GetCurrentException();
|
2019-05-15 09:46:45 +08:00
|
|
|
if (!exception)
|
|
|
|
return ThreadSP();
|
2018-12-20 10:01:59 +08:00
|
|
|
|
2019-05-15 09:46:45 +08:00
|
|
|
// NOTE: Even though this behavior is generalized, only ObjC is actually
|
|
|
|
// supported at the moment.
|
2019-05-30 02:08:22 +08:00
|
|
|
for (LanguageRuntime *runtime : GetProcess()->GetLanguageRuntimes()) {
|
|
|
|
if (auto bt = runtime->GetBacktraceThreadFromException(exception))
|
|
|
|
return bt;
|
2019-05-15 09:46:45 +08:00
|
|
|
}
|
2018-12-20 10:01:59 +08:00
|
|
|
|
2019-05-15 09:46:45 +08:00
|
|
|
return ThreadSP();
|
2018-12-20 10:01:59 +08:00
|
|
|
}
|