Mercurial > cpython-lru_cache-weakref
annotate Lib/bdb.py @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 684960fb1cbf |
| children | 3499ed6cbd07 |
| rev | line source |
|---|---|
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
1 """Debugger basics""" |
| 622 | 2 |
|
53776
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
3 import fnmatch |
| 622 | 4 import sys |
|
11270
2cc6a12cd411
canonic(): This used to be equivalent to str() but that caused too
Barry Warsaw <barry@python.org>
parents:
10036
diff
changeset
|
5 import os |
|
4411
d738490c8da1
Allow code objects to be passed to run() and eval().
Guido van Rossum <guido@python.org>
parents:
2437
diff
changeset
|
6 import types |
| 622 | 7 |
|
16070
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
15860
diff
changeset
|
8 __all__ = ["BdbQuit","Bdb","Breakpoint"] |
|
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
15860
diff
changeset
|
9 |
|
22704
18dccdf2c46d
Use docstrings for exception classes
Neal Norwitz <nnorwitz@gmail.com>
parents:
22702
diff
changeset
|
10 class BdbQuit(Exception): |
|
18dccdf2c46d
Use docstrings for exception classes
Neal Norwitz <nnorwitz@gmail.com>
parents:
22702
diff
changeset
|
11 """Exception to give up completely""" |
| 622 | 12 |
| 13 | |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
14 class Bdb: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
15 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
16 """Generic Python debugger base class. |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
17 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
18 This class takes care of details of the trace facility; |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
19 a derived class should implement user interaction. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
20 The standard debugger class (pdb.Pdb) is an example. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
21 """ |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
22 |
|
53776
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
23 def __init__(self, skip=None): |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
24 self.skip = set(skip) if skip else None |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
25 self.breaks = {} |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
26 self.fncache = {} |
|
11270
2cc6a12cd411
canonic(): This used to be equivalent to str() but that caused too
Barry Warsaw <barry@python.org>
parents:
10036
diff
changeset
|
27 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
28 def canonic(self, filename): |
|
21099
83fc88350f80
canonic(): don't use abspath() for filenames looking like <...>; this
Guido van Rossum <guido@python.org>
parents:
18272
diff
changeset
|
29 if filename == "<" + filename[1:-1] + ">": |
|
83fc88350f80
canonic(): don't use abspath() for filenames looking like <...>; this
Guido van Rossum <guido@python.org>
parents:
18272
diff
changeset
|
30 return filename |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
31 canonic = self.fncache.get(filename) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
32 if not canonic: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
33 canonic = os.path.abspath(filename) |
|
22050
ecff4046197d
canonic(): Fix by Edward K Ream to make breakpoints work better on
Guido van Rossum <guido@python.org>
parents:
21926
diff
changeset
|
34 canonic = os.path.normcase(canonic) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
35 self.fncache[filename] = canonic |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
36 return canonic |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
37 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
38 def reset(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
39 import linecache |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
40 linecache.checkcache() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
41 self.botframe = None |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
42 self._set_stopinfo(None, None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
43 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
44 def trace_dispatch(self, frame, event, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
45 if self.quitting: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
46 return # None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
47 if event == 'line': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
48 return self.dispatch_line(frame) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
49 if event == 'call': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
50 return self.dispatch_call(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
51 if event == 'return': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
52 return self.dispatch_return(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
53 if event == 'exception': |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
54 return self.dispatch_exception(frame, arg) |
|
31796
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
55 if event == 'c_call': |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
56 return self.trace_dispatch |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
57 if event == 'c_exception': |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
58 return self.trace_dispatch |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
59 if event == 'c_return': |
|
1c117dbb2def
Enable the profiling of C functions (builtins and extensions)
Nicholas Bastin <nick.bastin@gmail.com>
parents:
31515
diff
changeset
|
60 return self.trace_dispatch |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
28089
diff
changeset
|
61 print 'bdb.Bdb.dispatch: unknown debugging event:', repr(event) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
62 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
63 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
64 def dispatch_line(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
65 if self.stop_here(frame) or self.break_here(frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
66 self.user_line(frame) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
67 if self.quitting: raise BdbQuit |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
68 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
69 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
70 def dispatch_call(self, frame, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
71 # XXX 'arg' is no longer used |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
72 if self.botframe is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
73 # First call of dispatch since reset() |
|
23553
3aecdba45528
This is a Python 2.1 and 2.2 bugfix candidate:
Christian Tismer <tismer@stackless.com>
parents:
22830
diff
changeset
|
74 self.botframe = frame.f_back # (CT) Note that this may also be None! |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
75 return self.trace_dispatch |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
76 if not (self.stop_here(frame) or self.break_anywhere(frame)): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
77 # No need to trace this function |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
78 return # None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
79 self.user_call(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
80 if self.quitting: raise BdbQuit |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
81 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
82 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
83 def dispatch_return(self, frame, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
84 if self.stop_here(frame) or frame == self.returnframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
85 self.user_return(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
86 if self.quitting: raise BdbQuit |
|
18272
44122e7b49cf
Return self.trace_dispatch from dispatch_return() to enable stepping through generators. (An alternative would be to create a new "yield" debugger event, but that involves many more changes, and might break Bdb subclasses.)
Just van Rossum <just@letterror.com>
parents:
17342
diff
changeset
|
87 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
88 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
89 def dispatch_exception(self, frame, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
90 if self.stop_here(frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
91 self.user_exception(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
92 if self.quitting: raise BdbQuit |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
93 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
94 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
95 # Normally derived classes don't override the following |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
96 # methods, but they may if they want to redefine the |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
97 # definition of stopping and breakpoints. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
98 |
|
53776
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
99 def is_skipped_module(self, module_name): |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
100 for pattern in self.skip: |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
101 if fnmatch.fnmatch(module_name, pattern): |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
102 return True |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
103 return False |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
104 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
105 def stop_here(self, frame): |
|
23557
a399d8b13c2f
Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents:
23553
diff
changeset
|
106 # (CT) stopframe may now also be None, see dispatch_call. |
|
a399d8b13c2f
Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents:
23553
diff
changeset
|
107 # (CT) the former test for None is therefore removed from here. |
|
53776
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
108 if self.skip and \ |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
109 self.is_skipped_module(frame.f_globals.get('__name__')): |
|
c49bc330327c
#5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents:
50162
diff
changeset
|
110 return False |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
111 if frame is self.stopframe: |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
112 return frame.f_lineno >= self.stoplineno |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
113 while frame is not None and frame is not self.stopframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
114 if frame is self.botframe: |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
115 return True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
116 frame = frame.f_back |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
117 return False |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
118 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
119 def break_here(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
120 filename = self.canonic(frame.f_code.co_filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
121 if not filename in self.breaks: |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
122 return False |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
123 lineno = frame.f_lineno |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
124 if not lineno in self.breaks[filename]: |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
125 # The line itself has no breakpoint, but maybe the line is the |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
126 # first line of a function with breakpoint set by function name. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
127 lineno = frame.f_code.co_firstlineno |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
128 if not lineno in self.breaks[filename]: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
129 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
130 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
131 # flag says ok to delete temp. bp |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
132 (bp, flag) = effective(filename, lineno, frame) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
133 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
134 self.currentbp = bp.number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
135 if (flag and bp.temporary): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
136 self.do_clear(str(bp.number)) |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
137 return True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
138 else: |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
139 return False |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
140 |
|
17342
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
141 def do_clear(self, arg): |
|
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
142 raise NotImplementedError, "subclass of bdb must implement do_clear()" |
|
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
143 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
144 def break_anywhere(self, frame): |
|
48120
0d2d26ffe20e
Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents:
47221
diff
changeset
|
145 return self.canonic(frame.f_code.co_filename) in self.breaks |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
146 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
147 # Derived classes should override the user_* methods |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
148 # to gain control. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
149 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
150 def user_call(self, frame, argument_list): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
151 """This method is called when there is the remote possibility |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
152 that we ever need to stop in this function.""" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
153 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
154 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
155 def user_line(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
156 """This method is called when we stop or break at this line.""" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
157 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
158 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
159 def user_return(self, frame, return_value): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
160 """This method is called when a return trap is set here.""" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
161 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
162 |
|
48120
0d2d26ffe20e
Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents:
47221
diff
changeset
|
163 def user_exception(self, frame, exc_info): |
|
0d2d26ffe20e
Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents:
47221
diff
changeset
|
164 exc_type, exc_value, exc_traceback = exc_info |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
165 """This method is called if an exception occurs, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
166 but only if we are to stop at or just below this level.""" |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
167 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
168 |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
169 def _set_stopinfo(self, stopframe, returnframe, stoplineno=-1): |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
170 self.stopframe = stopframe |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
171 self.returnframe = returnframe |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
172 self.quitting = 0 |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
173 self.stoplineno = stoplineno |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
174 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
175 # Derived classes and clients can call the following methods |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
176 # to affect the stepping state. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
177 |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
178 def set_until(self, frame): #the name "until" is borrowed from gdb |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
179 """Stop when the line with the line no greater than the current one is |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
180 reached or when returning from current frame""" |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
181 self._set_stopinfo(frame, frame, frame.f_lineno+1) |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
182 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
183 def set_step(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
184 """Stop after one line of code.""" |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
185 self._set_stopinfo(None,None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
186 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
187 def set_next(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
188 """Stop on the next line in or below the given frame.""" |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
189 self._set_stopinfo(frame, None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
190 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
191 def set_return(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
192 """Stop when returning from the given frame.""" |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
193 self._set_stopinfo(frame.f_back, frame) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
194 |
|
33924
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
195 def set_trace(self, frame=None): |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
196 """Start debugging from `frame`. |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
197 |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
198 If frame is not specified, debugging starts from caller's frame. |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
199 """ |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
200 if frame is None: |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
201 frame = sys._getframe().f_back |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
202 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
203 while frame: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
204 frame.f_trace = self.trace_dispatch |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
205 self.botframe = frame |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
206 frame = frame.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
207 self.set_step() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
208 sys.settrace(self.trace_dispatch) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
209 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
210 def set_continue(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
211 # Don't stop except at breakpoints or when finished |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
212 self._set_stopinfo(self.botframe, None) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
213 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
214 # no breakpoints; run without debugger overhead |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
215 sys.settrace(None) |
|
23553
3aecdba45528
This is a Python 2.1 and 2.2 bugfix candidate:
Christian Tismer <tismer@stackless.com>
parents:
22830
diff
changeset
|
216 frame = sys._getframe().f_back |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
217 while frame and frame is not self.botframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
218 del frame.f_trace |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
219 frame = frame.f_back |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
220 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
221 def set_quit(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
222 self.stopframe = self.botframe |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
223 self.returnframe = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
224 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
225 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
226 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
227 # Derived classes and clients can call the following methods |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
228 # to manipulate breakpoints. These methods return an |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
229 # error message is something went wrong, None if all is well. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
230 # Set_break prints out the breakpoint line and file:lineno. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
231 # Call self.get_*break*() to see the breakpoints or better |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
232 # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint(). |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
233 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
234 def set_break(self, filename, lineno, temporary=0, cond = None, |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
235 funcname=None): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
236 filename = self.canonic(filename) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
237 import linecache # Import as late as possible |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
238 line = linecache.getline(filename, lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
239 if not line: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
240 return 'Line %s:%d does not exist' % (filename, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
241 lineno) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
242 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
243 self.breaks[filename] = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
244 list = self.breaks[filename] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
245 if not lineno in list: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
246 list.append(lineno) |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
247 bp = Breakpoint(filename, lineno, temporary, cond, funcname) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
248 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
249 def clear_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
250 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
251 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
252 return 'There are no breakpoints in %s' % filename |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
253 if lineno not in self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
254 return 'There is no breakpoint at %s:%d' % (filename, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
255 lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
256 # If there's only one bp in the list for that file,line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
257 # pair, then remove the breaks entry |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
258 for bp in Breakpoint.bplist[filename, lineno][:]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
259 bp.deleteMe() |
|
56436
684960fb1cbf
replace has_key with 'in' operator
Benjamin Peterson <benjamin@python.org>
parents:
53776
diff
changeset
|
260 if (filename, lineno) not in Breakpoint.bplist: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
261 self.breaks[filename].remove(lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
262 if not self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
263 del self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
264 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
265 def clear_bpbynumber(self, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
266 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
267 number = int(arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
268 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
269 return 'Non-numeric breakpoint number (%s)' % arg |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
270 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
271 bp = Breakpoint.bpbynumber[number] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
272 except IndexError: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
273 return 'Breakpoint number (%d) out of range' % number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
274 if not bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
275 return 'Breakpoint (%d) already deleted' % number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
276 self.clear_break(bp.file, bp.line) |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
277 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
278 def clear_all_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
279 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
280 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
281 return 'There are no breakpoints in %s' % filename |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
282 for line in self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
283 blist = Breakpoint.bplist[filename, line] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
284 for bp in blist: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
285 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
286 del self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
287 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
288 def clear_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
289 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
290 return 'There are no breakpoints' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
291 for bp in Breakpoint.bpbynumber: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
292 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
293 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
294 self.breaks = {} |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
295 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
296 def get_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
297 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
298 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
299 lineno in self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
300 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
301 def get_breaks(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
302 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
303 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
304 lineno in self.breaks[filename] and \ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
305 Breakpoint.bplist[filename, lineno] or [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
306 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
307 def get_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
308 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
309 if filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
310 return self.breaks[filename] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
311 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
312 return [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
313 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
314 def get_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
315 return self.breaks |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
316 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
317 # Derived classes and clients can call the following method |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
318 # to get a data structure representing a stack trace. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
319 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
320 def get_stack(self, f, t): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
321 stack = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
322 if t and t.tb_frame is f: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
323 t = t.tb_next |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
324 while f is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
325 stack.append((f, f.f_lineno)) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
326 if f is self.botframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
327 break |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
328 f = f.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
329 stack.reverse() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
330 i = max(0, len(stack) - 1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
331 while t is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
332 stack.append((t.tb_frame, t.tb_lineno)) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
333 t = t.tb_next |
|
49572
c6c32842e71d
Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48120
diff
changeset
|
334 if f is None: |
|
c6c32842e71d
Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48120
diff
changeset
|
335 i = max(0, len(stack) - 1) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
336 return stack, i |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
337 |
|
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
338 # |
|
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
339 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
340 def format_stack_entry(self, frame_lineno, lprefix=': '): |
|
47221
9fbc41abdd4b
Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents:
47085
diff
changeset
|
341 import linecache, repr |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
342 frame, lineno = frame_lineno |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
343 filename = self.canonic(frame.f_code.co_filename) |
|
31515
71a294bd7950
Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents:
28089
diff
changeset
|
344 s = '%s(%r)' % (filename, lineno) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
345 if frame.f_code.co_name: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
346 s = s + frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
347 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
348 s = s + "<lambda>" |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
349 if '__args__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
350 args = frame.f_locals['__args__'] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
351 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
352 args = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
353 if args: |
|
47221
9fbc41abdd4b
Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents:
47085
diff
changeset
|
354 s = s + repr.repr(args) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
355 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
356 s = s + '()' |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
357 if '__return__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
358 rv = frame.f_locals['__return__'] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
359 s = s + '->' |
|
47221
9fbc41abdd4b
Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents:
47085
diff
changeset
|
360 s = s + repr.repr(rv) |
|
50162
4264cf00a75c
Merged revisions 67750-67751 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49572
diff
changeset
|
361 line = linecache.getline(filename, lineno, frame.f_globals) |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
362 if line: s = s + lprefix + line.strip() |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
363 return s |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
364 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
365 # The following two methods can be called by clients to use |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
366 # a debugger to debug a statement, given as a string. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
367 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
368 def run(self, cmd, globals=None, locals=None): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
369 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
370 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
371 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
372 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
373 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
374 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
375 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
376 if not isinstance(cmd, types.CodeType): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
377 cmd = cmd+'\n' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
378 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
379 exec cmd in globals, locals |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
380 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
381 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
382 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
383 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
384 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
385 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
386 def runeval(self, expr, globals=None, locals=None): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
387 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
388 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
389 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
390 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
391 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
392 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
393 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
394 if not isinstance(expr, types.CodeType): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
395 expr = expr+'\n' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
396 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
397 return eval(expr, globals, locals) |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
398 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
399 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
400 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
401 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
402 sys.settrace(None) |
|
1006
903071377d29
Added a _v21 def to FL.py and added two new input field types
Guido van Rossum <guido@python.org>
parents:
786
diff
changeset
|
403 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
404 def runctx(self, cmd, globals, locals): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
405 # B/W compatibility |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
406 self.run(cmd, globals, locals) |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
407 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
408 # This method is more useful to debug a single function call. |
|
1006
903071377d29
Added a _v21 def to FL.py and added two new input field types
Guido van Rossum <guido@python.org>
parents:
786
diff
changeset
|
409 |
|
33823
db8710f13650
SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents:
33334
diff
changeset
|
410 def runcall(self, func, *args, **kwds): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
411 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
412 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
413 res = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
414 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
415 res = func(*args, **kwds) |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
416 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
417 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
418 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
419 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
420 sys.settrace(None) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
421 return res |
| 622 | 422 |
| 423 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
424 def set_trace(): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
425 Bdb().set_trace() |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
426 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
427 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
428 class Breakpoint: |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
429 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
430 """Breakpoint class |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
431 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
432 Implements temporary breakpoints, ignore counts, disabling and |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
433 (re)-enabling, and conditionals. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
434 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
435 Breakpoints are indexed by number through bpbynumber and by |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
436 the file,line tuple using bplist. The former points to a |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
437 single instance of class Breakpoint. The latter points to a |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
438 list of such instances since there may be more than one |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
439 breakpoint per line. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
440 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
441 """ |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
442 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
443 # XXX Keeping state in the class is a mistake -- this means |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
444 # you cannot have more than one active Bdb instance. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
445 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
446 next = 1 # Next bp to be assigned |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
447 bplist = {} # indexed by (file, lineno) tuple |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
448 bpbynumber = [None] # Each entry is None or an instance of Bpt |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
449 # index 0 is unused, except for marking an |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
450 # effective break .... see effective() |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
451 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
452 def __init__(self, file, line, temporary=0, cond=None, funcname=None): |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
453 self.funcname = funcname |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
454 # Needed if funcname is not None. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
455 self.func_first_executable_line = None |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
456 self.file = file # This better be in canonical form! |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
457 self.line = line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
458 self.temporary = temporary |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
459 self.cond = cond |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
460 self.enabled = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
461 self.ignore = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
462 self.hits = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
463 self.number = Breakpoint.next |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
464 Breakpoint.next = Breakpoint.next + 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
465 # Build the two lists |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
466 self.bpbynumber.append(self) |
|
56436
684960fb1cbf
replace has_key with 'in' operator
Benjamin Peterson <benjamin@python.org>
parents:
53776
diff
changeset
|
467 if (file, line) in self.bplist: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
468 self.bplist[file, line].append(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
469 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
470 self.bplist[file, line] = [self] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
471 |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
472 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
473 def deleteMe(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
474 index = (self.file, self.line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
475 self.bpbynumber[self.number] = None # No longer in list |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
476 self.bplist[index].remove(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
477 if not self.bplist[index]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
478 # No more bp for this f:l combo |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
479 del self.bplist[index] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
480 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
481 def enable(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
482 self.enabled = 1 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
483 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
484 def disable(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
485 self.enabled = 0 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
486 |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
487 def bpprint(self, out=None): |
|
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
488 if out is None: |
|
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
489 out = sys.stdout |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
490 if self.temporary: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
491 disp = 'del ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
492 else: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
493 disp = 'keep ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
494 if self.enabled: |
|
37734
4c6d4698a115
Patch #1191700: Adjust column alignment in bdb breakpoint lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
33924
diff
changeset
|
495 disp = disp + 'yes ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
496 else: |
|
37734
4c6d4698a115
Patch #1191700: Adjust column alignment in bdb breakpoint lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
33924
diff
changeset
|
497 disp = disp + 'no ' |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
498 print >>out, '%-4dbreakpoint %s at %s:%d' % (self.number, disp, |
|
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
499 self.file, self.line) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
500 if self.cond: |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
501 print >>out, '\tstop only if %s' % (self.cond,) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
502 if self.ignore: |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
503 print >>out, '\tignore next %d hits' % (self.ignore) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
504 if (self.hits): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
505 if (self.hits > 1): ss = 's' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
506 else: ss = '' |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
507 print >>out, ('\tbreakpoint already hit %d time%s' % |
|
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
508 (self.hits, ss)) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
509 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
510 # -----------end of Breakpoint class---------- |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
511 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
512 def checkfuncname(b, frame): |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
513 """Check whether we should break here because of `b.funcname`.""" |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
514 if not b.funcname: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
515 # Breakpoint was set via line number. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
516 if b.line != frame.f_lineno: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
517 # Breakpoint was set at a line with a def statement and the function |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
518 # defined is called: don't break. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
519 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
520 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
521 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
522 # Breakpoint set via function name. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
523 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
524 if frame.f_code.co_name != b.funcname: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
525 # It's not a function call, but rather execution of def statement. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
526 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
527 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
528 # We are in the right frame. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
529 if not b.func_first_executable_line: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
530 # The function is entered for the 1st time. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
531 b.func_first_executable_line = frame.f_lineno |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
532 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
533 if b.func_first_executable_line != frame.f_lineno: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
534 # But we are not at the first line number: don't break. |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
535 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
536 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
537 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
538 # Determines if there is an effective (active) breakpoint at this |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
539 # line of code. Returns breakpoint number or 0 if none |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
540 def effective(file, line, frame): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
541 """Determine which breakpoint for this file:line is to be acted upon. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
542 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
543 Called only if we know there is a bpt at this |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
544 location. Returns breakpoint that was triggered and a flag |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
545 that indicates if it is ok to delete a temporary bp. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
546 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
547 """ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
548 possibles = Breakpoint.bplist[file,line] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
549 for i in range(0, len(possibles)): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
550 b = possibles[i] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
551 if b.enabled == 0: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
552 continue |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
553 if not checkfuncname(b, frame): |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
554 continue |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
555 # Count every hit when bp is enabled |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
556 b.hits = b.hits + 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
557 if not b.cond: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
558 # If unconditional, and ignoring, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
559 # go on to next, else break |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
560 if b.ignore > 0: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
561 b.ignore = b.ignore -1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
562 continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
563 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
564 # breakpoint and marker that's ok |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
565 # to delete if temporary |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
566 return (b,1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
567 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
568 # Conditional bp. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
569 # Ignore count applies only to those bpt hits where the |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
570 # condition evaluates to true. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
571 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
572 val = eval(b.cond, frame.f_globals, |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
573 frame.f_locals) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
574 if val: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
575 if b.ignore > 0: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
576 b.ignore = b.ignore -1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
577 # continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
578 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
579 return (b,1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
580 # else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
581 # continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
582 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
583 # if eval fails, most conservative |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
584 # thing is to stop on breakpoint |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
585 # regardless of ignore count. |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
586 # Don't delete temporary, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
587 # as another hint to user. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
588 return (b,0) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
589 return (None, None) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
590 |
| 622 | 591 # -------------------- testing -------------------- |
| 592 | |
| 593 class Tdb(Bdb): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
594 def user_call(self, frame, args): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
595 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
596 if not name: name = '???' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
597 print '+++ call', name, args |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
598 def user_line(self, frame): |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
599 import linecache |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
600 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
601 if not name: name = '???' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
602 fn = self.canonic(frame.f_code.co_filename) |
|
50162
4264cf00a75c
Merged revisions 67750-67751 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49572
diff
changeset
|
603 line = linecache.getline(fn, frame.f_lineno, frame.f_globals) |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
604 print '+++', fn, frame.f_lineno, name, ':', line.strip() |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
605 def user_return(self, frame, retval): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
606 print '+++ return', retval |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
607 def user_exception(self, frame, exc_stuff): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
608 print '+++ exception', exc_stuff |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
609 self.set_continue() |
| 622 | 610 |
| 611 def foo(n): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
612 print 'foo(', n, ')' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
613 x = bar(n*10) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
614 print 'bar returned', x |
| 622 | 615 |
| 616 def bar(a): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
617 print 'bar(', a, ')' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
618 return a/2 |
| 622 | 619 |
| 620 def test(): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
621 t = Tdb() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
622 t.run('import bdb; bdb.foo(10)') |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
623 |
|
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
624 # end |
