Giter VIP home page Giter VIP logo

python3-trepan's Introduction

CircleCI Pypi Installs License Supported Python Versions

packagestatus

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.

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.

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.

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.

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.

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.

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 .

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.

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()

Sometimes you want small steps, and sometimes large stepping.

This fundamental issue is handled in a couple ways:

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.

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.

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.)

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.

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.

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.)

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.

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.

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: http://python3-trepan.readthedocs.org

python3-trepan's People

Contributors

abliss avatar bradelkin avatar devnodereact avatar movermeyer avatar rocky avatar woolenwang avatar yssource avatar zed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python3-trepan's Issues

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.

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.

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)
...

Problems with conditional breakpoints defined with "break {...} if {condition}" command.

Hi,

I have been testing conditional breakpoints, but I have found some problems applying the condition directly when defining the breakpoints:

Python script used as example:

import sys
def main(arguments):
    for i in range(10):
        print(i)
        print("Test")

if __name__ == '__main__':
    main(sys.argv)

Defining condition in break-point creation:

trepan3k --highlight=plain --different test.py 
(/tmp/python_example/test.py:1): <module>
-> 1 import sys
(trepan3k) break 4 if i==5
Breakpoint 1 set at line 4 of file /tmp/python_example/test.py
(trepan3k) break 5 if i==3
Breakpoint 2 set at line 5 of file /tmp/python_example/test.py
(trepan3k) info break
Num Type          Disp Enb    Where
-----------------------------------
1   breakpoint    keep y   at /tmp/python_example/test.py:4
	stop only if if i==5
2   breakpoint    keep y   at /tmp/python_example/test.py:5
	stop only if if i==3
(trepan3k) continue
(/tmp/python_example/test.py:4 @19): main
xx 4         print(i)

When printing breakpoints information, I have seen that 'if' word appears two times in condition definition information (stop only if if ...).

Defining condition after break-point creation:

trepan3k --highlight=plain --different test.py 
(/tmp/python_example/test.py:1): <module>
-> 1 import sys
(trepan3k) break 4
Breakpoint 1 set at line 4 of file /tmp/python_example/test.py
(trepan3k) condition 1 i==5
(trepan3k) break 5
Breakpoint 2 set at line 5 of file /tmp/python_example/test.py
(trepan3k) condition 2 i==3
(trepan3k) info break
Num Type          Disp Enb    Where
-----------------------------------
1   breakpoint    keep y   at /tmp/python_example/test.py:4
	stop only if i==5
2   breakpoint    keep y   at /tmp/python_example/test.py:5
	stop only if i==3
(trepan3k) continue
0
Test
1
Test
2
Test
3
(/tmp/python_example/test.py:5 @29): main
xx 5         print("Test")
(trepan3k) eval i
3

I hope that this information can be helpful.

tcp client get error when "info thread verbose"

