A gdb-like Python3 Debugger in the Trepan family

Overview

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

Comments
  • Broken trepan import in v0.8.4

    Broken trepan import in v0.8.4

    In a fresh Python 3.5.2 virtual environment on Ubuntu 16.04:

    > pip install trepan3k==0.8.4
    > trepan3k
    Traceback (most recent call last):
      File "/home/dan/.virtualenvs/python3/bin/trepan3k", line 7, in <module>
        from trepan.cli import main
    ImportError: No module named 'trepan'
    

    Going back to 0.8.3 makes the issue disappear.

    opened by dangirsh 10
  • Installing trepan3k-0.8.10 from PyPI  can fail due to incompatible xdis requirement

    Installing trepan3k-0.8.10 from PyPI can fail due to incompatible xdis requirement

    $ pip install trepan3k                                                                             ~   
    Collecting trepan3k                                                                                      
      Using cached trepan3k-0.8.10-py3-none-any.whl (338 kB)                                                 
    Collecting uncompyle6>=3.4.1
      Using cached uncompyle6-3.6.4-py3-none-any.whl (309 kB)
    ...
    Collecting xdis<4.1.0,>=4.0.4
      Using cached xdis-4.0.4-py37-none-any.whl (94 kB)
    ...
    ERROR: uncompyle6 3.6.4 has requirement xdis<4.3.0,>=4.2.2, but you'll have xdis 4.0.4 which is incompatible.
    ...
    

    Installing from master works fine:

    $ pip install -e git+ssh://[email protected]/rocky/python3-trepan.git#egg=trepan3k
    ...
    Collecting xdis<4.3.0,>=4.2.0
      Downloading xdis-4.2.2-py37-none-any.whl (101 kB)
    ...
    
    opened by zed 8
  • cannot install trepan on python3.3

    cannot install trepan on python3.3

    What steps will reproduce the problem?
    1. pip install trepan
    2.
    3.
    
    What is the expected output? What do you see instead?
    successful install.
    Downloading/unpacking trepan
      Could not fetch URL http://code.google.com/p/trepan/ (from https://pypi.python.org/simple/trepan/): HTTP Error 404: Not Found
      Will skip URL http://code.google.com/p/trepan/ when looking for download links for trepan
      Using version 0.2.8 (newest of versions: 0.2.8, 0.2.8, 0.2.7, 0.2.5)
      Downloading trepan-0.2.8.tar.gz (130kB): 
      Downloading from URL https://pypi.python.org/packages/source/t/trepan/trepan-0.2.8.tar.gz#md5=216a9ee0e60df183a4c90e412d0cbf37 (from https://pypi.python.org/simple/trepan/)
    ...Downloading trepan-0.2.8.tar.gz (130kB): 130kB downloaded
      Running setup.py egg_info for package trepan
        Traceback (most recent call last):
          File "<string>", line 16, in <module>
          File "/tmp/pip_build_root/trepan/setup.py", line 12, in <module>
            from __pkginfo__ import \
        ImportError: No module named '__pkginfo__'
        Complete output from command python setup.py egg_info:
        Traceback (most recent call last):
    
      File "<string>", line 16, in <module>
    
      File "/tmp/pip_build_root/trepan/setup.py", line 12, in <module>
    
        from __pkginfo__ import \
    
    ImportError: No module named '__pkginfo__'
    
    ----------------------------------------
    Cleaning up...
      Removing temporary dir /tmp/pip_build_root...
    Command python setup.py egg_info failed with error code 1 in 
    /tmp/pip_build_root/trepan
    Exception information:
    Traceback (most recent call last):
      File "/usr/lib/python3.3/site-packages/pip/basecommand.py", line 134, in main
        status = self.run(options, args)
      File "/usr/lib/python3.3/site-packages/pip/commands/install.py", line 236, in run
        requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
      File "/usr/lib/python3.3/site-packages/pip/req.py", line 1134, in prepare_files
        req_to_install.run_egg_info()
      File "/usr/lib/python3.3/site-packages/pip/req.py", line 259, in run_egg_info
        command_desc='python setup.py egg_info')
      File "/usr/lib/python3.3/site-packages/pip/util.py", line 670, in call_subprocess
        % (command_desc, proc.returncode, cwd))
    pip.exceptions.InstallationError: Command python setup.py egg_info failed with 
    error code 1 in /tmp/pip_build_root/trepan
    
    Storing complete log in /root/.pip/pip.log
    
    What version of the product are you using? On what operating system?
    linux fedora 20
    
    Please provide any additional information below.
    
    
    

    Original issue reported on code.google.com by [email protected] on 18 Jul 2014 at 12:56

    Type-Defect Priority-Medium auto-migrated 
    opened by GoogleCodeExporter 7
  • Error building python3k-trepan

    Error building python3k-trepan

    Hi,

    I've cloned the repo and tried building it with

    python setup.py build

    (seemed to work)

    then I tried:

    python setup.py install

    and it fails with the following error:

    _Installed /home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/trepan3k-0.8.11-py3.8.egg Processing dependencies for trepan3k==0.8.11 Searching for tracer>=0.3.2 Reading https://pypi.org/simple/tracer/ Downloading https://files.pythonhosted.org/packages/41/7c/73012494a7aa0d2e693ef0dc29304ea7968ac86a034ce8c0b0acd83640e3/tracer-0.3.2.tar.gz#sha256=1ddb3f438ea5ab4180776e8bb8bfa857edf7f52264f6b8189bba2bafb1a7cae3 Best match: tracer 0.3.2 Processing tracer-0.3.2.tar.gz Writing /tmp/easy_install-orrau7k9/tracer-0.3.2/setup.cfg Running tracer-0.3.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-orrau7k9/tracer-0.3.2/egg-dist-tmp-h9jpyk0z Traceback (most recent call last): File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 154, in save_modules yield saved File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 250, in run_setup _execfile(setup_script, ns) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 45, in _execfile exec(code, globals, locals) File "/tmp/easy_install-orrau7k9/tracer-0.3.2/setup.py", line 8, in if ((2, 4) <= SYS_VERSION <= (2, 7)): ImportError: cannot import name 'package_dir' from 'pkginfo' (/home/moutinho/projetos/python3-trepan/pkginfo.py)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "setup.py", line 30, in setup( File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/init.py", line 144, in setup return distutils.core.setup(**attrs) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/distutils/core.py", line 148, in setup dist.run_commands() File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/distutils/dist.py", line 966, in run_commands self.run_command(cmd) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/distutils/dist.py", line 985, in run_command cmd_obj.run() File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/install.py", line 67, in run self.do_egg_install() File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/install.py", line 117, in do_egg_install cmd.run(show_deprecation=False) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 425, in run self.easy_install(spec, not self.no_deps) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 674, in easy_install return self.install_item(None, spec, tmpdir, deps, True) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 721, in install_item self.process_distribution(spec, dist, deps) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 765, in process_distribution distros = WorkingSet([]).resolve( File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/pkg_resources/init.py", line 781, in resolve dist = best[req.key] = env.best_match( File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/pkg_resources/init.py", line 1066, in best_match return self.obtain(req, installer) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/pkg_resources/init.py", line 1078, in obtain return installer(requirement) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 693, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 719, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 904, in install_eggs return self.build_and_install(setup_script, setup_base) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 1172, in build_and_install self.run_setup(setup_script, setup_base, args) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 1158, in run_setup run_setup(setup_script, args) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 253, in run_setup raise File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/contextlib.py", line 131, in exit self.gen.throw(type, value, traceback) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/contextlib.py", line 131, in exit self.gen.throw(type, value, traceback) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 166, in save_modules saved_exc.resume() File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 141, in resume six.reraise(type, exc, self._tb) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/_vendor/six.py", line 685, in reraise raise value.with_traceback(tb) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 154, in save_modules yield saved File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 195, in setup_context yield File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 250, in run_setup _execfile(setup_script, ns) File "/home/moutinho/miniconda3/envs/pandas-dev/lib/python3.8/site-packages/setuptools/sandbox.py", line 45, in execfile exec(code, globals, locals) File "/tmp/easy_install-orrau7k9/tracer-0.3.2/setup.py", line 8, in if ((2, 4) <= SYS_VERSION <= (2, 7)): ImportError: cannot import name 'package_dir' from 'pkginfo' (/home/moutinho/projetos/python3-trepan/pkginfo.py)

    As you might notice, I was trying to install python3-trepan to debug an issue in pandas. That's why I'm inside pandas-dev environment on miniconda.

    opened by rmsilva1973 6
  • why Trenpan3k is struggling to develop users?

    why Trenpan3k is struggling to develop users?

    I discover Trenpan3k. Its specification is interesting. But I don't found any user experience about it(e.g. blog).

    why Trenpan3k is struggling to develop users? Because Trenpan3k isn't ready to use in production, it still has some bug? Or because it miss some feature compare to other debugger?

    opened by dev590t 5
  • start_opts={'startup-profile': True}

    start_opts={'startup-profile': True}

    import trepan.api; trepan.api.debug(start_opts={'startup-profile': True})
    
    # /tmp/p.py
    ``` python
    print('xxxxxxxxxxx')
    import trepan.api; trepan.api.debug(start_opts={'startup-profile': True})
    print('xxxxxxxxxxx')
    

    Traceback

    Traceback (most recent call last):
      File "/tmp/p.py", line 9, in <module>
        import trepan.api; trepan.api.debug(start_opts={'startup-profile': True})
      File "/home/xxx/workspace/python3-trepan/trepan/api.py", line 209, in debug
        options.add_startup_file(dbg_initfiles)
      File "/home/xxx/workspace/python3-trepan/trepan/options.py", line 49, in add_startup_file
        dbg_initfiles.append(startup_trepan_file)
    AttributeError: 'bool' object has no attribute 'append'
    trepan3k: That's all, folks...
    
    opened by yssource 5
  • high CPU consuming during the import

    high CPU consuming during the import

    trepan3k is very very slow during the import. My CPU increase until 100%.

    Reproduce the issue

    $ cat testTrepan3k.py 
    #!/usr/bin/env python3
    
    import pandas as pd
    
    $ trepan3k testTrepan3k.py 
    (/mnt/recoverData/linuxProgram/workspace/Finrl_python3.9/testTrepan3k.py:3): <module>
    -> 3 import pandas as pd
    (trepan3k) next # this command increase the CPU until 100%
    (/mnt/recoverData/linuxProgram/workspace/Finrl_python3.9/testTrepan3k.py:3 @10): <module>
    <- 3 import pandas as pd
    R=> None
    (trepan3k) 
    

    Additional information

    I don't have this CPU issue when I execute import os. The difference between os and pandas is their installation location.

    $ python3
    Python 3.9.9 (main, Jan  1 1970, 00:00:01) 
    [GCC 10.3.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import pandas
    >>> pandas
    <module 'pandas' from '/mnt/recoverData/linuxProgram/workspace/__pypackages__/3.9/lib/pandas/__init__.py'>
    >>> import os
    >>> os
    <module 'os' from '/gnu/store/sz7lkmic6qrhfblrhaqaw0fgc4s9n5s3-python-3.9.9/lib/python3.9/os.py'>
    

    Another point, I have install trepan3k with pip install --user trepan3k, without using root. Unlike in https://python3-trepan.readthedocs.io/en/latest/install.html. I don't know if that can cause a CPU issue.

    opened by dev590t 4
  • Fix the return tuples for parse_break_cmd

    Fix the return tuples for parse_break_cmd

    looks like a couple of modules were missed when you added the offset to the returned tuple for parse_break_cmd

    the returned tuples in continue.py and tbreak.py are misssing offset

    the returned tuples in break.py and line.py are ok.

    causes commands like "c 20" to fail when I use trepan3k 1.2.0

    (I tried to minimize code changes, so I didn't try to make it DRY)

    opened by bradelkin 2
  • Debug module

    Debug module

    It looks great, but I need some help.

    How to debug my module? In pure python I type:

    python3 -m mymodule
    

    With

    trepan3k transys/
    

    I've got

    [Errno 21] Is a directory: '/projects/mymodule'
    trepan3k: That's all, folks...
    

    With

    trepan3k transys/__main__.py
    

    I've got:

    Traceback (most recent call last):
      File "/projects/.venv/bin/trepan3k", line 10, in <module>
        sys.exit(main())
      File "/projects/.venv/lib/python3.7/site-packages/trepan/cli.py", line 212, in main
        normal_termination = dbg.run_script(mainpyfile)
      File "/projects/.venv/lib/python3.7/site-packages/trepan/debugger.py", line 217, in run_script
        exec(compiled, globals_, locals_)
      File "/projects/mymodule/__main__.py", line 2, in <module>
        from . import main
      File "/projects/.venv/lib/python3.7/site-packages/tracer.py", line 123, in _tracer_func
        if not hook.trace_fn(frame, event, arg):
      File "/projects/.venv/lib/python3.7/site-packages/trepan/lib/core.py", line 443, in trace_dispatch 
        return self.processor.event_processor(frame, self.event, arg)
      File "/projects/.venv/lib/python3.7/site-packages/trepan/processor/cmdproc.py", line 465, in event_processor
        self.process_commands()
      File "/projects/.venv/lib/python3.7/site-packages/trepan/processor/cmdproc.py", line 643, in process_commands
        self.location()
      File "/projects/.venv/lib/python3.7/site-packages/trepan/processor/cmdproc.py", line 360, in <lambda>
        self.location         = lambda : print_location(self)
      File "/projects/.venv/lib/python3.7/site-packages/trepan/processor/cmdproc.py", line 267, in print_location 
        fd.write(''.join(lines))
      File "/projects/.venv/lib/python3.7/tempfile.py", line 620, in func_wrapper
        return func(*args, **kwargs)
    TypeError: a bytes-like object is required, not 'str'
    Uncaught exception. Entering post-mortem debugger...
    (/projects/.venv/lib/python3.7/tempfile.py:620 @6): func_wrapper
    !! 620                 return func(*args, **kwargs)
    R=> (<class 'TypeError'>, TypeError("a bytes-like object is required, not 'str'"), <traceback object at 0x7f6e97628b08>)
    (Trepan3k:pm)
    

    And how to install trepan3k to catch build-in breakpoint()?

    opened by rysson 2
  • Universal wheel breaks for Python 3.8.

    Universal wheel breaks for Python 3.8.

    Because trepan3k tries to use decompyle3 for Pythons 3.7 and 3.8, the universal wheel doesn't work, allowing the debugger to start but with a missing import error message and no elaboration. Manually installing decompyle3 fixes things.

    opened by jaccarmac 1
  • info threads?

    info threads?

    Hi, I am trying to show info from threads (info threads) by using trepan3k 0.8.6 and debugging python3.5 programs. (command: trepan3k threads_sample.py)

    I only get the Mainthread.

    How can I show the threads info for a program? such as: ############################################################# import threading def worker(): """thread worker function""" print('Worker')

    threads = [] for i in range(5): t = threading.Thread(target=worker) threads.append(t) t.start() #############################################################

    Regards!

    help wanted 
    opened by agala-stratio 1
  • "Weird termination bug" occurring inconsistently.

    As I hinted at in https://github.com/rocky/python3-trepan/issues/22#issuecomment-1219634096, my use of breakpoint() to enter the debugger seems to be causing a strange error on termination. It seems similar to the issue fixed in 68474af585b7a1c4547ba912feb9c72cfb3cae42, as it points at a tracer.py line with inspect.currentframe with an AttributeError for that access. No such error appears if I debug using the trepan3k binary.

    opened by jaccarmac 3
  • Cannot set breakpoints if CWD is on a read-only FS

    Cannot set breakpoints if CWD is on a read-only FS

    Something underneath the breakpoint mechanic appears to create a file called .coverage, and if this fails, the breakpoint cannot be set.

    The file does not seem to actually be required, though: by editing the code to skip it, I am able to set breakpoints successfully. So, the creation of the file ought to be optional; failure to create it should probably not be fatal.

    opened by abliss 3
  • No support for PYTHONBREAKPOINT

    No support for PYTHONBREAKPOINT

    I was trying to use this debugger and expected some kind of compatibility with the pdb family of debuggers and the PYTHONBREAKPOINT and breakpoint() built-in that was introduced in Python 3.7+ with PEP 553.

    I ended up writing a small separate module that basically provides a set_trace kind of method that is configurable with some command line variables:

    import sys
    import os
    
    
    def set_trace():
        from trepan.interfaces import server as Mserver
        from trepan.api import debug
        interface = os.getenv('TREPAN3K_INTERFACE', 'USER')
        if interface == 'USER':
            dbg_opts = {}
        else:
            connection_opts = {'IO': 'TCP', 'PORT': os.getenv('TREPAN3K_TCP_PORT', 5555)}
            intf = Mserver.ServerInterface(connection_opts=connection_opts)
            dbg_opts = {'interface': intf}
            print(f'Starting {connection_opts["IO"]} server listening on {connection_opts["PORT"]}.', file=sys.stderr)
            print(f'Use `python3 -m trepan.client --port {connection_opts["PORT"]}` to enter debugger.', file=sys.stderr)
        debug(dbg_opts=dbg_opts, step_ignore=0, level=1)
    
    

    Usage would be something like that (if that function is put in trepan.api):

    export PYTHONBREAKPOINT=trepan.api.set_trace
    export TREPAN3K_INTERFACE=TCP
    export TREPAN3K_TCP_PORT=1095
    python3 run_some_script_that_calls_breakpoint_builtin.py
    python3 -m trepan.client --port 1095
    

    Is that something that would make sense to be in the core of this project or would you prefer it to be a standalone thing? As is, you can already use it with PYTHONBREAKPOINT=trepan.api.debug, so this would only make it easier to configure the parameters of the debug function using env vars.

    opened by jadkik 2
  • Broken

    Broken "list ." command

    dd81b32 is a simple modification that fixes the behaviour of "list .".

    While I was at it, with dd81b32 I also fixed the number of lines printed as a result of commands such as "list 25," and similar. According to my understanding the number of lines printed when one of the range limits is left blank should always be "listsize" (10 by default), while in many cases the number was actually 11.

    opened by gscelsi 4
  • Issue with breakpoints in multithreading

    Issue with breakpoints in multithreading

    Hi, It seems trepan3k is not able to stop in breakpoints put inside a function launched as a thread target. For example, for the script:

    import threading
    from queue import Queue
    
    fibo_dict = {}
    input_list = [3,5,7,9]
    shared_queue = Queue()
    queue_condition = threading.Condition()
    
    def fibonacci_task(condition):
          with condition: # line 10
    
            while shared_queue.empty():
                print("[{}] - waiting for elements in queue..".format(threading.current_thread().name))
                condition.wait()
    
            else:
                value = shared_queue.get()
                a, b = 0, 1
                for item in range(value):
                    a, b = b, a + b
                    fibo_dict[value] = a
    
            shared_queue.task_done()
            print("[{}] fibonacci of key [{}] with result [{}]".
                  format(threading.current_thread().name, value, fibo_dict[value]))
    
    def queue_task(condition):
        print('Starting queue_task...') # line 29
        with condition:
            for item in input_list:
                shared_queue.put(item)
    
            print("Notifying fibonacci task threads that the queue is ready to consume...")
            condition.notifyAll()
    
    def main():
        threads = []
        for i in range(3):
            thread = threading.Thread(target=fibonacci_task, args=(queue_condition,))
            thread.daemon = False
            threads.append(thread)
    
        [thread.start() for thread in threads]
    
        prod = threading.Thread(name='queue_task_thread', target=queue_task, args=(queue_condition,))
        prod.daemon = False
        prod.start()
    
        [thread.join() for thread in threads]
    
        print("[{}] - Result {}".format(threading.current_thread().name, fibo_dict))
    
    if __name__=='__main__':
        main()
    
    

    If we put breakpoints inside fibonacci_task or queue_task functions: Trepan3k Execution flow:

    $ trepan3k parallel_fibonacci.py
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:1): <module>
    -> 1 import threading
    (trepan3k) break 10
    Breakpoint 1 set at line 10 of file /tmp/python-debug/trepan3k_issue/parallel_fibonacci.py
    (trepan3k) break 29
    Breakpoint 2 set at line 29 of file /tmp/python-debug/trepan3k_issue/parallel_fibonacci.py
    (trepan3k) continue
    [Thread-1] - waiting for elements in queue..
    [Thread-2] - waiting for elements in queue..
    [Thread-3] - waiting for elements in queue..
    Starting queue_task...
    Notifying fibonacci task threads that the queue is ready to consume...
    [Thread-3] fibonacci of key [3] with result [2]
    [Thread-2] fibonacci of key [5] with result [5]
    [Thread-1] fibonacci of key [7] with result [13]
    [MainThread] - Result {3: 2, 5: 5, 7: 13}
    The program finished - quit or restart
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:56 @131): <module>
    -> 56     main()   
    

    The debug session ends without stopping in the breakpoints.

    If we launch the same debug sessoin with pydb: Pydb Execution flow:

    $ pydb --threading parallel_fibonacci.py 
    --Call level -1 
    Current thread is MainThread
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:1):  <module>
    1 import threading
    (Pydb) break 10
    Breakpoint 1 set in file /tmp/python-debug/trepan3k_issue/parallel_fibonacci.py, line 10.
    (Pydb) break 29
    Breakpoint 2 set in file /tmp/python-debug/trepan3k_issue/parallel_fibonacci.py, line 29.
    (Pydb) continue
    Current thread is Thread-1
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:10):  fibonacci_task
    10     with condition:
    (Pydb) continue
    Current thread is Thread-2
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:10):  fibonacci_task
    10     with condition:
    (Pydb) continue
    [Thread-1] - waiting for elements in queue..
    Current thread is Thread-3
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:10):  fibonacci_task
    10     with condition:
    (Pydb) continue
    Current thread is queue_task_thread
    (/tmp/python-debug/trepan3k_issue/parallel_fibonacci.py:29):  queue_task
    29     print('Starting queue_task...')
    (Pydb) [Thread-2] - waiting for elements in queue..
    

    Hope this is useful Regards

    opened by agala-stratio 1
Releases(1.2.8)
Owner
R. Bernstein
R. Bernstein
Visual Interaction with Code - A portable visual debugger for python

VIC Visual Interaction with Code A simple tool for debugging and interacting with running python code. This tool is designed to make it easy to inspec

Nathan Blank 1 Nov 16, 2021
Winpdb Reborn - A GPL Python Debugger, reborn from the unmaintained Winpdb

Note from Philippe Fremy The port of winpdb-reborn to Python 3 / WxPython 4 is unfortunately not working very well. So Winpdb for Python 3 does not re

Philippe F 84 Dec 22, 2022
A toolbar overlay for debugging Flask applications

Flask Debug-toolbar This is a port of the excellent django-debug-toolbar for Flask applications. Installation Installing is simple with pip: $ pip ins

863 Dec 29, 2022
Automated bug/error reporting for napari

napari-error-monitor Want to help out napari? Install this plugin! This plugin will automatically send error reports to napari (via sentry.io) wheneve

Talley Lambert 2 Sep 15, 2022
Dahua Console, access internal debug console and/or other researched functions in Dahua devices.

Dahua Console, access internal debug console and/or other researched functions in Dahua devices.

bashis 156 Dec 28, 2022
Sentry is cross-platform application monitoring, with a focus on error reporting.

Users and logs provide clues. Sentry provides answers. What's Sentry? Sentry is a service that helps you monitor and fix crashes in realtime. The serv

Sentry 32.9k Dec 31, 2022
pdb++, a drop-in replacement for pdb (the Python debugger)

pdb++, a drop-in replacement for pdb What is it? This module is an extension of the pdb module of the standard library. It is meant to be fully compat

1k Dec 24, 2022
Full featured multi arch/os debugger built on top of PyQt5 and frida

Full featured multi arch/os debugger built on top of PyQt5 and frida

iGio90 1.1k Dec 26, 2022
Inject code into running Python processes

pyrasite Tools for injecting arbitrary code into running Python processes. homepage: http://pyrasite.com documentation: http://pyrasite.rtfd.org downl

Luke Macken 2.7k Jan 08, 2023
Arghonaut is an interactive interpreter, visualizer, and debugger for Argh! and Aargh!

Arghonaut Arghonaut is an interactive interpreter, visualizer, and debugger for Argh! and Aargh!, which are Befunge-like esoteric programming language

Aaron Friesen 2 Dec 10, 2021
Integration of IPython pdb

IPython pdb Use ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better i

Godefroid Chapelle 1.7k Jan 07, 2023
Run-time type checker for Python

This library provides run-time type checking for functions defined with PEP 484 argument (and return) type annotations. Four principal ways to do type

Alex Grönholm 1.1k Jan 05, 2023
Hdbg - Historical Debugger

hdbg - Historical Debugger This is in no way a finished product. Do not use this

Fivreld 2 Jan 02, 2022
(OLD REPO) Line-by-line profiling for Python - Current repo ->

line_profiler and kernprof line_profiler is a module for doing line-by-line profiling of functions. kernprof is a convenient script for running either

Robert Kern 3.6k Jan 06, 2023
Python's missing debug print command and other development tools.

python devtools Python's missing debug print command and other development tools. For more information, see documentation. Install Just pip install de

Samuel Colvin 637 Jan 02, 2023
The official code of LM-Debugger, an interactive tool for inspection and intervention in transformer-based language models.

LM-Debugger is an open-source interactive tool for inspection and intervention in transformer-based language models. This repository includes the code

Mor Geva 110 Dec 28, 2022
Graphical Python debugger which lets you easily view the values of all evaluated expressions

birdseye birdseye is a Python debugger which records the values of expressions in a function call and lets you easily view them after the function exi

Alex Hall 1.5k Dec 24, 2022
Trace all method entries and exits, the exit also prints the return value, if it is of basic type

Trace all method entries and exits, the exit also prints the return value, if it is of basic type. The apk must have set the android:debuggable="true" flag.

Kurt Nistelberger 7 Aug 10, 2022
Debugger capable of attaching to and injecting code into python processes.

DISCLAIMER: This is not an official google project, this is just something I wrote while at Google. Pyringe What this is Pyringe is a python debugger

Google 1.6k Dec 15, 2022
Auto-detecting the n+1 queries problem in Python

nplusone nplusone is a library for detecting the n+1 queries problem in Python ORMs, including SQLAlchemy, Peewee, and the Django ORM. The Problem Man

Joshua Carp 837 Dec 29, 2022