brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.0 KiB · 20ca7a2 Raw
158 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "lldb/Host/Config.h"10#include "lldb/Target/ExecutionContext.h"11#include "lldb/Utility/Log.h"12#include "lldb/lldb-enumerations.h"13 14#if LLDB_ENABLE_PYTHON15 16// LLDB Python header must be included first17#include "../lldb-python.h"18 19#include "../SWIGPythonBridge.h"20#include "../ScriptInterpreterPythonImpl.h"21#include "ScriptedFramePythonInterface.h"22#include <optional>23 24using namespace lldb;25using namespace lldb_private;26using namespace lldb_private::python;27using Locker = ScriptInterpreterPythonImpl::Locker;28 29ScriptedFramePythonInterface::ScriptedFramePythonInterface(30    ScriptInterpreterPythonImpl &interpreter)31    : ScriptedFrameInterface(), ScriptedPythonInterface(interpreter) {}32 33llvm::Expected<StructuredData::GenericSP>34ScriptedFramePythonInterface::CreatePluginObject(35    const llvm::StringRef class_name, ExecutionContext &exe_ctx,36    StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj) {37  ExecutionContextRefSP exe_ctx_ref_sp =38      std::make_shared<ExecutionContextRef>(exe_ctx);39  StructuredDataImpl sd_impl(args_sp);40  return ScriptedPythonInterface::CreatePluginObject(class_name, script_obj,41                                                     exe_ctx_ref_sp, sd_impl);42}43 44lldb::user_id_t ScriptedFramePythonInterface::GetID() {45  Status error;46  StructuredData::ObjectSP obj = Dispatch("get_id", error);47 48  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,49                                                    error))50    return LLDB_INVALID_FRAME_ID;51 52  return obj->GetUnsignedIntegerValue(LLDB_INVALID_FRAME_ID);53}54 55lldb::addr_t ScriptedFramePythonInterface::GetPC() {56  Status error;57  StructuredData::ObjectSP obj = Dispatch("get_pc", error);58 59  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,60                                                    error))61    return LLDB_INVALID_ADDRESS;62 63  return obj->GetUnsignedIntegerValue(LLDB_INVALID_ADDRESS);64}65 66std::optional<SymbolContext> ScriptedFramePythonInterface::GetSymbolContext() {67  Status error;68  auto sym_ctx = Dispatch<SymbolContext>("get_symbol_context", error);69 70  if (error.Fail()) {71    return ErrorWithMessage<SymbolContext>(LLVM_PRETTY_FUNCTION,72                                           error.AsCString(), error);73  }74 75  return sym_ctx;76}77 78std::optional<std::string> ScriptedFramePythonInterface::GetFunctionName() {79  Status error;80  StructuredData::ObjectSP obj = Dispatch("get_function_name", error);81 82  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,83                                                    error))84    return {};85 86  return obj->GetStringValue().str();87}88 89std::optional<std::string>90ScriptedFramePythonInterface::GetDisplayFunctionName() {91  Status error;92  StructuredData::ObjectSP obj = Dispatch("get_display_function_name", error);93 94  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,95                                                    error))96    return {};97 98  return obj->GetStringValue().str();99}100 101bool ScriptedFramePythonInterface::IsInlined() {102  Status error;103  StructuredData::ObjectSP obj = Dispatch("is_inlined", error);104 105  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,106                                                    error))107    return false;108 109  return obj->GetBooleanValue();110}111 112bool ScriptedFramePythonInterface::IsArtificial() {113  Status error;114  StructuredData::ObjectSP obj = Dispatch("is_artificial", error);115 116  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,117                                                    error))118    return false;119 120  return obj->GetBooleanValue();121}122 123bool ScriptedFramePythonInterface::IsHidden() {124  Status error;125  StructuredData::ObjectSP obj = Dispatch("is_hidden", error);126 127  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,128                                                    error))129    return false;130 131  return obj->GetBooleanValue();132}133 134StructuredData::DictionarySP ScriptedFramePythonInterface::GetRegisterInfo() {135  Status error;136  StructuredData::DictionarySP dict =137      Dispatch<StructuredData::DictionarySP>("get_register_info", error);138 139  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, dict,140                                                    error))141    return {};142 143  return dict;144}145 146std::optional<std::string> ScriptedFramePythonInterface::GetRegisterContext() {147  Status error;148  StructuredData::ObjectSP obj = Dispatch("get_register_context", error);149 150  if (!ScriptedInterface::CheckStructuredDataObject(LLVM_PRETTY_FUNCTION, obj,151                                                    error))152    return {};153 154  return obj->GetAsString()->GetValue().str();155}156 157#endif158