brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 241ce82 Raw
101 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/Target/SyntheticFrameProvider.h"10#include "lldb/Core/PluginManager.h"11#include "lldb/Target/Thread.h"12#include "lldb/Utility/LLDBLog.h"13#include "lldb/Utility/Log.h"14#include "lldb/Utility/Status.h"15 16using namespace lldb;17using namespace lldb_private;18 19SyntheticFrameProvider::SyntheticFrameProvider(StackFrameListSP input_frames)20    : m_input_frames(std::move(input_frames)) {}21 22SyntheticFrameProvider::~SyntheticFrameProvider() = default;23 24void SyntheticFrameProviderDescriptor::Dump(Stream *s) const {25  if (!s)26    return;27 28  s->Printf("  Name: %s\n", GetName().str().c_str());29 30  // Show thread filter information.31  if (thread_specs.empty()) {32    s->PutCString("  Thread Filter: (applies to all threads)\n");33  } else {34    s->Printf("  Thread Filter: %zu specification(s)\n", thread_specs.size());35    for (size_t i = 0; i < thread_specs.size(); ++i) {36      const ThreadSpec &spec = thread_specs[i];37      s->Printf("    [%zu] ", i);38      spec.GetDescription(s, lldb::eDescriptionLevelVerbose);39      s->PutChar('\n');40    }41  }42}43 44llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(45    StackFrameListSP input_frames,46    const SyntheticFrameProviderDescriptor &descriptor) {47  if (!input_frames)48    return llvm::createStringError(49        "cannot create synthetic frame provider: invalid input frames");50 51  // Iterate through all registered ScriptedFrameProvider plugins.52  ScriptedFrameProviderCreateInstance create_callback = nullptr;53  for (uint32_t idx = 0;54       (create_callback =55            PluginManager::GetScriptedFrameProviderCreateCallbackAtIndex(56                idx)) != nullptr;57       ++idx) {58    auto provider_or_err = create_callback(input_frames, descriptor);59    if (!provider_or_err) {60      LLDB_LOG_ERROR(GetLog(LLDBLog::Target), provider_or_err.takeError(),61                     "Failed to create synthetic frame provider: {0}");62      continue;63    }64 65    if (auto frame_provider_up = std::move(*provider_or_err))66      return std::move(frame_provider_up);67  }68 69  return llvm::createStringError(70      "cannot create synthetic frame provider: no suitable plugin found");71}72 73llvm::Expected<SyntheticFrameProviderSP> SyntheticFrameProvider::CreateInstance(74    StackFrameListSP input_frames, llvm::StringRef plugin_name,75    const std::vector<ThreadSpec> &thread_specs) {76  if (!input_frames)77    return llvm::createStringError(78        "cannot create synthetic frame provider: invalid input frames");79 80  // Look up the specific C++ plugin by name.81  SyntheticFrameProviderCreateInstance create_callback =82      PluginManager::GetSyntheticFrameProviderCreateCallbackForPluginName(83          plugin_name);84 85  if (!create_callback)86    return llvm::createStringError(87        "cannot create synthetic frame provider: C++ plugin '%s' not found",88        plugin_name.str().c_str());89 90  auto provider_or_err = create_callback(input_frames, thread_specs);91  if (!provider_or_err)92    return provider_or_err.takeError();93 94  if (auto frame_provider_sp = std::move(*provider_or_err))95    return std::move(frame_provider_sp);96 97  return llvm::createStringError(98      "cannot create synthetic frame provider: C++ plugin '%s' returned null",99      plugin_name.str().c_str());100}101