Mercurial > cpython-lru_cache-weakref
annotate Lib/pdb.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 03a57af72218 |
| children | 86c279a848eb |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
4262
diff
changeset
|
1 #! /usr/bin/env python |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
2 |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
3 # pdb.py -- finally, a Python debugger! |
| 583 | 4 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
5 # (See pdb.doc for documentation.) |
| 566 | 6 |
| 7 import string | |
| 8 import sys | |
| 9 import linecache | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
10 import cmd |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
11 import bdb |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
12 import repr |
| 566 | 13 |
| 14 | |
|
1999
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
15 # Interaction prompt line will separate file and call info from code |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
16 # text using value of line_prefix string. A newline and arrow may |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
17 # be to your liking. You can set it once pdb is imported using the |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
18 # command "pdb.line_prefix = '\n% '". |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
19 # line_prefix = ': ' # Use this to get the old situation back |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
20 line_prefix = '\n-> ' # Probably a better default |
|
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
21 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
22 class Pdb(bdb.Bdb, cmd.Cmd): |
| 566 | 23 |
|
1317
ec312b647fcb
pdb.py, bdb.py, cmd.py: use __init__() instead of init()
Guido van Rossum <guido@python.org>
parents:
1261
diff
changeset
|
24 def __init__(self): |
|
ec312b647fcb
pdb.py, bdb.py, cmd.py: use __init__() instead of init()
Guido van Rossum <guido@python.org>
parents:
1261
diff
changeset
|
25 bdb.Bdb.__init__(self) |
|
ec312b647fcb
pdb.py, bdb.py, cmd.py: use __init__() instead of init()
Guido van Rossum <guido@python.org>
parents:
1261
diff
changeset
|
26 cmd.Cmd.__init__(self) |
| 566 | 27 self.prompt = '(Pdb) ' |
| 28 | |
| 29 def reset(self): | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
30 bdb.Bdb.reset(self) |
| 566 | 31 self.forget() |
| 32 | |
| 33 def forget(self): | |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
34 self.lineno = None |
| 566 | 35 self.stack = [] |
|
601
8cdd62bb515c
Added 'r(et)v(al) command.
Guido van Rossum <guido@python.org>
parents:
600
diff
changeset
|
36 self.curindex = 0 |
|
8cdd62bb515c
Added 'r(et)v(al) command.
Guido van Rossum <guido@python.org>
parents:
600
diff
changeset
|
37 self.curframe = None |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
38 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
39 def setup(self, f, t): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
40 self.forget() |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
41 self.stack, self.curindex = self.get_stack(f, t) |
|
601
8cdd62bb515c
Added 'r(et)v(al) command.
Guido van Rossum <guido@python.org>
parents:
600
diff
changeset
|
42 self.curframe = self.stack[self.curindex][0] |
| 566 | 43 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
44 # Override Bdb methods (except user_call, for now) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
45 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
46 def user_line(self, frame): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
47 # This function is called when we stop or break at this line |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
48 self.interaction(frame, None) |
|
601
8cdd62bb515c
Added 'r(et)v(al) command.
Guido van Rossum <guido@python.org>
parents:
600
diff
changeset
|
49 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
50 def user_return(self, frame, return_value): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
51 # This function is called when a return trap is set here |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
52 frame.f_locals['__return__'] = return_value |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
53 print '--Return--' |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
54 self.interaction(frame, None) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
55 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
56 def user_exception(self, frame, (exc_type, exc_value, exc_traceback)): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
57 # This function is called if an exception occurs, |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
58 # but only if we are to stop at or just below this level |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
59 frame.f_locals['__exception__'] = exc_type, exc_value |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
60 if type(exc_type) == type(''): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
61 exc_type_name = exc_type |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
62 else: exc_type_name = exc_type.__name__ |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
63 print exc_type_name + ':', repr.repr(exc_value) |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
64 self.interaction(frame, exc_traceback) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
65 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
66 # General interaction function |
| 566 | 67 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
68 def interaction(self, frame, traceback): |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
69 self.setup(frame, traceback) |
|
2280
650cb67d7659
fix formatting of stack entries
Guido van Rossum <guido@python.org>
parents:
1999
diff
changeset
|
70 self.print_stack_entry(self.stack[self.curindex]) |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
71 self.cmdloop() |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
72 self.forget() |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
73 |
| 566 | 74 def default(self, line): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
75 if line[:1] == '!': line = line[1:] |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
76 locals = self.curframe.f_locals |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
77 globals = self.curframe.f_globals |
|
1331
07900834cc97
* pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents:
1317
diff
changeset
|
78 globals['__privileged__'] = 1 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
79 try: |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
80 code = compile(line + '\n', '<stdin>', 'single') |
|
2922
4f082be5902a
use new "single" compile option
Guido van Rossum <guido@python.org>
parents:
2437
diff
changeset
|
81 exec code in globals, locals |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
82 except: |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
83 if type(sys.exc_type) == type(''): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
84 exc_type_name = sys.exc_type |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
85 else: exc_type_name = sys.exc_type.__name__ |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
86 print '***', exc_type_name + ':', sys.exc_value |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
87 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
88 # Command definitions, called by cmdloop() |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
89 # The argument is the remaining string on the command line |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
90 # Return true to exit from the command loop |
| 566 | 91 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
92 do_h = cmd.Cmd.do_help |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
93 |
| 566 | 94 def do_break(self, arg): |
| 95 if not arg: | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
96 print self.get_all_breaks() # XXX |
| 566 | 97 return |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
98 # Try line number as argument |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
99 try: |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
100 arg = eval(arg, self.curframe.f_globals, |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
101 self.curframe.f_locals) |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
102 except: |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
103 print '*** Could not eval argument:', arg |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
104 return |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
105 |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
106 # Check for condition |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
107 try: arg, cond = arg |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
108 except: arg, cond = arg, None |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
109 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
110 try: |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
111 lineno = int(arg) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
112 filename = self.curframe.f_code.co_filename |
| 566 | 113 except: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
114 # Try function name as the argument |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
115 import codehack |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
116 try: |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
117 func = arg |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
118 if hasattr(func, 'im_func'): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
119 func = func.im_func |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
120 code = func.func_code |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
121 except: |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
122 print '*** The specified object', |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
123 print 'is not a function', arg |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
124 return |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
125 lineno = codehack.getlineno(code) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
126 filename = code.co_filename |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
127 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
128 # now set the break point |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
129 err = self.set_break(filename, lineno, cond) |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
130 if err: print '***', err |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
131 |
| 566 | 132 do_b = do_break |
| 133 | |
| 134 def do_clear(self, arg): | |
| 135 if not arg: | |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
136 try: |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
137 reply = raw_input('Clear all breaks? ') |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
138 except EOFError: |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
139 reply = 'no' |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
140 reply = string.lower(string.strip(reply)) |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
141 if reply in ('y', 'yes'): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
142 self.clear_all_breaks() |
| 566 | 143 return |
| 144 try: | |
| 145 lineno = int(eval(arg)) | |
| 146 except: | |
| 147 print '*** Error in argument:', `arg` | |
| 148 return | |
| 149 filename = self.curframe.f_code.co_filename | |
|
1110
1d06b1499eb9
* Got entirely rid of path.py.
Guido van Rossum <guido@python.org>
parents:
1086
diff
changeset
|
150 err = self.clear_break(filename, lineno) |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
151 if err: print '***', err |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
152 do_cl = do_clear # 'c' is already an abbreviation for 'continue' |
| 566 | 153 |
| 154 def do_where(self, arg): | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
155 self.print_stack_trace() |
| 566 | 156 do_w = do_where |
| 157 | |
| 158 def do_up(self, arg): | |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
159 if self.curindex == 0: |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
160 print '*** Oldest frame' |
| 566 | 161 else: |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
162 self.curindex = self.curindex - 1 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
163 self.curframe = self.stack[self.curindex][0] |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
164 self.print_stack_entry(self.stack[self.curindex]) |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
1041
diff
changeset
|
165 self.lineno = None |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
166 do_u = do_up |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
167 |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
168 def do_down(self, arg): |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
169 if self.curindex + 1 == len(self.stack): |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
170 print '*** Newest frame' |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
171 else: |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
172 self.curindex = self.curindex + 1 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
173 self.curframe = self.stack[self.curindex][0] |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
174 self.print_stack_entry(self.stack[self.curindex]) |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
1041
diff
changeset
|
175 self.lineno = None |
| 566 | 176 do_d = do_down |
| 177 | |
| 178 def do_step(self, arg): | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
179 self.set_step() |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
180 return 1 |
| 566 | 181 do_s = do_step |
| 182 | |
| 183 def do_next(self, arg): | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
184 self.set_next(self.curframe) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
185 return 1 |
| 566 | 186 do_n = do_next |
| 187 | |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
188 def do_return(self, arg): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
189 self.set_return(self.curframe) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
190 return 1 |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
191 do_r = do_return |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
192 |
| 566 | 193 def do_continue(self, arg): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
194 self.set_continue() |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
195 return 1 |
| 566 | 196 do_c = do_cont = do_continue |
| 197 | |
| 198 def do_quit(self, arg): | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
199 self.set_quit() |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
200 return 1 |
| 566 | 201 do_q = do_quit |
| 202 | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
203 def do_args(self, arg): |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
204 if self.curframe.f_locals.has_key('__args__'): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
205 print `self.curframe.f_locals['__args__']` |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
206 else: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
207 print '*** No arguments?!' |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
208 do_a = do_args |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
209 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
210 def do_retval(self, arg): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
211 if self.curframe.f_locals.has_key('__return__'): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
212 print self.curframe.f_locals['__return__'] |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
213 else: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
214 print '*** Not yet returned!' |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
215 do_rv = do_retval |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
216 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
217 def do_p(self, arg): |
|
1331
07900834cc97
* pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents:
1317
diff
changeset
|
218 self.curframe.f_globals['__privileged__'] = 1 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
219 try: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
220 value = eval(arg, self.curframe.f_globals, \ |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
221 self.curframe.f_locals) |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
222 except: |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
223 if type(sys.exc_type) == type(''): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
224 exc_type_name = sys.exc_type |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
225 else: exc_type_name = sys.exc_type.__name__ |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
226 print '***', exc_type_name + ':', `sys.exc_value` |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
227 return |
|
1331
07900834cc97
* pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents:
1317
diff
changeset
|
228 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
229 print `value` |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
230 |
| 566 | 231 def do_list(self, arg): |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
232 self.lastcmd = 'list' |
| 566 | 233 last = None |
| 234 if arg: | |
| 235 try: | |
| 236 x = eval(arg, {}, {}) | |
| 237 if type(x) == type(()): | |
| 238 first, last = x | |
| 239 first = int(first) | |
| 240 last = int(last) | |
| 241 if last < first: | |
| 242 # Assume it's a count | |
| 243 last = first + last | |
| 244 else: | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
1041
diff
changeset
|
245 first = max(1, int(x) - 5) |
| 566 | 246 except: |
| 247 print '*** Error in argument:', `arg` | |
| 248 return | |
| 249 elif self.lineno is None: | |
| 250 first = max(1, self.curframe.f_lineno - 5) | |
| 251 else: | |
| 252 first = self.lineno + 1 | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
1041
diff
changeset
|
253 if last == None: |
| 566 | 254 last = first + 10 |
| 255 filename = self.curframe.f_code.co_filename | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
256 breaklist = self.get_file_breaks(filename) |
| 566 | 257 try: |
| 258 for lineno in range(first, last+1): | |
| 259 line = linecache.getline(filename, lineno) | |
| 260 if not line: | |
| 261 print '[EOF]' | |
| 262 break | |
| 263 else: | |
| 264 s = string.rjust(`lineno`, 3) | |
| 265 if len(s) < 4: s = s + ' ' | |
| 266 if lineno in breaklist: s = s + 'B' | |
| 267 else: s = s + ' ' | |
| 268 if lineno == self.curframe.f_lineno: | |
| 269 s = s + '->' | |
| 270 print s + '\t' + line, | |
| 271 self.lineno = lineno | |
| 272 except KeyboardInterrupt: | |
| 273 pass | |
| 274 do_l = do_list | |
|
1261
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
275 |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
276 def do_whatis(self, arg): |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
277 try: |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
278 value = eval(arg, self.curframe.f_globals, \ |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
279 self.curframe.f_locals) |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
280 except: |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
281 if type(sys.exc_type) == type(''): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
282 exc_type_name = sys.exc_type |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
283 else: exc_type_name = sys.exc_type.__name__ |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
284 print '***', exc_type_name + ':', `sys.exc_value` |
|
1261
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
285 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
286 code = None |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
287 # Is it a function? |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
288 try: code = value.func_code |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
289 except: pass |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
290 if code: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
291 print 'Function', code.co_name |
|
1261
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
292 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
293 # Is it an instance method? |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
294 try: code = value.im_func.func_code |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
295 except: pass |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
296 if code: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
297 print 'Method', code.co_name |
|
1261
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
298 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
299 # None of the above... |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
300 print type(value) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
301 |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
302 # Print a traceback starting at the top stack frame. |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
303 # The most recently entered frame is printed last; |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
304 # this is different from dbx and gdb, but consistent with |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
305 # the Python interpreter's stack trace. |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
306 # It is also consistent with the up/down commands (which are |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
307 # compatible with dbx and gdb: up moves towards 'main()' |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
308 # and down moves towards the most recent stack frame). |
| 566 | 309 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
310 def print_stack_trace(self): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
311 try: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
312 for frame_lineno in self.stack: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
313 self.print_stack_entry(frame_lineno) |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
314 except KeyboardInterrupt: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
315 pass |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
316 |
|
2280
650cb67d7659
fix formatting of stack entries
Guido van Rossum <guido@python.org>
parents:
1999
diff
changeset
|
317 def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
318 frame, lineno = frame_lineno |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
319 if frame is self.curframe: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
320 print '>', |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
321 else: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
322 print ' ', |
|
1999
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
323 print self.format_stack_entry(frame_lineno, prompt_prefix) |
| 566 | 324 |
| 325 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
326 # Help methods (derived from pdb.doc) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
327 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
328 def help_help(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
329 self.help_h() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
330 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
331 def help_h(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
332 print """h(elp) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
333 Without argument, print the list of available commands. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
334 With a command name as argument, print help about that command |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
335 "help pdb" pipes the full documentation file to the $PAGER |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
336 "help exec" gives help on the ! command""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
337 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
338 def help_where(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
339 self.help_w() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
340 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
341 def help_w(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
342 print """w(here) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
343 Print a stack trace, with the most recent frame at the bottom. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
344 An arrow indicates the "current frame", which determines the |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
345 context of most commands.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
346 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
347 def help_down(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
348 self.help_d() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
349 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
350 def help_d(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
351 print """d(own) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
352 Move the current frame one level down in the stack trace |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
353 (to an older frame).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
354 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
355 def help_up(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
356 self.help_u() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
357 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
358 def help_u(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
359 print """u(p) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
360 Move the current frame one level up in the stack trace |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
361 (to a newer frame).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
362 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
363 def help_break(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
364 self.help_b() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
365 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
366 def help_b(self): |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
367 print """b(reak) [lineno | function] [, "condition"] |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
368 With a line number argument, set a break there in the current |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
369 file. With a function name, set a break at the entry of that |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
370 function. Without argument, list all breaks. If a second |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
371 argument is present, it is a string specifying an expression |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
372 which must evaluate to true before the breakpoint is honored. |
|
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
373 """ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
374 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
375 def help_clear(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
376 self.help_cl() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
377 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
378 def help_cl(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
379 print """cl(ear) [lineno] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
380 With a line number argument, clear that break in the current file. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
381 Without argument, clear all breaks (but first ask confirmation).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
382 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
383 def help_step(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
384 self.help_s() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
385 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
386 def help_s(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
387 print """s(tep) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
388 Execute the current line, stop at the first possible occasion |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
389 (either in a function that is called or in the current function).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
390 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
391 def help_next(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
392 self.help_n() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
393 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
394 def help_n(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
395 print """n(ext) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
396 Continue execution until the next line in the current function |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
397 is reached or it returns.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
398 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
399 def help_return(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
400 self.help_r() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
401 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
402 def help_r(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
403 print """r(eturn) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
404 Continue execution until the current function returns.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
405 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
406 def help_continue(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
407 self.help_c() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
408 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
409 def help_cont(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
410 self.help_c() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
411 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
412 def help_c(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
413 print """c(ont(inue)) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
414 Continue execution, only stop when a breakpoint is encountered.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
415 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
416 def help_list(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
417 self.help_l() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
418 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
419 def help_l(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
420 print """l(ist) [first [,last]] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
421 List source code for the current file. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
422 Without arguments, list 11 lines around the current line |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
423 or continue the previous listing. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
424 With one argument, list 11 lines starting at that line. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
425 With two arguments, list the given range; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
426 if the second argument is less than the first, it is a count.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
427 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
428 def help_args(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
429 self.help_a() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
430 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
431 def help_a(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
432 print """a(rgs) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
433 Print the argument list of the current function.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
434 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
435 def help_p(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
436 print """p expression |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
437 Print the value of the expression.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
438 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
439 def help_exec(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
440 print """(!) statement |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
441 Execute the (one-line) statement in the context of |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
442 the current stack frame. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
443 The exclamation point can be omitted unless the first word |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
444 of the statement resembles a debugger command. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
445 To assign to a global variable you must always prefix the |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
446 command with a 'global' command, e.g.: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
447 (Pdb) global list_options; list_options = ['-l'] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
448 (Pdb)""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
449 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
450 def help_quit(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
451 self.help_q() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
452 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
453 def help_q(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
454 print """q(uit) Quit from the debugger. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
455 The program being executed is aborted.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
456 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
457 def help_pdb(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
458 help() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
459 |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
460 # Simplified interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
461 |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
462 def run(statement, globals=None, locals=None): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
463 Pdb().run(statement, globals, locals) |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
464 |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
465 def runeval(expression, globals=None, locals=None): |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
466 return Pdb().runeval(expression, globals, locals) |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
467 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
468 def runctx(statement, globals, locals): |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
469 # B/W compatibility |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
470 run(statement, globals, locals) |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
471 |
|
1006
903071377d29
Added a _v21 def to FL.py and added two new input field types
Guido van Rossum <guido@python.org>
parents:
649
diff
changeset
|
472 def runcall(*args): |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
473 return apply(Pdb().runcall, args) |
|
1006
903071377d29
Added a _v21 def to FL.py and added two new input field types
Guido van Rossum <guido@python.org>
parents:
649
diff
changeset
|
474 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
475 def set_trace(): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
476 Pdb().set_trace() |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
477 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
478 # Post-Mortem interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
479 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
480 def post_mortem(t): |
|
1317
ec312b647fcb
pdb.py, bdb.py, cmd.py: use __init__() instead of init()
Guido van Rossum <guido@python.org>
parents:
1261
diff
changeset
|
481 p = Pdb() |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
482 p.reset() |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
483 while t.tb_next <> None: t = t.tb_next |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
484 p.interaction(t.tb_frame, t) |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
485 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
486 def pm(): |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
487 import sys |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
488 post_mortem(sys.last_traceback) |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
489 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
490 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
491 # Main program for testing |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
492 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
493 TESTCMD = 'import x; x.main()' |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
494 |
| 566 | 495 def test(): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
496 run(TESTCMD) |
|
1357
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
497 |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
498 # print help |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
499 def help(): |
|
1358
3e33ca54fbdc
Added missing "import os" to pdb.help()
Guido van Rossum <guido@python.org>
parents:
1357
diff
changeset
|
500 import os |
|
1357
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
501 for dirname in sys.path: |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
502 fullname = os.path.join(dirname, 'pdb.doc') |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
503 if os.path.exists(fullname): |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
504 sts = os.system('${PAGER-more} '+fullname) |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
505 if sts: print '*** Pager exit status:', sts |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
506 break |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
507 else: |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
508 print 'Sorry, can\'t find the help file "pdb.doc"', |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
509 print 'along the Python search path' |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
510 |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
511 # When invoked as main program, invoke the debugger on a script |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
512 if __name__=='__main__': |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
513 import sys |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
514 import os |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
515 if not sys.argv[1:]: |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
516 print "usage: pdb.py scriptfile [arg] ..." |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
517 sys.exit(2) |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
518 |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
519 filename = sys.argv[1] # Get script filename |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
520 |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
521 del sys.argv[0] # Hide "pdb.py" from argument list |
|
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
522 |
|
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
523 # Insert script directory in front of module search path |
|
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
524 sys.path.insert(0, os.path.dirname(filename)) |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
525 |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
526 run('execfile(' + `filename` + ')', {'__name__': '__main__'}) |
