1061da546Spatrick //===-- SWIG Interface for SBError ------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9061da546Spatrick namespace lldb { 10061da546Spatrick 11061da546Spatrick %feature("docstring", 12061da546Spatrick "Represents a container for holding any error code. 13061da546Spatrick 14*be691f3bSpatrick For example (from test/python_api/hello_world/TestHelloWorld.py), :: 15061da546Spatrick 16061da546Spatrick def hello_world_attach_with_id_api(self): 17061da546Spatrick '''Create target, spawn a process, and attach to it by id.''' 18061da546Spatrick 19061da546Spatrick target = self.dbg.CreateTarget(self.exe) 20061da546Spatrick 21061da546Spatrick # Spawn a new process and don't display the stdout if not in TraceOn() mode. 22061da546Spatrick import subprocess 23061da546Spatrick popen = subprocess.Popen([self.exe, 'abc', 'xyz'], 24061da546Spatrick stdout = open(os.devnull, 'w') if not self.TraceOn() else None) 25061da546Spatrick 26061da546Spatrick listener = lldb.SBListener('my.attach.listener') 27061da546Spatrick error = lldb.SBError() 28061da546Spatrick process = target.AttachToProcessWithID(listener, popen.pid, error) 29061da546Spatrick 30061da546Spatrick self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 31061da546Spatrick 32061da546Spatrick # Let's check the stack traces of the attached process. 33061da546Spatrick import lldbutil 34061da546Spatrick stacktraces = lldbutil.print_stacktraces(process, string_buffer=True) 35061da546Spatrick self.expect(stacktraces, exe=False, 36061da546Spatrick substrs = ['main.c:%d' % self.line2, 37061da546Spatrick '(int)argc=3']) 38061da546Spatrick 39061da546Spatrick listener = lldb.SBListener('my.attach.listener') 40061da546Spatrick error = lldb.SBError() 41061da546Spatrick process = target.AttachToProcessWithID(listener, popen.pid, error) 42061da546Spatrick 43061da546Spatrick self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 44061da546Spatrick 45061da546Spatrick checks that after the attach, there is no error condition by asserting 46061da546Spatrick that error.Success() is True and we get back a valid process object. 47061da546Spatrick 48*be691f3bSpatrick And (from test/python_api/event/TestEvent.py), :: 49061da546Spatrick 50061da546Spatrick # Now launch the process, and do not stop at entry point. 51061da546Spatrick error = lldb.SBError() 52061da546Spatrick process = target.Launch(listener, None, None, None, None, None, None, 0, False, error) 53061da546Spatrick self.assertTrue(error.Success() and process, PROCESS_IS_VALID) 54061da546Spatrick 55061da546Spatrick checks that after calling the target.Launch() method there's no error 56061da546Spatrick condition and we get back a void process object.") SBError; 57061da546Spatrick 58061da546Spatrick class SBError { 59061da546Spatrick public: 60061da546Spatrick SBError (); 61061da546Spatrick 62061da546Spatrick SBError (const lldb::SBError &rhs); 63061da546Spatrick 64061da546Spatrick ~SBError(); 65061da546Spatrick 66061da546Spatrick const char * 67061da546Spatrick GetCString () const; 68061da546Spatrick 69061da546Spatrick void 70061da546Spatrick Clear (); 71061da546Spatrick 72061da546Spatrick bool 73061da546Spatrick Fail () const; 74061da546Spatrick 75061da546Spatrick bool 76061da546Spatrick Success () const; 77061da546Spatrick 78061da546Spatrick uint32_t 79061da546Spatrick GetError () const; 80061da546Spatrick 81061da546Spatrick lldb::ErrorType 82061da546Spatrick GetType () const; 83061da546Spatrick 84061da546Spatrick void 85061da546Spatrick SetError (uint32_t err, lldb::ErrorType type); 86061da546Spatrick 87061da546Spatrick void 88061da546Spatrick SetErrorToErrno (); 89061da546Spatrick 90061da546Spatrick void 91061da546Spatrick SetErrorToGenericError (); 92061da546Spatrick 93061da546Spatrick void 94061da546Spatrick SetErrorString (const char *err_str); 95061da546Spatrick 96061da546Spatrick %varargs(3, char *str = NULL) SetErrorStringWithFormat; 97061da546Spatrick int 98061da546Spatrick SetErrorStringWithFormat (const char *format, ...); 99061da546Spatrick 100061da546Spatrick bool 101061da546Spatrick IsValid () const; 102061da546Spatrick 103061da546Spatrick explicit operator bool() const; 104061da546Spatrick 105061da546Spatrick bool 106061da546Spatrick GetDescription (lldb::SBStream &description); 107061da546Spatrick 108061da546Spatrick STRING_EXTENSION(SBError) 109061da546Spatrick 110061da546Spatrick #ifdef SWIGPYTHON 111061da546Spatrick %pythoncode %{ 112061da546Spatrick value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''') 113061da546Spatrick fail = property(Fail, None, doc='''A read only property that returns the same result as Fail().''') 114061da546Spatrick success = property(Success, None, doc='''A read only property that returns the same result as Success().''') 115061da546Spatrick description = property(GetCString, None, doc='''A read only property that returns the same result as GetCString().''') 116061da546Spatrick type = property(GetType, None, doc='''A read only property that returns the same result as GetType().''') 117061da546Spatrick %} 118061da546Spatrick #endif 119061da546Spatrick 120061da546Spatrick }; 121061da546Spatrick 122061da546Spatrick } // namespace lldb 123