Commit Graph

537 Commits

Author SHA1 Message Date
Zachary Turner e867044824 Fix a build issue where the python module could become stale.
We are using hardlinks instead of symlinks, and we attempted to
have some logic where we don't re-create the link if the target
file already exists.  This logic is faulty, however, when you
manually delete the source file (e.g. liblldb.dll) and then rebuild
lldb so that a brand new liblldb.dll gets written.  Now the two files
have different inodes, but the target exists, so we would not remake
the link and the target would become stale.

We fix this by only doing the optimization if they are really the
exact same file (by comparing inode numbers), and if they are not
the same file but the target exists, we delete it and re-create
the link.

llvm-svn: 263844
2016-03-18 22:33:59 +00:00
Jim Ingham c134810cfb Check for a NULL input filehandle before referencing it.
<rdar://problem/25105824>

llvm-svn: 263274
2016-03-11 18:49:38 +00:00
Jim Ingham d815c9ab88 Fix SBDebugger.GetOutputFileHandle() on OS X.
The swig typemaps had some magic for output File *'s on OS X that made:

SBDebugger.GetOutputFileHandle() 

actually work.  That was protected by a "#ifdef __MACOSX__", but the corresponding define
got lost going from the Darwin shell scripts to the python scripts for running
swig, so the code was elided.  I need to pass the define to SWIG, but only when
targetting Darwin.

So I added a target-platform argument to prepare_bindings, and if that 
is Darwin, I pass -D__APPLE__ to swig, and that activates this code again, and
GetOutputFileHandle works again.  Note, I only pass that argument for the Xcode
build.  I'm sure it is possible to do that for cmake, but my cmake-foo is weak.

I should have been able to write a test for this by creating a debugger, setting the 
output file handle to something file, writing to it, getting the output file handle 
and reading it.  But SetOutputFileHandle doesn't seem to work from Python, so I'd 
have to write a pexpect test to test this, which I'd rather not do.

llvm-svn: 263183
2016-03-11 01:57:45 +00:00
Siva Chandra 29d9bea93f Adjust for Python-3.
Summary:
This does not yet give us a clean testsuite run but it does help with:
1. Actually building on linux
2. Run the testsuite with over 70% tests passing on linux.

Reviewers: tfiala, labath, zturner

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D17182

llvm-svn: 260721
2016-02-12 20:30:47 +00:00
Enrico Granata 14086ed75d Change lldb.value.__int__() so that it takes into account the signedness of the value being cast to return a Python number with the proper value
The explicit APIs on SBValue obviously remain if one wants to be explicit in intent, or override this guess, but since __int__() has to pick one, an educated guess is definitely better than than always going to signed regardless

Fixes rdar://24556976

llvm-svn: 260349
2016-02-10 02:12:42 +00:00
Eugene Zelenko c33088f41e Remove autoconf support from source directories.
Differential revision: http://reviews.llvm.org/D16662

llvm-svn: 259098
2016-01-28 22:05:24 +00:00
Zachary Turner 4407396fb9 Fix some issues with bytes and strings in Python 3.
SBProcess::ReadMemory and other related functions such as
WriteMemory are returning Python string() objects.  This means
that in Python 3 that are returning Unicode objects.  In reality
they should be returning bytes objects which is the same as a string
in Python 2, but different in Python 3.  This patch updates the
generated SWIG code to return Python bytes objects for all
memory related functions.

One quirk of this patch is that the C++ signature of ReadCStringFromMemory
has it writing c-string data into a void*.  This confuses our swig
typemaps which expect that a void* means byte data.  So I hacked up
a custom typemap which maps this specific function to treat the
void* as string data instead of byte data.

llvm-svn: 258743
2016-01-25 23:21:18 +00:00
Zachary Turner bea3a85151 Fix more occurrences of string/bytes/bytearray in swig typemaps.
llvm-svn: 258742
2016-01-25 23:21:13 +00:00
Zachary Turner f9d6d204e8 Fix swig typemap for SBEvent.
This needs to be able to handle bytes, strings, and bytearray objects.
In Python 2 this was easy because bytes and strings are the same thing,
but in Python 3 the 2 cases need to be handled separately.  So as not
to mix raw Python C API code with PythonDataObjects code, I've also
introduced a PythonByteArray class to PythonDataObjects to make the
paradigm used here consistent.

