{"id":26131932,"url":"https://github.com/trepan-debuggers/python3-trepan","last_synced_at":"2025-12-14T15:47:47.901Z","repository":{"id":29266682,"uuid":"32799332","full_name":"Trepan-Debuggers/python3-trepan","owner":"Trepan-Debuggers","description":"A gdb-like Python3 Debugger in the Trepan family","archived":false,"fork":false,"pushed_at":"2025-02-08T03:45:49.000Z","size":1898,"stargazers_count":160,"open_issues_count":10,"forks_count":16,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-28T07:01:39.474Z","etag":null,"topics":["debugger","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Trepan-Debuggers.png","metadata":{"files":{"readme":"README.rst","changelog":"ChangeLog-spell-corrected.diff","contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["rocky"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"rocky","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-03-24T13:09:01.000Z","updated_at":"2025-03-10T11:29:11.000Z","dependencies_parsed_at":"2024-06-20T00:06:43.835Z","dependency_job_id":"2ad553e2-3459-4a14-8e9e-ba1787863701","html_url":"https://github.com/Trepan-Debuggers/python3-trepan","commit_stats":{"total_commits":703,"total_committers":11,"mean_commits":63.90909090909091,"dds":0.02560455192034139,"last_synced_commit":"a24009865cd1382bfbf0d3378e58a06866a9ab29"},"previous_names":["trepan-debuggers/python3-trepan","rocky/python3-trepan"],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trepan-Debuggers%2Fpython3-trepan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trepan-Debuggers%2Fpython3-trepan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trepan-Debuggers%2Fpython3-trepan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trepan-Debuggers%2Fpython3-trepan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Trepan-Debuggers","download_url":"https://codeload.github.com/Trepan-Debuggers/python3-trepan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247294516,"owners_count":20915340,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugger","python3"],"created_at":"2025-03-10T22:21:22.948Z","updated_at":"2025-12-14T15:47:47.888Z","avatar_url":"https://github.com/Trepan-Debuggers.png","language":"Python","funding_links":["https://github.com/sponsors/rocky","https://liberapay.com/rocky"],"categories":[],"sub_categories":[],"readme":"|CircleCI| |PyPI Installs| |license| |docs| |Supported Python Versions|\n\n|packagestatus|\n\n.. contents:: :local:\n\nAbstract\n========\n\nThis is a gdb-like debugger for Python. It is a rewrite of *pdb* from\nthe ground up. I was disappointed with the flakiness, imprecision, and\npoor quality of coding, modularity, and level of documentation when I\nfirst looked at *pdb*.\n\n*pdb* has gotten better since then. But a complete debugger is way more complex than what you'd expect from\na Standard Python module; it requires a larger set of supporting packages than is found in the Standard Python library.\n\n``trepan3k`` is both a high-level debugger as well as a lower-level\nbytecode debugger inspector. The code understands a lot about byte\ncode and the Python code object. The debugger makes use of this\nknowledge to get more precise and accurate results and provide more\nreliable operations.\n\nA command-line interface (CLI) is provided as well as remote access\ninterface over TCP/IP.\n\nSee the entry-exit_ for the various ways you can enter the debugger.\n\nThis code supports versions of Python back to version 3.0 using\ndifferent *git* branches. See trepan2_ for the same code modified to\nwork with Python 2.\n\nFeatures\n========\n\nSince this debugger is similar to other_ trepanning_ debuggers_ and *gdb*\nin general, knowledge gained by learning this is transferable to those\ndebuggers and vice versa.\n\nThere's a lot of cool stuff here that's not in the stock\nPython debugger *pdb*, or any other Python debugger that I know about.\n\n\nMore Exact location information\n-------------------------------\n\nPython reports line information on the granularity of a line. For\nPython versions up to 3.8. To get more precise information, we can\n(de)parse into Python the bytecode around a bytecode offset, such as\nthe place you are stopped at.\n\nSo far as I know, there is no other debugger that decompiles code at\nruntime to narrow the position down to the specific bytecode\ninstruction.\n\nSee the deparse_ command for details on getting this kind of\ninformation.\n\nThe problem with deparsing after 3.8 is that there is no decompiler\nthat can deparse code and give associations to bytecode\ninstructions. I am slowly working on that, though.\n\nWe use information in Python's code object line number table in bytes\nto understand which lines are breakpointable, and in which module or\nfunction the line appears. Use info-line_ to see this\ninformation. Most, if not all, other debuggers do go to such lengths,\nand as a result, it is possible to request stopping on a line number\nthat can never occur without complaint.\n\nIn the future, we may allow specifying an offset to indicate which\noffset to stop at when there are several choices for a given line\nnumber.\n\n\nDebugging Python bytecode (no source available)\n-----------------------------------------------\n\nYou can pass the debugger the name of Python bytecode, and many times, the debugger will merrily proceed.  This debugger tries very hard to find the source code. Either by using the current executable search path (e.g. ``PATH``) or for some by looking inside the bytecode for a filename in the main code object (``co_filename``) and applying that with a search path that takes into account the directory where the bytecode lives.\n\nFailing to find source code this way, and in other situations where\nsource code can't be found, the debugger will decompile the bytecode\nand use that for showing the source text. *This allows us to debug ``eval``'d\nor ``exec``'d code.*\n\nBut if you happen to know where the source code is located, you can\nassociate a file source code with the current name listed in the\nbytecode. See the set-substitute_ command for details here.\n\nSource-code Syntax Colorization\n-------------------------------\n\nTerminal source code is colorized via pygments_. And with that, you\ncan set the pygments color style, e.g., \"colorful\", \"paraiso-dark\". See\nset-style_ . Furthermore, we make use of terminal bold\nand emphasized text in debugger output and help text. Of course, you\ncan also turn this off. You can use your own pygments_style_, provided\nyou have a terminal that supports 256 colors. If your terminal\nsupports the basic ANSI color sequences only, we support that too in\nboth dark and light themes.\n\n\nCommand Completion\n------------------\n\nCommand completion is available for GNU readline and\n``prompt_toolkit``. While prompt_toolkit is new, command completion for\nGNU Readline is not just a simple static list but varies depending on\nthe context. For example, for frame-changing commands that take\noptional numbers, the list of *valid numbers* is considered.\n\nIn time (and perhaps with some volunteers), ``prompt_toolkit`` will be as good as GNU Readline completion.\n\nTerminal Handling\n-----------------\n\nWe can adjust the debugger output depending on the line width of your\nterminal. If it changes, or you want to adjust it, see set-width_.\n\nSignal Handling\n-----------------\n\nFollowing *gdb*, we provide its rich set of signal handling. From the *gdb* documentation:\n\n  GDB has the ability to detect any occurrence of a signal in your program. You can tell GDB in advance what to do for each kind of signal.\n\nBetter Support for Thread Debugging\n------------------------------------\n\nWhen you are stopped inside a thread, the thread name is shown to make\nthis fact clearer, and you can see and switch between frames in\ndifferent threads. See frame_ for more information.\n\nAnd following *gdb*, you can list the threads too. See info-threads_ for more information.\n\n\nSmart Eval\n----------\n\nIf you want to evaluate the current source line before it is run in\nthe code, use ``eval``. To evaluate the text of a common fragment of a\nline, such as the expression part of an *if* statement, you can do\nthat with ``eval?``. See eval_ for more information.\n\nFunction Breakpoints\n---------------------\n\nMany Python debuggers only allow setting a breakpoint at a line event, and functions are treated like line numbers. But functions and lines\nare fundamentally different. If I write:\n\n     def five(): return 5\n\nthis line contains three different kinds of things. First, there is\nthe code in Python that defines the function ``five()`` for the first\ntime. Then there is the function itself, and then there is some code\ninside that function.\n\nIn this debugger, you can give the name of a *function* by surrounding\nadding ``()`` at the end::\n\n    break five()\n\nAlso ``five`` could be a method of an object that is currently defined when the\n``breakpoint`` command is given::\n\n    self.five()\n\nMore Stepping Control\n---------------------\n\nSometimes you want small steps, and sometimes large steps.\n\nThis fundamental issue is handled in a couple of ways:\n\nStep Granularity\n................\n\nThere are now ``step`` *event* and ``next`` *event* commands with\naliases to ``s+``, ``s\u003e``, and so on. The plus-suffixed commands force\na different line on a subsequent stop; the dash-suffixed commands\ndon't.  Suffixes ``\u003e``, ``\u003c``, and ``!`` specify ``call``, ``return``\nand ``exception`` events respectively. And without a suffix, you get\nthe default; this is set by the ``set different`` command.\n\nEvent Filtering and Tracing\n...........................\n\nBy default, the debugger stops at every event: ``call``, ``return``,\n``line``, ``exception``, ``c-call``, ``c-exception``. If you just want\nto stop at ``line`` events (which is largely what happens in\n*pdb*), you can. If, however, you just want to stop at calls and returns,\nthat's possible too. Or pick some combination.\n\nIn conjunction with handling *all* events by default, the event status is shown when stopped. The reason for stopping is also available via ``info program``.\n\nEvent Tracing of Calls and Returns\n----------------------------------\n\nI'm not sure why this was not done before. Probably because of the lack of the ability to set and move by different granularities,\ntracing calls and returns leads to too many uninteresting stops (such\nas at the same place you just were). Also, stopping on function\ndefinitions probably added to this tedium.\n\nBecause we're handling return events, we can stop on the\nreturn. This is a little more precise than *pdb*'s *retval* command.\n\nDebugger Macros via Python Lambda Expressions\n---------------------------------------------\n\nThere are debugger macros.  In *gdb*, there is a *macro* debugger command to extend debugger commands.\n\nHowever, Python has its own rich programming language, so it seems silly\nto recreate the macro language that is in *gdb*. Simpler and more\npowerful is just to use Python here. A debugger macro here is just a\nlambda expression that returns a string or a list of strings. Each\nstring returned should be a debugger command.\n\nWe also have *aliases* for the extremely simple situation where you\nwant to give an alias to an existing debugger command. But beware:\nSome commands, like step_ inspect command suffixes, and change their\nbehavior accordingly.\n\nWe also provide a means to extend the debugger through additional Python packages.\n\nByte-code Instruction Introspection\n------------------------------------\n\nWe do more in the way of looking at the byte codes to give better information. Through this, we can provide:\n\n* A *skip* command. It is like the *jump* command, but you don't have\n  to deal with line numbers.\n* Disassembly of code fragments. You can now disassemble relative to\n  the stack frames you are currently stopped at.\n* Better interpretation of where you are when inside *execfile* or\n  *exec*. (But really, though this is probably a Python compiler\n  misfeature.)\n* Check that breakpoints are set only where they make sense.\n* A more accurate determination of whether you are at a function-defining\n  *def* or *class* statements (because the caller's instruction contains\n  ``MAKE_FUNCTION`` or ``BUILD_CLASS``.)\n\nEven without \"deparsing\" mentioned above, the ability to disassemble\nwhere the PC is currently located (see info-pc_), by line number range or byte-offset range lets you tell exactly where you are and code is getting run.\n\nSome Debugger Command Arguments can be Variables and Expressions\n----------------------------------------------------------------\n\nCommands that take integer arguments like *up*, *list*, or\n*disassemble* allow you to use a Python expression that may include\nlocal or global variables that evaluate to an integer. This\neliminates the need in *gdb* for special \"dollar\" debugger\nvariables. (Note, however, because of *shlex* parsing, expressions can't\nhave embedded blanks.)\n\nOut-of-Process Debugging\n------------------------\n\nYou can now debug your program in a different process or even on a different computer on a different network!\n\nRelated is flexible support for remapping path names from the file\nsystem, e.g., the filesystem seen inside a Docker container or on a remote filesystem\nwith locally-installed files. See subst_ for more information.\n\nEgg, Wheel, and Tarballs\n------------------------\n\nCan be installed via the usual *pip* or *easy_install*. There is a\nsource tarball. `How To Install\n\u003chttps://python3-trepan.readthedocs.io/en/latest/install.html\u003e`_ has\nfull instructions and installation using *git* or by other means.\n\nModularity\n----------\n\nBecause this debugger is modular, I have been able to use it as the basis\nfor debuggers in other projects. In particular, it is used as a module in trepanxpy_, a debugger for Python interpreter, x-python_, written in Python.\n\nIt is also used as a module inside an experimental open-source Wolfram Mathematica interpreter, Mathics3_.\n\nUsing pytracer_, the Debugger plays nicely with other trace hooks. You\ncan have several debugger objects.\n\nMany of the things listed below do not directly impact end-users, but\nit does eventually by way of more robust and featureful code. And\nkeeping developers happy is a good thing.(TM)\n\n* Commands and subcommands are individual classes now, not methods in a class. This means they now have properties like the context in which they can be run, minimum abbreviation names, or alias names. To add a new command, you add a file under the command directory.\n* I/O is its own layer. This simplifies interactive readline behavior from reading commands over a TCP socket.\n* An interface is its own layer. Local debugging, remote debugging, and running debugger commands from a file (``source``) are different interfaces. This means, for example, that we are able to give better error reporting if a debugger command file has an error.\n* There is an experimental Python-friendly interface for front-ends\n* more testable. Much more unit and functional tests.\n\nDocumentation\n-------------\n\nDocumentation: http://python3-trepan.readthedocs.org\n\nSee Also\n--------\n\n* trepanxpy_: trepan debugger for `x-python \u003chttps://pypi.python.org/pypi/x-python\u003e`_, the bytecode interpreter written in Python\n* https://github.com/rocky/trepan-xpy: Python debugger using this code to support `x-python \u003chttps://pypi.python.org/pypi/x-python\u003e`_\n* https://pypi.python.org/pypi/uncompyle6: Python decompiler\n* https://pypi.python.org/pypi/decompyle3: Python 3.7 and 3.8 decompiler\n* https://pypi.python.org/pypi/xdis: cross-platform disassembler\n\n\n.. _pytracer: https://pypi.python.org/pypi/pytracer\n.. _x-python: https://pypi.python.org/pypi/x-python\n.. _Mathics3:  https://mathics.org\n.. _pygments:  https://pygments.org\n.. _pygments_style:  https://pygments.org/docs/styles/\n.. _howtoinstall: https://github.com/rocky/python3-trepan/wiki/How-to-Install\n.. _pydb:  https://bashdb.sf.net/pydb\n.. _pydbgr: https://pypi.python.org/pypi/pydbgr\n.. _trepan2: https://pypi.python.org/pypi/trepan2\n.. _trepan3: https://github.com/rocky/python3-trepan\n.. _trepanxpy: https://pypi.python.org/pypi/trepanxpy\n.. _other: https://repology.org/project/zshdb/versions\n.. _trepanning: https://rubygems.org/gems/trepanning\n.. _debuggers: https://metacpan.org/pod/Devel::Trepan\n.. _this: https://bashdb.sourceforge.net/pydb/features.html\n.. _entry-exit: https://python3-trepan.readthedocs.io/en/latest/entry-exit.html\n.. _trepanxpy: https://pypi.python.org/pypi/trepanxpy\n.. |downloads| image:: https://img.shields.io/pypi/dd/trepan3k.svg\n   :target: https://pypi.python.org/pypi/trepan3k/\n.. |CircleCI| image:: https://circleci.com/gh/Trepan-Debuggers/python3-trepan/tree/master.svg?style=svg\n        :target: https://app.circleci.com/pipelines/github/Trepan-Debuggers/python3-trepan\n.. _ipython-trepan: https://github.com/rocky/ipython-trepan\n.. |license| image:: https://img.shields.io/pypi/l/trepan.svg\n    :target: https://pypi.python.org/pypi/trepan3k\n    :alt: License\n.. _deparse:  https://python3-trepan.readthedocs.io/en/latest/commands/data/deparse.html\n.. _info-line:  https://python3-trepan.readthedocs.io/en/latest/commands/info/line.html\n.. _info-pc:  https://python3-trepan.readthedocs.io/en/latest/commands/info/pc.html\n.. _info-threads:  https://python3-trepan.readthedocs.io/en/latest/commands/info/threads.html\n.. _frame:  https://python3-trepan.readthedocs.io/en/latest/commands/stack/frame.html\n.. _set-style:  https://python3-trepan.readthedocs.org/en/latest/commands/set/style.html\n.. _set-substitute:  https://python3-trepan.readthedocs.org/en/latest/commands/set/substitute.html\n.. _set-width:  https://python3-trepan.readthedocs.org/en/latest/commands/set/width.html\n.. _eval: https://python3-trepan.readthedocs.org/en/latest/commands/data/eval.html\n.. _step: https://python3-trepan.readthedocs.org/en/latest/commands/running/step.html\n.. _subst: https://python3-trepan.readthedocs.io/en/latest/commands/set/substitute.html\n.. _install: https://python3-trepan.readthedocs.org/en/latest/install.html\n.. |Supported Python Versions| image:: https://img.shields.io/pypi/pyversions/trepan3k.svg\n   :target: https://pypi.python.org/pypi/trepan3k/\n.. |PyPI Installs| image:: https://img.shields.io/pypi/dm/trepan3k\n\t\t\t   :alt: PyPI - Downloads\n.. |packagestatus| image:: https://repology.org/badge/vertical-allrepos/python:trepan3k.svg\n\t\t :target: https://repology.org/project/python:trepan3k/versions\n.. |docs| image:: https://readthedocs.org/projects/python3-trepan/badge/?version=latest\n    :target: https://python3-trepan.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrepan-debuggers%2Fpython3-trepan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrepan-debuggers%2Fpython3-trepan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrepan-debuggers%2Fpython3-trepan/lists"}