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