llvm-svn: 258741
2016-01-25 23:21:09 +00:00
Zachary Turner 21da1ed15b Fix ResourceWarning about unclosed file in use_lldb_suite_root.py.
llvm-svn: 257945
2016-01-15 22:22:35 +00:00
Zachary Turner 673cf7e80b Get rid of const char** typemaps.
We already have char** typemaps which were near copy-pastes of
the const char** versions.  This way we have only one version that
works for both.

llvm-svn: 257670
2016-01-13 21:21:54 +00:00
Zachary Turner 19e2ea8fb6 Fix TestProcessLaunch for Python 3.
There were a number of problems preventing this from working:

1. The SWIG typemaps for converting Python lists to and from C++
   arrays were not updated for Python 3.  So they were doing things
   like PyString_Check instead of using the PythonString from
   PythonDataObjects.
2. ProcessLauncherWindows was ignoring the environment completely.
   So any test that involved launching an inferior with any kind
   of environment variable would have failed.
3. The test itself was using process.GetSTDOUT(), which isn't
   implemented on Windows.  So this was changed to save the
   value of the environment variable in a local variable and
   have the debugger look at the value of the variable.

llvm-svn: 257669
2016-01-13 21:21:49 +00:00
Enrico Granata 744959b9c9 Fix an issue where scripted commands would not actually print any of their output if an immediate output file was set in the result object via a Python file object
Fixes rdar://24130303

llvm-svn: 257644
2016-01-13 18:11:45 +00:00
Zachary Turner 7a76845c48 Fix Python 3 issues related to OS plugins.
* lldb::tid_t was being converted incorrectly, so this is updated to use
PythonInteger instead of manual Python Native API calls.
* OSPlugin_RegisterContextData was assuming that the result of
  get_register_data was a string, when in fact it is a bytes.  So this
  method is updated to use PythonBytes to do the work.

llvm-svn: 257398
2016-01-11 22:16:17 +00:00
Enrico Granata 31ccb51a7f __ne__ is the actual Python operator; __neq__ is a typo
llvm-svn: 256053
2015-12-18 22:46:58 +00:00
Ted Woodward ec2422364f Change finishSwigPythonLLDB.py to copy six.py instead of simlink it
Summary: If six.py is simlink'd, an installation won't be able to find it unless it has access to the source tree that lldb was built from.

Reviewers: zturner

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D15422

llvm-svn: 255340
2015-12-11 15:43:36 +00:00
Zachary Turner 4c152690be Remove `lldb.root` and just look for the file we care about.
llvm-svn: 253679
2015-11-20 17:40:57 +00:00
Todd Fiala f6508db485 Revert "prepare_bindings.py: enable static bindings"
This reverts commit 40f789f2dc6bb80fd25a33f91e452d081ed9d0ee.

llvm-svn: 253575
2015-11-19 16:56:12 +00:00
Todd Fiala 223f4bb9b2 Remove superseded buildSwigWrapperClasses.py and buildSwigPython.py classes
This closes:
http://reviews.llvm.org/D14783

llvm-svn: 253513
2015-11-18 22:21:47 +00:00
Todd Fiala a52e2c8376 Remove the scripts/Python/build-swig-Python.sh script.
This logically goes with my previous commit.

llvm-svn: 253491
2015-11-18 19:37:51 +00:00
Zachary Turner 48ef8d4c37 Fix some issues with swig & string conversion.
This patch fixes two issues:

1) Popen needs to be used with universal_newlines=True by default.
   This elicits automatic decoding from bytes -> string in Py3,
   and has no negative effects in other Py versions.
2) The swig typemaps for converting between string and (char*, int)
   did not work correctly when the length of the string was 0,
   indicating an error.  In this case we would try to construct a
   string from uninitialized data.
3) Ironically, the bug mentioned in #2 led to a test passing on
   Windows that was actually broken, because the test was written
   such that the assertion was never even getting checked, so it
   passed by default.  So we additionally fix this test to also
   fail if the method errors.  By fixing this test it's now broken
   on Windows, so we also xfail it.

