[lldb/API] Add convenience constructor for SBError (NFC)
authorMed Ismail Bennani <medismail.bennani@gmail.com>
Sat, 15 Apr 2023 00:09:37 +0000 (17:09 -0700)
committerMed Ismail Bennani <medismail.bennani@gmail.com>
Tue, 25 Apr 2023 22:02:34 +0000 (15:02 -0700)
This patch adds a new convience constructor to the SBError to initialize
it with a string message to avoid having to create the object and call
the `SetErrorString` method afterwards.

This is very handy to report errors from lldb scripted affordances.

Differential Revision: https://reviews.llvm.org/D148401

Signed-off-by: Med Ismail Bennani <medismail.bennani@gmail.com>
lldb/include/lldb/API/SBError.h
lldb/source/API/SBError.cpp

index 16300bd..f6d5b74 100644 (file)
@@ -23,6 +23,8 @@ public:
 
   SBError(const lldb::SBError &rhs);
 
+  SBError(const char *message);
+
 #ifndef SWIG
   SBError(const lldb_private::Status &error);
 #endif
index 1a03415..2eb9e92 100644 (file)
@@ -25,6 +25,12 @@ SBError::SBError(const SBError &rhs) {
   m_opaque_up = clone(rhs.m_opaque_up);
 }
 
+SBError::SBError(const char *message) {
+  LLDB_INSTRUMENT_VA(this, message);
+
+  SetErrorString(message);
+}
+
 SBError::SBError(const lldb_private::Status &status)
     : m_opaque_up(new Status(status)) {
   LLDB_INSTRUMENT_VA(this, status);