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
34 virtual llvm::SmallVector<llvm::StringLiteral> GetAbstractMethods() const = 0;
35
36 template <typename Ret>
37 static Ret ErrorWithMessage(llvm::StringRef caller_name,
38 llvm::StringRef error_msg, Status &error,
39 LLDBLog log_caterogy = LLDBLog::Process) {
40 LLDB_LOGF(GetLog(log_caterogy), "%s ERROR = %s", caller_name.data(),
41 error_msg.data());
42 std::string full_error_message =
43 llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
44 llvm::Twine(error_msg))
45 .str();
46 if (const char *detailed_error = error.AsCString())
47 full_error_message +=
48 llvm::Twine(llvm::Twine(" (") + llvm::Twine(detailed_error) +
49 llvm::Twine(")"))
50 .str();
51 error.SetErrorString(full_error_message);
52 return {};
53 }
54
55 template <typename T = StructuredData::ObjectSP>
56 static bool CheckStructuredDataObject(llvm::StringRef caller, T obj,
57 Status &error) {
58 if (!obj)
59 return ErrorWithMessage<bool>(caller, "Null Structured Data object",
60 error);
61
62 if (!obj->IsValid()) {
63 return ErrorWithMessage<bool>(caller, "Invalid StructuredData object",
64 error);
65 }
66
67 if (error.Fail())
68 return ErrorWithMessage<bool>(caller, error.AsCString(), error);
69
70 return true;
71 }
72
75 return false;
76 }
77
78protected:
80};
81} // namespace lldb_private
82#endif // LLDB_INTERPRETER_INTERFACES_SCRIPTEDINTERFACE_H
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:366
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_caterogy=LLDBLog::Process)
virtual ~ScriptedInterface()=default
static bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
StructuredData::GenericSP GetScriptObjectInstance()
static bool CreateInstance(lldb::ScriptLanguage language, ScriptedInterfaceUsages usages)
virtual llvm::SmallVector< llvm::StringLiteral > GetAbstractMethods() const =0
StructuredData::GenericSP m_object_instance_sp
An error handling class.
Definition: Status.h:44
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:331
ScriptLanguage
Script interpreter types.