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_SCRIPTEDINTERFACE_H
10 #define LLDB_INTERPRETER_SCRIPTEDINTERFACE_H
11 
14 #include "lldb/Utility/LLDBLog.h"
15 #include "lldb/Utility/Log.h"
16 #include "lldb/lldb-private.h"
17 
18 #include "llvm/Support/Compiler.h"
19 
20 #include <string>
21 
22 namespace lldb_private {
24 public:
25  ScriptedInterface() = default;
26  virtual ~ScriptedInterface() = default;
27 
29  CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx,
31  StructuredData::Generic *script_obj = nullptr) = 0;
32 
33  template <typename Ret>
34  static Ret ErrorWithMessage(llvm::StringRef caller_name,
35  llvm::StringRef error_msg, Status &error,
36  LLDBLog log_caterogy = LLDBLog::Process) {
37  LLDB_LOGF(GetLog(log_caterogy), "%s ERROR = %s", caller_name.data(),
38  error_msg.data());
39  error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
40  llvm::Twine(error_msg))
41  .str());
42  return {};
43  }
44 
45  template <typename T = StructuredData::ObjectSP>
46  bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error) {
47  if (!obj) {
48  return ErrorWithMessage<bool>(caller,
49  llvm::Twine("Null StructuredData object (" +
50  llvm::Twine(error.AsCString()) +
51  llvm::Twine(")."))
52  .str(),
53  error);
54  }
55 
56  if (!obj->IsValid()) {
57  return ErrorWithMessage<bool>(
58  caller,
59  llvm::Twine("Invalid StructuredData object (" +
60  llvm::Twine(error.AsCString()) + llvm::Twine(")."))
61  .str(),
62  error);
63  }
64 
65  if (error.Fail())
66  return ErrorWithMessage<bool>(caller, error.AsCString(), error);
67 
68  return true;
69  }
70 
71 protected:
73 };
74 } // namespace lldb_private
75 #endif // LLDB_INTERPRETER_SCRIPTEDINTERFACE_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:292
lldb_private::ScriptedInterface::~ScriptedInterface
virtual ~ScriptedInterface()=default
lldb_private::StructuredData::GenericSP
std::shared_ptr< Generic > GenericSP
Definition: StructuredData.h:68
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:343
lldb_private::ScriptedInterface::m_object_instance_sp
StructuredData::GenericSP m_object_instance_sp
Definition: ScriptedInterface.h:72
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::LLDBLog
LLDBLog
Definition: LLDBLog.h:18
Log.h
lldb_private::LLDBLog::Process
@ Process
lldb_private::StructuredData::DictionarySP
std::shared_ptr< Dictionary > DictionarySP
Definition: StructuredData.h:67
lldb_private::ScriptedInterface::CheckStructuredDataObject
bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error)
Definition: ScriptedInterface.h:46
lldb_private::ScriptedInterface::CreatePluginObject
virtual StructuredData::GenericSP CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx, StructuredData::DictionarySP args_sp, StructuredData::Generic *script_obj=nullptr)=0
lldb_private::StructuredData::Generic
Definition: StructuredData.h:543
lldb-private.h
lldb_private::ScriptedInterface::ErrorWithMessage
static Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, LLDBLog log_caterogy=LLDBLog::Process)
Definition: ScriptedInterface.h:34
lldb_private::Status
Definition: Status.h:44
lldb_private::ScriptedInterface
Definition: ScriptedInterface.h:23
StructuredDataImpl.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::ScriptedInterface::ScriptedInterface
ScriptedInterface()=default
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
LLDBLog.h
ExecutionContext.h