Mercurial > cpython-lru_cache-weakref
annotate Lib/pdb.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 67d258edd3d9 |
| children | 73758db2f464 |
| rev | line source |
|---|---|
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
1 #! /usr/local/bin/python |
|
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 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
99 try: |
| 566 | 100 lineno = int(eval(arg)) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
101 filename = self.curframe.f_code.co_filename |
| 566 | 102 except: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
103 # Try function name as the argument |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
104 import codehack |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
105 try: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
106 func = eval(arg, self.curframe.f_globals, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
107 self.curframe.f_locals) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
108 if hasattr(func, 'im_func'): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
109 func = func.im_func |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
110 code = func.func_code |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
111 except: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
112 print '*** Could not eval argument:', arg |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
113 return |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
114 lineno = codehack.getlineno(code) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
115 filename = code.co_filename |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
116 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
117 # now set the break point |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
118 err = self.set_break(filename, lineno) |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
119 if err: print '***', err |
| 566 | 120 do_b = do_break |
| 121 | |
| 122 def do_clear(self, arg): | |
| 123 if not arg: | |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
124 try: |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
125 reply = raw_input('Clear all breaks? ') |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
126 except EOFError: |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
127 reply = 'no' |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
128 reply = string.lower(string.strip(reply)) |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
129 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
|
130 self.clear_all_breaks() |
| 566 | 131 return |
| 132 try: | |
| 133 lineno = int(eval(arg)) | |
| 134 except: | |
| 135 print '*** Error in argument:', `arg` | |
| 136 return | |
| 137 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
|
138 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
|
139 if err: print '***', err |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
140 do_cl = do_clear # 'c' is already an abbreviation for 'continue' |
| 566 | 141 |
| 142 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
|
143 self.print_stack_trace() |
| 566 | 144 do_w = do_where |
| 145 | |
| 146 def do_up(self, arg): | |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
147 if self.curindex == 0: |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
148 print '*** Oldest frame' |
| 566 | 149 else: |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
150 self.curindex = self.curindex - 1 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
151 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
|
152 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
|
153 self.lineno = None |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
154 do_u = do_up |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
155 |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
156 def do_down(self, arg): |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
157 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
|
158 print '*** Newest frame' |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
159 else: |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
160 self.curindex = self.curindex + 1 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
161 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
|
162 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
|
163 self.lineno = None |
| 566 | 164 do_d = do_down |
| 165 | |
| 166 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
|
167 self.set_step() |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
168 return 1 |
| 566 | 169 do_s = do_step |
| 170 | |
| 171 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
|
172 self.set_next(self.curframe) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
173 return 1 |
| 566 | 174 do_n = do_next |
| 175 | |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
176 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
|
177 self.set_return(self.curframe) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
178 return 1 |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
179 do_r = do_return |
|
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
180 |
| 566 | 181 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
|
182 self.set_continue() |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
183 return 1 |
| 566 | 184 do_c = do_cont = do_continue |
| 185 | |
| 186 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
|
187 self.set_quit() |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
188 return 1 |
| 566 | 189 do_q = do_quit |
| 190 | |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
191 def do_args(self, arg): |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
192 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
|
193 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
|
194 else: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
195 print '*** No arguments?!' |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
196 do_a = do_args |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
197 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
198 def do_retval(self, arg): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
199 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
|
200 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
|
201 else: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
202 print '*** Not yet returned!' |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
203 do_rv = do_retval |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
204 |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
205 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
|
206 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
|
207 try: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
208 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
|
209 self.curframe.f_locals) |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
210 except: |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 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
|
215 return |
|
1331
07900834cc97
* pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents:
1317
diff
changeset
|
216 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
217 print `value` |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
218 |
| 566 | 219 def do_list(self, arg): |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
220 self.lastcmd = 'list' |
| 566 | 221 last = None |
| 222 if arg: | |
| 223 try: | |
| 224 x = eval(arg, {}, {}) | |
| 225 if type(x) == type(()): | |
| 226 first, last = x | |
| 227 first = int(first) | |
| 228 last = int(last) | |
| 229 if last < first: | |
| 230 # Assume it's a count | |
| 231 last = first + last | |
| 232 else: | |
|
1086
db817f3a1c65
* change default line numbers for 'list' in pdb.py
Guido van Rossum <guido@python.org>
parents:
1041
diff
changeset
|
233 first = max(1, int(x) - 5) |
| 566 | 234 except: |
| 235 print '*** Error in argument:', `arg` | |
| 236 return | |
| 237 elif self.lineno is None: | |
| 238 first = max(1, self.curframe.f_lineno - 5) | |
| 239 else: | |
| 240 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
|
241 if last == None: |
| 566 | 242 last = first + 10 |
| 243 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
|
244 breaklist = self.get_file_breaks(filename) |
| 566 | 245 try: |
| 246 for lineno in range(first, last+1): | |
| 247 line = linecache.getline(filename, lineno) | |
| 248 if not line: | |
| 249 print '[EOF]' | |
| 250 break | |
| 251 else: | |
| 252 s = string.rjust(`lineno`, 3) | |
| 253 if len(s) < 4: s = s + ' ' | |
| 254 if lineno in breaklist: s = s + 'B' | |
| 255 else: s = s + ' ' | |
| 256 if lineno == self.curframe.f_lineno: | |
| 257 s = s + '->' | |
| 258 print s + '\t' + line, | |
| 259 self.lineno = lineno | |
| 260 except KeyboardInterrupt: | |
| 261 pass | |
| 262 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
|
263 |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
264 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
|
265 try: |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
266 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
|
267 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
|
268 except: |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
269 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
|
270 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
|
271 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
|
272 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
|
273 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
274 code = None |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
275 # 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
|
276 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
|
277 except: pass |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
278 if code: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
279 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
|
280 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
281 # 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
|
282 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
|
283 except: pass |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
284 if code: |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
285 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
|
286 return |
|
2c515f07367a
Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents:
1110
diff
changeset
|
287 # 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
|
288 print type(value) |
|
575
deae80e07a81
Almost complete rewritten. Documentation added.
Guido van Rossum <guido@python.org>
parents:
571
diff
changeset
|
289 |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
290 # 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
|
291 # 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
|
292 # 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
|
293 # the Python interpreter's stack trace. |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
294 # 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
|
295 # 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
|
296 # and down moves towards the most recent stack frame). |
| 566 | 297 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
298 def print_stack_trace(self): |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
299 try: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
300 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
|
301 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
|
302 except KeyboardInterrupt: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
303 pass |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
304 |
|
2280
650cb67d7659
fix formatting of stack entries
Guido van Rossum <guido@python.org>
parents:
1999
diff
changeset
|
305 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
|
306 frame, lineno = frame_lineno |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
307 if frame is self.curframe: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
308 print '>', |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
309 else: |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
310 print ' ', |
|
1999
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
311 print self.format_stack_entry(frame_lineno, prompt_prefix) |
| 566 | 312 |
| 313 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
314 # Help methods (derived from pdb.doc) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
315 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
316 def help_help(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
317 self.help_h() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
318 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
319 def help_h(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
320 print """h(elp) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
321 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
|
322 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
|
323 "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
|
324 "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
|
325 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
326 def help_where(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
327 self.help_w() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
328 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
329 def help_w(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
330 print """w(here) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
331 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
|
332 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
|
333 context of most commands.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
334 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
335 def help_down(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
336 self.help_d() |
|
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_d(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
339 print """d(own) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
340 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
|
341 (to an older frame).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
342 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
343 def help_up(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
344 self.help_u() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
345 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
346 def help_u(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
347 print """u(p) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
348 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
|
349 (to a newer frame).""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
350 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
351 def help_break(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
352 self.help_b() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
353 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
354 def help_b(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
355 print """b(reak) [lineno | function] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
356 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
|
357 file. With a function name, set a break at the entry of that |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
358 function. Without argument, list all breaks.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
359 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
360 def help_clear(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
361 self.help_cl() |
|
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_cl(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
364 print """cl(ear) [lineno] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
365 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
|
366 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
|
367 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
368 def help_step(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
369 self.help_s() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
370 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
371 def help_s(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
372 print """s(tep) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
373 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
|
374 (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
|
375 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
376 def help_next(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
377 self.help_n() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
378 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
379 def help_n(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
380 print """n(ext) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
381 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
|
382 is reached or it returns.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
383 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
384 def help_return(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
385 self.help_r() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
386 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
387 def help_r(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
388 print """r(eturn) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
389 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
|
390 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
391 def help_continue(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
392 self.help_c() |
|
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_cont(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
395 self.help_c() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
396 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
397 def help_c(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
398 print """c(ont(inue)) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
399 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
|
400 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
401 def help_list(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
402 self.help_l() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
403 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
404 def help_l(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
405 print """l(ist) [first [,last]] |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
406 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
|
407 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
|
408 or continue the previous listing. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
413 def help_args(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
414 self.help_a() |
|
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_a(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
417 print """a(rgs) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
418 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
|
419 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
420 def help_p(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
421 print """p expression |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
422 Print the value of the expression.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
423 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
424 def help_exec(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
425 print """(!) statement |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
426 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
|
427 the current stack frame. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
428 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
|
429 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
|
430 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
|
431 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
|
432 (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
|
433 (Pdb)""" |
|
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_quit(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
436 self.help_q() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
437 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
438 def help_q(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
439 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
|
440 The program being executed is aborted.""" |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
441 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
442 def help_pdb(self): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
443 help() |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
444 |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
445 # Simplified interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
446 |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
447 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
|
448 Pdb().run(statement, globals, locals) |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
449 |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
450 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
|
451 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
|
452 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
453 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
|
454 # B/W compatibility |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
455 run(statement, globals, locals) |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
456 |
|
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
|
457 def runcall(*args): |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
458 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
|
459 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
460 def set_trace(): |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
461 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
|
462 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
463 # Post-Mortem interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
464 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
465 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
|
466 p = Pdb() |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
467 p.reset() |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
468 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
|
469 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
|
470 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
471 def pm(): |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
472 import sys |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
473 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
|
474 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
475 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
476 # 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
|
477 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
478 TESTCMD = 'import x; x.main()' |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
479 |
| 566 | 480 def test(): |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
481 run(TESTCMD) |
|
1357
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
482 |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
483 # print help |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
484 def help(): |
|
1358
3e33ca54fbdc
Added missing "import os" to pdb.help()
Guido van Rossum <guido@python.org>
parents:
1357
diff
changeset
|
485 import os |
|
1357
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
486 for dirname in sys.path: |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
487 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
|
488 if os.path.exists(fullname): |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
489 sts = os.system('${PAGER-more} '+fullname) |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
490 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
|
491 break |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
492 else: |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
493 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
|
494 print 'along the Python search path' |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
495 |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
496 # 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
|
497 if __name__=='__main__': |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
498 import sys |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
499 import os |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
500 if not sys.argv[1:]: |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
501 print "usage: pdb.py scriptfile [arg] ..." |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
502 sys.exit(2) |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
503 |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
504 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
|
505 |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
506 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
|
507 |
|
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
508 # 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
|
509 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
|
510 |
|
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
511 run('execfile(' + `filename` + ')', {'__name__': '__main__'}) |
