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
32 }
33
35 llvm::StringLiteral name;
36 size_t min_arg_count = 0;
37 };
38
39 virtual llvm::SmallVector<AbstractMethodRequirement>
41
42 llvm::SmallVector<llvm::StringLiteral> const GetAbstractMethods() const {
43 llvm::SmallVector<llvm::StringLiteral> abstract_methods;
44 llvm::transform(GetAbstractMethodRequirements(), abstract_methods.begin(),
45 [](const AbstractMethodRequirement &requirement) {
46 return requirement.name;
47 });
48 return abstract_methods;
49 }
50
51 template <typename Ret>
52 static Ret ErrorWithMessage(llvm::StringRef caller_name,
53 llvm::StringRef error_msg, Status &error,
54 LLDBLog log_category = LLDBLog::Process) {
55 LLDB_LOGF(GetLog(log_category), "%s ERROR = %s", caller_name.data(),
56 error_msg.data());
57 std::string full_error_message =
58 llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
59 llvm::Twine(error_msg))
60 .str();
61 if (const char *detailed_error = error.AsCString())
62 full_error_message +=
63 llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
64 llvm::Twine(")"))
65 .str();
66 error = Status(std::move(full_error_message));
67 return {};
68 }
69
70 template <typename T = StructuredData::ObjectSP>
71 static bool CheckStructuredDataObject(llvm::StringRef caller, T obj,
72 Status &error) {
73 if (!obj)
74 return ErrorWithMessage<bool>(caller, "Null Structured Data object",
75 error);
76
77 if (!obj->IsValid()) {
78 return ErrorWithMessage<bool>(caller, "Invalid StructuredData object",
79 error);
80 }
81
82 if (error.Fail())
83 return ErrorWithMessage<bool>(caller, error.AsCString(), error);
84
85 return true;
86 }
87
90 return false;
91 }
92
93protected:
95};
96} // namespace lldb_private
97#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)
StructuredData::GenericSP GetScriptObjectInstance()
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
StructuredData::GenericSP m_object_instance_sp
An error handling class.
Definition: Status.h:115
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.