Mercurial > cpython-lru_cache-weakref
annotate Lib/bdb.py @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 95eea8624d05 |
| children |
| 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 |
|
53777
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
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 |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
6 from inspect import CO_GENERATOR |
| 622 | 7 |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
8 __all__ = ["BdbQuit", "Bdb", "Breakpoint"] |
|
16070
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): |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
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: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
15 """Generic Python debugger base class. |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
16 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
17 This class takes care of details of the trace facility; |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
18 a derived class should implement user interaction. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
19 The standard debugger class (pdb.Pdb) is an example. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
20 """ |
|
9941
06c7fff5274a
Change clear_break() to the old signature clear_break(file, line).
Guido van Rossum <guido@python.org>
parents:
9500
diff
changeset
|
21 |
|
53777
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
22 def __init__(self, skip=None): |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
23 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
|
24 self.breaks = {} |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
25 self.fncache = {} |
|
76676
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
26 self.frame_returning = None |
|
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 |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
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 |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
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 |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
79 # Ignore call events in generator except when stepping. |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
80 if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
81 return self.trace_dispatch |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
82 self.user_call(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
83 if self.quitting: raise BdbQuit |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
84 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
85 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
86 def dispatch_return(self, frame, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
87 if self.stop_here(frame) or frame == self.returnframe: |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
88 # Ignore return events in generator except when stepping. |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
89 if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
90 return self.trace_dispatch |
|
76676
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
91 try: |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
92 self.frame_returning = frame |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
93 self.user_return(frame, arg) |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
94 finally: |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
95 self.frame_returning = None |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
96 if self.quitting: raise BdbQuit |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
97 # The user issued a 'next' or 'until' command. |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
98 if self.stopframe is frame and self.stoplineno != -1: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
99 self._set_stopinfo(None, None) |
|
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
|
100 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
101 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
102 def dispatch_exception(self, frame, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
103 if self.stop_here(frame): |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
104 # When stepping with next/until/return in a generator frame, skip |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
105 # the internal StopIteration exception (with no traceback) |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
106 # triggered by a subiterator run with the 'yield from' statement. |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
107 if not (frame.f_code.co_flags & CO_GENERATOR |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
108 and arg[0] is StopIteration and arg[2] is None): |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
109 self.user_exception(frame, arg) |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
110 if self.quitting: raise BdbQuit |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
111 # Stop at the StopIteration or GeneratorExit exception when the user |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
112 # has set stopframe in a generator by issuing a return command, or a |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
113 # next/until command at the last statement in the generator before the |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
114 # exception. |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
115 elif (self.stopframe and frame is not self.stopframe |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
116 and self.stopframe.f_code.co_flags & CO_GENERATOR |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
117 and arg[0] in (StopIteration, GeneratorExit)): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
118 self.user_exception(frame, arg) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
119 if self.quitting: raise BdbQuit |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
120 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
121 return self.trace_dispatch |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
122 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
123 # 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
|
124 # 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
|
125 # definition of stopping and breakpoints. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
126 |
|
53777
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
127 def is_skipped_module(self, module_name): |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
128 for pattern in self.skip: |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
129 if fnmatch.fnmatch(module_name, pattern): |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
130 return True |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
131 return False |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
132 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
133 def stop_here(self, frame): |
|
23557
a399d8b13c2f
Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents:
23553
diff
changeset
|
134 # (CT) stopframe may now also be None, see dispatch_call. |
|
a399d8b13c2f
Whitespace normalization
Neal Norwitz <nnorwitz@gmail.com>
parents:
23553
diff
changeset
|
135 # (CT) the former test for None is therefore removed from here. |
|
53777
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
136 if self.skip and \ |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
137 self.is_skipped_module(frame.f_globals.get('__name__')): |
|
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
50164
diff
changeset
|
138 return False |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
139 if frame is self.stopframe: |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
140 if self.stoplineno == -1: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
141 return False |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
142 return frame.f_lineno >= self.stoplineno |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
143 if not self.stopframe: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
144 return True |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
145 return False |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
146 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
147 def break_here(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
148 filename = self.canonic(frame.f_code.co_filename) |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
149 if filename not 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
|
150 return False |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
151 lineno = frame.f_lineno |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
152 if lineno not 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
|
153 # 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
|
154 # 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
|
155 lineno = frame.f_code.co_firstlineno |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
156 if lineno not 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
|
157 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
158 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
159 # flag says ok to delete temp. bp |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
160 (bp, flag) = effective(filename, lineno, frame) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
161 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
162 self.currentbp = bp.number |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
163 if (flag and bp.temporary): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
164 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
|
165 return True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
166 else: |
|
22830
a9dd5e6d6805
Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents:
22704
diff
changeset
|
167 return False |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
168 |
|
17342
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
169 def do_clear(self, arg): |
|
43020
907a45df1295
Raise statement normalization in Lib/.
Collin Winter <collinw@gmail.com>
parents:
41717
diff
changeset
|
170 raise NotImplementedError("subclass of bdb must implement do_clear()") |
|
17342
9876d6baf843
Make it clear that a bdb subclass must implement do_clear().
Guido van Rossum <guido@python.org>
parents:
16479
diff
changeset
|
171 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
172 def break_anywhere(self, frame): |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
38147
diff
changeset
|
173 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
|
174 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
175 # Derived classes should override the user_* methods |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
176 # to gain control. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
177 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
178 def user_call(self, frame, argument_list): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
179 """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
|
180 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
|
181 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
182 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
183 def user_line(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
184 """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
|
185 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
186 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
187 def user_return(self, frame, return_value): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
188 """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
|
189 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
190 |
|
41717
9ad84070b22d
Merged revisions 55328-55341 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40775
diff
changeset
|
191 def user_exception(self, frame, exc_info): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
192 """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
|
193 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
|
194 pass |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
195 |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
196 def _set_stopinfo(self, stopframe, returnframe, stoplineno=0): |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
197 self.stopframe = stopframe |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
198 self.returnframe = returnframe |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
199 self.quitting = False |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
200 # stoplineno >= 0 means: stop at line >= the stoplineno |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
201 # stoplineno -1 means: don't stop at all |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
202 self.stoplineno = stoplineno |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
203 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
204 # 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
|
205 # to affect the stepping state. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
206 |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
207 def set_until(self, frame, lineno=None): |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
208 """Stop when the line with the line no greater than the current one is |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
209 reached or when returning from current frame""" |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
210 # the name "until" is borrowed from gdb |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
211 if lineno is None: |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
212 lineno = frame.f_lineno + 1 |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
213 self._set_stopinfo(frame, frame, lineno) |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
214 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
215 def set_step(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
216 """Stop after one line of code.""" |
|
76676
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
217 # Issue #13183: pdb skips frames after hitting a breakpoint and running |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
218 # step commands. |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
219 # Restore the trace function in the caller (that may not have been set |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
220 # for performance reasons) when returning from the current frame. |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
221 if self.frame_returning: |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
222 caller_frame = self.frame_returning.f_back |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
223 if caller_frame and not caller_frame.f_trace: |
|
96cb47f8142e
issue13183 - Fix pdb skipping frames after hitting a breakpoint and running step. Patch by Xavier de Gaye
Senthil Kumaran <senthil@uthcode.com>
parents:
68257
diff
changeset
|
224 caller_frame.f_trace = self.trace_dispatch |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
225 self._set_stopinfo(None, None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
226 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
227 def set_next(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
228 """Stop on the next line in or below the given frame.""" |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46217
diff
changeset
|
229 self._set_stopinfo(frame, 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 def set_return(self, frame): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
232 """Stop when returning from the given frame.""" |
|
87318
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
233 if frame.f_code.co_flags & CO_GENERATOR: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
234 self._set_stopinfo(frame, None, -1) |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
235 else: |
|
95eea8624d05
Better behavior when stepping over yield[from]. Fixes issue 16596. By Xavier de Gaye.
Guido van Rossum <guido@dropbox.com>
parents:
76676
diff
changeset
|
236 self._set_stopinfo(frame.f_back, frame) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
237 |
|
33924
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
238 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
|
239 """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
|
240 |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
241 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
|
242 """ |
|
662c155106e4
Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents:
33823
diff
changeset
|
243 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
|
244 frame = sys._getframe().f_back |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
245 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
246 while frame: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
247 frame.f_trace = self.trace_dispatch |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
248 self.botframe = frame |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
249 frame = frame.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
250 self.set_step() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
251 sys.settrace(self.trace_dispatch) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
252 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
253 def set_continue(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
254 # Don't stop except at breakpoints or when finished |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
255 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
|
256 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
257 # no breakpoints; run without debugger overhead |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
258 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
|
259 frame = sys._getframe().f_back |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
260 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
|
261 del frame.f_trace |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
262 frame = frame.f_back |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
263 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
264 def set_quit(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
265 self.stopframe = self.botframe |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
266 self.returnframe = None |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
267 self.quitting = True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
268 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
269 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
270 # 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
|
271 # to manipulate breakpoints. These methods return an |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
272 # 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
|
273 # 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
|
274 # 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
|
275 # for bp in Breakpoint.bpbynumber: if bp: bp.bpprint(). |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
276 |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
277 def set_break(self, filename, lineno, temporary=False, cond=None, |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
278 funcname=None): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
279 filename = self.canonic(filename) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
280 import linecache # Import as late as possible |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
281 line = linecache.getline(filename, lineno) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
282 if not line: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
283 return 'Line %s:%d does not exist' % (filename, lineno) |
|
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
284 list = self.breaks.setdefault(filename, []) |
|
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
285 if lineno not in list: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
286 list.append(lineno) |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
287 bp = Breakpoint(filename, lineno, temporary, cond, funcname) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
288 |
|
66535
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
289 def _prune_breaks(self, filename, lineno): |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
290 if (filename, lineno) not in Breakpoint.bplist: |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
291 self.breaks[filename].remove(lineno) |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
292 if not self.breaks[filename]: |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
293 del self.breaks[filename] |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
294 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
295 def clear_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
296 filename = self.canonic(filename) |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
297 if filename not in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
298 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
|
299 if lineno not in self.breaks[filename]: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
300 return 'There is no breakpoint at %s:%d' % (filename, lineno) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
301 # 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
|
302 # pair, then remove the breaks entry |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
303 for bp in Breakpoint.bplist[filename, lineno][:]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
304 bp.deleteMe() |
|
66535
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
305 self._prune_breaks(filename, lineno) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
306 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
307 def clear_bpbynumber(self, arg): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
308 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
309 bp = self.get_bpbynumber(arg) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
310 except ValueError as err: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
311 return str(err) |
|
66535
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
312 bp.deleteMe() |
|
2e0d9009ab6b
Merged revisions 86861 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
63453
diff
changeset
|
313 self._prune_breaks(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
|
314 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
315 def clear_all_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
316 filename = self.canonic(filename) |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
317 if filename not in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
318 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
|
319 for line in self.breaks[filename]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
320 blist = Breakpoint.bplist[filename, line] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
321 for bp in blist: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
322 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
323 del self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
324 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
325 def clear_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
326 if not self.breaks: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
327 return 'There are no breakpoints' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
328 for bp in Breakpoint.bpbynumber: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
329 if bp: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
330 bp.deleteMe() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
331 self.breaks = {} |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
332 |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
333 def get_bpbynumber(self, arg): |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
334 if not arg: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
335 raise ValueError('Breakpoint number expected') |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
336 try: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
337 number = int(arg) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
338 except ValueError: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
339 raise ValueError('Non-numeric breakpoint number %s' % arg) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
340 try: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
341 bp = Breakpoint.bpbynumber[number] |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
342 except IndexError: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
343 raise ValueError('Breakpoint number %d out of range' % number) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
344 if bp is None: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
345 raise ValueError('Breakpoint %d already deleted' % number) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
346 return bp |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
347 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
348 def get_break(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
349 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
350 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
351 lineno in self.breaks[filename] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
352 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
353 def get_breaks(self, filename, lineno): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
354 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
355 return filename in self.breaks and \ |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
356 lineno in self.breaks[filename] and \ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
357 Breakpoint.bplist[filename, lineno] or [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
358 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
359 def get_file_breaks(self, filename): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
360 filename = self.canonic(filename) |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
361 if filename in self.breaks: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
362 return self.breaks[filename] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
363 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
364 return [] |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
365 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
366 def get_all_breaks(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
367 return self.breaks |
|
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 # 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
|
370 # to get a data structure representing a stack trace. |
|
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 get_stack(self, f, t): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
373 stack = [] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
374 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
|
375 t = t.tb_next |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
376 while f is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
377 stack.append((f, f.f_lineno)) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
378 if f is self.botframe: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
379 break |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
380 f = f.f_back |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
381 stack.reverse() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
382 i = max(0, len(stack) - 1) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
383 while t is not None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
384 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
|
385 t = t.tb_next |
|
49587
f66688e69f66
Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47088
diff
changeset
|
386 if f is None: |
|
f66688e69f66
Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47088
diff
changeset
|
387 i = max(0, len(stack) - 1) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
388 return stack, i |
|
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 format_stack_entry(self, frame_lineno, lprefix=': '): |
|
47088
4f1a079df427
Rename the repr module to reprlib.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
47067
diff
changeset
|
391 import linecache, reprlib |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
392 frame, lineno = frame_lineno |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
393 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
|
394 s = '%s(%r)' % (filename, lineno) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
395 if frame.f_code.co_name: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
396 s += frame.f_code.co_name |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
397 else: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
398 s += "<lambda>" |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
399 if '__args__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
400 args = frame.f_locals['__args__'] |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
401 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
402 args = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
403 if args: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
404 s += reprlib.repr(args) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
405 else: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
406 s += '()' |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23557
diff
changeset
|
407 if '__return__' in frame.f_locals: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
408 rv = frame.f_locals['__return__'] |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
409 s += '->' |
|
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
410 s += reprlib.repr(rv) |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49587
diff
changeset
|
411 line = linecache.getline(filename, lineno, frame.f_globals) |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
412 if line: |
|
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
413 s += lprefix + line.strip() |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
414 return s |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
415 |
|
63310
c5bfe1860a5d
#1472251: remove addition of "\n" to code given to pdb.run[eval](), the bug in exec() that made this necessary has been fixed. Also document that you can give code objects to run() and runeval(), and add some tests to test_pdb.
Georg Brandl <georg@python.org>
parents:
63307
diff
changeset
|
416 # The following methods can be called by clients to use |
|
c5bfe1860a5d
#1472251: remove addition of "\n" to code given to pdb.run[eval](), the bug in exec() that made this necessary has been fixed. Also document that you can give code objects to run() and runeval(), and add some tests to test_pdb.
Georg Brandl <georg@python.org>
parents:
63307
diff
changeset
|
417 # a debugger to debug a statement or an expression. |
|
c5bfe1860a5d
#1472251: remove addition of "\n" to code given to pdb.run[eval](), the bug in exec() that made this necessary has been fixed. Also document that you can give code objects to run() and runeval(), and add some tests to test_pdb.
Georg Brandl <georg@python.org>
parents:
63307
diff
changeset
|
418 # Both can be given as a string, or a code object. |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
419 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
420 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
|
421 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
422 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
423 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
424 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
425 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
426 self.reset() |
|
67394
92f2d7d28fee
Issue #10492: bdb.Bdb.run() only traces the execution of the code
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66714
diff
changeset
|
427 if isinstance(cmd, str): |
|
92f2d7d28fee
Issue #10492: bdb.Bdb.run() only traces the execution of the code
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66714
diff
changeset
|
428 cmd = compile(cmd, "<string>", "exec") |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
429 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
430 try: |
|
46217
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
431 exec(cmd, globals, locals) |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
432 except BdbQuit: |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
433 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
434 finally: |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
435 self.quitting = True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
436 sys.settrace(None) |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
437 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
438 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
|
439 if globals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
440 import __main__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
441 globals = __main__.__dict__ |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
442 if locals is None: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
443 locals = globals |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
444 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
445 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
446 try: |
|
46217
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
447 return eval(expr, globals, locals) |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
448 except BdbQuit: |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
449 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
450 finally: |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
451 self.quitting = True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
452 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
|
453 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
454 def runctx(self, cmd, globals, locals): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
455 # B/W compatibility |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
456 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
|
457 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
458 # 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
|
459 |
|
33823
db8710f13650
SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents:
33334
diff
changeset
|
460 def runcall(self, func, *args, **kwds): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
461 self.reset() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
462 sys.settrace(self.trace_dispatch) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
463 res = None |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
464 try: |
|
46217
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
465 res = func(*args, **kwds) |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
466 except BdbQuit: |
|
6042914e8286
Merged revisions 62018 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
43020
diff
changeset
|
467 pass |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
468 finally: |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
469 self.quitting = True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
470 sys.settrace(None) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
471 return res |
| 622 | 472 |
| 473 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
474 def set_trace(): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
475 Bdb().set_trace() |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
476 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
477 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
478 class Breakpoint: |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
479 """Breakpoint class. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
480 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
481 Implements temporary breakpoints, ignore counts, disabling and |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
482 (re)-enabling, and conditionals. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
483 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 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
|
488 breakpoint per line. |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
489 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
490 """ |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
491 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
492 # 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
|
493 # 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
|
494 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
495 next = 1 # Next bp to be assigned |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
496 bplist = {} # indexed by (file, lineno) tuple |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
497 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
|
498 # 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
|
499 # effective break .... see effective() |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
500 |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
501 def __init__(self, file, line, temporary=False, cond=None, funcname=None): |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
502 self.funcname = funcname |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
503 # 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
|
504 self.func_first_executable_line = None |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
505 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
|
506 self.line = line |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
507 self.temporary = temporary |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
508 self.cond = cond |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
509 self.enabled = True |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
510 self.ignore = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
511 self.hits = 0 |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
512 self.number = Breakpoint.next |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
513 Breakpoint.next += 1 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
514 # Build the two lists |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
515 self.bpbynumber.append(self) |
|
39575
63237fcefd99
Get rid of dict.has_key(). Boy this has a lot of repercussions!
Guido van Rossum <guido@python.org>
parents:
38147
diff
changeset
|
516 if (file, line) in self.bplist: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
517 self.bplist[file, line].append(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
518 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
519 self.bplist[file, line] = [self] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
520 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
521 def deleteMe(self): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
522 index = (self.file, self.line) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
523 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
|
524 self.bplist[index].remove(self) |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
525 if not self.bplist[index]: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
526 # 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
|
527 del self.bplist[index] |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
528 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
529 def enable(self): |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
530 self.enabled = True |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
531 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
532 def disable(self): |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66542
diff
changeset
|
533 self.enabled = False |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
534 |
|
38147
7fe49dbcbbda
Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents:
37734
diff
changeset
|
535 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
|
536 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
|
537 out = sys.stdout |
|
63326
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
538 print(self.bpformat(), file=out) |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
539 |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
540 def bpformat(self): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
541 if self.temporary: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
542 disp = 'del ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
543 else: |
|
15860
083a5c75ed90
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
11691
diff
changeset
|
544 disp = 'keep ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
545 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
|
546 disp = disp + 'yes ' |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
547 else: |
|
37734
4c6d4698a115
Patch #1191700: Adjust column alignment in bdb breakpoint lists.
Martin v. Löwis <martin@v.loewis.de>
parents:
33924
diff
changeset
|
548 disp = disp + 'no ' |
|
63326
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
549 ret = '%-4dbreakpoint %s at %s:%d' % (self.number, disp, |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
550 self.file, self.line) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
551 if self.cond: |
|
63326
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
552 ret += '\n\tstop only if %s' % (self.cond,) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
553 if self.ignore: |
|
63326
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
554 ret += '\n\tignore next %d hits' % (self.ignore,) |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
555 if self.hits: |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
556 if self.hits > 1: |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
557 ss = 's' |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
558 else: |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
559 ss = '' |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
560 ret += '\n\tbreakpoint already hit %d time%s' % (self.hits, ss) |
|
934b090dfec8
Add Breakpoint.bpformat(), which returns the info usually printed by bpprint(). Necessary for major refactoring of pdb output handling.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
561 return ret |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
562 |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
563 def __str__(self): |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63316
diff
changeset
|
564 return 'breakpoint %s at %s:%s' % (self.number, self.file, self.line) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
565 |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
566 # -----------end of Breakpoint class---------- |
|
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
567 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
568 def checkfuncname(b, frame): |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
569 """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
|
570 if not b.funcname: |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
571 # 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
|
572 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
|
573 # 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
|
574 # 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
|
575 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
576 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
577 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
578 # 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
|
579 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
580 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
|
581 # 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
|
582 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
583 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
584 # 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
|
585 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
|
586 # 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
|
587 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
|
588 |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
589 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
|
590 # 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
|
591 return False |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
592 return True |
|
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
593 |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
594 # 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
|
595 # 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
|
596 def effective(file, line, frame): |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
597 """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
|
598 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
603 """ |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
604 possibles = Breakpoint.bplist[file, line] |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
605 for b in possibles: |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
606 if not b.enabled: |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
607 continue |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
31796
diff
changeset
|
608 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
|
609 continue |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
610 # Count every hit when bp is enabled |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
611 b.hits += 1 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
612 if not b.cond: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
613 # If unconditional, and ignoring go on to next, else break |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
614 if b.ignore > 0: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
615 b.ignore -= 1 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
616 continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
617 else: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
618 # breakpoint and marker that it's ok to delete if temporary |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
619 return (b, True) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
620 else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
621 # Conditional bp. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
622 # 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
|
623 # condition evaluates to true. |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
624 try: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
625 val = eval(b.cond, frame.f_globals, frame.f_locals) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
626 if val: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
627 if b.ignore > 0: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
628 b.ignore -= 1 |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
629 # continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
630 else: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
631 return (b, True) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
632 # else: |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
633 # continue |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
634 except: |
|
66486
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
635 # if eval fails, most conservative thing is to stop on |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
636 # breakpoint regardless of ignore count. Don't delete |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
637 # temporary, as another hint to user. |
|
46feaec729bd
Modernize code in effective().
Georg Brandl <georg@python.org>
parents:
63326
diff
changeset
|
638 return (b, False) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
639 return (None, None) |
|
9090
26f5bfd715a4
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
6347
diff
changeset
|
640 |
|
66542
e89aa9147624
Code style cleanup in bdb.
Georg Brandl <georg@python.org>
parents:
66534
diff
changeset
|
641 |
| 622 | 642 # -------------------- testing -------------------- |
| 643 | |
| 644 class Tdb(Bdb): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
645 def user_call(self, frame, args): |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
646 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
647 if not name: name = '???' |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
648 print('+++ call', name, args) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
649 def user_line(self, frame): |
|
16479
d59663d3e433
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16070
diff
changeset
|
650 import linecache |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
651 name = frame.f_code.co_name |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
652 if not name: name = '???' |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
653 fn = self.canonic(frame.f_code.co_filename) |
|
50164
252927a2f32d
Merged revisions 67753 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49587
diff
changeset
|
654 line = linecache.getline(fn, frame.f_lineno, frame.f_globals) |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
655 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
|
656 def user_return(self, frame, retval): |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
657 print('+++ return', retval) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
658 def user_exception(self, frame, exc_stuff): |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
659 print('+++ exception', exc_stuff) |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
660 self.set_continue() |
| 622 | 661 |
| 662 def foo(n): | |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
663 print('foo(', n, ')') |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
664 x = bar(n*10) |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
665 print('bar returned', x) |
| 622 | 666 |
| 667 def bar(a): | |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
39782
diff
changeset
|
668 print('bar(', a, ')') |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
669 return a/2 |
| 622 | 670 |
| 671 def test(): | |
|
11691
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
672 t = Tdb() |
|
e34991022571
Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents:
11668
diff
changeset
|
673 t.run('import bdb; bdb.foo(10)') |
