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"
18#include "lldb/lldb-private.h"
19
20#include "llvm/Support/Compiler.h"
21
22#include <string>
23
24namespace lldb_private {
26public:
27 ScriptedInterface() = default;
28 virtual ~ScriptedInterface() = default;
29
33
35 llvm::StringLiteral name;
36 size_t min_arg_count = 0;
37 };
38
39 virtual llvm::SmallVector<AbstractMethodRequirement>
41
42 virtual llvm::Expected<FileSpec> GetScriptedModulePath() {
43 return llvm::make_error<UnimplementedError>();
44 }
45
46 llvm::SmallVector<llvm::StringLiteral> const GetAbstractMethods() const {
47 llvm::SmallVector<llvm::StringLiteral> abstract_methods;
48 llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
49 [](const AbstractMethodRequirement &requirement) {
50 return requirement.name;
51 });
52 return abstract_methods;
53 }
54
55 template <typename Ret>
56 static Ret ErrorWithMessage(llvm::StringRef caller_name,
57 llvm::StringRef error_msg, Status &error,
58 LLDBLog log_category = LLDBLog::Process) {
59 LLDB_LOGF(GetLog(log_category), "%s ERROR = %s", caller_name.data(),
60 error_msg.data());
61 std::string full_error_message =
62 llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
63 llvm::Twine(error_msg))
64 .str();
65 if (const char *detailed_error = error.AsCString())
66 full_error_message +=
67 llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
68 llvm::Twine(")"))
69 .str();
70 error = Status(std::move(full_error_message));
71 return {};
72 }
73
74 template <typename T = StructuredData::ObjectSP>
75 static bool CheckStructuredDataObject(llvm::StringRef caller, T obj,
76 Status &error) {
77 if (!obj)
78 return ErrorWithMessage<bool>(caller, "Null Structured Data object",
79 error);
80
81 if (!obj->IsValid()) {
82 return ErrorWithMessage<bool>(caller, "Invalid StructuredData object",
83 error);
84 }
85
86 if (error.Fail())
87 return ErrorWithMessage<bool>(caller, error.AsCString(), error);
88
89 return true;
90 }
91
94 return false;
95 }
96
97protected:
99};
100} // namespace lldb_private
101#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_category=LLDBLog::Process)
virtual ~ScriptedInterface()=default
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)
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:332
ScriptLanguage
Script interpreter types.