2011-07-20 06:41:47 +08:00
|
|
|
//===-- SWIG Interface for SBError ------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-07-20 06:41:47 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace lldb {
|
|
|
|
|
2011-07-20 08:23:11 +08:00
|
|
|
%feature("docstring",
|
|
|
|
"Represents a container for holding any error code.
|
|
|
|
|
2021-01-15 21:43:26 +08:00
|
|
|
For example (from test/python_api/hello_world/TestHelloWorld.py), ::
|
2011-07-20 08:23:11 +08:00
|
|
|
|
|
|
|
def hello_world_attach_with_id_api(self):
|
|
|
|
'''Create target, spawn a process, and attach to it by id.'''
|
|
|
|
|
|
|
|
target = self.dbg.CreateTarget(self.exe)
|
|
|
|
|
|
|
|
# Spawn a new process and don't display the stdout if not in TraceOn() mode.
|
|
|
|
import subprocess
|
|
|
|
popen = subprocess.Popen([self.exe, 'abc', 'xyz'],
|
|
|
|
stdout = open(os.devnull, 'w') if not self.TraceOn() else None)
|
|
|
|
|
|
|
|
listener = lldb.SBListener('my.attach.listener')
|
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.AttachToProcessWithID(listener, popen.pid, error)
|
|
|
|
|
|
|
|
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
|
|
|
|
|
|
|
|
# Let's check the stack traces of the attached process.
|
|
|
|
import lldbutil
|
|
|
|
stacktraces = lldbutil.print_stacktraces(process, string_buffer=True)
|
|
|
|
self.expect(stacktraces, exe=False,
|
|
|
|
substrs = ['main.c:%d' % self.line2,
|
|
|
|
'(int)argc=3'])
|
|
|
|
|
|
|
|
listener = lldb.SBListener('my.attach.listener')
|
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.AttachToProcessWithID(listener, popen.pid, error)
|
|
|
|
|
|
|
|
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
|
|
|
|
|
|
|
|
checks that after the attach, there is no error condition by asserting
|
|
|
|
that error.Success() is True and we get back a valid process object.
|
|
|
|
|
2021-01-15 21:43:26 +08:00
|
|
|
And (from test/python_api/event/TestEvent.py), ::
|
2011-07-20 08:23:11 +08:00
|
|
|
|
|
|
|
# Now launch the process, and do not stop at entry point.
|
|
|
|
error = lldb.SBError()
|
|
|
|
process = target.Launch(listener, None, None, None, None, None, None, 0, False, error)
|
|
|
|
self.assertTrue(error.Success() and process, PROCESS_IS_VALID)
|
|
|
|
|
|
|
|
checks that after calling the target.Launch() method there's no error
|
2019-04-19 00:23:33 +08:00
|
|
|
condition and we get back a void process object.") SBError;
|
2015-10-14 01:54:15 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
class SBError {
|
|
|
|
public:
|
|
|
|
SBError ();
|
|
|
|
|
|
|
|
SBError (const lldb::SBError &rhs);
|
|
|
|
|
|
|
|
~SBError();
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetCString () const;
|
|
|
|
|
|
|
|
void
|
|
|
|
Clear ();
|
|
|
|
|
|
|
|
bool
|
|
|
|
Fail () const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
Success () const;
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
GetError () const;
|
|
|
|
|
|
|
|
lldb::ErrorType
|
|
|
|
GetType () const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetError (uint32_t err, lldb::ErrorType type);
|
|
|
|
|
|
|
|
void
|
|
|
|
SetErrorToErrno ();
|
|
|
|
|
|
|
|
void
|
|
|
|
SetErrorToGenericError ();
|
|
|
|
|
|
|
|
void
|
|
|
|
SetErrorString (const char *err_str);
|
|
|
|
|
2015-10-14 01:54:15 +08:00
|
|
|
%varargs(3, char *str = NULL) SetErrorStringWithFormat;
|
2011-07-20 06:41:47 +08:00
|
|
|
int
|
|
|
|
SetErrorStringWithFormat (const char *format, ...);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsValid () const;
|
|
|
|
|
Add "operator bool" to SB APIs
Summary:
Our python version of the SB API has (the python equivalent of)
operator bool, but the C++ version doesn't.
This is because our python operators are added by modify-python-lldb.py,
which performs postprocessing on the swig-generated interface files.
In this patch, I add the "operator bool" to all SB classes which have an
IsValid method (which is the same logic used by modify-python-lldb.py).
This way, we make the two interfaces more constent, and it allows us to
rely on swig's automatic syntesis of python __nonzero__ methods instead
of doing manual fixups.
Reviewers: zturner, jingham, clayborg, jfb, serge-sans-paille
Subscribers: jdoerfert, lldb-commits
Differential Revision: https://reviews.llvm.org/D58792
llvm-svn: 355824
2019-03-11 21:58:46 +08:00
|
|
|
explicit operator bool() const;
|
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
bool
|
|
|
|
GetDescription (lldb::SBStream &description);
|
|
|
|
|
2020-01-09 08:13:03 +08:00
|
|
|
STRING_EXTENSION(SBError)
|
|
|
|
|
2019-12-09 06:46:48 +08:00
|
|
|
#ifdef SWIGPYTHON
|
2019-07-03 02:04:55 +08:00
|
|
|
%pythoncode %{
|
2019-07-03 06:18:35 +08:00
|
|
|
value = property(GetError, None, doc='''A read only property that returns the same result as GetError().''')
|
|
|
|
fail = property(Fail, None, doc='''A read only property that returns the same result as Fail().''')
|
|
|
|
success = property(Success, None, doc='''A read only property that returns the same result as Success().''')
|
|
|
|
description = property(GetCString, None, doc='''A read only property that returns the same result as GetCString().''')
|
|
|
|
type = property(GetType, None, doc='''A read only property that returns the same result as GetType().''')
|
2019-07-03 02:04:55 +08:00
|
|
|
%}
|
2019-12-09 06:46:48 +08:00
|
|
|
#endif
|
2019-07-03 02:04:55 +08:00
|
|
|
|
|
|
|
};
|
2019-07-03 01:25:20 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
} // namespace lldb
|