Mercurial > cpython-lru_cache-weakref
annotate Lib/bdb.py @ 65035:87f4b32905df 2.7
Cosmetic fix to use print function.
| author | Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> |
|---|---|
| date | Fri, 01 Oct 2010 10:48:47 +0000 |
| parents | 3499ed6cbd07 |
| children | 8fd13c5d3882 |
| 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: |
|
63452
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
112 if self.stoplineno == -1: |
|
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
113 return False |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
114 return frame.f_lineno >= self.stoplineno |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
115 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
|
116 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
|
117 return True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
118 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
|
119 return False |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
120 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
121 def break_here(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
122 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
|
123 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
|
124 return False |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
125 lineno = frame.f_lineno |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
126 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
|
127 # 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
|
128 # 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
|
129 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
|
130 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
|
131 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
132 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
133 # flag says ok to delete temp. bp |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
134 (bp, flag) = effective(filename, lineno, frame) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
135 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
136 self.currentbp = bp.number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
137 if (flag and bp.temporary): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
138 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
|
139 return True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
140 else: |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
141 return False |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
142 |
|
17342
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
143 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
|
144 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
|
145 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
146 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
|
147 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
|
148 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
149 # Derived classes should override the user_* methods |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
150 # to gain control. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
151 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
152 def user_call(self, frame, argument_list): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
153 """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
|
154 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
|
155 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
156 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
157 def user_line(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
158 """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
|
159 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
160 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
161 def user_return(self, frame, return_value): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
162 """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
|
163 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
164 |
|
48120
0d2d26ffe20e
Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents:
47221
diff
changeset
|
165 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
|
166 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
|
167 """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
|
168 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
|
169 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
170 |
|
63452
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
171 def _set_stopinfo(self, stopframe, returnframe, stoplineno=0): |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
172 self.stopframe = stopframe |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
173 self.returnframe = returnframe |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
174 self.quitting = 0 |
|
63452
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
175 # stoplineno >= 0 means: stop at line >= the stoplineno |
|
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
176 # stoplineno -1 means: don't stop at all |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
177 self.stoplineno = stoplineno |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
178 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
179 # 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
|
180 # to affect the stepping state. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
181 |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
182 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
|
183 """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
|
184 reached or when returning from current frame""" |
|
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
185 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
|
186 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
187 def set_step(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
188 """Stop after one line of code.""" |
|
63452
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
189 self._set_stopinfo(None, 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_next(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
192 """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
|
193 self._set_stopinfo(frame, None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
194 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
195 def set_return(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
196 """Stop when returning from the given frame.""" |
|
46882
a73e87f15ffa
Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents:
46172
diff
changeset
|
197 self._set_stopinfo(frame.f_back, frame) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
198 |
|
33924
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
199 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
|
200 """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
|
201 |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
202 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
|
203 """ |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
204 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
|
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 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
207 while frame: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
208 frame.f_trace = self.trace_dispatch |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
209 self.botframe = frame |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
210 frame = frame.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
211 self.set_step() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
212 sys.settrace(self.trace_dispatch) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
213 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
214 def set_continue(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
215 # Don't stop except at breakpoints or when finished |
|
63452
3499ed6cbd07
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56436
diff
changeset
|
216 self._set_stopinfo(self.botframe, None, -1) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
217 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
218 # no breakpoints; run without debugger overhead |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
219 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
|
220 frame = sys._getframe().f_back |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
221 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
|
222 del frame.f_trace |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
223 frame = frame.f_back |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
224 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
225 def set_quit(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
226 self.stopframe = self.botframe |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
227 self.returnframe = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
228 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
229 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
230 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
231 # 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
|
232 # to manipulate breakpoints. These methods return an |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
233 # 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
|
234 # 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
|
235 # 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
|
236 # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint(). |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
237 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
238 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
|
239 funcname=None): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
240 filename = self.canonic(filename) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
241 import linecache # Import as late as possible |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
242 line = linecache.getline(filename, lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
243 if not line: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
244 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
|
245 lineno) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
246 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
247 self.breaks[filename] = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
248 list = self.breaks[filename] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
249 if not lineno in list: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
250 list.append(lineno) |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
251 bp = Breakpoint(filename, lineno, temporary, cond, funcname) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
252 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
253 def clear_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
254 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
255 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
256 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
|
257 if lineno not in self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
258 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
|
259 lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
260 # 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
|
261 # pair, then remove the breaks entry |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
262 for bp in Breakpoint.bplist[filename, lineno][:]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
263 bp.deleteMe() |
|
56436
684960fb1cbf
replace has_key with 'in' operator
Benjamin Peterson <benjamin@python.org>
parents:
53776
diff
changeset
|
264 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
|
265 self.breaks[filename].remove(lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
266 if not self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
267 del self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
268 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
269 def clear_bpbynumber(self, 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 number = int(arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
272 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
273 return 'Non-numeric breakpoint number (%s)' % arg |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
274 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
275 bp = Breakpoint.bpbynumber[number] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
276 except IndexError: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
277 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
|
278 if not bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
279 return 'Breakpoint (%d) already deleted' % number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
280 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
|
281 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
282 def clear_all_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
283 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
284 if not filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
285 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
|
286 for line in self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
287 blist = Breakpoint.bplist[filename, line] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
288 for bp in blist: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
289 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
290 del self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
291 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
292 def clear_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
293 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
294 return 'There are no breakpoints' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
295 for bp in Breakpoint.bpbynumber: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
296 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
297 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
298 self.breaks = {} |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
299 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
300 def get_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
301 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
302 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
303 lineno in self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
304 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
305 def get_breaks(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
306 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
307 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
308 lineno in self.breaks[filename] and \ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
309 Breakpoint.bplist[filename, lineno] or [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
310 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
311 def get_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
312 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
313 if filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
314 return self.breaks[filename] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
315 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
316 return [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
317 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
318 def get_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
319 return self.breaks |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
320 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
321 # 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
|
322 # to get a data structure representing a stack trace. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
323 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
324 def get_stack(self, f, t): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
325 stack = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
326 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
|
327 t = t.tb_next |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
328 while f is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
329 stack.append((f, f.f_lineno)) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
330 if f is self.botframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
331 break |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
332 f = f.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
333 stack.reverse() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
334 i = max(0, len(stack) - 1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
335 while t is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
336 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
|
337 t = t.tb_next |
|
49572
c6c32842e71d
Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48120
diff
changeset
|
338 if f is None: |
|
c6c32842e71d
Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
48120
diff
changeset
|
339 i = max(0, len(stack) - 1) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
340 return stack, i |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
341 |
|
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
342 # |
|
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
343 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
344 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
|
345 import linecache, repr |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
346 frame, lineno = frame_lineno |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
347 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
|
348 s = '%s(%r)' % (filename, lineno) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
349 if frame.f_code.co_name: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
350 s = s + frame.f_code.co_name |
|
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 s = s + "<lambda>" |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
353 if '__args__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
354 args = frame.f_locals['__args__'] |
|
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 args = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
357 if args: |
|
47221
9fbc41abdd4b
Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents:
47085
diff
changeset
|
358 s = s + repr.repr(args) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
359 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
360 s = s + '()' |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
361 if '__return__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
362 rv = frame.f_locals['__return__'] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
363 s = s + '->' |
|
47221
9fbc41abdd4b
Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents:
47085
diff
changeset
|
364 s = s + repr.repr(rv) |
|
50162
4264cf00a75c
Merged revisions 67750-67751 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49572
diff
changeset
|
365 line = linecache.getline(filename, lineno, frame.f_globals) |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
366 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
|
367 return s |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
368 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
369 # 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
|
370 # a debugger to debug a statement, given as a string. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
371 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
372 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
|
373 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
374 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
375 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
376 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
377 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
378 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
379 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
380 if not isinstance(cmd, types.CodeType): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
381 cmd = cmd+'\n' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
382 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
383 exec cmd in globals, locals |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
384 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
385 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
386 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
387 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
388 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
389 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
390 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
|
391 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
392 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
393 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
394 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
395 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
396 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
397 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
398 if not isinstance(expr, types.CodeType): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
399 expr = expr+'\n' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
400 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
401 return eval(expr, globals, locals) |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
402 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
403 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
404 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
405 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
406 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
|
407 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
408 def runctx(self, cmd, globals, locals): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
409 # B/W compatibility |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
410 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
|
411 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
412 # 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
|
413 |
|
33823
db8710f13650
SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents:
33334
diff
changeset
|
414 def runcall(self, func, *args, **kwds): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
415 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
416 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
417 res = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
418 try: |
|
46172
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
419 res = func(*args, **kwds) |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
420 except BdbQuit: |
|
9734a42cfa15
#2498 modernized try, except, finally statements in bdb
Benjamin Peterson <benjamin@python.org>
parents:
38147
diff
changeset
|
421 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
422 finally: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
423 self.quitting = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
424 sys.settrace(None) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
425 return res |
| 622 | 426 |
| 427 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
428 def set_trace(): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
429 Bdb().set_trace() |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
430 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
431 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
432 class Breakpoint: |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
433 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
434 """Breakpoint class |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
435 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
436 Implements temporary breakpoints, ignore counts, disabling and |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
437 (re)-enabling, and conditionals. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
438 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 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
|
443 breakpoint per line. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
444 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
445 """ |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
446 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
447 # 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
|
448 # 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
|
449 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
450 next = 1 # Next bp to be assigned |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
451 bplist = {} # indexed by (file, lineno) tuple |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
452 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
|
453 # 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
|
454 # effective break .... see effective() |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
455 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
456 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
|
457 self.funcname = funcname |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
458 # 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
|
459 self.func_first_executable_line = None |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
460 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
|
461 self.line = line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
462 self.temporary = temporary |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
463 self.cond = cond |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
464 self.enabled = 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
465 self.ignore = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
466 self.hits = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
467 self.number = Breakpoint.next |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
468 Breakpoint.next = Breakpoint.next + 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
469 # Build the two lists |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
470 self.bpbynumber.append(self) |
|
56436
684960fb1cbf
replace has_key with 'in' operator
Benjamin Peterson <benjamin@python.org>
parents:
53776
diff
changeset
|
471 if (file, line) in self.bplist: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
472 self.bplist[file, line].append(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
473 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
474 self.bplist[file, line] = [self] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
475 |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
476 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
477 def deleteMe(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
478 index = (self.file, self.line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
479 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
|
480 self.bplist[index].remove(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
481 if not self.bplist[index]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
482 # 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
|
483 del self.bplist[index] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
484 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
485 def enable(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
486 self.enabled = 1 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
487 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
488 def disable(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
489 self.enabled = 0 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
490 |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
491 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
|
492 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
|
493 out = sys.stdout |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
494 if self.temporary: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
495 disp = 'del ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
496 else: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
497 disp = 'keep ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
498 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
|
499 disp = disp + 'yes ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
500 else: |
|
37734
4c6d4698a115
Patch #1191700: Adjust column alignment in bdb breakpoint lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
33924
diff
changeset
|
501 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
|
502 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
|
503 self.file, self.line) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
504 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
|
505 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
|
506 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
|
507 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
|
508 if (self.hits): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
509 if (self.hits > 1): ss = 's' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
510 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
|
511 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
|
512 (self.hits, ss)) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
513 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
514 # -----------end of Breakpoint class---------- |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
515 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
516 def checkfuncname(b, frame): |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
517 """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
|
518 if not b.funcname: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
519 # 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
|
520 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
|
521 # 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
|
522 # 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
|
523 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
524 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
525 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
526 # 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
|
527 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
528 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
|
529 # 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
|
530 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
531 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
532 # 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
|
533 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
|
534 # 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
|
535 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
|
536 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
537 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
|
538 # 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
|
539 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
540 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
541 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
542 # 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
|
543 # 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
|
544 def effective(file, line, frame): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
545 """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
|
546 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
551 """ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
552 possibles = Breakpoint.bplist[file,line] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
553 for i in range(0, len(possibles)): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
554 b = possibles[i] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
555 if b.enabled == 0: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
556 continue |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
557 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
|
558 continue |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
559 # Count every hit when bp is enabled |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
560 b.hits = b.hits + 1 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
561 if not b.cond: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
562 # If unconditional, and ignoring, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
563 # go on to next, else break |
|
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 # breakpoint and marker that's ok |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
569 # to delete if temporary |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
570 return (b,1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
571 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
572 # Conditional bp. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
573 # 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
|
574 # condition evaluates to true. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
575 try: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
576 val = eval(b.cond, frame.f_globals, |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
577 frame.f_locals) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
578 if val: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
579 if b.ignore > 0: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
580 b.ignore = b.ignore -1 |
|
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 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
583 return (b,1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
584 # else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
585 # continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
586 except: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
587 # if eval fails, most conservative |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
588 # thing is to stop on breakpoint |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
589 # regardless of ignore count. |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
590 # Don't delete temporary, |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
591 # as another hint to user. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
592 return (b,0) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
593 return (None, None) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
594 |
| 622 | 595 # -------------------- testing -------------------- |
| 596 | |
| 597 class Tdb(Bdb): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
598 def user_call(self, frame, args): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
599 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
600 if not name: name = '???' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
601 print '+++ call', name, args |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
602 def user_line(self, frame): |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
603 import linecache |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
604 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
605 if not name: name = '???' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
606 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
|
607 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
|
608 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
|
609 def user_return(self, frame, retval): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
610 print '+++ return', retval |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
611 def user_exception(self, frame, exc_stuff): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
612 print '+++ exception', exc_stuff |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
613 self.set_continue() |
| 622 | 614 |
| 615 def foo(n): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
616 print 'foo(', n, ')' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
617 x = bar(n*10) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
618 print 'bar returned', x |
| 622 | 619 |
| 620 def bar(a): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
621 print 'bar(', a, ')' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
622 return a/2 |
| 622 | 623 |
| 624 def test(): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
625 t = Tdb() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
626 t.run('import bdb; bdb.foo(10)') |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
627 |
|
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
628 # end |