llvm-svn: 253487
2015-11-18 18:40:16 +00:00
Todd Fiala d434a1d3e0 prepare_bindings.py: enable static bindings
Added a new flag, --allow-static-binding.  When specified,
if (and only if) the swig binary cannot be found, then the
LLDBWrapPython.cpp and lldb.py from the
scripts/Python/{static-binding-dir} are copied into the place where
swig would have generated them.

{static-binding-dir} defaults to static-binding, and can be
overridden with the --static-binding-dir command line argument.

The static bindings checked in are from r253424.

llvm-svn: 253448
2015-11-18 08:52:33 +00:00
Todd Fiala 84c72b6d75 Add Pythonic language binding wrapper generation script.
This is only used by Xcode at the moment.  It replaces the
buildSwigWrapperClasses.py and related per-script-language
scripts.  It also fixes a couple bugs in those w/r/t Xcode
usage:

* the presence of the GCC_PREPROCESSOR_DEFINITIONS env var
  should not be short-circuiting generation of the language
  binding; rather, only if LLDB_DISABLE_PYTHON is present
  within that environment variable.

* some logic around what to do when building in "non-Makefile"
  mode.  I've switched the handling of that to be on a
  "--framework" flag - if specified, we build an OS X-style
  framework; otherwise, we go with non.

Putting this up now only attached to the Xcode build so
others can look at it but not be affected by it yet.
After this, I'll tackle the finalizer, along with trying
it locally on Linux.

llvm-svn: 253317
2015-11-17 07:17:38 +00:00
Zachary Turner eddf19f995 Insert the SWIG version into LLDB's __init__.py
The goal here is to allow us to add skip / xfail decorators
based on SWIG version.

llvm-svn: 253262
2015-11-16 22:40:20 +00:00
Zachary Turner 32ac147b00 Python3 - Fix some issues related to `PythonFile` class.
Python 3 has lots of new debug asserts, and some of these were
firing on PythonFile.  Specifically related to handling of invalid
files.

llvm-svn: 253261
2015-11-16 22:40:12 +00:00
Bruce Mitchener 60cd65aac2 Allow to override python-config executable name from command line
Summary: pkgsrc (on NetBSD) ships with python2.7-config.

Patch by Kamil Rytarowski. Thanks!

Reviewers: emaste, clayborg

Subscribers: brucem, lldb-commits, joerg

Differential Revision: http://reviews.llvm.org/D14528

llvm-svn: 253152
2015-11-15 01:56:21 +00:00
Zachary Turner b359b10725 Delete `PyObjectToString` and use `PythonObject::Str()`.
The latter function, from PythonDataObjects, is Python 3 ready and
the former was not.

llvm-svn: 252992
2015-11-13 01:24:25 +00:00
Zachary Turner 5b1ffdf674 Finish PyCallable -> PythonCallable conversion.
This finishes the effort to port python-wrapper.swig code over to
using PythonDataObjects.

Also included in this patch is the removal of `PyCallable` from
`python-wrapper.swig`, as it is no longer used after having been
replaced by `PythonCallable` everywhere.

There might be additional cleanup as followup patches, but it should
be all fairly simple and minor.

llvm-svn: 252939
2015-11-12 20:11:02 +00:00
Zachary Turner 02bf92d226 Fix non-Windows build after r252906.
llvm-svn: 252909
2015-11-12 17:01:48 +00:00
Zachary Turner b58fb2f47a Begin converting uses of PyCallable to PythonCallable.
PyCallable is a class that exists solely within the swig wrapper
code.  PythonCallable is a more generic implementation of the same
idea that can be used by any Python-related interop code, and lives
in PythonDataObjects.h

The CL is mostly mechanical, and it doesn't cover every possible
user of PyCallable, because I want to minimize the impact of this
change (as well as making it easier to figure out what went wrong
in case this causes a failure).  I plan to finish up the rest of
the changes in a subsequent patch, culminating in the removal of
PyCallable entirely.

