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