Skip to main content

GDB-like Python Debugger in the Trepan family

Project description

TravisCI CircleCI Pypi Installs License Supported Python Versions

packagestatus

Abstract

This is a gdb-like debugger for Python. It is a rewrite of pdb from the ground up. It is both a high-level debugger as well as a lower-level bytecode debugger. By lower-level debugger, I mean that it understands a lot about byte code and will try to make use of that in its normal higher-level instructions.

A command-line interface (CLI) is provided as well as an remote access interface over TCP/IP.

See the Tutorial for how to use. See ipython-trepan for using this in ipython or an ipython notebook.

This package is for Python 3.2 and above. See trepan2 for the same code modified to work with Python 2.

Features

Since this debugger is similar to other trepanning debuggers and gdb in general, knowledge gained by learning this is transferable to those debuggers and vice versa.

There’s a lot of cool stuff here that’s not in the stock Python debugger pdb, or in any other Python debugger that I know about.

More Exact location information

Python reports line information on the granularity of a line. To get more precise information, we can (de)parse into Python the byte code around a bytecode offset such as the place you are stopped at.

So far as I know, there is no other debugger that decompile code at runtime.

See the deparse command for details.

We use information in the line number table in byte to understand which lines are breakpointable, and in which module or function the line appears in. Use info_line to see this information.

In the future we may allow specifiying an offset to indicate which offset to stop at when there are several choices for a given line number.

Debugging Python bytecode (no source available)

You can pass the debugger the name of Python bytecode and many times, the debugger will merrily proceed. This debugger tries very hard 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 which takes into account directory where the bytecode lives.