llvm-svn: 252906
2015-11-12 16:23:16 +00:00
Zachary Turner b8058a5e6e Remove `FindSessionDictionary` and rely on PythonDataObjects.
This had been relegated to a simple forwarding function, so just
delete it in preparation of migrating all of these functions out
of python-wrapper.swig.

llvm-svn: 252803
2015-11-11 21:07:29 +00:00
Zachary Turner caab921f8a Convert python-wrapper.swig to use PythonDataObjects.
This only begins to port python-wrapper.swig over.  Since this
code can be pretty hairy, I plan to do this incrementally over a
series of patches, each time removing or converting more code
over to the PythonDataObjects code.

llvm-svn: 252788
2015-11-11 19:42:35 +00:00
Zachary Turner 7d7814ae8a Symlink the `six` module during swig generation.
llvm-svn: 252764
2015-11-11 17:59:34 +00:00
Greg Clayton fe68904fa6 Fixed TypeMemberFunctionImpl to not use clang types directly but use the new CompilerDecl class to do the job in an abstract way.
Fixed a crash that would happen if you tried to get the name of a constructor or destructor by calling "getDeclName()" instead of calling getName() (which would assert and crash).

Added the ability to get function arguments names from SBFunction.

llvm-svn: 252622
2015-11-10 17:47:04 +00:00
Zachary Turner 88ab3c70e6 Use PythonDataObjects in swig helper functions.
Relying on manual Python C API calls is error prone, especially
when trying to maintain compatibility with Python 2 and Python 3.

This patch additionally fixes what appears to be a potentially
serious memory leak, in that were were incref'ing two values
returned from the session dictionary but never decref'ing them.
There was a comment indicating that it was intentional, but the
reasoning was, I believe, faulty and it resulted in a legitimate
memory leak.

Switching everything to PythonObject based classes solves both
the compatibility issues as well as the resource leak issues.

llvm-svn: 252536
2015-11-09 23:23:52 +00:00
Zachary Turner 37a0fc483b Remove a debug print statement.
llvm-svn: 252384
2015-11-07 01:12:53 +00:00
Zachary Turner c22811bbcc Python 3 - Use __bool__() instead of __nonzero__() for truthiness.
Python has a complicated mechanism of checking an objects truthity.
This involves a number of steps, which end with calling two private
methods on an object (if they are implemented).  In Python 2 these
two methods are `__nonzero__` and `__len__`, and in Python 3 they
are `__bool__` and `__len__`.  Because we *also* define a __len__
method for certain iterable types, this was triggering a situation
in Python 3 where `__nonzero__` wasn't defined, so it was calling
`__len__`, which was returning 0 (for example an SBDebugger with
no targets), and as a result the truthosity was determined to be
False.

We fix this by correctly using ` __bool__` for Python 3, and leave
the behavior under Python 2 unchanged.

Note that this fix is only implemented in the SWIG generation
python script, and not the SWIG generation shell script.  Someone
more familiar than me with shell scripts will need to fix them
to support this for Python 3 if desired.

llvm-svn: 252382
2015-11-07 01:08:25 +00:00
Bruce Mitchener ddcd2de0d1 [swig] Remove check_lldb_swig_executable_file_exists.
Summary:
Code that tried to find swig and then split the path into
a separate path and filename is being removed. The invoking
build system always provides the location of swig and we
don't need to split it into 2 pieces only to recombine it
a short time later.

Reviewers: zturner, domipheus

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D14415

llvm-svn: 252330
2015-11-06 18:53:29 +00:00
Bruce Mitchener a18231a5e9 [swig] Start of pylint on python build scripts.
Summary:
This does a broad first pass on cleaning up a lot of the noise when
using pylint on these scripts. It mostly addresses issues of:

* Mixed tabs and spaces.
* Trailing whitespace.
* Semicolons where they aren't needed.
* Incorrect whitespace around () and [].
* Superfluous parentheses.

There will be subsequent patches with further changes that build
upon these.

Reviewers: zturner, domipheus

Subscribers: lldb-commits

Differential Revision: http://reviews.llvm.org/D14375

llvm-svn: 252244
2015-11-05 23:57:33 +00:00
Zachary Turner ff836df6a4 Revert "Python 3 - Don't add the _d suffix to the symlink on Windows."
This reverts commit e59c95ca936f5a0a8abb987b8605fd8bf82b03b6.

