Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/Interfaces/ScriptedThreadPythonInterface.cpp
39688 views
//===-- ScriptedThreadPythonInterface.cpp ---------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Host/Config.h"9#include "lldb/Target/ExecutionContext.h"10#include "lldb/Utility/Log.h"11#include "lldb/lldb-enumerations.h"1213#if LLDB_ENABLE_PYTHON1415// LLDB Python header must be included first16#include "../lldb-python.h"1718#include "../SWIGPythonBridge.h"19#include "../ScriptInterpreterPythonImpl.h"20#include "ScriptedThreadPythonInterface.h"21#include <optional>2223using namespace lldb;24using namespace lldb_private;25using namespace lldb_private::python;26using Locker = ScriptInterpreterPythonImpl::Locker;2728ScriptedThreadPythonInterface::ScriptedThreadPythonInterface(29ScriptInterpreterPythonImpl &interpreter)30: ScriptedThreadInterface(), ScriptedPythonInterface(interpreter) {}3132llvm::Expected<StructuredData::GenericSP>33ScriptedThreadPythonInterface::CreatePluginObject(34const llvm::StringRef class_name, ExecutionContext &exe_ctx,35StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {36ExecutionContextRefSP exe_ctx_ref_sp =37std::make_shared<ExecutionContextRef>(exe_ctx);38StructuredDataImpl sd_impl(args_sp);39return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,40exe_ctx_ref_sp, sd_impl);41}4243lldb::tid_t ScriptedThreadPythonInterface::GetThreadID() {44Status error;45StructuredData::ObjectSP obj = Dispatch("get_thread_id", error);4647if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,48error))49return LLDB_INVALID_THREAD_ID;5051return obj->GetUnsignedIntegerValue(LLDB_INVALID_THREAD_ID);52}5354std::optional<std::string> ScriptedThreadPythonInterface::GetName() {55Status error;56StructuredData::ObjectSP obj = Dispatch("get_name", error);5758if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,59error))60return {};6162return obj->GetStringValue().str();63}6465lldb::StateType ScriptedThreadPythonInterface::GetState() {66Status error;67StructuredData::ObjectSP obj = Dispatch("get_state", error);6869if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,70error))71return eStateInvalid;7273return static_cast<StateType>(obj->GetUnsignedIntegerValue(eStateInvalid));74}7576std::optional<std::string> ScriptedThreadPythonInterface::GetQueue() {77Status error;78StructuredData::ObjectSP obj = Dispatch("get_queue", error);7980if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,81error))82return {};8384return obj->GetStringValue().str();85}8687StructuredData::DictionarySP ScriptedThreadPythonInterface::GetStopReason() {88Status error;89StructuredData::DictionarySP dict =90Dispatch<StructuredData::DictionarySP>("get_stop_reason", error);9192if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,93error))94return {};9596return dict;97}9899StructuredData::ArraySP ScriptedThreadPythonInterface::GetStackFrames() {100Status error;101StructuredData::ArraySP arr =102Dispatch<StructuredData::ArraySP>("get_stackframes", error);103104if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,105error))106return {};107108return arr;109}110111StructuredData::DictionarySP ScriptedThreadPythonInterface::GetRegisterInfo() {112Status error;113StructuredData::DictionarySP dict =114Dispatch<StructuredData::DictionarySP>("get_register_info", error);115116if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,117error))118return {};119120return dict;121}122123std::optional<std::string> ScriptedThreadPythonInterface::GetRegisterContext() {124Status error;125StructuredData::ObjectSP obj = Dispatch("get_register_context", error);126127if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,128error))129return {};130131return obj->GetAsString()->GetValue().str();132}133134StructuredData::ArraySP ScriptedThreadPythonInterface::GetExtendedInfo() {135Status error;136StructuredData::ArraySP arr =137Dispatch<StructuredData::ArraySP>("get_extended_info", error);138139if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, arr,140error))141return {};142143return arr;144}145146#endif147148149