[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- Thread.cpp --------------------------------------------------------===//
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Target/Thread.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"
|
2019-10-04 06:50:18 +08:00
|
|
|
#include "lldb/Core/StructuredDataImpl.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"
|
|
|
|
#include "lldb/Target/ThreadPlanCallFunction.h"
|
2014-09-30 07:17:18 +08:00
|
|
|
#include "lldb/Target/ThreadPlanPython.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadPlanRunToAddress.h"
|
2020-03-11 07:18:11 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStack.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Target/ThreadPlanStepInRange.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepInstruction.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOut.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepOverRange.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepThrough.h"
|
|
|
|
#include "lldb/Target/ThreadPlanStepUntil.h"
|
2010-06-16 10:00:15 +08:00
|
|
|
#include "lldb/Target/ThreadSpec.h"
|
2020-03-09 21:36:15 +08:00
|
|
|
#include "lldb/Target/UnwindLLDB.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;
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
const ThreadPropertiesSP &Thread::GetGlobalProperties() {
|
2016-02-27 07:20:08 +08:00
|
|
|
// 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-02-27 07:20:08 +08:00
|
|
|
return *g_settings_sp_ptr;
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_thread
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "TargetProperties.inc"
|
2012-08-23 01:17:09 +08:00
|
|
|
|
|
|
|
enum {
|
2019-07-26 05:36:37 +08:00
|
|
|
#define LLDB_PROPERTIES_thread
|
2019-07-30 01:22:10 +08:00
|
|
|
#include "TargetPropertiesEnum.inc"
|
2012-08-23 01:17:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class ThreadOptionValueProperties : public OptionValueProperties {
|
|
|
|
public:
|
2019-03-07 05:22:25 +08:00
|
|
|
ThreadOptionValueProperties(ConstString name)
|
2012-08-23 01:17:09 +08:00
|
|
|
: OptionValueProperties(name) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
// 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)
|
2012-08-23 02:39:03 +08:00
|
|
|
: OptionValueProperties(*global_properties->GetValueProperties()) {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
|
|
|
|
bool will_modify,
|
|
|
|
uint32_t idx) const override {
|
2014-07-02 05:22:11 +08:00
|
|
|
// 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.
|
2012-08-23 01:17:09 +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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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"));
|
2019-07-30 00:41:30 +08:00
|
|
|
m_collection_sp->Initialize(g_thread_properties);
|
2012-08-23 01:17:09 +08:00
|
|
|
} 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
|
|
|
|
|
|
|
const RegularExpression *ThreadProperties::GetSymbolsToAvoidRegexp() {
|
|
|
|
const uint32_t idx = ePropertyStepAvoidRegex;
|
2015-12-15 09:33:19 +08:00
|
|
|
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 {
|
2014-01-24 05:52:47 +08:00
|
|
|
const uint32_t idx = ePropertyStepAvoidLibraries;
|
2019-04-24 04:17:04 +08:00
|
|
|
const OptionValueFileSpecList *option_value =
|
2015-12-15 09:33:19 +08:00
|
|
|
m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
|
|
|
|
false, idx);
|
2014-01-24 05:52:47 +08:00
|
|
|
assert(option_value);
|
|
|
|
return option_value->GetCurrentValue();
|
|
|
|
}
|
|
|
|
|
2012-08-23 01:17:09 +08:00
|
|
|
bool ThreadProperties::GetTraceEnabledState() const {
|
|
|
|
const uint32_t idx = ePropertyEnableThreadTrace;
|
2015-12-15 09:33:19 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_thread_properties[idx].default_uint_value != 0);
|
2012-08-23 01:17:09 +08:00
|
|
|
}
|
|
|
|
|
2014-03-13 10:47:14 +08:00
|
|
|
bool ThreadProperties::GetStepInAvoidsNoDebug() const {
|
|
|
|
const uint32_t idx = ePropertyStepInAvoidsNoDebug;
|
2015-12-15 09:33:19 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_thread_properties[idx].default_uint_value != 0);
|
2014-03-13 10:47:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ThreadProperties::GetStepOutAvoidsNoDebug() const {
|
|
|
|
const uint32_t idx = ePropertyStepOutAvoidsNoDebug;
|
2015-12-15 09:33:19 +08:00
|
|
|
return m_collection_sp->GetPropertyAtIndexAsBoolean(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_thread_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(
|
2019-07-30 00:41:30 +08:00
|
|
|
nullptr, idx, g_thread_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() {
|
2012-10-11 02:32:14 +08:00
|
|
|
static ConstString g_flavor("Thread::ThreadEventData");
|
|
|
|
return g_flavor;
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread::ThreadEventData::ThreadEventData(const lldb::ThreadSP thread_sp)
|
|
|
|
: m_thread_sp(thread_sp), m_stack_id() {}
|
|
|
|
|
|
|
|
Thread::ThreadEventData::ThreadEventData(const lldb::ThreadSP thread_sp,
|
|
|
|
const StackID &stack_id)
|
|
|
|
: m_thread_sp(thread_sp), m_stack_id(stack_id) {}
|
|
|
|
|
|
|
|
Thread::ThreadEventData::ThreadEventData() : m_thread_sp(), m_stack_id() {}
|
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
Thread::ThreadEventData::~ThreadEventData() = default;
|
2012-10-11 02:32:14 +08:00
|
|
|
|
|
|
|
void Thread::ThreadEventData::Dump(Stream *s) const {}
|
|
|
|
|
|
|
|
const Thread::ThreadEventData *
|
|
|
|
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());
|
|
|
|
}
|
2015-12-15 09:33:19 +08:00
|
|
|
return nullptr;
|
2012-10-11 02:32:14 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP
|
2012-10-11 02:32:14 +08:00
|
|
|
Thread::ThreadEventData::GetStackFrameFromEvent(const Event *event_ptr) {
|
|
|
|
const ThreadEventData *event_data = GetEventDataFromEvent(event_ptr);
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP frame_sp;
|
2012-10-11 02:32:14 +08:00
|
|
|
if (event_data) {
|
|
|
|
ThreadSP thread_sp = event_data->GetThread();
|
|
|
|
if (thread_sp) {
|
|
|
|
frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID(
|
|
|
|
event_data->GetStackID());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-11 02:32:14 +08:00
|
|
|
return frame_sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Thread class
|
|
|
|
|
|
|
|
ConstString &Thread::GetStaticBroadcasterClass() {
|
|
|
|
static ConstString class_name("lldb.thread");
|
|
|
|
return class_name;
|
|
|
|
}
|
|
|
|
|
2016-05-18 09:59:10 +08:00
|
|
|
Thread::Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id)
|
|
|
|
: ThreadProperties(false), UserID(tid),
|
|
|
|
Broadcaster(process.GetTarget().GetDebugger().GetBroadcasterManager(),
|
|
|
|
Thread::GetStaticBroadcasterClass().AsCString()),
|
|
|
|
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(),
|
2020-03-11 07:18:11 +08:00
|
|
|
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),
|
|
|
|
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),
|
|
|
|
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
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
CheckInWithManager();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
Thread::~Thread() {
|
2013-03-28 07:08:40 +08:00
|
|
|
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());
|
2010-11-18 10:47:07 +08:00
|
|
|
/// If you hit this assert, it means your derived class forgot to call
|
|
|
|
/// DoDestroy in its destructor.
|
|
|
|
assert(m_destroy_called);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-11-18 10:47:07 +08:00
|
|
|
void Thread::DestroyThread() {
|
2012-10-30 04:52:08 +08:00
|
|
|
m_destroy_called = true;
|
2013-05-09 09:55:29 +08:00
|
|
|
m_stop_info_sp.reset();
|
2012-10-30 04:52:08 +08:00
|
|
|
m_reg_context_sp.reset();
|
2019-02-13 14:25:41 +08:00
|
|
|
m_unwinder_up.reset();
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
|
2012-10-30 04:52:08 +08:00
|
|
|
m_curr_frames_sp.reset();
|
|
|
|
m_prev_frames_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
void Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) {
|
|
|
|
if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged))
|
|
|
|
BroadcastEvent(eBroadcastBitSelectedFrameChanged,
|
|
|
|
new ThreadEventData(this->shared_from_this(), new_frame_id));
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP Thread::GetSelectedFrame() {
|
2015-08-06 11:27:10 +08:00
|
|
|
StackFrameListSP stack_frame_list_sp(GetStackFrameList());
|
|
|
|
StackFrameSP frame_sp = stack_frame_list_sp->GetFrameAtIndex(
|
|
|
|
stack_frame_list_sp->GetSelectedFrameIndex());
|
2020-05-22 07:22:01 +08:00
|
|
|
FrameSelectedCallback(frame_sp.get());
|
2015-08-06 11:27:10 +08:00
|
|
|
return frame_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
uint32_t Thread::SetSelectedFrame(lldb_private::StackFrame *frame,
|
|
|
|
bool broadcast) {
|
2012-10-11 02:32:14 +08:00
|
|
|
uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
|
|
|
|
if (broadcast)
|
|
|
|
BroadcastSelectedFrameChange(frame->GetStackID());
|
2020-05-22 07:22:01 +08:00
|
|
|
FrameSelectedCallback(frame);
|
2012-10-11 02:32:14 +08:00
|
|
|
return ret_value;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
bool Thread::SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast) {
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex(frame_idx));
|
2012-10-11 02:32:14 +08:00
|
|
|
if (frame_sp) {
|
|
|
|
GetStackFrameList()->SetSelectedFrame(frame_sp.get());
|
|
|
|
if (broadcast)
|
|
|
|
BroadcastSelectedFrameChange(frame_sp->GetStackID());
|
2020-05-22 07:22:01 +08:00
|
|
|
FrameSelectedCallback(frame_sp.get());
|
2012-10-11 02:32:14 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2012-10-11 02:32:14 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
bool Thread::SetSelectedFrameByIndexNoisily(uint32_t frame_idx,
|
2013-02-01 05:46:01 +08:00
|
|
|
Stream &output_stream) {
|
2012-10-11 02:32:14 +08:00
|
|
|
const bool broadcast = true;
|
2013-02-01 05:46:01 +08:00
|
|
|
bool success = SetSelectedFrameByIndex(frame_idx, broadcast);
|
|
|
|
if (success) {
|
2012-10-11 02:32:14 +08:00
|
|
|
StackFrameSP frame_sp = GetSelectedFrame();
|
|
|
|
if (frame_sp) {
|
2013-02-01 05:46:01 +08:00
|
|
|
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) {
|
2012-10-11 02:32:14 +08:00
|
|
|
already_shown = Host::OpenFileInExternalEditor(
|
2010-06-09 00:52:24 +08:00
|
|
|
frame_sc.line_entry.file, frame_sc.line_entry.line);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool show_frame_info = true;
|
|
|
|
bool show_source = !already_shown;
|
2020-05-22 07:22:01 +08:00
|
|
|
FrameSelectedCallback(frame_sp.get());
|
2010-06-09 00:52:24 +08:00
|
|
|
return frame_sp->GetStatus(output_stream, show_frame_info, show_source);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-11 02:32:14 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2012-10-11 02:32:14 +08:00
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-05-22 07:22:01 +08:00
|
|
|
void Thread::FrameSelectedCallback(StackFrame *frame) {
|
|
|
|
if (!frame)
|
|
|
|
return;
|
|
|
|
|
2020-05-22 08:42:24 +08:00
|
|
|
if (frame->HasDebugInformation() &&
|
|
|
|
(GetProcess()->GetWarningsOptimization() ||
|
|
|
|
GetProcess()->GetWarningsUnsupportedLanguage())) {
|
2010-11-18 10:47:07 +08:00
|
|
|
SymbolContext sc =
|
|
|
|
frame->GetSymbolContext(eSymbolContextFunction | eSymbolContextModule);
|
|
|
|
GetProcess()->PrintWarningOptimization(sc);
|
2020-05-22 08:42:24 +08:00
|
|
|
GetProcess()->PrintWarningUnsupportedLanguage(sc);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-11-18 10:47:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::StopInfoSP Thread::GetStopInfo() {
|
|
|
|
if (m_destroy_called)
|
|
|
|
return m_stop_info_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-15 19:42:47 +08:00
|
|
|
ThreadPlanSP completed_plan_sp(GetCompletedPlan());
|
2012-02-21 08:09:25 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
2013-10-19 01:11:02 +08:00
|
|
|
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());
|
2013-10-19 01:11:02 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 05:37:52 +08:00
|
|
|
void Thread::CalculatePublicStopInfo() {
|
|
|
|
ResetStopInfo();
|
|
|
|
SetStopInfo(GetStopInfo());
|
|
|
|
}
|
|
|
|
|
2013-10-19 01:11:02 +08:00
|
|
|
lldb::StopInfoSP Thread::GetPrivateStopInfo() {
|
2012-10-30 04:52:08 +08:00
|
|
|
if (m_destroy_called)
|
2010-11-18 10:47:07 +08:00
|
|
|
return m_stop_info_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-11-18 10:47:07 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
2013-05-09 09:55:29 +08:00
|
|
|
if (process_sp) {
|
2010-11-18 10:47:07 +08:00
|
|
|
const uint32_t process_stop_id = process_sp->GetStopID();
|
2013-05-14 23:20:12 +08:00
|
|
|
if (m_stop_info_stop_id != process_stop_id) {
|
2013-05-09 09:55:29 +08:00
|
|
|
if (m_stop_info_sp) {
|
2010-11-18 10:47:07 +08:00
|
|
|
if (m_stop_info_sp->IsValid() || IsStillAtLastBreakpointHit() ||
|
|
|
|
GetCurrentPlan()->IsVirtualStep())
|
2013-05-14 23:20:12 +08:00
|
|
|
SetStopInfo(m_stop_info_sp);
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2010-11-18 10:47:07 +08:00
|
|
|
m_stop_info_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
if (!m_stop_info_sp) {
|
2013-07-30 08:23:06 +08:00
|
|
|
if (!CalculateStopInfo())
|
2013-05-14 23:20:12 +08:00
|
|
|
SetStopInfo(StopInfoSP());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2020-05-15 04:08:01 +08:00
|
|
|
// Architecture::OverrideStopInfo() for more information on the stop
|
2018-05-01 00:49:04 +08:00
|
|
|
// info override callback.
|
2013-07-30 08:23:06 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-09 09:55:29 +08:00
|
|
|
return m_stop_info_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-11-12 03:26:09 +08:00
|
|
|
lldb::StopReason Thread::GetStopReason() {
|
2013-07-30 08:23:06 +08:00
|
|
|
lldb::StopInfoSP stop_info_sp(GetStopInfo());
|
2012-09-25 10:40:06 +08:00
|
|
|
if (stop_info_sp)
|
2012-09-28 23:55:43 +08:00
|
|
|
return stop_info_sp->GetStopReason();
|
2012-09-25 10:40:06 +08:00
|
|
|
return eStopReasonNone;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-07-18 07:42:28 +08:00
|
|
|
bool Thread::StopInfoIsUpToDate() const {
|
2012-02-21 08:09:25 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
2013-05-09 09:55:29 +08:00
|
|
|
if (process_sp)
|
|
|
|
return m_stop_info_stop_id == process_sp->GetStopID();
|
|
|
|
else
|
2012-10-30 04:52:08 +08:00
|
|
|
return true; // Process is no longer around so stop info is always up to
|
2016-05-18 09:59:10 +08:00
|
|
|
// date...
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-02-15 19:42:47 +08:00
|
|
|
void Thread::ResetStopInfo() {
|
|
|
|
if (m_stop_info_sp) {
|
|
|
|
m_stop_info_sp.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
void Thread::SetStopInfo(const lldb::StopInfoSP &stop_info_sp) {
|
2013-05-09 09:55:29 +08:00
|
|
|
m_stop_info_sp = stop_info_sp;
|
2012-10-11 02:32:14 +08:00
|
|
|
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);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
|
|
|
if (process_sp)
|
|
|
|
m_stop_info_stop_id = process_sp->GetStopID();
|
2016-09-07 04:57:50 +08:00
|
|
|
else
|
2012-10-11 02:32:14 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-10-11 02:32:14 +08:00
|
|
|
void Thread::SetShouldReportStop(Vote vote) {
|
|
|
|
if (vote == eVoteNoOpinion)
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
else {
|
2012-10-11 02:32:14 +08:00
|
|
|
m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo);
|
2014-12-10 07:31:02 +08:00
|
|
|
if (m_stop_info_sp)
|
2013-05-09 09:55:29 +08:00
|
|
|
m_stop_info_sp->OverrideShouldNotify(m_override_should_notify ==
|
|
|
|
eLazyBoolYes);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2015-08-06 11:27:10 +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.
|
2015-08-06 11:27:10 +08:00
|
|
|
SetStopInfo(
|
|
|
|
StopInfo::CreateStopReasonWithSignal(*this, LLDB_INVALID_SIGNAL_NUMBER));
|
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
bool Thread::ThreadStoppedForAReason(void) {
|
2012-10-11 02:32:14 +08:00
|
|
|
return (bool)GetPrivateStopInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Thread::CheckpointThreadState(ThreadStateCheckpoint &saved_state) {
|
2013-11-04 17:33:30 +08:00
|
|
|
saved_state.register_backup_sp.reset();
|
|
|
|
lldb::StackFrameSP frame_sp(GetStackFrameAtIndex(0));
|
2012-10-11 02:32:14 +08:00
|
|
|
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());
|
2015-08-06 11:27:10 +08:00
|
|
|
if (reg_ctx_sp && reg_ctx_sp->ReadAllRegisterValues(*reg_checkpoint_sp))
|
2012-10-11 02:32:14 +08:00
|
|
|
saved_state.register_backup_sp = reg_checkpoint_sp;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-11-14 07:28:31 +08:00
|
|
|
if (!saved_state.register_backup_sp)
|
2012-10-11 02:32:14 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-01-20 10:03:18 +08:00
|
|
|
saved_state.stop_info_sp = GetStopInfo();
|
2012-02-21 08:09:25 +08:00
|
|
|
ProcessSP process_sp(GetProcess());
|
2015-07-18 07:42:28 +08:00
|
|
|
if (process_sp)
|
2012-02-21 08:09:25 +08:00
|
|
|
saved_state.orig_stop_id = process_sp->GetStopID();
|
2012-09-08 07:36:43 +08:00
|
|
|
saved_state.current_inlined_depth = GetCurrentInlinedDepth();
|
2020-03-11 07:18:11 +08:00
|
|
|
saved_state.m_completed_plan_checkpoint =
|
|
|
|
GetPlans().CheckpointCompletedPlans();
|
2017-05-29 16:25:46 +08:00
|
|
|
|
2015-07-18 07:42:28 +08:00
|
|
|
return true;
|
2012-10-11 02:32:14 +08:00
|
|
|
}
|
|
|
|
|
2013-02-01 05:46:01 +08:00
|
|
|
bool Thread::RestoreRegisterStateFromCheckpoint(
|
|
|
|
ThreadStateCheckpoint &saved_state) {
|
|
|
|
if (saved_state.register_backup_sp) {
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP frame_sp(GetStackFrameAtIndex(0));
|
2013-02-01 05:46:01 +08:00
|
|
|
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);
|
|
|
|
|
|
|
|
// 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();
|
2013-02-01 05:46:01 +08:00
|
|
|
return ret;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-11-27 07:52:18 +08:00
|
|
|
bool Thread::RestoreThreadStateFromCheckpoint(
|
2011-01-20 10:03:18 +08:00
|
|
|
ThreadStateCheckpoint &saved_state) {
|
2011-01-25 10:47:23 +08:00
|
|
|
if (saved_state.stop_info_sp)
|
2013-02-01 05:46:01 +08:00
|
|
|
saved_state.stop_info_sp->MakeStopInfoValid();
|
2011-01-20 10:03:18 +08:00
|
|
|
SetStopInfo(saved_state.stop_info_sp);
|
2013-02-01 05:46:01 +08:00
|
|
|
GetStackFrameList()->SetCurrentInlinedDepth(
|
|
|
|
saved_state.current_inlined_depth);
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().RestoreCompletedPlanCheckpoint(
|
|
|
|
saved_state.m_completed_plan_checkpoint);
|
2015-07-18 07:42:28 +08:00
|
|
|
return true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
StateType Thread::GetState() const {
|
|
|
|
// If any other threads access this we will need a mutex for it
|
2013-02-01 05:46:01 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
return m_state;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Thread::SetState(StateType state) {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_state_mutex);
|
2010-06-09 00:52:24 +08:00
|
|
|
m_state = state;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-02-05 00:53:26 +08:00
|
|
|
std::string Thread::GetStopDescription() {
|
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(0);
|
|
|
|
|
|
|
|
if (!frame_sp)
|
|
|
|
return GetStopDescriptionRaw();
|
|
|
|
|
|
|
|
auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
|
|
|
|
|
|
|
|
if (!recognized_frame_sp)
|
|
|
|
return GetStopDescriptionRaw();
|
|
|
|
|
|
|
|
std::string recognized_stop_description =
|
|
|
|
recognized_frame_sp->GetStopDescription();
|
|
|
|
|
|
|
|
if (!recognized_stop_description.empty())
|
|
|
|
return recognized_stop_description;
|
|
|
|
|
|
|
|
return GetStopDescriptionRaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Thread::GetStopDescriptionRaw() {
|
|
|
|
StopInfoSP stop_info_sp = GetStopInfo();
|
|
|
|
std::string raw_stop_description;
|
2020-02-06 13:47:33 +08:00
|
|
|
if (stop_info_sp && stop_info_sp->IsValid()) {
|
2020-02-05 00:53:26 +08:00
|
|
|
raw_stop_description = stop_info_sp->GetDescription();
|
2020-02-06 13:47:33 +08:00
|
|
|
assert((!raw_stop_description.empty() ||
|
|
|
|
stop_info_sp->GetStopReason() == eStopReasonNone) &&
|
|
|
|
"StopInfo returned an empty description.");
|
|
|
|
}
|
2020-02-05 00:53:26 +08:00
|
|
|
return raw_stop_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::SelectMostRelevantFrame() {
|
|
|
|
Log *log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD);
|
|
|
|
|
|
|
|
auto frames_list_sp = GetStackFrameList();
|
|
|
|
|
|
|
|
// Only the top frame should be recognized.
|
|
|
|
auto frame_sp = frames_list_sp->GetFrameAtIndex(0);
|
|
|
|
|
|
|
|
auto recognized_frame_sp = frame_sp->GetRecognizedFrame();
|
|
|
|
|
|
|
|
if (!recognized_frame_sp) {
|
|
|
|
LLDB_LOG(log, "Frame #0 not recognized");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (StackFrameSP most_relevant_frame_sp =
|
|
|
|
recognized_frame_sp->GetMostRelevantFrame()) {
|
|
|
|
LLDB_LOG(log, "Found most relevant frame at index {0}",
|
|
|
|
most_relevant_frame_sp->GetFrameIndex());
|
|
|
|
SetSelectedFrame(most_relevant_frame_sp.get());
|
|
|
|
} else {
|
|
|
|
LLDB_LOG(log, "No relevant frame!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Thread::WillStop() {
|
|
|
|
ThreadPlan *current_plan = GetCurrentPlan();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-02-05 00:53:26 +08:00
|
|
|
SelectMostRelevantFrame();
|
|
|
|
|
2013-02-01 05:46:01 +08:00
|
|
|
// FIXME: I may decide to disallow threads with no plans. In which
|
|
|
|
// case this should go to an assert.
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (!current_plan)
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
current_plan->WillStop();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Thread::SetupForResume() {
|
|
|
|
if (GetResumeState() != eStateSuspended) {
|
2013-02-01 05:46:01 +08:00
|
|
|
// 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
|
|
|
|
2013-02-01 05:46:01 +08:00
|
|
|
lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
|
2013-11-14 07:28:31 +08:00
|
|
|
if (reg_ctx_sp) {
|
2014-12-10 07:31:02 +08:00
|
|
|
const addr_t thread_pc = reg_ctx_sp->GetPC();
|
|
|
|
BreakpointSiteSP bp_site_sp =
|
2013-02-01 05:46:01 +08:00
|
|
|
GetProcess()->GetBreakpointSiteList().FindByAddress(thread_pc);
|
2013-04-03 04:32:37 +08:00
|
|
|
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
|
|
|
|
2013-04-03 04:32:37 +08:00
|
|
|
ThreadPlan *cur_plan = GetCurrentPlan();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-10 07:31:02 +08:00
|
|
|
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;
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2014-12-10 07:31:02 +08:00
|
|
|
push_step_over_bp_plan = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-12-10 07:31:02 +08:00
|
|
|
if (push_step_over_bp_plan) {
|
2014-09-30 07:17:18 +08:00
|
|
|
ThreadPlanSP step_bp_plan_sp(new ThreadPlanStepOverBreakpoint(*this));
|
|
|
|
if (step_bp_plan_sp) {
|
|
|
|
step_bp_plan_sp->SetPrivate(true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-03 04:32:37 +08:00
|
|
|
if (GetCurrentPlan()->RunState() != eStateStepping) {
|
2014-09-30 07:17:18 +08:00
|
|
|
ThreadPlanStepOverBreakpoint *step_bp_plan =
|
|
|
|
static_cast<ThreadPlanStepOverBreakpoint *>(
|
|
|
|
step_bp_plan_sp.get());
|
2013-04-03 04:32:37 +08:00
|
|
|
step_bp_plan->SetAutoContinue(true);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
QueueThreadPlan(step_bp_plan_sp, false);
|
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
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
}
|
|
|
|
|
2015-08-06 11:27:10 +08:00
|
|
|
bool Thread::ShouldResume(StateType resume_state) {
|
2015-08-07 05:54:29 +08:00
|
|
|
// At this point clear the completed plan stack.
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().WillResume();
|
2015-08-07 05:54:29 +08:00
|
|
|
m_override_should_notify = eLazyBoolCalculate;
|
2015-08-06 11:27:10 +08:00
|
|
|
|
2010-08-04 09:40:35 +08:00
|
|
|
StateType prev_resume_state = GetTemporaryResumeState();
|
2013-07-30 08:23:06 +08:00
|
|
|
|
2010-10-20 08:39:53 +08:00
|
|
|
SetTemporaryResumeState(resume_state);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-20 08:39:53 +08:00
|
|
|
lldb::ThreadSP backing_thread_sp(GetBackingThread());
|
|
|
|
if (backing_thread_sp)
|
2015-11-07 06:45:57 +08:00
|
|
|
backing_thread_sp->SetTemporaryResumeState(resume_state);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-10-20 08:39:53 +08:00
|
|
|
// Make sure m_stop_info_sp is valid. Don't do this for threads we suspended
|
2013-05-08 02:35:34 +08:00
|
|
|
// in the previous run.
|
|
|
|
if (prev_resume_state != eStateSuspended)
|
|
|
|
GetPrivateStopInfo();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-01 07:09:20 +08:00
|
|
|
// 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
|
2012-02-01 07:09:20 +08:00
|
|
|
// about the fact that we are resuming...
|
2013-05-08 02:35:34 +08:00
|
|
|
const uint32_t process_stop_id = GetProcess()->GetStopID();
|
2012-05-02 02:38:37 +08:00
|
|
|
if (m_stop_info_stop_id == process_stop_id &&
|
|
|
|
(m_stop_info_sp && m_stop_info_sp->IsValid())) {
|
2014-07-08 09:07:32 +08:00
|
|
|
StopInfo *stop_info = GetPrivateStopInfo().get();
|
|
|
|
if (stop_info)
|
|
|
|
stop_info->WillResume(resume_state);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-07-08 09:07:32 +08:00
|
|
|
// 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
|
|
|
|
2013-04-20 08:27:58 +08:00
|
|
|
bool need_to_resume = false;
|
2014-07-08 09:07:32 +08:00
|
|
|
ThreadPlan *plan_ptr = GetCurrentPlan();
|
2013-04-20 08:27:58 +08:00
|
|
|
if (plan_ptr) {
|
2014-07-08 09:07:32 +08:00
|
|
|
need_to_resume = plan_ptr->WillResume(resume_state, true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-08 09:07:32 +08:00
|
|
|
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
|
|
|
|
2013-05-09 09:55:29 +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
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
if (need_to_resume && resume_state != eStateSuspended) {
|
|
|
|
m_stop_info_sp.reset();
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
if (need_to_resume) {
|
2013-11-14 07:28:31 +08:00
|
|
|
ClearStackFrames();
|
2013-05-02 05:54:04 +08:00
|
|
|
// Let Thread subclasses do any special work they need to prior to resuming
|
2013-04-20 08:27:58 +08:00
|
|
|
WillResume(resume_state);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-01 09:02:41 +08:00
|
|
|
return need_to_resume;
|
2013-05-09 09:55:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::DidResume() { SetResumeSignal(LLDB_INVALID_SIGNAL_NUMBER); }
|
2013-07-30 08:23:06 +08:00
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
void Thread::DidStop() { SetState(eStateStopped); }
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool Thread::ShouldStop(Event *event_ptr) {
|
|
|
|
ThreadPlan *current_plan = GetCurrentPlan();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool should_stop = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-02-01 07:09:20 +08:00
|
|
|
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());
|
2013-11-14 07:28:31 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-01 07:09:20 +08:00
|
|
|
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());
|
2012-02-01 07:09:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
// 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.
|
2013-05-14 23:20:12 +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);
|
2012-02-01 07:09:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ^^^^^^^^");
|
2010-06-09 00:52:24 +08:00
|
|
|
StreamString s;
|
2011-10-15 08:23:43 +08:00
|
|
|
s.IndentMore();
|
2020-03-19 03:05:08 +08:00
|
|
|
GetProcess()->DumpThreadPlansForTID(
|
|
|
|
s, GetID(), eDescriptionLevelVerbose, true /* internal */,
|
|
|
|
false /* condense_trivial */, true /* skip_unreported */);
|
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
|
|
|
}
|
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
// The top most plan always gets to do the trace log...
|
2010-11-12 03:26:09 +08:00
|
|
|
current_plan->DoTraceLog();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-04-21 05:16:56 +08:00
|
|
|
// 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.
|
2013-05-14 23:20:12 +08:00
|
|
|
StopInfoSP private_stop_info(GetPrivateStopInfo());
|
2015-12-15 09:33:19 +08:00
|
|
|
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.");
|
2012-02-01 07:09:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
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.
|
2012-09-06 05:12:49 +08:00
|
|
|
if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr))
|
2012-02-01 07:09:20 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
// Before the plans see the state of the world, calculate the current inlined
|
2012-09-06 05:12:49 +08:00
|
|
|
// depth.
|
|
|
|
GetStackFrameList()->CalculateCurrentInlinedDepth();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-12-03 09:52:59 +08:00
|
|
|
// 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
|
|
|
|
2011-12-03 09:52:59 +08:00
|
|
|
bool done_processing_current_plan = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-05-14 23:20:12 +08:00
|
|
|
if (!current_plan->PlanExplainsStop(event_ptr)) {
|
2011-12-03 09:52:59 +08:00
|
|
|
if (current_plan->TracerExplainsStop()) {
|
|
|
|
done_processing_current_plan = true;
|
|
|
|
should_stop = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
} 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.
|
2011-12-03 09:52:59 +08:00
|
|
|
ThreadPlan *plan_ptr = current_plan;
|
2015-12-15 09:33:19 +08:00
|
|
|
while ((plan_ptr = GetPreviousPlan(plan_ptr)) != nullptr) {
|
2013-02-09 09:29:05 +08:00
|
|
|
if (plan_ptr->PlanExplainsStop(event_ptr)) {
|
2011-12-03 09:52:59 +08:00
|
|
|
should_stop = plan_ptr->ShouldStop(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
|
2011-12-03 09:52:59 +08:00
|
|
|
if (plan_ptr->MischiefManaged()) {
|
2012-05-12 07:49:49 +08:00
|
|
|
// We're going to pop the plans up to and including the plan that
|
|
|
|
// explains the stop.
|
2012-05-12 07:47:32 +08:00
|
|
|
ThreadPlan *prev_plan_ptr = GetPreviousPlan(plan_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
do {
|
2013-05-14 23:20:12 +08:00
|
|
|
if (should_stop)
|
2011-12-03 09:52:59 +08:00
|
|
|
current_plan->WillStop();
|
|
|
|
PopPlan();
|
2013-05-09 09:55:29 +08:00
|
|
|
} 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.
|
2011-12-03 09:52:59 +08:00
|
|
|
done_processing_current_plan =
|
2015-12-15 09:33:19 +08:00
|
|
|
(plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2011-12-03 09:52:59 +08:00
|
|
|
done_processing_current_plan = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
break;
|
2013-05-08 02:35:34 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-03 09:52:59 +08:00
|
|
|
if (!done_processing_current_plan) {
|
2010-06-19 12:45:32 +08:00
|
|
|
bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
|
2011-02-08 13:20:59 +08:00
|
|
|
// We're starting from the base plan, so just let it decide;
|
2020-03-11 07:18:11 +08:00
|
|
|
if (current_plan->IsBasePlan()) {
|
2011-02-08 13:20:59 +08:00
|
|
|
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) {
|
2020-03-11 07:18:11 +08:00
|
|
|
if (current_plan->IsBasePlan())
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
|
2011-02-08 13:20:59 +08:00
|
|
|
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);
|
2011-02-08 13:20:59 +08:00
|
|
|
if (current_plan->MischiefManaged()) {
|
2011-12-03 09:52:59 +08:00
|
|
|
if (should_stop)
|
|
|
|
current_plan->WillStop();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
|
2011-02-08 13:20:59 +08:00
|
|
|
if (should_stop && current_plan->IsMasterPlan() &&
|
|
|
|
!current_plan->OkayToDiscard()) {
|
2011-12-03 09:52:59 +08:00
|
|
|
PopPlan();
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
} else {
|
2011-12-03 09:52:59 +08:00
|
|
|
PopPlan();
|
2014-12-10 07:31:02 +08:00
|
|
|
|
|
|
|
current_plan = GetCurrentPlan();
|
|
|
|
if (current_plan == nullptr) {
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
if (over_ride_stop)
|
2011-12-03 09:52:59 +08:00
|
|
|
should_stop = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-09 09:55:29 +08:00
|
|
|
// 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
|
|
|
|
2011-12-03 09:52:59 +08:00
|
|
|
if (should_stop) {
|
2014-10-08 09:03:54 +08:00
|
|
|
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
|
2020-03-11 07:18:11 +08:00
|
|
|
while (!plan_ptr->IsBasePlan()) {
|
2013-05-09 09:55:29 +08:00
|
|
|
bool stale = plan_ptr->IsPlanStale();
|
2014-10-08 09:03:54 +08:00
|
|
|
ThreadPlan *examined_plan = plan_ptr;
|
|
|
|
plan_ptr = GetPreviousPlan(examined_plan);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-10-08 09:03:54 +08:00
|
|
|
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) {
|
2010-06-09 00:52:24 +08:00
|
|
|
StreamString s;
|
2011-10-15 08:23:43 +08:00
|
|
|
s.IndentMore();
|
2020-03-19 03:05:08 +08:00
|
|
|
GetProcess()->DumpThreadPlansForTID(
|
|
|
|
s, GetID(), eDescriptionLevelVerbose, true /* internal */,
|
|
|
|
false /* condense_trivial */, true /* skip_unreported */);
|
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
|
|
|
}
|
2013-05-09 09:55:29 +08:00
|
|
|
return should_stop;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Vote Thread::ShouldReportStop(Event *event_ptr) {
|
|
|
|
StateType thread_state = GetResumeState();
|
2012-02-01 07:09:20 +08:00
|
|
|
StateType temp_thread_state = GetTemporaryResumeState();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-09-04 01:10:42 +08:00
|
|
|
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);
|
2010-06-09 00:52:24 +08:00
|
|
|
return eVoteNoOpinion;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
if (temp_thread_state == eStateSuspended ||
|
2012-02-01 07:09:20 +08:00
|
|
|
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);
|
2012-09-25 10:40:06 +08:00
|
|
|
return eVoteNoOpinion;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
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);
|
2010-06-09 00:52:24 +08:00
|
|
|
return eVoteNoOpinion;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
if (GetPlans().AnyCompletedPlans()) {
|
|
|
|
// Pass skip_private = false to GetCompletedPlan, since we want to ask
|
|
|
|
// the last plan, regardless of whether it is private or not.
|
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());
|
2020-03-11 07:18:11 +08:00
|
|
|
return GetPlans().GetCompletedPlan(false)->ShouldReportStop(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2012-09-25 10:40:06 +08:00
|
|
|
Vote thread_vote = eVoteNoOpinion;
|
2014-10-08 09:03:54 +08:00
|
|
|
ThreadPlan *plan_ptr = GetCurrentPlan();
|
2019-05-24 08:44:33 +08:00
|
|
|
while (true) {
|
2012-09-25 10:40:06 +08:00
|
|
|
if (plan_ptr->PlanExplainsStop(event_ptr)) {
|
2013-02-09 09:29:05 +08:00
|
|
|
thread_vote = plan_ptr->ShouldReportStop(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
2020-03-11 07:18:11 +08:00
|
|
|
if (plan_ptr->IsBasePlan())
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
else
|
2013-02-09 09:29:05 +08:00
|
|
|
plan_ptr = GetPreviousPlan(plan_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
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
|
|
|
|
2012-09-25 10:40:06 +08:00
|
|
|
return thread_vote;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
}
|
|
|
|
|
2015-07-18 07:42:28 +08:00
|
|
|
Vote Thread::ShouldReportRun(Event *event_ptr) {
|
|
|
|
StateType thread_state = GetResumeState();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-07-18 07:42:28 +08:00
|
|
|
if (thread_state == eStateSuspended || thread_state == eStateInvalid) {
|
|
|
|
return eVoteNoOpinion;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-07-18 07:42:28 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2020-03-11 07:18:11 +08:00
|
|
|
if (GetPlans().AnyCompletedPlans()) {
|
|
|
|
// Pass skip_private = false to GetCompletedPlan, since we want to ask
|
|
|
|
// the last plan, regardless of whether it is private or not.
|
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()),
|
2020-03-11 07:18:11 +08:00
|
|
|
GetCompletedPlan()->GetName());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
return GetPlans().GetCompletedPlan(false)->ShouldReportRun(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
} 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
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
return GetCurrentPlan()->ShouldReportRun(event_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2015-07-18 07:42:28 +08:00
|
|
|
}
|
2012-09-25 10:40:06 +08:00
|
|
|
|
2011-01-20 10:03:18 +08:00
|
|
|
bool Thread::MatchesSpec(const ThreadSpec *spec) {
|
2013-05-09 09:55:29 +08:00
|
|
|
return (spec == nullptr) ? true : spec->ThreadPassesBasicTests(*this);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlanStack &Thread::GetPlans() const {
|
|
|
|
ThreadPlanStack *plans = GetProcess()->FindThreadPlans(GetID());
|
2020-03-19 03:05:08 +08:00
|
|
|
if (plans)
|
|
|
|
return *plans;
|
|
|
|
|
|
|
|
// History threads don't have a thread plan, but they do ask get asked to
|
|
|
|
// describe themselves, which usually involves pulling out the stop reason.
|
|
|
|
// That in turn will check for a completed plan on the ThreadPlanStack.
|
|
|
|
// Instead of special-casing at that point, we return a Stack with a
|
|
|
|
// ThreadPlanNull as its base plan. That will give the right answers to the
|
|
|
|
// queries GetDescription makes, and only assert if you try to run the thread.
|
|
|
|
if (!m_null_plan_stack_up)
|
|
|
|
m_null_plan_stack_up.reset(new ThreadPlanStack(*this, true));
|
|
|
|
return *(m_null_plan_stack_up.get());
|
2020-03-11 07:18:11 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
void Thread::PushPlan(ThreadPlanSP thread_plan_sp) {
|
|
|
|
assert(thread_plan_sp && "Don't push an empty thread plan.");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
|
|
|
if (log) {
|
|
|
|
StreamString s;
|
|
|
|
thread_plan_sp->GetDescription(&s, lldb::eDescriptionLevelFull);
|
|
|
|
LLDB_LOGF(log, "Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
static_cast<void *>(this), s.GetData(),
|
|
|
|
thread_plan_sp->GetThread().GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-03-11 07:18:11 +08:00
|
|
|
|
|
|
|
GetPlans().PushPlan(std::move(thread_plan_sp));
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
void Thread::PopPlan() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlanSP popped_plan_sp = GetPlans().PopPlan();
|
|
|
|
if (log) {
|
|
|
|
LLDB_LOGF(log, "Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
popped_plan_sp->GetName(), popped_plan_sp->GetThread().GetID());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2011-01-20 10:03:18 +08:00
|
|
|
void Thread::DiscardPlan() {
|
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_STEP));
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlanSP discarded_plan_sp = GetPlans().PopPlan();
|
2011-01-20 10:03:18 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
LLDB_LOGF(log, "Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".",
|
|
|
|
discarded_plan_sp->GetName(),
|
|
|
|
discarded_plan_sp->GetThread().GetID());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlan *Thread::GetCurrentPlan() const {
|
|
|
|
return GetPlans().GetCurrentPlan().get();
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlanSP Thread::GetCompletedPlan() const {
|
|
|
|
return GetPlans().GetCompletedPlan();
|
2012-11-27 07:52:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ValueObjectSP Thread::GetReturnValueObject() const {
|
|
|
|
return GetPlans().GetReturnValueObject();
|
2011-01-20 10:03:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ExpressionVariableSP Thread::GetExpressionVariable() const {
|
|
|
|
return GetPlans().GetExpressionVariable();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
bool Thread::IsThreadPlanDone(ThreadPlan *plan) const {
|
|
|
|
return GetPlans().IsPlanDone(plan);
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
bool Thread::WasThreadPlanDiscarded(ThreadPlan *plan) const {
|
|
|
|
return GetPlans().WasPlanDiscarded(plan);
|
2017-02-15 19:42:47 +08:00
|
|
|
}
|
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
bool Thread::CompletedPlanOverridesBreakpoint() const {
|
|
|
|
return GetPlans().AnyCompletedPlans();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlan *Thread::GetPreviousPlan(ThreadPlan *current_plan) const{
|
|
|
|
return GetPlans().GetPreviousPlan(current_plan);
|
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;
|
|
|
|
}
|
|
|
|
|
2014-12-10 07:31:02 +08:00
|
|
|
if (abort_other_plans)
|
2014-09-30 07:17:18 +08:00
|
|
|
DiscardThreadPlans(true);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-04-03 04:32:37 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
void Thread::EnableTracer(bool value, bool single_stepping) {
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().EnableTracer(value, single_stepping);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-04-20 08:27:58 +08:00
|
|
|
|
2015-12-15 09:33:19 +08:00
|
|
|
void Thread::SetTracer(lldb::ThreadPlanTracerSP &tracer_sp) {
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().SetTracer(tracer_sp);
|
2013-04-20 08:27:58 +08:00
|
|
|
}
|
2012-09-01 09:02:41 +08:00
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
bool Thread::DiscardUserThreadPlansUpToIndex(uint32_t plan_index) {
|
2013-05-02 05:54:04 +08:00
|
|
|
// 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
|
|
|
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlan *up_to_plan_ptr = GetPlans().GetPlanByIndex(plan_index).get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (up_to_plan_ptr == nullptr)
|
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
DiscardThreadPlansUpToPlan(up_to_plan_ptr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-05-11 01:19:04 +08:00
|
|
|
void Thread::DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp) {
|
|
|
|
DiscardThreadPlansUpToPlan(up_to_plan_sp.get());
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
void Thread::DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr) {
|
2013-06-22 08:27:45 +08:00
|
|
|
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));
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().DiscardPlansUpToPlan(up_to_plan_ptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-11-06 03:25:48 +08:00
|
|
|
void Thread::DiscardThreadPlans(bool force) {
|
2012-02-01 07:09:20 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
if (force) {
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().DiscardAllPlans();
|
2013-05-02 05:54:04 +08:00
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2020-03-11 07:18:11 +08:00
|
|
|
GetPlans().DiscardConsultingMasterPlans();
|
2012-02-01 07:09:20 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::UnwindInnermostExpression() {
|
|
|
|
Status error;
|
2020-03-11 07:18:11 +08:00
|
|
|
ThreadPlan *innermost_expr_plan = GetPlans().GetInnermostExpression();
|
|
|
|
if (!innermost_expr_plan) {
|
|
|
|
error.SetErrorString("No expressions currently active on this thread");
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
DiscardThreadPlansUpToPlan(innermost_expr_plan);
|
2013-02-01 05:46:01 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2010-11-12 03:26:09 +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;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-04-04 12:06:10 +08:00
|
|
|
|
2012-04-21 05:16:56 +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) {
|
2012-04-21 05:16:56 +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);
|
2012-04-21 05:16:56 +08:00
|
|
|
return thread_plan_sp;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2012-05-12 07:47:32 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepOverRange(
|
2014-10-08 09:03:54 +08:00
|
|
|
bool abort_other_plans, const AddressRange &range,
|
2013-05-02 05:54:04 +08:00
|
|
|
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) {
|
2014-07-08 09:07:32 +08:00
|
|
|
ThreadPlanSP thread_plan_sp;
|
2019-02-12 07:13:08 +08:00
|
|
|
thread_plan_sp = std::make_shared<ThreadPlanStepOverRange>(
|
2012-05-04 05:19:36 +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);
|
2013-07-19 05:48:26 +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.
|
2015-12-15 08:40:30 +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);
|
2015-12-15 08:40:30 +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);
|
2015-12-15 08:40:30 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 02:39:37 +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,
|
2015-10-24 02:39:37 +08:00
|
|
|
LazyBool step_in_avoids_code_without_debug_info,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
2014-09-30 07:17:18 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(
|
|
|
|
new ThreadPlanStepInRange(*this, range, addr_context, stop_other_threads,
|
2014-03-13 10:47:14 +08:00
|
|
|
step_in_avoids_code_without_debug_info,
|
2014-09-30 07:17:18 +08:00
|
|
|
step_out_avoids_code_without_debug_info));
|
|
|
|
ThreadPlanStepInRange *plan =
|
|
|
|
static_cast<ThreadPlanStepInRange *>(thread_plan_sp.get());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
if (step_in_target)
|
|
|
|
plan->SetStepInTarget(step_in_target);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2013-07-19 05:48:26 +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.
|
|
|
|
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,
|
2015-12-15 08:40:30 +08:00
|
|
|
LazyBool step_in_avoids_code_without_debug_info,
|
2016-01-09 05:40:11 +08:00
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
2019-05-07 04:01:21 +08:00
|
|
|
const bool include_inlined_functions = false;
|
2011-01-21 14:11:58 +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,
|
2011-01-21 14:11:58 +08:00
|
|
|
step_in_avoids_code_without_debug_info,
|
2016-01-09 05:40:11 +08:00
|
|
|
step_out_avoids_code_without_debug_info);
|
2014-03-13 10:47:14 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-10-24 02:39:37 +08:00
|
|
|
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) {
|
2014-09-30 07:17:18 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanStepOut(
|
2012-08-01 06:19:25 +08:00
|
|
|
*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote,
|
2012-05-10 09:35:39 +08:00
|
|
|
frame_idx, step_out_avoids_code_without_debug_info));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +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-08-24 01:55:21 +08:00
|
|
|
const bool calculate_return_value =
|
2010-06-09 00:52:24 +08:00
|
|
|
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,
|
2012-10-11 02:32:14 +08:00
|
|
|
frame_idx, eLazyBoolNo, continue_to_next_branch, calculate_return_value));
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
ThreadPlanStepOut *new_plan =
|
2010-06-09 00:52:24 +08:00
|
|
|
static_cast<ThreadPlanStepOut *>(thread_plan_sp.get());
|
|
|
|
new_plan->ClearShouldStopHereCallbacks();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-07-19 05:48:26 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForStepThrough(StackID &return_stack_id,
|
2015-10-24 02:39:37 +08:00
|
|
|
bool abort_other_plans,
|
2018-11-15 09:18:15 +08:00
|
|
|
bool stop_other_threads,
|
|
|
|
Status &status) {
|
2012-05-10 09:35:39 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(
|
|
|
|
new ThreadPlanStepThrough(*this, return_stack_id, stop_other_threads));
|
2010-06-09 00:52:24 +08:00
|
|
|
if (!thread_plan_sp || !thread_plan_sp->ValidatePlan(nullptr))
|
2014-03-13 10:47:14 +08:00
|
|
|
return ThreadPlanSP();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-15 09:18:15 +08:00
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2013-07-19 05:48:26 +08:00
|
|
|
return thread_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
ThreadPlanSP Thread::QueueThreadPlanForRunToAddress(bool abort_other_plans,
|
|
|
|
Address &target_addr,
|
2018-11-15 09:18:15 +08:00
|
|
|
bool stop_other_threads,
|
|
|
|
Status &status) {
|
2012-05-10 09:35:39 +08:00
|
|
|
ThreadPlanSP thread_plan_sp(
|
2014-03-13 10:47:14 +08:00
|
|
|
new ThreadPlanRunToAddress(*this, target_addr, stop_other_threads));
|
2018-11-15 09:18:15 +08:00
|
|
|
|
|
|
|
status = QueueThreadPlan(thread_plan_sp, abort_other_plans);
|
2013-07-19 05:48:26 +08:00
|
|
|
return thread_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
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) {
|
2011-01-21 14:11:58 +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);
|
2013-07-19 05:48:26 +08:00
|
|
|
return thread_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
lldb::ThreadPlanSP Thread::QueueThreadPlanForStepScripted(
|
2019-10-04 06:50:18 +08:00
|
|
|
bool abort_other_plans, const char *class_name,
|
|
|
|
StructuredData::ObjectSP extra_args_sp, bool stop_other_threads,
|
2018-11-15 09:18:15 +08:00
|
|
|
Status &status) {
|
2019-10-04 06:50:18 +08:00
|
|
|
|
|
|
|
StructuredDataImpl *extra_args_impl = nullptr;
|
|
|
|
if (extra_args_sp) {
|
|
|
|
extra_args_impl = new StructuredDataImpl();
|
|
|
|
extra_args_impl->SetObjectSP(extra_args_sp);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadPlanSP thread_plan_sp(new ThreadPlanPython(*this, class_name,
|
|
|
|
extra_args_impl));
|
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
|
|
|
}
|
|
|
|
|
2014-09-30 07:17:18 +08:00
|
|
|
uint32_t Thread::GetIndexID() const { return m_index_id; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
TargetSP Thread::CalculateTarget() {
|
2012-02-21 08:09:25 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ProcessSP Thread::CalculateProcess() { return GetProcess(); }
|
|
|
|
|
2012-02-18 13:35:26 +08:00
|
|
|
ThreadSP Thread::CalculateThread() { return shared_from_this(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP Thread::CalculateStackFrame() { return StackFrameSP(); }
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-10-04 09:05:56 +08:00
|
|
|
void Thread::CalculateExecutionContext(ExecutionContext &exe_ctx) {
|
2012-02-21 08:09:25 +08:00
|
|
|
exe_ctx.SetContext(shared_from_this());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2010-08-25 08:35:26 +08:00
|
|
|
StackFrameListSP Thread::GetStackFrameList() {
|
2016-05-18 09:59:10 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void Thread::ClearStackFrames() {
|
2016-05-18 09:59:10 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> guard(m_frame_mutex);
|
2012-03-29 09:41:38 +08:00
|
|
|
|
2020-03-09 21:10:41 +08:00
|
|
|
GetUnwinder().Clear();
|
2013-05-02 05:54:04 +08:00
|
|
|
|
2012-02-29 11:40:22 +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())
|
2011-08-13 05:40:01 +08:00
|
|
|
m_prev_frames_sp.swap(m_curr_frames_sp);
|
|
|
|
m_curr_frames_sp.reset();
|
2014-06-13 10:37:02 +08:00
|
|
|
|
|
|
|
m_extended_info.reset();
|
|
|
|
m_extended_info_fetched = false;
|
2010-08-12 10:14:28 +08:00
|
|
|
}
|
|
|
|
|
2011-01-07 06:15:06 +08:00
|
|
|
lldb::StackFrameSP Thread::GetFrameWithConcreteFrameIndex(uint32_t unwind_idx) {
|
2012-03-29 09:41:38 +08:00
|
|
|
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) {
|
2013-11-04 17:33:30 +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
|
|
|
|
|
|
|
if (!frame_sp) {
|
2013-02-01 05:46:01 +08:00
|
|
|
return_error.SetErrorStringWithFormat(
|
2012-09-12 08:40:39 +08:00
|
|
|
"Could not find frame with index %d in thread 0x%" PRIx64 ".",
|
2012-09-27 09:15:29 +08:00
|
|
|
frame_idx, GetID());
|
|
|
|
}
|
|
|
|
|
2013-04-03 04:32:37 +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
|
|
|
|
|
|
|
if (!frame_sp) {
|
|
|
|
return_error.SetErrorString("Can't return to a null frame.");
|
|
|
|
return return_error;
|
|
|
|
}
|
|
|
|
|
2010-10-04 09:05:56 +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);
|
2012-02-21 08:09:25 +08:00
|
|
|
if (!older_frame_sp) {
|
|
|
|
return_error.SetErrorString("No older frame to return to.");
|
|
|
|
return return_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-02-21 08:09:25 +08:00
|
|
|
if (return_value_sp) {
|
|
|
|
lldb::ABISP abi = thread->GetProcess()->GetABI();
|
2015-12-15 09:33:19 +08:00
|
|
|
if (!abi) {
|
|
|
|
return_error.SetErrorString("Could not find ABI to set return value.");
|
2012-02-21 08:09:25 +08:00
|
|
|
return return_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-09-22 12:58:26 +08:00
|
|
|
SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-09-22 12:58:26 +08:00
|
|
|
// FIXME: ValueObject::Cast doesn't currently work correctly, at least not
|
2012-09-27 09:15:29 +08:00
|
|
|
// for scalars.
|
|
|
|
// Turn that back on when that works.
|
2019-05-24 08:44:33 +08:00
|
|
|
if (/* DISABLES CODE */ (false) && sc.function != nullptr) {
|
2012-09-27 09:15:29 +08:00
|
|
|
Type *function_type = sc.function->GetType();
|
|
|
|
if (function_type) {
|
2015-08-25 07:46:31 +08:00
|
|
|
CompilerType return_type =
|
2011-09-22 12:58:26 +08:00
|
|
|
sc.function->GetCompilerType().GetFunctionReturnType();
|
2012-09-27 09:15:29 +08:00
|
|
|
if (return_type) {
|
2011-09-22 12:58:26 +08:00
|
|
|
StreamString s;
|
2013-07-12 06:46:58 +08:00
|
|
|
return_type.DumpTypeDescription(&s);
|
|
|
|
ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type);
|
2012-09-27 09:15:29 +08:00
|
|
|
if (cast_value_sp) {
|
2011-09-22 12:58:26 +08:00
|
|
|
cast_value_sp->SetFormat(eFormatHex);
|
2012-09-27 09:15:29 +08:00
|
|
|
return_value_sp = cast_value_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-14 10:14:15 +08:00
|
|
|
return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp);
|
2015-02-05 06:00:53 +08:00
|
|
|
if (!return_error.Success())
|
2012-09-12 08:40:39 +08:00
|
|
|
return return_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-02-05 06:00:53 +08:00
|
|
|
StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0);
|
2013-02-01 05:46:01 +08:00
|
|
|
if (youngest_frame_sp) {
|
2013-04-03 04:32:37 +08:00
|
|
|
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();
|
2015-02-05 06:00:53 +08:00
|
|
|
if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged))
|
2013-04-03 04:32:37 +08:00
|
|
|
BroadcastEvent(eBroadcastBitStackChanged,
|
2015-02-05 06:00:53 +08:00
|
|
|
new ThreadEventData(this->shared_from_this()));
|
2016-09-07 04:57:50 +08:00
|
|
|
} else {
|
2013-04-03 04:32:37 +08:00
|
|
|
return_error.SetErrorString("Could not reset register values.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-03 04:32:37 +08:00
|
|
|
return_error.SetErrorString("Frame has no register context.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-02-01 05:46:01 +08:00
|
|
|
return_error.SetErrorString("Returned past top frame.");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2012-09-12 08:40:39 +08:00
|
|
|
return return_error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2015-02-05 06:00:53 +08:00
|
|
|
static void DumpAddressList(Stream &s, const std::vector<Address> &list,
|
2013-09-12 10:20:34 +08:00
|
|
|
ExecutionContextScope *exe_scope) {
|
2015-02-05 06:00:53 +08:00
|
|
|
for (size_t n = 0; n < list.size(); n++) {
|
2013-09-12 10:20:34 +08:00
|
|
|
s << "\t";
|
|
|
|
list[n].Dump(&s, exe_scope, Address::DumpStyleResolvedDescription,
|
|
|
|
Address::DumpStyleSectionNameOffset);
|
|
|
|
s << "\n";
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::JumpToLine(const FileSpec &file, uint32_t line,
|
|
|
|
bool can_leave_function, std::string *warnings) {
|
2013-09-12 10:20:34 +08:00
|
|
|
ExecutionContext exe_ctx(GetStackFrameAtIndex(0));
|
2015-02-05 06:00:53 +08:00
|
|
|
Target *target = exe_ctx.GetTargetPtr();
|
2015-12-15 09:33:19 +08:00
|
|
|
TargetSP target_sp = exe_ctx.GetTargetSP();
|
2013-09-12 10:20:34 +08:00
|
|
|
RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
|
2015-12-15 09:33:19 +08:00
|
|
|
StackFrame *frame = exe_ctx.GetFramePtr();
|
|
|
|
const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-09-12 10:20:34 +08:00
|
|
|
// Find candidate locations.
|
2015-02-05 06:00:53 +08:00
|
|
|
std::vector<Address> candidates, within_function, outside_function;
|
|
|
|
target->GetImages().FindAddressesForLine(target_sp, file, line, sc.function,
|
2013-09-12 10:20:34 +08:00
|
|
|
within_function, outside_function);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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.
|
2013-09-12 10:20:34 +08:00
|
|
|
if (!within_function.empty())
|
|
|
|
candidates = within_function;
|
2015-02-05 06:00:53 +08:00
|
|
|
else if (outside_function.size() == 1 && can_leave_function)
|
2013-09-12 10:20:34 +08:00
|
|
|
candidates = outside_function;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-09-12 10:20:34 +08:00
|
|
|
// 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);
|
2013-09-12 10:20:34 +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 {
|
2013-09-12 10:20:34 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 10:20:34 +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",
|
2015-02-05 06:00:53 +08:00
|
|
|
file.GetFilename().AsCString(), line);
|
2013-09-12 10:20:34 +08:00
|
|
|
DumpAddressList(sstr, candidates, target);
|
2020-01-29 03:23:46 +08:00
|
|
|
*warnings = std::string(sstr.GetString());
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2013-09-12 10:20:34 +08:00
|
|
|
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) {
|
2012-02-21 08:09:25 +08:00
|
|
|
ExecutionContext exe_ctx(shared_from_this());
|
|
|
|
Process *process = exe_ctx.GetProcessPtr();
|
2011-03-11 06:14:10 +08:00
|
|
|
if (process == nullptr)
|
2016-09-07 04:57:50 +08:00
|
|
|
return;
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP frame_sp;
|
2010-10-04 09:05:56 +08:00
|
|
|
SymbolContext frame_sc;
|
2015-01-28 09:17:26 +08:00
|
|
|
if (frame_idx != LLDB_INVALID_FRAME_ID) {
|
2011-09-22 12:58:26 +08:00
|
|
|
frame_sp = GetStackFrameAtIndex(frame_idx);
|
2010-06-09 00:52:24 +08:00
|
|
|
if (frame_sp) {
|
2011-09-22 12:58:26 +08:00
|
|
|
exe_ctx.SetFrameSP(frame_sp);
|
2014-01-28 07:43:24 +08:00
|
|
|
frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2010-10-04 09:05:56 +08:00
|
|
|
assert(thread_format);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-02-05 06:00:53 +08:00
|
|
|
FormatEntity::Format(*thread_format, strm, frame_sp ? &frame_sc : nullptr,
|
2012-11-30 05:49:15 +08:00
|
|
|
&exe_ctx, nullptr, nullptr, false, false);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2011-03-11 06:14:10 +08:00
|
|
|
void Thread::SettingsInitialize() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2011-03-11 06:14:10 +08:00
|
|
|
void Thread::SettingsTerminate() {}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
lldb::addr_t Thread::GetThreadPointer() { return LLDB_INVALID_ADDRESS; }
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-07-02 01:17:23 +08:00
|
|
|
addr_t Thread::GetThreadLocalData(const ModuleSP module,
|
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
|
|
|
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.
|
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
|
|
|
DynamicLoader *loader = GetProcess()->GetDynamicLoader();
|
|
|
|
if (loader)
|
2016-07-02 01:17:23 +08:00
|
|
|
return loader->GetThreadLocalData(module, shared_from_this(),
|
|
|
|
tls_file_addr);
|
2016-09-07 04:57:50 +08:00
|
|
|
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-07-02 01:17:23 +08:00
|
|
|
bool Thread::SafeToCallFunctions() {
|
2014-05-14 06:02:48 +08:00
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (process) {
|
|
|
|
SystemRuntime *runtime = process->GetSystemRuntime();
|
|
|
|
if (runtime) {
|
|
|
|
return runtime->SafeToCallFunctionsOnThisThread(shared_from_this());
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2014-05-14 06:02:48 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-04 17:33:30 +08:00
|
|
|
lldb::StackFrameSP
|
|
|
|
Thread::GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr) {
|
|
|
|
return GetStackFrameList()->GetStackFrameSPForStackFramePtr(stack_frame_ptr);
|
2010-11-12 03:26:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-11-12 03:26:09 +08:00
|
|
|
const char *Thread::StopReasonAsCString(lldb::StopReason reason) {
|
|
|
|
switch (reason) {
|
2012-12-21 07:08:03 +08:00
|
|
|
case eStopReasonInvalid:
|
|
|
|
return "invalid";
|
|
|
|
case eStopReasonNone:
|
|
|
|
return "none";
|
|
|
|
case eStopReasonTrace:
|
|
|
|
return "trace";
|
|
|
|
case eStopReasonBreakpoint:
|
|
|
|
return "breakpoint";
|
LLDB AddressSanitizer instrumentation runtime plugin, breakpint on error and report data extraction
Reviewed at http://reviews.llvm.org/D5592
This patch gives LLDB some ability to interact with AddressSanitizer runtime library, on top of what we already have (historical memory stack traces provided by ASan). Namely, that's the ability to stop on an error caught by ASan, and access the report information that are associated with it. The report information is also exposed into SB API.
More precisely this patch...
adds a new plugin type, InstrumentationRuntime, which should serve as a generic superclass for other instrumentation runtime libraries, these plugins get notified when modules are loaded, so they get a chance to "activate" when a specific dynamic library is loaded
an instance of this plugin type, AddressSanitizerRuntime, which activates itself when it sees the ASan dynamic library or founds ASan statically linked in the executable
adds a collection of these plugins into the Process class
AddressSanitizerRuntime sets an internal breakpoint on __asan::AsanDie(), and when this breakpoint gets hit, it retrieves the report information from ASan
this breakpoint is then exposed as a new StopReason, eStopReasonInstrumentation, with a new StopInfo subclass, InstrumentationRuntimeStopInfo
the StopInfo superclass is extended with a m_extended_info field (it's a StructuredData::ObjectSP), that can hold arbitrary JSON-like data, which is the way the new plugin provides the report data
the "thread info" command now accepts a "-s" flag that prints out the JSON data of a stop reason (same way the "-j" flag works now)
SBThread has a new API, GetStopReasonExtendedInfoAsJSON, which dumps the JSON string into a SBStream
adds a test case for all of this
I plan to also get rid of the original ASan plugin (memory history stack traces) and use an instance of AddressSanitizerRuntime for that purpose.
Kuba
llvm-svn: 219546
2014-10-11 07:43:03 +08:00
|
|
|
case eStopReasonWatchpoint:
|
2012-10-16 08:09:33 +08:00
|
|
|
return "watchpoint";
|
2012-12-21 07:08:03 +08:00
|
|
|
case eStopReasonSignal:
|
|
|
|
return "signal";
|
LLDB AddressSanitizer instrumentation runtime plugin, breakpint on error and report data extraction
Reviewed at http://reviews.llvm.org/D5592
This patch gives LLDB some ability to interact with AddressSanitizer runtime library, on top of what we already have (historical memory stack traces provided by ASan). Namely, that's the ability to stop on an error caught by ASan, and access the report information that are associated with it. The report information is also exposed into SB API.
More precisely this patch...
adds a new plugin type, InstrumentationRuntime, which should serve as a generic superclass for other instrumentation runtime libraries, these plugins get notified when modules are loaded, so they get a chance to "activate" when a specific dynamic library is loaded
an instance of this plugin type, AddressSanitizerRuntime, which activates itself when it sees the ASan dynamic library or founds ASan statically linked in the executable
adds a collection of these plugins into the Process class
AddressSanitizerRuntime sets an internal breakpoint on __asan::AsanDie(), and when this breakpoint gets hit, it retrieves the report information from ASan
this breakpoint is then exposed as a new StopReason, eStopReasonInstrumentation, with a new StopInfo subclass, InstrumentationRuntimeStopInfo
the StopInfo superclass is extended with a m_extended_info field (it's a StructuredData::ObjectSP), that can hold arbitrary JSON-like data, which is the way the new plugin provides the report data
the "thread info" command now accepts a "-s" flag that prints out the JSON data of a stop reason (same way the "-j" flag works now)
SBThread has a new API, GetStopReasonExtendedInfoAsJSON, which dumps the JSON string into a SBStream
adds a test case for all of this
I plan to also get rid of the original ASan plugin (memory history stack traces) and use an instance of AddressSanitizerRuntime for that purpose.
Kuba
llvm-svn: 219546
2014-10-11 07:43:03 +08:00
|
|
|
case eStopReasonException:
|
2010-11-12 03:26:09 +08:00
|
|
|
return "exception";
|
LLDB AddressSanitizer instrumentation runtime plugin, breakpint on error and report data extraction
Reviewed at http://reviews.llvm.org/D5592
This patch gives LLDB some ability to interact with AddressSanitizer runtime library, on top of what we already have (historical memory stack traces provided by ASan). Namely, that's the ability to stop on an error caught by ASan, and access the report information that are associated with it. The report information is also exposed into SB API.
More precisely this patch...
adds a new plugin type, InstrumentationRuntime, which should serve as a generic superclass for other instrumentation runtime libraries, these plugins get notified when modules are loaded, so they get a chance to "activate" when a specific dynamic library is loaded
an instance of this plugin type, AddressSanitizerRuntime, which activates itself when it sees the ASan dynamic library or founds ASan statically linked in the executable
adds a collection of these plugins into the Process class
AddressSanitizerRuntime sets an internal breakpoint on __asan::AsanDie(), and when this breakpoint gets hit, it retrieves the report information from ASan
this breakpoint is then exposed as a new StopReason, eStopReasonInstrumentation, with a new StopInfo subclass, InstrumentationRuntimeStopInfo
the StopInfo superclass is extended with a m_extended_info field (it's a StructuredData::ObjectSP), that can hold arbitrary JSON-like data, which is the way the new plugin provides the report data
the "thread info" command now accepts a "-s" flag that prints out the JSON data of a stop reason (same way the "-j" flag works now)
SBThread has a new API, GetStopReasonExtendedInfoAsJSON, which dumps the JSON string into a SBStream
adds a test case for all of this
I plan to also get rid of the original ASan plugin (memory history stack traces) and use an instance of AddressSanitizerRuntime for that purpose.
Kuba
llvm-svn: 219546
2014-10-11 07:43:03 +08:00
|
|
|
case eStopReasonExec:
|
2012-12-21 07:08:03 +08:00
|
|
|
return "exec";
|
|
|
|
case eStopReasonPlanComplete:
|
2010-06-09 00:52:24 +08:00
|
|
|
return "plan complete";
|
2013-05-02 05:54:04 +08:00
|
|
|
case eStopReasonThreadExiting:
|
2012-12-21 07:08:03 +08:00
|
|
|
return "thread exiting";
|
|
|
|
case eStopReasonInstrumentation:
|
|
|
|
return "instrumentation break";
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 07:08:03 +08:00
|
|
|
static char unknown_state_string[64];
|
2010-11-12 03:26:09 +08:00
|
|
|
snprintf(unknown_state_string, sizeof(unknown_state_string),
|
2012-12-21 07:08:03 +08:00
|
|
|
"StopReason = %i", reason);
|
2010-11-12 03:26:09 +08:00
|
|
|
return unknown_state_string;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2010-11-12 03:26:09 +08:00
|
|
|
const char *Thread::RunModeAsCString(lldb::RunMode mode) {
|
|
|
|
switch (mode) {
|
2012-12-21 07:08:03 +08:00
|
|
|
case eOnlyThisThread:
|
2010-11-12 03:26:09 +08:00
|
|
|
return "only this thread";
|
|
|
|
case eAllThreads:
|
2012-12-21 07:08:03 +08:00
|
|
|
return "all threads";
|
|
|
|
case eOnlyDuringStepping:
|
|
|
|
return "only during stepping";
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 07:08:03 +08:00
|
|
|
static char unknown_state_string[64];
|
|
|
|
snprintf(unknown_state_string, sizeof(unknown_state_string), "RunMode = %i",
|
2016-09-07 04:57:50 +08:00
|
|
|
mode);
|
2012-12-21 07:08:03 +08:00
|
|
|
return unknown_state_string;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
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;
|
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
|
|
|
if (num_frames > 0) {
|
2012-12-21 07:08:03 +08:00
|
|
|
strm.IndentMore();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2012-12-21 07:08:03 +08:00
|
|
|
const bool show_frame_info = true;
|
2017-06-13 00:25:24 +08:00
|
|
|
const bool show_frame_unique = only_stacks;
|
2015-12-15 09:33:19 +08:00
|
|
|
const char *selected_frame_marker = nullptr;
|
2017-06-13 00:25:24 +08:00
|
|
|
if (num_frames == 1 || only_stacks ||
|
2012-12-21 07:08:03 +08:00
|
|
|
(GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID()))
|
LLDB AddressSanitizer instrumentation runtime plugin, breakpint on error and report data extraction
Reviewed at http://reviews.llvm.org/D5592
This patch gives LLDB some ability to interact with AddressSanitizer runtime library, on top of what we already have (historical memory stack traces provided by ASan). Namely, that's the ability to stop on an error caught by ASan, and access the report information that are associated with it. The report information is also exposed into SB API.
More precisely this patch...
adds a new plugin type, InstrumentationRuntime, which should serve as a generic superclass for other instrumentation runtime libraries, these plugins get notified when modules are loaded, so they get a chance to "activate" when a specific dynamic library is loaded
an instance of this plugin type, AddressSanitizerRuntime, which activates itself when it sees the ASan dynamic library or founds ASan statically linked in the executable
adds a collection of these plugins into the Process class
AddressSanitizerRuntime sets an internal breakpoint on __asan::AsanDie(), and when this breakpoint gets hit, it retrieves the report information from ASan
this breakpoint is then exposed as a new StopReason, eStopReasonInstrumentation, with a new StopInfo subclass, InstrumentationRuntimeStopInfo
the StopInfo superclass is extended with a m_extended_info field (it's a StructuredData::ObjectSP), that can hold arbitrary JSON-like data, which is the way the new plugin provides the report data
the "thread info" command now accepts a "-s" flag that prints out the JSON data of a stop reason (same way the "-j" flag works now)
SBThread has a new API, GetStopReasonExtendedInfoAsJSON, which dumps the JSON string into a SBStream
adds a test case for all of this
I plan to also get rid of the original ASan plugin (memory history stack traces) and use an instance of AddressSanitizerRuntime for that purpose.
Kuba
llvm-svn: 219546
2014-10-11 07:43:03 +08:00
|
|
|
strm.IndentMore();
|
|
|
|
else
|
|
|
|
selected_frame_marker = "* ";
|
2010-11-12 03:26:09 +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);
|
2010-11-12 03:26:09 +08:00
|
|
|
if (num_frames == 1)
|
|
|
|
strm.IndentLess();
|
|
|
|
strm.IndentLess();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-11-12 03:26:09 +08:00
|
|
|
return num_frames_shown;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-11-12 03:26:09 +08:00
|
|
|
strm.Printf("\n");
|
|
|
|
|
|
|
|
StructuredData::ObjectSP thread_info = GetExtendedInfo();
|
|
|
|
|
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
|
|
|
if (print_json_thread || print_json_stopinfo) {
|
2012-02-21 08:09:25 +08:00
|
|
|
if (thread_info && print_json_thread) {
|
|
|
|
thread_info->Dump(strm);
|
|
|
|
strm.Printf("\n");
|
|
|
|
}
|
2015-04-09 05:19:12 +08:00
|
|
|
|
2014-06-13 10:37:02 +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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
if (thread_info) {
|
|
|
|
StructuredData::ObjectSP activity =
|
2014-06-13 10:37:02 +08:00
|
|
|
thread_info->GetObjectForDotSeparatedPath("activity");
|
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
|
|
|
StructuredData::ObjectSP breadcrumb =
|
2014-06-13 10:37:02 +08:00
|
|
|
thread_info->GetObjectForDotSeparatedPath("breadcrumb");
|
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
|
|
|
StructuredData::ObjectSP messages =
|
|
|
|
thread_info->GetObjectForDotSeparatedPath("trace_messages");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
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
|
|
|
bool printed_activity = false;
|
2017-05-29 16:25:46 +08:00
|
|
|
if (activity && activity->GetType() == eStructuredDataTypeDictionary) {
|
2012-02-21 08:09:25 +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(),
|
2011-08-22 10:49:39 +08:00
|
|
|
id->GetAsInteger()->GetValue());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
printed_activity = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2011-08-22 10:49:39 +08:00
|
|
|
bool printed_breadcrumb = false;
|
2017-05-29 16:25:46 +08:00
|
|
|
if (breadcrumb && breadcrumb->GetType() == eStructuredDataTypeDictionary) {
|
2011-08-22 10:49:39 +08:00
|
|
|
if (printed_activity)
|
2014-06-13 10:37:02 +08:00
|
|
|
strm.Printf("\n");
|
2011-08-22 10:49:39 +08:00
|
|
|
StructuredData::Dictionary *breadcrumb_dict =
|
|
|
|
breadcrumb->GetAsDictionary();
|
2014-06-13 10:37:02 +08:00
|
|
|
StructuredData::ObjectSP breadcrumb_text =
|
2011-08-22 10:49:39 +08:00
|
|
|
breadcrumb_dict->GetValueForKey("name");
|
2014-06-13 10:37:02 +08:00
|
|
|
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());
|
2012-05-18 10:38:05 +08:00
|
|
|
}
|
2012-10-16 08:09:33 +08:00
|
|
|
printed_breadcrumb = true;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2017-05-29 16:25:46 +08:00
|
|
|
if (messages && messages->GetType() == eStructuredDataTypeArray) {
|
2012-10-16 08:09:33 +08:00
|
|
|
if (printed_breadcrumb)
|
|
|
|
strm.Printf("\n");
|
2013-05-09 09:55:29 +08:00
|
|
|
StructuredData::Array *messages_array = messages->GetAsArray();
|
|
|
|
const size_t msg_count = messages_array->GetSize();
|
2013-04-03 04:32:37 +08:00
|
|
|
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) {
|
2014-06-13 10:37:02 +08:00
|
|
|
StructuredData::Dictionary *message_dict =
|
2013-04-03 04:32:37 +08:00
|
|
|
message->GetAsDictionary();
|
|
|
|
StructuredData::ObjectSP message_text =
|
2014-06-13 10:37:02 +08:00
|
|
|
message_dict->GetValueForKey("message");
|
2014-04-02 11:51:35 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-16 08:09:33 +08:00
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
size_t Thread::GetStackFrameStatus(Stream &strm, uint32_t first_frame,
|
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
|
|
|
uint32_t num_frames, bool show_frame_info,
|
2014-01-28 07:43:24 +08:00
|
|
|
uint32_t num_frames_with_source) {
|
|
|
|
return GetStackFrameList()->GetStatus(
|
|
|
|
strm, first_frame, num_frames, show_frame_info, num_frames_with_source);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2020-03-09 21:10:41 +08:00
|
|
|
Unwind &Thread::GetUnwinder() {
|
2020-03-05 22:14:45 +08:00
|
|
|
if (!m_unwinder_up)
|
|
|
|
m_unwinder_up.reset(new UnwindLLDB(*this));
|
2020-03-09 21:10:41 +08:00
|
|
|
return *m_unwinder_up;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2013-05-02 05:54:04 +08:00
|
|
|
void Thread::Flush() {
|
2014-01-28 07:43:24 +08:00
|
|
|
ClearStackFrames();
|
|
|
|
m_reg_context_sp.reset();
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
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.
|
2014-01-28 07:43:24 +08:00
|
|
|
if (m_stop_info_sp) {
|
2013-05-09 09:55:29 +08:00
|
|
|
StopReason stop_reason = m_stop_info_sp->GetStopReason();
|
2012-10-16 08:09:33 +08:00
|
|
|
if (stop_reason == lldb::eStopReasonBreakpoint) {
|
2013-05-09 09:55:29 +08:00
|
|
|
uint64_t value = m_stop_info_sp->GetValue();
|
2014-01-28 07:43:24 +08:00
|
|
|
lldb::RegisterContextSP reg_ctx_sp(GetRegisterContext());
|
2013-04-03 04:32:37 +08:00
|
|
|
if (reg_ctx_sp) {
|
|
|
|
lldb::addr_t pc = reg_ctx_sp->GetPC();
|
2014-12-10 07:31:02 +08:00
|
|
|
BreakpointSiteSP bp_site_sp =
|
2014-01-28 07:43:24 +08:00
|
|
|
GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
|
|
|
|
if (bp_site_sp && static_cast<break_id_t>(value) == bp_site_sp->GetID())
|
|
|
|
return true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2016-08-24 01:55:21 +08:00
|
|
|
return false;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
{
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2014-01-28 07:43:24 +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;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
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,
|
2015-12-15 08:40:30 +08:00
|
|
|
step_in_avoids_code_without_debug_info,
|
2014-03-13 10:47:14 +08:00
|
|
|
step_out_avoids_code_without_debug_info);
|
2014-01-28 07:43:24 +08:00
|
|
|
} else {
|
|
|
|
new_plan_sp = QueueThreadPlanForStepSingleInstruction(
|
2018-11-15 09:18:15 +08:00
|
|
|
false, abort_other_plans, run_mode, error);
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// 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");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
return error;
|
2014-01-28 07:43:24 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::StepOver(bool source_step,
|
|
|
|
LazyBool step_out_avoids_code_without_debug_info) {
|
|
|
|
Status error;
|
2014-01-28 07:43:24 +08:00
|
|
|
Process *process = GetProcess().get();
|
|
|
|
if (StateIsStoppedState(process->GetState(), true)) {
|
2013-11-04 17:33:30 +08:00
|
|
|
StackFrameSP frame_sp = GetStackFrameAtIndex(0);
|
2014-01-28 07:43:24 +08:00
|
|
|
ThreadPlanSP new_plan_sp;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
const lldb::RunMode run_mode = eOnlyThisThread;
|
|
|
|
const bool abort_other_plans = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
if (source_step && frame_sp && frame_sp->HasDebugInformation()) {
|
2011-08-16 08:07:28 +08:00
|
|
|
SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
|
2014-01-28 07:43:24 +08:00
|
|
|
new_plan_sp = QueueThreadPlanForStepOverRange(
|
2018-11-15 09:18:15 +08:00
|
|
|
abort_other_plans, sc.line_entry, sc, run_mode, error,
|
2015-12-15 08:40:30 +08:00
|
|
|
step_out_avoids_code_without_debug_info);
|
2014-01-28 07:43:24 +08:00
|
|
|
} else {
|
2015-10-24 02:39:37 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// 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");
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2013-02-01 05:46:01 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status Thread::StepOut() {
|
|
|
|
Status error;
|
2014-01-28 07:43:24 +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;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-12-15 09:33:19 +08:00
|
|
|
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
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
new_plan_sp->SetIsMasterPlan(true);
|
|
|
|
new_plan_sp->SetOkayToDiscard(false);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// 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
|
|
|
}
|