`
(Trepan*) info thread verbose

<_MainThread(MainThread, started 2832)>: 2832
_fetchall_impl(self=<sqlalchemy.engine.result.ResultProxy object at 0x00000248F5A27288>)
 called from file 'e:\git\python37_x64\lib\site-packages\sqlalchemy\engine\result.py' at line 1161
 fetchall(self=<sqlalchemy.engine.result.ResultProxy object at 0x00000248F5A27288>)
 called from file 'e:\git\python37_x64\lib\site-packages\sqlalchemy\engine\result.py' at line 1211
 instances(query=<sqlalchemy.orm.query.Query object at 0x00000248F5A4BC48>, cursor=<sqlalchemy.engine.result.R...)
 called from file 'e:\git\python37_x64\lib\site-packages\sqlalchemy\orm\loading.py' at line 81
 all(self=<sqlalchemy.orm.query.Query object at 0x00000248F5A4BC48>)
 called from file 'e:\git\python37_x64\lib\site-packages\sqlalchemy\orm\query.py' at line 3186
 get_stock_concepts(self=<woolen_data_source.stores.db.sql.sqlite.pk.concept_store.ConceptStoreSqlite object at 0x00000...)
 called from file 'e:\git\wds\woolen_data_source\stores\db\sql\sqlite\pk\concept_store.py' at line 64
 get_stock_concepts(self=<woolen_data_source.models.instrument.ConceptModel object at 0x00000248F8A76688>, stock='30038...)
 called from file 'e:\git\wds\woolen_data_source\models\instrument.py' at line 176
 concept_names(self={'proxy_instance': <woolen_data_source.models.base_model.ModelProxy object at 0x00000248EEF4A2...)
 called from file 'e:\git\wds\woolen_data_source\models\instrument.py' at line 270
 wrapper(*args=({'proxy_instance': <woolen_data_source.models.base_model.ModelProxy object at 0x00000248EEF4...)
 called from file 'e:\git\python37_x64\lib\site-packages\fastcache\__init__.py' at line 67
 __getitem__(self={'proxy_instance': <woolen_data_source.models.base_model.ModelProxy object at 0x00000248EEF4A2...)
 called from file 'e:\git\wds\woolen_data_source\models\instrument.py' at line 289
 concept_names(self=Instrument({'order_book_id': '300382.XSHE', 'symbol': '斯莱克', 'symbol_id': '300382.XSHE_斯莱克', '...)

Traceback (most recent call last):
File "E:\git\py_help\py_help\cli\router.py", line 491, in real_call
ret = handler(**self.params)
│ └ <woolen_quant.cli.router.WoolenQuantRouter object at 0x000001F2BA4AD748>
└ <function Api._get_api_wrapper..api_wrapper at 0x000001F2BBA7EB88>
File "E:\git\py_help\py_help\api_help\api_wrapper.py", line 107, in api_wrapper
ret = self.api_call(*api_args, **api_kwargs)
│ │ └ {}
│ └ ()
└ <py_help.api_help.api_wrapper.Api object at 0x000001F2BBA8A8C8>
File "E:\git\py_help\py_help\api_help\api_wrapper.py", line 152, in api_call
return self.api_info.call_api(*args, **kwargs)
│ │ └ {}
│ └ ()
└ <py_help.api_help.api_wrapper.Api object at 0x000001F2BBA8A8C8>
File "E:\git\py_help\py_help\api_help\api_info.py", line 43, in call_api
return api_func(*args, **valid_args)
│ │ └ {'debug_port': 61001, 'ip': '127.0.0.1', 'ctrl_port': 61000}
│ └ ()
└ <function gdb_connect at 0x000001F2BBA7E8B8>
File "E:\git\py_help\py_help\cli\builtin_command\debug.py", line 32, in gdb_connect
start_client({'open': True, 'IO': 'TCP', 'PORT': debug_port, 'HOST': ip})
│ │ └ '127.0.0.1'
│ └ 61001
└ <function start_client at 0x000001F2BF0CA048>
File "E:\git\python37_x64\lib\site-packages\trepan\client.py", line 105, in start_client
control, remote_msg = intf.read_remote()
│ │ └ <trepan.interfaces.client.ClientInterface object at 0x000001F2BED9C348>
│ └ " concept_names(self=Instrument({'order_book_id': '300382.XSHE', 'symbol': '斯莱克', 'symbol_id': '300382.XSHE_斯莱克', '...)\n ...
└ '.'
File "E:\git\python37_x64\lib\site-packages\trepan\interfaces\client.py", line 59, in read_remote
coded_line = self.inout.read_msg()
└ <trepan.interfaces.client.ClientInterface object at 0x000001F2BED9C348>
File "E:\git\python37_x64\lib\site-packages\trepan\inout\tcpclient.py", line 97, in read_msg
self.buf, data = Mtcpfns.unpack_msg(self.buf)
│ │ └ <trepan.inout.tcpclient.TCPClient object at 0x000001F2BEDAF288>
│ └ <module 'trepan.inout.tcpfns' from 'E:\git\python37_x64\lib\site-packages\trepan\inout\tcpfns.py'>
└ <trepan.inout.tcpclient.TCPClient object at 0x000001F2BEDAF288>
File "E:\git\python37_x64\lib\site-packages\trepan\inout\tcpfns.py", line 30, in unpack_msg
length = int(buf[0:LOG_MAX_MSG])
│ └ 4
└ b'at line 197\n'
ValueError: invalid literal for int() with base 10: b'at l'
`
becasue of the msg has some chinese data so the length was not correct.

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...

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!

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.

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

"Weird termination bug" occurring inconsistently.

As I hinted at in #22 (comment), 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 68474af, 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.

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

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.

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.

Error importing deparse: <class ModuleNotFoundError'> + ....deval

I'm running newest version of trepan3k (1.2.10) on ubuntu.20.04.

I've pip installed deparse (v0.2.0 (?)) but still getting the message:

Error importing deparse: <class ModuleNotFoundError'>
Error importing deval: <class ModuleNotFoundError'>

then the program being debugged starts, BUT 'n' command is sometimes unusably slow (takes a few minutes to complete). pdb does is very fast in contrast.

I'd like to get rid of messages above in hope this is the reason for very slow python3-trepan work

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()?

Broken mental model -- documentation

I've installed trepan3k in my python34 environment. I can run trepan3k. I can invoke it from within my python program. However whenever I try to issue gdb-like commands, I get errors. The program seems to be in a REPL-sort of mode where all it's willing to do is to interpret python commands. So "list 3" doesn't work, "next" tells me that next is a , and print("hello world") works fine, but I don't need a REPL, I need a debugger. I'm obviously missing something simple, but I think that reflects perhaps an opportunity to improve the documentation. And advice? Thanks, --KS

Compatible with ddd?

I just tried using this with DDD on Debian and it doesn't appear to be compatible at this point. DDD does support a --debugger flag and it seems like it should be able to call trepan3k with that, but it appears to be only loading pydb. But the source isn't being displayed in the DDD gui.

Is trepan3k really gdb compatible? Because I used to just 'p' to print a variable, but appears I have to use 'pr' or 'pp' to do that.

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?

Step into a child process?

Can trepan3k step into a child process started with multiprocessing.Process()? I tried stepping down into proc.start() in the tiny example below, but can't seem to find the fork() call. Setting a breakpoint in child() doesn't work, either.

import time
from multiprocessing import Process

def child():
    while True:
        print("I am the child")
        time.sleep(10)

proc = Process(target=child)
proc.start()
proc.join() 

Thanks!

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.