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/Log.h"
15 #include "lldb/Utility/Logging.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,
30  StructuredData::DictionarySP args_sp) = 0;
31 
32  template <typename Ret>
33  Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg,
34  Status &error,
35  uint32_t log_caterogy = LIBLLDB_LOG_PROCESS) {
36  LLDB_LOGF(GetLogIfAllCategoriesSet(log_caterogy), "%s ERROR = %s",
37  caller_name.data(), error_msg.data());
38  error.SetErrorString(llvm::Twine(caller_name + llvm::Twine(" ERROR = ") +
39  llvm::Twine(error_msg))
40  .str());
41  return {};
42  }
43 
44  template <typename T = StructuredData::ObjectSP>
45  bool CheckStructuredDataObject(llvm::StringRef caller, T obj, Status &error) {
46  if (!obj) {
47  return ErrorWithMessage<bool>(caller,
48  llvm::Twine("Null StructuredData object (" +
49  llvm::Twine(error.AsCString()) +
50  llvm::Twine(")."))
51  .str(),
52  error);
53  }
54 
55  if (!obj->IsValid()) {
56  return ErrorWithMessage<bool>(
57  caller,
58  llvm::Twine("Invalid StructuredData object (" +
59  llvm::Twine(error.AsCString()) + llvm::Twine(")."))
60  .str(),
61  error);
62  }
63 
64  if (error.Fail())
65  return ErrorWithMessage<bool>(caller, error.AsCString(), error);
66 
67  return true;
68  }
69 
70 protected:
72 };
73 } // namespace lldb_private
74 #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_private::ScriptedInterface::ErrorWithMessage
Ret ErrorWithMessage(llvm::StringRef caller_name, llvm::StringRef error_msg, Status &error, uint32_t log_caterogy=LIBLLDB_LOG_PROCESS)
Definition: ScriptedInterface.h:33
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
lldb_private::ScriptedInterface::m_object_instance_sp
StructuredData::GenericSP m_object_instance_sp
Definition: ScriptedInterface.h:71
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
Log.h
lldb_private::GetLogIfAllCategoriesSet
Log * GetLogIfAllCategoriesSet(uint32_t mask)
Definition: Logging.cpp:58
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:45
lldb-private.h
lldb_private::Status
Definition: Status.h:44
uint32_t
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
Logging.h
LIBLLDB_LOG_PROCESS
#define LIBLLDB_LOG_PROCESS
Definition: Logging.h:15
ExecutionContext.h
lldb_private::ScriptedInterface::CreatePluginObject
virtual StructuredData::GenericSP CreatePluginObject(llvm::StringRef class_name, ExecutionContext &exe_ctx, StructuredData::DictionarySP args_sp)=0