2011-07-20 06:41:47 +08:00
|
|
|
//===-- SWIG Interface for SBFileSpec ---------------------------*- 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 09:06:37 +08:00
|
|
|
%feature("docstring",
|
2014-07-02 05:22:11 +08:00
|
|
|
"Represents a file specification that divides the path into a directory and
|
2011-07-20 09:06:37 +08:00
|
|
|
basename. The string values of the paths are put into uniqued string pools
|
|
|
|
for fast comparisons and efficient memory usage.
|
|
|
|
|
2021-01-15 21:43:26 +08:00
|
|
|
For example, the following code ::
|
2011-07-20 09:06:37 +08:00
|
|
|
|
|
|
|
lineEntry = context.GetLineEntry()
|
|
|
|
self.expect(lineEntry.GetFileSpec().GetDirectory(), 'The line entry should have the correct directory',
|
|
|
|
exe=False,
|
|
|
|
substrs = [self.mydir])
|
|
|
|
self.expect(lineEntry.GetFileSpec().GetFilename(), 'The line entry should have the correct filename',
|
|
|
|
exe=False,
|
|
|
|
substrs = ['main.c'])
|
|
|
|
self.assertTrue(lineEntry.GetLine() == self.line,
|
|
|
|
'The line entry's line number should match ')
|
|
|
|
|
|
|
|
gets the line entry from the symbol context when a thread is stopped.
|
|
|
|
It gets the file spec corresponding to the line entry and checks that
|
2019-04-19 00:23:33 +08:00
|
|
|
the filename and the directory matches what we expect.") SBFileSpec;
|
2011-07-20 06:41:47 +08:00
|
|
|
class SBFileSpec
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SBFileSpec ();
|
|
|
|
|
|
|
|
SBFileSpec (const lldb::SBFileSpec &rhs);
|
|
|
|
|
2014-07-02 05:22:11 +08:00
|
|
|
SBFileSpec (const char *path);// Deprecated, use SBFileSpec (const char *path, bool resolve)
|
2011-07-20 06:41:47 +08:00
|
|
|
|
|
|
|
SBFileSpec (const char *path, bool resolve);
|
|
|
|
|
|
|
|
~SBFileSpec ();
|
|
|
|
|
Make operator==s consistent between c++ and python APIs
Summary:
modify-python-lldb.py had code to insert python equality operators to
some classes. Some of those classes already had c++ equality operators,
and some didn't.
This makes the situation more consistent, by removing all equality
handilng from modify-python-lldb. Instead, I add c++ operators to
classes where they were missing, and expose them in the swig interface
files so that they are available to python too.
The only tricky case was the SBAddress class, which had an operator==
defined as a free function, which is not handled by swig. This function
cannot be removed without breaking ABI, and we cannot add an extra
operator== member, as that would make equality comparisons ambiguous.
For this class, I define a python __eq__ function by hand and have it
delegate to the operator!=, which I have defined as a member function.
This isn't fully NFC, as the semantics of some equality functions in
python changes slightly, but I believe it changes for the better (e.g.,
previously SBBreakpoint.__eq__ would consider two breakpoints with the
same ID as equal, even if they belonged to different targets; now they
are only equal if they belong to the same target).
Reviewers: jingham, clayborg, zturner
Subscribers: jdoerfert, JDevlieghere, lldb-commits
Differential Revision: https://reviews.llvm.org/D59819
llvm-svn: 357463
2019-04-02 18:18:46 +08:00
|
|
|
bool operator==(const SBFileSpec &rhs) const;
|
|
|
|
|
|
|
|
bool operator!=(const SBFileSpec &rhs) const;
|
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
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
|
|
|
|
Exists () const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
ResolveExecutableLocation ();
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetFilename() const;
|
|
|
|
|
|
|
|
const char *
|
|
|
|
GetDirectory() const;
|
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
void
|
|
|
|
SetFilename(const char *filename);
|
2019-04-19 00:23:33 +08:00
|
|
|
|
2013-11-21 05:07:01 +08:00
|
|
|
void
|
|
|
|
SetDirectory(const char *directory);
|
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
uint32_t
|
|
|
|
GetPath (char *dst_path, size_t dst_len) const;
|
|
|
|
|
|
|
|
static int
|
|
|
|
ResolvePath (const char *src_path, char *dst_path, size_t dst_len);
|
|
|
|
|
|
|
|
bool
|
|
|
|
GetDescription (lldb::SBStream &description) const;
|
2016-02-19 08:05:17 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
AppendPathComponent (const char *file_or_directory);
|
|
|
|
|
2020-01-09 08:13:03 +08:00
|
|
|
STRING_EXTENSION(SBFileSpec)
|
|
|
|
|
2019-12-09 06:46:48 +08:00
|
|
|
#ifdef SWIGPYTHON
|
2012-01-29 14:07:39 +08:00
|
|
|
%pythoncode %{
|
2012-02-01 16:09:32 +08:00
|
|
|
def __get_fullpath__(self):
|
|
|
|
spec_dir = self.GetDirectory()
|
|
|
|
spec_file = self.GetFilename()
|
|
|
|
if spec_dir and spec_file:
|
|
|
|
return '%s/%s' % (spec_dir, spec_file)
|
|
|
|
elif spec_dir:
|
|
|
|
return spec_dir
|
|
|
|
elif spec_file:
|
|
|
|
return spec_file
|
|
|
|
return None
|
|
|
|
|
2019-07-03 06:18:35 +08:00
|
|
|
fullpath = property(__get_fullpath__, None, doc='''A read only property that returns the fullpath as a python string.''')
|
|
|
|
basename = property(GetFilename, None, doc='''A read only property that returns the path basename as a python string.''')
|
|
|
|
dirname = property(GetDirectory, None, doc='''A read only property that returns the path directory name as a python string.''')
|
|
|
|
exists = property(Exists, None, doc='''A read only property that returns a boolean value that indicates if the file exists.''')
|
2012-01-29 14:07:39 +08:00
|
|
|
%}
|
2019-12-09 06:46:48 +08:00
|
|
|
#endif
|
2012-01-29 14:07:39 +08:00
|
|
|
|
2011-07-20 06:41:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace lldb
|