aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp102
1 files changed, 84 insertions, 18 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp b/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
index b6cbb62fd6e6..e28f66015dd5 100644
--- a/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -15,9 +15,7 @@
#include "lldb/Target/StopInfo.h"
#include "lldb/Target/Unwind.h"
#include "lldb/Utility/DataBufferHeap.h"
-#include "lldb/Utility/Log.h"
-#include "lldb/Utility/Logging.h"
-
+#include "lldb/Utility/LLDBLog.h"
#include <memory>
using namespace lldb;
@@ -123,25 +121,25 @@ ScriptedThread::CreateRegisterContextForFrame(StackFrame *frame) {
llvm::Optional<std::string> reg_data = GetInterface()->GetRegisterContext();
if (!reg_data)
- return GetInterface()->ErrorWithMessage<lldb::RegisterContextSP>(
+ return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers data.",
- error, LIBLLDB_LOG_THREAD);
+ error, LLDBLog::Thread);
DataBufferSP data_sp(
std::make_shared<DataBufferHeap>(reg_data->c_str(), reg_data->size()));
if (!data_sp->GetByteSize())
- return GetInterface()->ErrorWithMessage<lldb::RegisterContextSP>(
+ return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
LLVM_PRETTY_FUNCTION, "Failed to copy raw registers data.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
std::shared_ptr<RegisterContextMemory> reg_ctx_memory =
std::make_shared<RegisterContextMemory>(
*this, 0, *GetDynamicRegisterInfo(), LLDB_INVALID_ADDRESS);
if (!reg_ctx_memory)
- return GetInterface()->ErrorWithMessage<lldb::RegisterContextSP>(
+ return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
LLVM_PRETTY_FUNCTION, "Failed to create a register context.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
reg_ctx_memory->SetAllRegisterData(data_sp);
m_reg_context_sp = reg_ctx_memory;
@@ -149,30 +147,97 @@ ScriptedThread::CreateRegisterContextForFrame(StackFrame *frame) {
return m_reg_context_sp;
}
+bool ScriptedThread::LoadArtificialStackFrames() {
+ StructuredData::ArraySP arr_sp = GetInterface()->GetStackFrames();
+
+ Status error;
+ if (!arr_sp)
+ return ScriptedInterface::ErrorWithMessage<bool>(
+ LLVM_PRETTY_FUNCTION, "Failed to get scripted thread stackframes.",
+ error, LLDBLog::Thread);
+
+ size_t arr_size = arr_sp->GetSize();
+ if (arr_size > std::numeric_limits<uint32_t>::max())
+ return ScriptedInterface::ErrorWithMessage<bool>(
+ LLVM_PRETTY_FUNCTION,
+ llvm::Twine(
+ "StackFrame array size (" + llvm::Twine(arr_size) +
+ llvm::Twine(
+ ") is greater than maximum autorized for a StackFrameList."))
+ .str(),
+ error, LLDBLog::Thread);
+
+ StackFrameListSP frames = GetStackFrameList();
+
+ for (size_t idx = 0; idx < arr_size; idx++) {
+
+ StructuredData::Dictionary *dict;
+
+ if (!arr_sp->GetItemAtIndexAsDictionary(idx, dict) || !dict)
+ return ScriptedInterface::ErrorWithMessage<bool>(
+ LLVM_PRETTY_FUNCTION,
+ llvm::Twine(
+ "Couldn't get artificial stackframe dictionary at index (" +
+ llvm::Twine(idx) + llvm::Twine(") from stackframe array."))
+ .str(),
+ error, LLDBLog::Thread);
+
+ lldb::addr_t pc;
+ if (!dict->GetValueForKeyAsInteger("pc", pc))
+ return ScriptedInterface::ErrorWithMessage<bool>(
+ LLVM_PRETTY_FUNCTION,
+ "Couldn't find value for key 'pc' in stackframe dictionary.", error,
+ LLDBLog::Thread);
+
+ Address symbol_addr;
+ symbol_addr.SetLoadAddress(pc, &this->GetProcess()->GetTarget());
+
+ lldb::addr_t cfa = LLDB_INVALID_ADDRESS;
+ bool cfa_is_valid = false;
+ const bool behaves_like_zeroth_frame = false;
+ SymbolContext sc;
+ symbol_addr.CalculateSymbolContext(&sc);
+
+ StackFrameSP synth_frame_sp = std::make_shared<StackFrame>(
+ this->shared_from_this(), idx, idx, cfa, cfa_is_valid, pc,
+ StackFrame::Kind::Artificial, behaves_like_zeroth_frame, &sc);
+
+ if (!frames->SetFrameAtIndex(static_cast<uint32_t>(idx), synth_frame_sp))
+ return ScriptedInterface::ErrorWithMessage<bool>(
+ LLVM_PRETTY_FUNCTION,
+ llvm::Twine("Couldn't add frame (" + llvm::Twine(idx) +
+ llvm::Twine(") to ScriptedThread StackFrameList."))
+ .str(),
+ error, LLDBLog::Thread);
+ }
+
+ return true;
+}
+
bool ScriptedThread::CalculateStopInfo() {
StructuredData::DictionarySP dict_sp = GetInterface()->GetStopReason();
Status error;
if (!dict_sp)
- return GetInterface()->ErrorWithMessage<bool>(
+ return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION, "Failed to get scripted thread stop info.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
lldb::StopInfoSP stop_info_sp;
lldb::StopReason stop_reason_type;
if (!dict_sp->GetValueForKeyAsInteger("type", stop_reason_type))
- return GetInterface()->ErrorWithMessage<bool>(
+ return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION,
"Couldn't find value for key 'type' in stop reason dictionary.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
StructuredData::Dictionary *data_dict;
if (!dict_sp->GetValueForKeyAsDictionary("data", data_dict))
- return GetInterface()->ErrorWithMessage<bool>(
+ return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION,
"Couldn't find value for key 'data' in stop reason dictionary.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
switch (stop_reason_type) {
case lldb::eStopReasonNone:
@@ -201,12 +266,12 @@ bool ScriptedThread::CalculateStopInfo() {
StopInfo::CreateStopReasonWithException(*this, description.data());
} break;
default:
- return GetInterface()->ErrorWithMessage<bool>(
+ return ScriptedInterface::ErrorWithMessage<bool>(
LLVM_PRETTY_FUNCTION,
llvm::Twine("Unsupported stop reason type (" +
llvm::Twine(stop_reason_type) + llvm::Twine(")."))
.str(),
- error, LIBLLDB_LOG_THREAD);
+ error, LLDBLog::Thread);
}
if (!stop_info_sp)
@@ -218,6 +283,7 @@ bool ScriptedThread::CalculateStopInfo() {
void ScriptedThread::RefreshStateAfterStop() {
GetRegisterContext()->InvalidateIfNeeded(/*force=*/false);
+ LoadArtificialStackFrames();
}
lldb::ScriptedThreadInterfaceSP ScriptedThread::GetInterface() const {
@@ -236,7 +302,7 @@ std::shared_ptr<DynamicRegisterInfo> ScriptedThread::GetDynamicRegisterInfo() {
->ErrorWithMessage<std::shared_ptr<DynamicRegisterInfo>>(
LLVM_PRETTY_FUNCTION,
"Failed to get scripted thread registers info.", error,
- LIBLLDB_LOG_THREAD);
+ LLDBLog::Thread);
m_register_info_sp = std::make_shared<DynamicRegisterInfo>(
*reg_info, m_scripted_process.GetTarget().GetArchitecture());