aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2023-04-14 21:41:27 +0000
committerDimitry Andric <dim@FreeBSD.org>2023-06-22 18:20:56 +0000
commitbdd1243df58e60e85101c09001d9812a789b6bc4 (patch)
treea1ce621c7301dd47ba2ddc3b8eaa63b441389481 /contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
parent781624ca2d054430052c828ba8d2c2eaf2d733e7 (diff)
parente3b557809604d036af6e00c60f012c2025b59a5e (diff)
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.cpp83
1 files changed, 65 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 e28f66015dd5..ad0d26af8879 100644
--- a/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
+++ b/contrib/llvm-project/lldb/source/Plugins/Process/scripted/ScriptedThread.cpp
@@ -9,6 +9,7 @@
#include "ScriptedThread.h"
#include "Plugins/Process/Utility/RegisterContextThreadMemory.h"
+#include "Plugins/Process/Utility/StopInfoMachException.h"
#include "lldb/Target/OperatingSystem.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/RegisterContext.h"
@@ -17,6 +18,7 @@
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/LLDBLog.h"
#include <memory>
+#include <optional>
using namespace lldb;
using namespace lldb_private;
@@ -44,7 +46,7 @@ ScriptedThread::Create(ScriptedProcess &process,
llvm::StringRef thread_class_name;
if (!script_object) {
- llvm::Optional<std::string> class_name =
+ std::optional<std::string> class_name =
process.GetInterface().GetScriptedThreadPluginName();
if (!class_name || class_name->empty())
return llvm::createStringError(
@@ -56,8 +58,8 @@ ScriptedThread::Create(ScriptedProcess &process,
ExecutionContext exe_ctx(process);
StructuredData::GenericSP owned_script_object_sp =
scripted_thread_interface->CreatePluginObject(
- thread_class_name, exe_ctx,
- process.m_scripted_process_info.GetArgsSP(), script_object);
+ thread_class_name, exe_ctx, process.m_scripted_metadata.GetArgsSP(),
+ script_object);
if (!owned_script_object_sp)
return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -84,7 +86,7 @@ ScriptedThread::~ScriptedThread() { DestroyThread(); }
const char *ScriptedThread::GetName() {
CheckInterpreterAndScriptObject();
- llvm::Optional<std::string> thread_name = GetInterface()->GetName();
+ std::optional<std::string> thread_name = GetInterface()->GetName();
if (!thread_name)
return nullptr;
return ConstString(thread_name->c_str()).AsCString();
@@ -92,7 +94,7 @@ const char *ScriptedThread::GetName() {
const char *ScriptedThread::GetQueueName() {
CheckInterpreterAndScriptObject();
- llvm::Optional<std::string> queue_name = GetInterface()->GetQueue();
+ std::optional<std::string> queue_name = GetInterface()->GetQueue();
if (!queue_name)
return nullptr;
return ConstString(queue_name->c_str()).AsCString();
@@ -119,7 +121,7 @@ ScriptedThread::CreateRegisterContextForFrame(StackFrame *frame) {
lldb::RegisterContextSP reg_ctx_sp;
Status error;
- llvm::Optional<std::string> reg_data = GetInterface()->GetRegisterContext();
+ std::optional<std::string> reg_data = GetInterface()->GetRegisterContext();
if (!reg_data)
return ScriptedInterface::ErrorWithMessage<lldb::RegisterContextSP>(
LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers data.",
@@ -163,16 +165,14 @@ bool ScriptedThread::LoadArtificialStackFrames() {
llvm::Twine(
"StackFrame array size (" + llvm::Twine(arr_size) +
llvm::Twine(
- ") is greater than maximum autorized for a StackFrameList."))
+ ") is greater than maximum authorized 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,
@@ -259,11 +259,46 @@ bool ScriptedThread::CalculateStopInfo() {
StopInfo::CreateStopReasonWithSignal(*this, signal, description.data());
} break;
case lldb::eStopReasonException: {
- llvm::StringRef description;
- data_dict->GetValueForKeyAsString("desc", description);
-
+#if defined(__APPLE__)
+ StructuredData::Dictionary *mach_exception;
+ if (data_dict->GetValueForKeyAsDictionary("mach_exception",
+ mach_exception)) {
+ llvm::StringRef value;
+ mach_exception->GetValueForKeyAsString("type", value);
+ auto exc_type =
+ StopInfoMachException::MachException::ExceptionCode(value.data());
+
+ if (!exc_type)
+ return false;
+
+ uint32_t exc_data_size = 0;
+ llvm::SmallVector<uint64_t, 3> raw_codes;
+
+ StructuredData::Array *exc_rawcodes;
+ mach_exception->GetValueForKeyAsArray("rawCodes", exc_rawcodes);
+ if (exc_rawcodes) {
+ auto fetch_data = [&raw_codes](StructuredData::Object *obj) {
+ if (!obj)
+ return false;
+ raw_codes.push_back(obj->GetIntegerValue());
+ return true;
+ };
+
+ exc_rawcodes->ForEach(fetch_data);
+ exc_data_size = raw_codes.size();
+ }
+
+ stop_info_sp = StopInfoMachException::CreateStopReasonWithMachException(
+ *this, *exc_type, exc_data_size,
+ exc_data_size >= 1 ? raw_codes[0] : 0,
+ exc_data_size >= 2 ? raw_codes[1] : 0,
+ exc_data_size >= 3 ? raw_codes[2] : 0);
+
+ break;
+ }
+#endif
stop_info_sp =
- StopInfo::CreateStopReasonWithException(*this, description.data());
+ StopInfo::CreateStopReasonWithException(*this, "EXC_BAD_ACCESS");
} break;
default:
return ScriptedInterface::ErrorWithMessage<bool>(
@@ -298,11 +333,10 @@ std::shared_ptr<DynamicRegisterInfo> ScriptedThread::GetDynamicRegisterInfo() {
Status error;
if (!reg_info)
- return GetInterface()
- ->ErrorWithMessage<std::shared_ptr<DynamicRegisterInfo>>(
- LLVM_PRETTY_FUNCTION,
- "Failed to get scripted thread registers info.", error,
- LLDBLog::Thread);
+ return ScriptedInterface::ErrorWithMessage<
+ std::shared_ptr<DynamicRegisterInfo>>(
+ LLVM_PRETTY_FUNCTION, "Failed to get scripted thread registers info.",
+ error, LLDBLog::Thread);
m_register_info_sp = std::make_shared<DynamicRegisterInfo>(
*reg_info, m_scripted_process.GetTarget().GetArchitecture());
@@ -310,3 +344,16 @@ std::shared_ptr<DynamicRegisterInfo> ScriptedThread::GetDynamicRegisterInfo() {
return m_register_info_sp;
}
+
+StructuredData::ObjectSP ScriptedThread::FetchThreadExtendedInfo() {
+ CheckInterpreterAndScriptObject();
+
+ Status error;
+ StructuredData::ArraySP extended_info_sp = GetInterface()->GetExtendedInfo();
+
+ if (!extended_info_sp || !extended_info_sp->GetSize())
+ return ScriptedInterface::ErrorWithMessage<StructuredData::ObjectSP>(
+ LLVM_PRETTY_FUNCTION, "No extended information found", error);
+
+ return extended_info_sp;
+}