This was a mistake on my part.  The real problem was with my
environment.  I was using a release interpreter to try to load
my debug extension module.  I noticed this after I finally managed
to get into my extension module's init method, and then it segfaulted
with heap errors due to mismatched CRT (debug vs. release)

llvm-svn: 252030
2015-11-04 01:26:48 +00:00
Zachary Turner b20ef35645 Python 3 - Don't add the _d suffix to the symlink on Windows.
In Python 2, a debug extension module required an _d suffix, so
for example the extension module `_lldb` would be backed by the file
`_lldb_d.pyd` if built in debug mode, and `_lldb.pyd` if built in
release mode.  In Python 2, although undocumented, this seems to
no longer be the case, and even for a debug extension module, the
interpreter will only look for the `_lldb.pyd` name.

llvm-svn: 252026
2015-11-04 01:03:57 +00:00
Zachary Turner a7cd16b252 Revert part of r239007 related to creating the Python symlink.
This has apparently been broken since June, but only on non-Windows.
Perhaps nobody noticed it because if the symlink is already there
it won't try to re-create it, and nobody ever tried doing a clean
build.

In any case, I will let the original author attempt to fix this if
he is still interested.  the problem is that in the normal case
of not setting BUILD_SHARED_LIBS and simply running ninja, it would
link _lldb.so to a non-existent location, creating a dangling
symlink.

llvm-svn: 251840
2015-11-02 22:13:13 +00:00
Todd Fiala 15c0fbaae1 Rename argdumper to lldb-argdumper
http://reviews.llvm.org/D14169

llvm-svn: 251616
2015-10-29 05:07:12 +00:00
Siva Chandra 9ac7a6c51f [SBValue] Add a method GetNumChildren(uint32_t max)
Summary:
Along with this, support for an optional argument to the "num_children"
method of a Python synthetic child provider has also been added. These have
been added with the following use case in mind:

Synthetic child providers currently have a method "has_children" and
"num_children". While the former is good enough to know if there are
children, it does not give any insight into how many children there are.
Though the latter serves this purpose, calculating the number for children
of a data structure could be an O(N) operation if the data structure has N
children. The new method added in this change provide a middle ground.
One can call GetNumChildren(K) to know if a child exists at an index K
which can be as large as the callers tolerance can be. If the caller wants
to know about children beyond K, it can make an other call with 2K. If the
synthetic child provider maintains state about it counting till K
previosly, then the next call is only an O(K) operation. Infact, all
calls made progressively with steps of K will be O(K) operations.

Reviewers: vharron, clayborg, granata.enrico

Subscribers: labath, lldb-commits

Differential Revision: http://reviews.llvm.org/D13778

llvm-svn: 250930
2015-10-21 19:28:08 +00:00
Zachary Turner 1756e05688 Run py2to3 on lldb/scripts folder.
This mostly fixes some print statements, but there were also some
instances of dict.iteritems() lingering that this found.

llvm-svn: 250762
2015-10-19 23:45:25 +00:00
Saleem Abdulrasool a8bf774b96 Python: follow python guidelines for header usage
Python requires that Python.h is included before any std header.  Not doing so
results in conflicts with standards macros such as `_XOPEN_SOURCE`.  NFC.

llvm-svn: 250673
2015-10-19 01:16:17 +00:00
Zachary Turner 5c3a198266 Make swig generation python scripts python 3 compatible.
llvm-svn: 250532
2015-10-16 17:52:12 +00:00
Zachary Turner 7d6d218e12 Convert SWIG typemap string operations to PythonObjects.
llvm-svn: 250530
2015-10-16 17:51:49 +00:00
Zachary Turner eda01c3175 Update SWIG typemaps to use `PythonFile`.
Using the Python native C API is non-portable across Python versions,
so this patch changes them to use the `PythonFile` class which hides
the version specific differences behind a single interface.

llvm-svn: 250525
2015-10-16 16:39:18 +00:00
Zachary Turner 60c24f70fe Change swig interface files to use PythonDataObjects.
llvm-svn: 250303
2015-10-14 16:59:32 +00:00