Failing to find source code this way, and in other situations where source code can’t be found, the debugger will decompile the bytecode and use that for showing source test. This allows us to debug `eval`’d or `exec’’d code.

But if you happen to know where the source code is located, you can associate a file source code with the current name listed in the bytecode. See the set_substitute command for details here.

Source-code Syntax Colorization

Terminal source code is colorized via pygments . And with that you can set the pygments color style, e.g. “colorful”, “paraiso-dark”. See set_style . Furthermore, we make use of terminal bold and emphasized text in debugger output and help text. Of course, you can also turn this off. You can use your own pygments_style, provided you have a terminal that supports 256 colors. If your terminal supports the basic ANSI color sequences only, we support that too in both dark and light themes.

Command Completion

GNU readline command completion is available. Command completion is not just a simple static list, but varies depending on the context. For example, for frame-changing commands which take optional numbers, on the list of valid numbers is considered.

Terminal Handling

We can adjust debugger output depending on the line width of your terminal. If it changes, or you want to adjust it, see set_width .

Smart Eval

If you want to evaluate the current source line before it is run in the code, use eval. To evaluate text of a common fragment of line, such as the expression part of an if statement, you can do that with eval?. See eval for more information.

Function Breakpoints

Many Python debuggers only allow setting a breakpoint at a line event and functions are treated like line numbers. But functions and lines are fundamentally different. If I write:

def five(): return 5

this line means has three different kinds of things. First there is the code in Python that defines function five() for the first time. Then there is the function itself, and then there is some code inside that function.

In this debugger, you can give the name of a function by surrounding adding () at the end:

break five()

Also five could be a method of an object that is currently defined when the breakpoint command is given:

self.five()

More Stepping Control

Sometimes you want small steps, and sometimes large stepping.

This fundamental issue is handled in a couple ways:

Step Granularity

There are now step event and next event commands with aliases to s+, s> and so on. The plus-suffixed commands force a different line on a subsequent stop, the dash-suffixed commands don’t. Suffixes >, <, and ! specify call, return and exception events respectively. And without a suffix you get the default; this is set by the set different command.

Event Filtering and Tracing

By default the debugger stops at every event: call, return, line, exception, c-call, c-exception. If you just want to stop at line events (which is largely what you happens in pdb) you can. If however you just want to stop at calls and returns, that’s possible too. Or pick some combination.

In conjunction with handling all events by default, the event status is shown when stopped. The reason for stopping is also available via info program.

Event Tracing of Calls and Returns

I’m not sure why this was not done before. Probably because of the lack of the ability to set and move by different granularities, tracing calls and returns lead to too many uninteresting stops (such as at the same place you just were at). Also, stopping on function definitions probably also added to this tedium.

Because we’re really handling return events, we can show you the return value. (pdb has an “undocumented” retval command that doesn’t seem to work.)

Debugger Macros via Python Lambda expressions

There are debugger macros. In gdb, there is a macro debugger command to extend debugger commands.

However Python has its own rich programming language so it seems silly to recreate the macro language that is in gdb. Simpler and more powerful is just to use Python here. A debugger macro here is just a lambda expression which returns a string or a list of strings. Each string returned should be a debugger command.

We also have aliases for the extremely simple situation where you want to give an alias to an existing debugger command. But beware: some commands, like step inspect command suffixes and change their behavior accordingly.

We also envision a number of other ways to allow extension of this debugger either through additional modules, or user-supplied debugger command directories.

Byte-code Instruction Introspection

We do more in the way of looking at the byte codes to give better information. Through this we can provide:

  • a skip command. It is like the jump command, but you don’t have to deal with line numbers.

  • disassembly of code fragments. You can now disassemble relative to the stack frames you are currently stopped at.

  • Better interpretation of where you are when inside execfile or exec. (But really though this is probably a Python compiler misfeature.)

  • Check that breakpoints are set only where they make sense.

  • A more accurate determination of if you are at a function-defining def or class statements (because the caller instruction contains MAKE_FUNCTION or BUILD_CLASS.)

Even without “deparsing” mentioned above, the ability to disassemble where 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.

Some Debugger Command Arguments can be Variables and Expressions

Commands that take integer arguments like up, list, or disassemble allow you to use a Python expression which may include local or global variables that evaluates to an integer. This eliminates the need in gdb for special “dollar” debugger variables. (Note however because of shlex parsing, expressions can’t have embedded blanks.)

Out-of-Process Debugging

You can now debug your program in a different process or even a different computer on a different network!

Related, is flexible support for remapping path names from file system, e.g. that inside a docker container or on a remote filesystem with locally-installed files. See subst for more information.

Egg, Wheel, and Tarballs

Can be installed via the usual pip or easy_install. There is a source tarball. How To Install has full instructions and installing from git and by other means.

Modularity

The Debugger plays nice with other trace hooks. You can have several debugger objects.

Many of the things listed below doesn’t directly effect end-users, but it does eventually by way of more robust and featureful code. And keeping developers happy is a good thing.(TM)

  • 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 name or alias names. To add a new command you basically add a file in a directory.

  • I/O is it’s own layer. This simplifies interactive readline behavior from reading commands over a TCP socket.

  • An interface is it’s own layer. Local debugging, remote debugging, 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.

  • There is an experimental Python-friendly interface for front-ends

  • more testable. Much more unit and functional tests. More of pydb’s integration test will eventually be added.

Documentation

Documentation: http://python3-trepan.readthedocs.org

See Also

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trepan3k-1.2.7.tar.gz (516.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

trepan3k-1.2.7-py3.9.egg (658.0 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.8.egg (658.5 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.7.egg (657.0 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.6.egg (656.7 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.5.egg (666.8 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.4.egg (668.8 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.3.egg (678.8 kB view details)

Uploaded Egg

trepan3k-1.2.7-py3.2.egg (669.0 kB view details)

Uploaded Egg

trepan3k-1.2.7-py2.py3-none-any.whl (347.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file trepan3k-1.2.7.tar.gz.

File metadata

  • Download URL: trepan3k-1.2.7.tar.gz
  • Upload date:
  • Size: 516.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7.tar.gz
Algorithm Hash digest
SHA256 2d0b49f82ac50581e0bfa3e80bee57906587f7276b06fd91acd5ffd3b1081543
MD5 8683d7a0f764ad98f483d7b29c7e271a
BLAKE2b-256 404a70208e85ca72e610382adb23293c21a5dd88819a24a05a1bc89e49ff428d

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.9.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.9.egg
  • Upload date:
  • Size: 658.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.9.egg
Algorithm Hash digest
SHA256 226ecd547915a5925922481899bc9b0425eeccc66db1b98c9fb790336890fc65
MD5 ff4fee90ae2f51b6fbdae61c9530c54a
BLAKE2b-256 48e24e7a921deba37e12a1c9b213719c9fba0334f6badb9a2bda2cf29cdb43a7

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.8.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.8.egg
  • Upload date:
  • Size: 658.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.8.egg
Algorithm Hash digest
SHA256 34e7a15405a997105d5c277ac86b7976d658f4de0ef3317176a2aa4cf3c9d734
MD5 1ef89f1e526cb68bc598c1ae1517e7d7
BLAKE2b-256 fa99b02dc6ca599c64624593ab41663f4b186142ad9178f995198a0d8f3b6e30

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.7.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.7.egg
  • Upload date:
  • Size: 657.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.7.egg
Algorithm Hash digest
SHA256 31caa61bcad6854371dc4ec2896ccc8b3330dec6f759d1c2449479933aeeba53
MD5 40b1f38bf03db9eb05ace0be86d4d103
BLAKE2b-256 ef66ac447613f756d63b29f83b5c2642b8346d2f334ea6c093d60f4ed772542d

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.6.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.6.egg
  • Upload date:
  • Size: 656.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.6.egg
Algorithm Hash digest
SHA256 0772db2f61453c3dd6cb00536976be0afa342619e4f2a3eb9e0f6dae1d58f046
MD5 0e1a3455174bf9836bc410b17c80e6cc
BLAKE2b-256 6bc3c7eeb3f9382f01f7770cc6f0c6a32cc16b372ab60e2b26eaaf9075157df2

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.5.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.5.egg
  • Upload date:
  • Size: 666.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.5.egg
Algorithm Hash digest
SHA256 69453affd0ed3a2ec767b5437d0940eed37ac0baeb2a4fdd42422e4e5ab7f1ed
MD5 84eb3251084b62f38921179faebcb343
BLAKE2b-256 90c2d32741bc0873ea08705e910c2d867b1acd99034c2c0f6fe13de7473f677a

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.4.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.4.egg
  • Upload date:
  • Size: 668.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.4.egg
Algorithm Hash digest
SHA256 309df93e1ecef2dc4c014f52b166fbb65ae6b5899c77d5f7c001efb60f60e2b2
MD5 c65c5be226a3b8e54d97170c7ac9b4dd
BLAKE2b-256 596c3f5b6c79976a2d0dec114eaf9fd3e2de7d1ee10210c51604e78442dd9a20

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.3.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.3.egg
  • Upload date:
  • Size: 678.8 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.3.egg
Algorithm Hash digest
SHA256 8a8c1f4f0211d32d26b119a401aab65b1949289d3e2ae9e985b28790adc455a6
MD5 240ea018a208224db82f5f7047c716cd
BLAKE2b-256 edf357ebfb4bb8b538a2616aec1e565a1bc127ca5f99b6c57193c067c82d9861

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py3.2.egg.

File metadata

  • Download URL: trepan3k-1.2.7-py3.2.egg
  • Upload date:
  • Size: 669.0 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py3.2.egg
Algorithm Hash digest
SHA256 8280db13b9c38f03a23e2d5e599d501589e2bfc881a7044fecc79b762f01ceaf
MD5 b3a5e7921f81b6e30f0cf1103c9cc1ac
BLAKE2b-256 13fdf228fd990f7c89f25e3b1c4629a09737fcdc96e5666213822251b6053342

See more details on using hashes here.

File details

Details for the file trepan3k-1.2.7-py2.py3-none-any.whl.

File metadata

  • Download URL: trepan3k-1.2.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 347.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6

File hashes

Hashes for trepan3k-1.2.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 181fbc2c143b40d6459dfaef801706a75ab6cdf6d3974187cb817d3ae34eacd4
MD5 d59f65479143bf35257c980665d33205
BLAKE2b-256 f9fa20836b6fd26056a98aef6cde06998f4a3ae8822acc3d553186479f08ed0b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page