-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugging.txt
More file actions
94 lines (62 loc) · 1.95 KB
/
Copy pathdebugging.txt
File metadata and controls
94 lines (62 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
Saturday January 23, 2016
README
Waheed Brown
CONTENTS
--------
1. Python Debugger
2. Valgrind
3. Bytecode - .pyc Files
1. PYTHON DEBUGGER
Python Debugger (Python 2.x):
https://docs.python.org/2/library/pdb.html
- The below trace() method is by far the easiest for debugging, without
command line arguments.
- If you want to provide command line arguments to the program then use
the below "$ python -d" method.
METHOD 1:
Set breakpoint:
import pdb; pdb.set_trace()
METHOD 2:
$ python -d
>>> import pdb
>>> import test
>>> argv = ['arg1', 'arg2', 'arg3']
>>> pdb.run( 'test.main(argv)' )
...
(Pdb) step
(Pdb) print opt
(Pdb) args # print argument list of current function
(Pd.) print __name__ # print name of current function
(Pdb) continue
...
(Pdb) exit
DEBUGGER COMMANDS:
- [s]tep
- [p]rint
example:
> p j, num, i # prints comma separated values in brackets
> (5, 10, 2)
2. VALGRIND
In order to use Python with Valgrind you need to build the Python source
code [1] with specific options (try to pick the same source code release
number as your default installed Python version):
$ ./configure --with-pydebug --without-pymalloc --prefix /opt/debugpython/
$ make OPT=-g
$ make install
The install location for the binary is:
/opt/debugpython/bin/python
This means that you need to change the shebang line in any Python code that
you wish to test with Valgrind:
#!/opt/debugpython/bin/python
Alternatively, you can leave your code unmodified and just point to the
debug Python version when you execute Valgrind:
$ valgrind /opt/debugpython/bin/python your_program.py
REFERENCES:
1. https://www.python.org/downloads/release
2. https://code.google.com/archive/p/distnumpy/wikis/valgrind.wiki
3. BYTECODE - .pyc FILES
$ python -m your_program.py
This will produce a .pyc file which can be imported as a module
in other Python programs. Mildly obfuscates your code. To
recursively compile all code in nested folders run:
$ python -m compileall