LLDB mainline
ScriptedInterface.h
Go to the documentation of this file.
1//===-- ScriptedInterface.h -------------------------------------*- C++ -*-===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
10#define LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
11
13
16#include "lldb/Utility/Log.h"
19#include "lldb/lldb-private.h"
20
21#include "llvm/Support/Compiler.h"
22
23#include <optional>
24#include <string>
25
26namespace lldb_private {
28public:
29 ScriptedInterface() = default;
30 virtual ~ScriptedInterface() = default;
31
35
36 const std::optional<ScriptedMetadata> &GetScriptedMetadata() const {
38 }
39
41 llvm::StringLiteral name;
42 size_t min_arg_count = 0;
43 };
44
45 virtual llvm::SmallVector<AbstractMethodRequirement>
47
48 virtual llvm::Expected<FileSpec> GetScriptedModulePath() {
49 return llvm::make_error<UnimplementedError>();
50 }
51
52 llvm::SmallVector<llvm::StringLiteral> const GetAbstractMethods() const {
53 llvm::SmallVector<llvm::StringLiteral> abstract_methods;
54 llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
55 [](const AbstractMethodRequirement &requirement) {
56 return requirement.name;
57 });
58 return abstract_methods;
59 }
60
61 template <typename Ret>
62 static Ret ErrorWithMessage(llvm::StringRef caller_name,
63 llvm::StringRef error_msg, Status &error,
64 LLDBLog log_category = LLDBLog::Process) {
65 LLDB_LOGF(GetLog(log_category), "%s ERROR = %s", caller_name.data(),
66 error_msg.data());
67 std::string full_error_message =
68 llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
69 llvm::Twine(error_msg))
70 .str();
71 if (const char *detailed_error = error.AsCString())
72 full_error_message +=
73 llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
74 llvm::Twine(")"))
75 .str();
76 error = Status(std::move(full_error_message));
77 return {};
78 }
79
80 template <typename T = StructuredData::ObjectSP>
81 static bool CheckStructuredDataObject(llvm::StringRef caller, T obj,
82 Status &error) {
83 if (!obj)
84 return ErrorWithMessage<bool>(caller, "Null Structured Data object",
85 error);
86
87 if (!obj->IsValid()) {
88 return ErrorWithMessage<bool>(caller, "Invalid StructuredData object",
89 error);
90 }
91
92 if (error.Fail())
93 return ErrorWithMessage<bool>(caller, error.AsCString(), error);
94
95 return true;
96 }
97
100 return false;
101 }
102
103protected:
105 std::optional<ScriptedMetadata> m_scripted_metadata;
106};
107} // namespace lldb_private
108#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:378
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_category=LLDBLog::Process)
virtual ~ScriptedInterface()=default
std::optional< ScriptedMetadata > m_scripted_metadata
llvm::SmallVector< llvm::StringLiteral > const GetAbstractMethods() const
virtual llvm::SmallVector< AbstractMethodRequirement > GetAbstractMethodRequirements() const =0
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
virtual llvm::Expected< FileSpec > GetScriptedModulePath()
StructuredData::GenericSP GetScriptObjectInstance()
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
const std::optional< ScriptedMetadata > & GetScriptedMetadata() const
StructuredData::GenericSP m_object_instance_sp
An error handling class.
Definition Status.h:118
std::shared_ptr< Generic > GenericSP
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
ScriptLanguage
Script interpreter types.