# -*- coding: utf-8 -*-
from setuptools import setup

modules = \
['cpython_lldb']
install_requires = \
['six>=1.0.0,<2.0.0']

setup_kwargs = {
    'name': 'cpython-lldb',
    'version': '0.3.0',
    'description': 'LLDB script for debugging of CPython processes',
    'long_description': 'Overview\n========\n\n`cpython_lldb` is an LLDB extension for debugging Python programs.\n\nIt may be useful for troubleshooting stuck threads and crashes in the interpreter,\nor external libraries. Unlike most Python debuggers, LLDB allows you to attach to\na running process w/o instrumenting it in advance, or load a coredump and do a\npost-mortem analysis of a problem.\n\nWhen analyzing the state of a Python process, normally you would only have\naccess to the *intepreter-level* information: every variable would be of type\nPyObject\\*, and stack traces would only contain CPython internal calls and\ncalls to external libraries. Unless you are a CPython developer troubleshooting\nsome bug in the implementation of the interpreter, that is typically not\nvery useful. This extension, however, allows you to extract the *application-level*\ninformation about execution of a program: print the values of variables,\nlist the source code, display Python stack traces, etc.\n\nWhile CPython itself provides a similar extension for gdb [out of the box](\nhttps://github.com/python/cpython/blob/master/Tools/gdb/libpython.py),\none might still prefer to use LLDB as a debugger, e.g. on Mac OS.\n\n`cpython_lldb` requires CPython to be built with debugging symbols, which is\nnot the case for some Linux distros (most notably Arch Linux). CPython official\n[Docker images](https://hub.docker.com/_/python) are known to work correctly,\nas they are used for integration testing.\n\n\nFeatures\n========\n\n`cpython_lldb` targets CPython 3.5+ and supports the following features:\n\n* pretty-priting of built-in types (int, bool, float, bytes, str, none, tuple, list, set, frozenset, dict)\n* printing of Python-level stack traces\n* printing of local variables\n* listing the source code\n* walking up and down the Python call stack\n\nInstallation\n============\n\nIf your version of LLDB is linked against system libpython, it\'s recommended\nthat you install the extension to the user site packages directory and allow\nit to be loaded automatically on start of a new LLDB session:\n\n```shell\n$ python -m pip install --user cpython-lldb\n$ echo "command script import cpython_lldb" >> ~/.lldbinit\n$ chmod +x ~/.lldbinit\n```\n\nAlternatively, you can install the extension to some other location on disk\nand tell LLDB to load it from there, e.g. ~/.lldb:\n\n```shell\n$ mkdir -p ~/.lldb/cpython_lldb\n$ python -m pip install --target ~/.lldb/cpython_lldb cpython-lldb\n$ echo "command script import ~/.lldb/cpython_lldb/cpython_lldb.py" >> ~/.lldbinit\n$ chmod +x ~/.lldbinit\n```\n\nUsage\n=====\n\nStart a new LLDB session:\n\n```shell\n$ lldb /usr/bin/python\n```\n\nor attach to an existing CPython process:\n\n```shell\n$ lldb /usr/bin/python -p $PID\n```\n\nIf you\'ve followed the installation steps, the extension will now be automatically\nloaded on start of a new LLDB session and register some Python-specific commands:\n\n```\n(lldb) help\n...\nCurrent user-defined commands:\n  py-bt     -- Print a Python-level call trace of the selected thread.\n  py-down   -- Select a newer Python stack frame.\n  py-list   -- List the source code of the Python module that is currently being executed.\n  py-locals -- Print the values of local variables in the selected Python frame.\n  py-up     -- Select an older Python stack frame.\nFor more information on any command, type \'help <command-name>\'.\n```\n\nPretty-printing\n---------------\n\nAll known `PyObject`\'s (i.e. built-in types) are automatically pretty-printed\nwhen encountered, as if you tried to get a `repr()` of something in Python REPL,\ne.g.:\n\n```\n(lldb) frame variable v\n(PyObject *) v = 0x0000000100793c00 42\n(lldb) p v->ob_type->tp_name\n(const char *) $3 = 0x000000010017d42a "int"\n```\n\nStack traces\n------------\n\nUse `py-bt` to print a full application-level stack trace of the current thread, e.g.:\n\n```\n(lldb) py-bt\nTraceback (most recent call last):\n  File "test.py", line 15, in <module>\n    fc()\n  File "test.py", line 12, in fc\n    fb()\n  File "test.py", line 8, in fb\n    fa()\n  File "test.py", line 2, in fa\n    abs(1)\n```\n\nWalking up and down the call stack\n----------------------------------\n\nUse `py-up` and `py-down` to select an older or a newer Python call stack frame, e.g.:\n\n```\n(lldb) py-up\n  File "/Users/malor/src/cpython/test.py", line 6, in cb\n    self.ca()\n(lldb) py-up\n  File "/Users/malor/src/cpython/test.py", line 20, in f_static\n    c.cb()\n(lldb) py-down\n  File "/Users/malor/src/cpython/test.py", line 6, in cb\n    self.ca()\n(lldb) py-down\n  File "/Users/malor/src/cpython/test.py", line 3, in ca\n    abs(1)\n(lldb) py-down\n*** Newest frame\n```\n\nPrinting of local variables\n---------------------------\n\nUse `py-locals` to print the values of local variables in the selected frame:\n\n```\n(lldb) py-locals\na = 42\nargs = (1, 2, 3)\nb = [1, u\'hello\', u\'\\\\u0442\\\\u0435\\\\u0441\\\\u0442\']\nc = ([1], 2, [[3]])\nd = u\'test\'\ne = {u\'a\': -1, u\'b\': 0, u\'c\': 1}\neggs = 42\nkwargs = {u\'foo\': \'spam\'}\nspam = u\'foobar\'\n```\n\nListing the source code\n-----------------------\n\nUse `py-list` to list the source code that is currently being executed in the selected\nPython frame, e.g.:\n\n```\n(lldb) py-list\n    1    SOME_CONST = 42\n    2\n    3\n    4    def fa():\n   >5        abs(1)\n    6        return 1\n    7\n    8\n    9    def fb():\n   10        1 + 1\n```\n\nThe command also accepts optional `start` and `end` arguments that allow to\nlist the source code within a specific range of lines, e.g.:\n\n```\n(lldb) py-list 4\n    4    def fa():\n   >5        abs(1)\n    6        return 1\n    7\n    8\n    9    def fb():\n   10        1 + 1\n   11        fa()\n   12\n   13\n   14    def fc():\n```\n\nor:\n\n```\n(lldb) py-list 4 11\n    4    def fa():\n   >5        abs(1)\n    6        return 1\n    7\n    8\n    9    def fb():\n   10        1 + 1\n   11        fa()\n```\n\nPotential issues and how to solve them\n======================================\n\nCPython 2.7.x\n-------------\n\nCPython 2.7.x is not supported. There are currently no plans to support it in the future.\n\nMissing debugging symbols\n-------------------------\n\nCPython debugging symbols are required. You can check if they are available as follows:\n\n```shell\n$ lldb /usr/bin/python\n$ (lldb) type lookup PyObject\n```\n\nIf debugging symbols are not available, you\'ll see something like:\n\n```shell\nno type was found matching \'PyObject\'\n```\n\nSome Linux distros ship debugging symbols separately. To fix the problem on Debian / Ubuntu do:\n\n```shell\n$ sudo apt-get install python-dbg\n```\n\non CentOS / Fedora / RHEL do:\n\n```shell\n$ sudo yum install python-debuginfo\n```\n\nOther distros, like Arch Linux, do not provide debugging symbols in the package repos. In this case,\nyou would need to build CPython from source. Please refer to official [CPython](https://devguide.python.org/setup/#compiling)\nor [distro](https://wiki.archlinux.org/index.php/Debug_-_Getting_Traces) docs for instructions.\n\nAlternatively, you can use official CPython [Docker images](https://hub.docker.com/_/python).\n\n\nBroken LLDB scripting\n---------------------\n\nSome Linux distros (most notably Debian Stretch) are shipped with a version of LLDB in which Python scripting\ntriggers a segmentation fault when executing any non-trivial operation:\n\n```shell\n$ lldb\n(lldb) script\nPython Interactive Interpreter. To exit, type \'quit()\', \'exit()\' or Ctrl-D.\n>>> import io\n>>> Segmentation fault\n```\n\nIt\'s recommended that you use the latest LLDB release from the official [APT repo](https://apt.llvm.org/) instead\nof the one shipped with your distro.\n\nConflicting Python versions on Mac OS\n-------------------------------------\n\nIf you see an error like this:\n\n```\nTraceback (most recent call last):\n  File "<input>", line 1, in <module>\n  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>\n    import _io\nImportError: dlopen(/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder\n  Referenced from: /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so\n  Expected in: flat namespace\n in /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so\n```\n\nthen the version of LLDB, that is shipped with Mac OS and linked against the system CPython,\nis trying to use CPython installed via Homebrew. This won\'t work. You need to make sure LLDB\npicks up the correct CPython version on start. One way to achieve that would be modifying\n`$PATH`, e.g. by creating a wrapper for `lldb`:\n\n```\n#!/bin/sh\n\nexport PATH=/usr/bin:$PATH\nexec lldb "$@"\n```\n\nand putting it to `/usr/local/bin`.\n\nSee this [page](https://github.com/vadimcn/vscode-lldb/wiki/Troubleshooting) for advice on\ntroubleshooting of LLDB.\n\nDevelopment\n===========\n\nRunning tests\n-------------\n\nTests currently require `make` and `docker` to be installed.\n\nTo run the tests against the *latest* released CPython version, do:\n\n```\n$ make test\n```\n\nTo run the tests against a specific CPython (or LLDB) version, do:\n\n```\n$ PY_VERSION=X.Y LLDB_VERSION=Z make test\n```\n\nSupported CPython versions are:\n* `3.5`\n* `3.6`\n* `3.7`\n* `3.8`\n* `3.9`\n* `3.10`\n\nSupported LLDB versions:\n* `7`\n* `8`\n* `9`\n* `10`\n* `11`\n\nContributors\n============\n\nKudos to everyone who have contributed to this project!\n\n* Marco Neumann\n',
    'author': 'Roman Podoliaka',
    'author_email': 'roman.podoliaka@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/malor/cpython-lldb',
    'py_modules': modules,
    'install_requires': install_requires,
    'python_requires': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
}


setup(**setup_kwargs)
