1 //===-- SWIG Interface for SBError ------------------------------*- 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 namespace lldb { 10 11 %feature("docstring", 12 "Represents a container for holding any error code. 13 14 For example (from test/python_api/hello_world/TestHelloWorld.py), :: 15 16 def hello_world_attach_with_id_api(self): 17 '''Create target, spawn a process, and attach to it by id.''' 18 19 target = self.dbg.CreateTarget(self.exe) 20 21 # Spawn a new process and don't display the stdout if not in TraceOn() mode. 22 import subprocess 23 popen = subprocess.Popen([self.exe, 'abc', 'xyz'], 24 stdout = open(os.devnull, 'w') if not self.TraceOn() else None) 25 26 listener = lldb.SBListener('my.attach.listener') 27 error = lldb.SBError() 28 process = target.AttachToProcessWithID(listener, popen.pid, error) 29 30 self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 31 32 # Let's check the stack traces of the attached process. 33 import lldbutil 34 stacktraces = lldbutil.print_stacktraces(process, string_buffer=True) 35 self.expect(stacktraces, exe=False, 36 substrs = ['main.c:%d' % self.line2, 37 '(int)argc=3']) 38 39 listener = lldb.SBListener('my.attach.listener') 40 error = lldb.SBError() 41 process = target.AttachToProcessWithID(listener, popen.pid, error) 42 43 self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 44 45 checks that after the attach, there is no error condition by asserting 46 that error.Success() is True and we get back a valid process object. 47 48 And (from test/python_api/event/TestEvent.py), :: 49 50 # Now launch the process, and do not stop at entry point. 51 error = lldb.SBError() 52 process = target.Launch(listener, None, None, None, None, None, None, 0, False, error) 53 self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 54 55 checks that after calling the target.Launch() method there's no error 56 condition and we get back a void process object.") SBError; 57 58 class SBError { 59 public: 60 SBError (); 61 62 SBError (const lldb::SBError &rhs); 63 64 ~SBError(); 65 66 const char * 67 GetCString () const; 68 69 void 70 Clear (); 71 72 bool 73 Fail () const; 74 75 bool 76 Success () const; 77 78 uint32_t 79 GetError () const; 80 81 lldb::ErrorType 82 GetType () const; 83 84 void 85 SetError (uint32_t err, lldb::ErrorType type); 86 87 void 88 SetErrorToErrno (); 89 90 void 91 SetErrorToGenericError (); 92 93 void 94 SetErrorString (const char *err_str); 95 96 %varargs(3, char *str = NULL) SetErrorStringWithFormat; 97 int 98 SetErrorStringWithFormat (const char *format, ...); 99 100 bool 101 IsValid () const; 102 103 explicit operator bool() const; 104 105 bool 106 GetDescription (lldb::SBStream &description); 107 108 STRING_EXTENSION(SBError) 109 110 #ifdef SWIGPYTHON 111 %pythoncode %{ 112 value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''') 113 fail = property(Fail, None, doc='''A read only property that returns the same result as Fail().''') 114 success = property(Success, None, doc='''A read only property that returns the same result as Success().''') 115 description = property(GetCString, None, doc='''A read only property that returns the same result as GetCString().''') 116 type = property(GetType, None, doc='''A read only property that returns the same result as GetType().''') 117 %} 118 #endif 119 120 }; 121 122 } // namespace lldb 123