annotate Lib/pdb.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 f7dd5178f36a
children d234dd21374a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4573
73758db2f464 /usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents: 4262
diff changeset
1 #! /usr/bin/env python
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
2
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 11706
diff changeset
3 """A Python debugger."""
583
c72f26ac491b Added to-do list.
Guido van Rossum <guido@python.org>
parents: 575
diff changeset
4
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
5 # (See pdb.doc for documentation.)
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 import sys
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 import linecache
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
9 import cmd
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
10 import bdb
25195
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
11 from repr import Repr
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
12 import os
11269
2e087539da60 Pdb.lineinfo(): Don't use os.popen('egrep ...') to find the line in
Barry Warsaw <barry@python.org>
parents: 10824
diff changeset
13 import re
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
14 import pprint
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
15 import traceback
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
16
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
17
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
18 class Restart(Exception):
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
19 """Causes a debugger to be restarted for the debugged python program."""
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
20 pass
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
21
25195
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
22 # Create a custom safe Repr instance and increase its maxstring.
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
23 # The default of 30 truncates error messages too easily.
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
24 _repr = Repr()
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
25 _repr.maxstring = 200
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
26 _saferepr = _repr.repr
4b32be661778 At Jim Fulton's request, increase the maxstring value of _saferepr to
Guido van Rossum <guido@python.org>
parents: 25003
diff changeset
27
16474
4d406c26c16e a few more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 16068
diff changeset
28 __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace",
4d406c26c16e a few more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 16068
diff changeset
29 "post_mortem", "help"]
4d406c26c16e a few more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 16068
diff changeset
30
11269
2e087539da60 Pdb.lineinfo(): Don't use os.popen('egrep ...') to find the line in
Barry Warsaw <barry@python.org>
parents: 10824
diff changeset
31 def find_function(funcname, filename):
39767
7c5e29362803 [Bug #1526834] Fix crash in pdb when you do 'b f(';
Andrew M. Kuchling <amk@amk.ca>
parents: 39208
diff changeset
32 cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname))
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
33 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
34 fp = open(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
35 except IOError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
36 return None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
37 # consumer of this info expects the first line to be 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
38 lineno = 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
39 answer = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
40 while 1:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
41 line = fp.readline()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
42 if line == '':
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
43 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
44 if cre.match(line):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
45 answer = funcname, filename, lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
46 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
47 lineno = lineno + 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
48 fp.close()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
49 return answer
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
1999
c5a514f8f3e3 improved prompt format
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
52 # Interaction prompt line will separate file and call info from code
c5a514f8f3e3 improved prompt format
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
53 # text using value of line_prefix string. A newline and arrow may
c5a514f8f3e3 improved prompt format
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
54 # be to your liking. You can set it once pdb is imported using the
c5a514f8f3e3 improved prompt format
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
55 # command "pdb.line_prefix = '\n% '".
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
56 # line_prefix = ': ' # Use this to get the old situation back
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
57 line_prefix = '\n-> ' # Probably a better default
1999
c5a514f8f3e3 improved prompt format
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
58
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
59 class Pdb(bdb.Bdb, cmd.Cmd):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
60
53776
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents: 52736
diff changeset
61 def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None):
c49bc330327c #5142: add module skipping feature to pdb.
Georg Brandl <georg@python.org>
parents: 52736
diff changeset
62 bdb.Bdb.__init__(self, skip=skip)
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
63 cmd.Cmd.__init__(self, completekey, stdin, stdout)
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
64 if stdout:
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
65 self.use_rawinput = 0
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
66 self.prompt = '(Pdb) '
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
67 self.aliases = {}
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
68 self.mainpyfile = ''
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
69 self._wait_for_mainpyfile = 0
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
70 # Try to load readline if it exists
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
71 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
72 import readline
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
73 except ImportError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
74 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
75
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
76 # Read $HOME/.pdbrc and ./.pdbrc
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
77 self.rcLines = []
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23036
diff changeset
78 if 'HOME' in os.environ:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
79 envHome = os.environ['HOME']
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
80 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
81 rcFile = open(os.path.join(envHome, ".pdbrc"))
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
82 except IOError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
83 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
84 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
85 for line in rcFile.readlines():
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
86 self.rcLines.append(line)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
87 rcFile.close()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
88 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
89 rcFile = open(".pdbrc")
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
90 except IOError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
91 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
92 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
93 for line in rcFile.readlines():
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
94 self.rcLines.append(line)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
95 rcFile.close()
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
96
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
97 self.commands = {} # associates a command list to breakpoint numbers
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
98 self.commands_doprompt = {} # for each bp num, tells if the prompt
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
99 # must be disp. after execing the cmd list
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
100 self.commands_silent = {} # for each bp num, tells if the stack trace
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
101 # must be disp. after execing the cmd list
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
102 self.commands_defining = False # True while in the process of defining
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
103 # a command list
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
104 self.commands_bnum = None # The breakpoint number for which we are
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
105 # defining a list
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
106
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
107 def reset(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
108 bdb.Bdb.reset(self)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
109 self.forget()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
110
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
111 def forget(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
112 self.lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
113 self.stack = []
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
114 self.curindex = 0
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
115 self.curframe = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
116
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
117 def setup(self, f, t):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
118 self.forget()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
119 self.stack, self.curindex = self.get_stack(f, t)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
120 self.curframe = self.stack[self.curindex][0]
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
121 # The f_locals dictionary is updated from the actual frame
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
122 # locals whenever the .f_locals accessor is called, so we
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
123 # cache it here to ensure that modifications are not overwritten.
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
124 self.curframe_locals = self.curframe.f_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
125 self.execRcLines()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
126
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
127 # Can be executed earlier than 'setup' if desired
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
128 def execRcLines(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
129 if self.rcLines:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
130 # Make local copy because of recursion
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
131 rcLines = self.rcLines
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
132 # executed only once
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
133 self.rcLines = []
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
134 for line in rcLines:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
135 line = line[:-1]
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
136 if len(line) > 0 and line[0] != '#':
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
137 self.onecmd(line)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
138
25003
c744144c4049 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 24844
diff changeset
139 # Override Bdb methods
24844
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24213
diff changeset
140
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24213
diff changeset
141 def user_call(self, frame, argument_list):
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24213
diff changeset
142 """This method is called when there is the remote possibility
cf5928fab108 This is my patch
Michael W. Hudson <mwh@python.net>
parents: 24213
diff changeset
143 that we ever need to stop in this function."""
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
144 if self._wait_for_mainpyfile:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
145 return
27556
24e34abc6295 I believe this fixes
Michael W. Hudson <mwh@python.net>
parents: 27236
diff changeset
146 if self.stop_here(frame):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
147 print >>self.stdout, '--Call--'
27556
24e34abc6295 I believe this fixes
Michael W. Hudson <mwh@python.net>
parents: 27236
diff changeset
148 self.interaction(frame, None)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
149
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
150 def user_line(self, frame):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
151 """This function is called when we stop or break at this line."""
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
152 if self._wait_for_mainpyfile:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
153 if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
154 or frame.f_lineno<= 0):
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
155 return
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
156 self._wait_for_mainpyfile = 0
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
157 if self.bp_commands(frame):
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
158 self.interaction(frame, None)
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
159
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
160 def bp_commands(self,frame):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
161 """Call every command that was set for the current active breakpoint
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
162 (if there is one).
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
163
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
164 Returns True if the normal interaction function must be called,
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
165 False otherwise."""
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
166 # self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
167 if getattr(self, "currentbp", False) and \
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
168 self.currentbp in self.commands:
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
169 currentbp = self.currentbp
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
170 self.currentbp = 0
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
171 lastcmd_back = self.lastcmd
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
172 self.setup(frame, None)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
173 for line in self.commands[currentbp]:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
174 self.onecmd(line)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
175 self.lastcmd = lastcmd_back
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
176 if not self.commands_silent[currentbp]:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
177 self.print_stack_entry(self.stack[self.curindex])
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
178 if self.commands_doprompt[currentbp]:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
179 self.cmdloop()
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
180 self.forget()
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
181 return
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
182 return 1
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
183
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
184 def user_return(self, frame, return_value):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
185 """This function is called when a return trap is set here."""
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
186 if self._wait_for_mainpyfile:
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
187 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
188 frame.f_locals['__return__'] = return_value
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
189 print >>self.stdout, '--Return--'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
190 self.interaction(frame, None)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
191
48120
0d2d26ffe20e Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents: 47221
diff changeset
192 def user_exception(self, frame, exc_info):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
193 """This function is called if an exception occurs,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
194 but only if we are to stop at or just below this level."""
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
195 if self._wait_for_mainpyfile:
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
196 return
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
197 exc_type, exc_value, exc_traceback = exc_info
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
198 frame.f_locals['__exception__'] = exc_type, exc_value
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
199 if type(exc_type) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
200 exc_type_name = exc_type
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
201 else: exc_type_name = exc_type.__name__
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
202 print >>self.stdout, exc_type_name + ':', _saferepr(exc_value)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
203 self.interaction(frame, exc_traceback)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
204
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
205 # General interaction function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
206
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
207 def interaction(self, frame, traceback):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
208 self.setup(frame, traceback)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
209 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
210 self.cmdloop()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
211 self.forget()
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
212
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
213 def displayhook(self, obj):
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
214 """Custom displayhook for the exec in default(), which prevents
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
215 assignment of the _ variable in the builtins.
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
216 """
56830
97d7cd365dd5 Merged revisions 73206,73232,73299,73683,74020,74185,74544,74643,74647,74817,74838-74839,74865,74946,75402,75459,75604,75696 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52900
diff changeset
217 # reproduce the behavior of the standard displayhook, not printing None
97d7cd365dd5 Merged revisions 73206,73232,73299,73683,74020,74185,74544,74643,74647,74817,74838-74839,74865,74946,75402,75459,75604,75696 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52900
diff changeset
218 if obj is not None:
97d7cd365dd5 Merged revisions 73206,73232,73299,73683,74020,74185,74544,74643,74647,74817,74838-74839,74865,74946,75402,75459,75604,75696 via svnmerge from
Georg Brandl <georg@python.org>
parents: 52900
diff changeset
219 print repr(obj)
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
220
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
221 def default(self, line):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
222 if line[:1] == '!': line = line[1:]
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
223 locals = self.curframe_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
224 globals = self.curframe.f_globals
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
225 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
226 code = compile(line + '\n', '<stdin>', 'single')
44698
f302cf999633 test_doctest fails since r59984.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44694
diff changeset
227 save_stdout = sys.stdout
f302cf999633 test_doctest fails since r59984.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44694
diff changeset
228 save_stdin = sys.stdin
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
229 save_displayhook = sys.displayhook
44694
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
230 try:
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
231 sys.stdin = self.stdin
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
232 sys.stdout = self.stdout
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
233 sys.displayhook = self.displayhook
44694
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
234 exec code in globals, locals
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
235 finally:
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
236 sys.stdout = save_stdout
28c81c27389e Issue #1786 (by myself): pdb should use its own stdin/stdout around an
Guido van Rossum <guido@python.org>
parents: 41532
diff changeset
237 sys.stdin = save_stdin
52900
4acbbb3e65e2 Merged revisions 70866-70868,70870-70871,70893,70896,70902,70905,70907,70912,70915,70927,70933,70940,70944,70954,70963,70998,71056 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50162
diff changeset
238 sys.displayhook = save_displayhook
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
239 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
240 t, v = sys.exc_info()[:2]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
241 if type(t) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
242 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
243 else: exc_type_name = t.__name__
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
244 print >>self.stdout, '***', exc_type_name + ':', v
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
245
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
246 def precmd(self, line):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
247 """Handle alias expansion and ';;' separator."""
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
248 if not line.strip():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
249 return line
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
250 args = line.split()
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23036
diff changeset
251 while args[0] in self.aliases:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
252 line = self.aliases[args[0]]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
253 ii = 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
254 for tmpArg in args[1:]:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
255 line = line.replace("%" + str(ii),
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
256 tmpArg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
257 ii = ii + 1
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
258 line = line.replace("%*", ' '.join(args[1:]))
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
259 args = line.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
260 # split into ';;' separated commands
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
261 # unless it's an alias command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
262 if args[0] != 'alias':
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
263 marker = line.find(';;')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
264 if marker >= 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
265 # queue up everything after marker
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
266 next = line[marker+2:].lstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
267 self.cmdqueue.append(next)
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
268 line = line[:marker].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
269 return line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
270
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
271 def onecmd(self, line):
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
272 """Interpret the argument as though it had been typed in response
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
273 to the prompt.
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
274
39205
8ca3068ea343 Reformat docstring; fix typo
Andrew M. Kuchling <amk@amk.ca>
parents: 38147
diff changeset
275 Checks whether this line is typed at the normal prompt or in
39208
c18a6694a066 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 39205
diff changeset
276 a breakpoint command list definition.
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
277 """
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
278 if not self.commands_defining:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
279 return cmd.Cmd.onecmd(self, line)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
280 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
281 return self.handle_command_def(line)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
282
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
283 def handle_command_def(self,line):
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
284 """Handles one command line during command list definition."""
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
285 cmd, arg, line = self.parseline(line)
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
286 if not cmd:
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
287 return
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
288 if cmd == 'silent':
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
289 self.commands_silent[self.commands_bnum] = True
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
290 return # continue to handle other cmd def in the cmd list
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
291 elif cmd == 'end':
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
292 self.cmdqueue = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
293 return 1 # end of cmd list
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
294 cmdlist = self.commands[self.commands_bnum]
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
295 if arg:
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
296 cmdlist.append(cmd+' '+arg)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
297 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
298 cmdlist.append(cmd)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
299 # Determine if we must stop
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
300 try:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
301 func = getattr(self, 'do_' + cmd)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
302 except AttributeError:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
303 func = self.default
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
304 # one of the resuming commands
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
305 if func.func_name in self.commands_resuming:
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
306 self.commands_doprompt[self.commands_bnum] = False
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
307 self.cmdqueue = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
308 return 1
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
309 return
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
310
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
311 # Command definitions, called by cmdloop()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
312 # The argument is the remaining string on the command line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
313 # Return true to exit from the command loop
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
314
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
315 do_h = cmd.Cmd.do_help
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
316
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
317 def do_commands(self, arg):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
318 """Defines a list of commands associated to a breakpoint.
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
319
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
320 Those commands will be executed whenever the breakpoint causes
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
321 the program to stop execution."""
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
322 if not arg:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
323 bnum = len(bdb.Breakpoint.bpbynumber)-1
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
324 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
325 try:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
326 bnum = int(arg)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
327 except:
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
328 print >>self.stdout, "Usage : commands [bnum]\n ..." \
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
329 "\n end"
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
330 return
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
331 self.commands_bnum = bnum
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
332 self.commands[bnum] = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
333 self.commands_doprompt[bnum] = True
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
334 self.commands_silent[bnum] = False
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
335 prompt_back = self.prompt
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
336 self.prompt = '(com) '
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
337 self.commands_defining = True
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
338 try:
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
339 self.cmdloop()
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
340 finally:
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
341 self.commands_defining = False
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
342 self.prompt = prompt_back
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
343
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
344 def do_break(self, arg, temporary = 0):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
345 # break [ ([filename:]lineno | function) [, "condition"] ]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
346 if not arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
347 if self.breaks: # There's at least one
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
348 print >>self.stdout, "Num Type Disp Enb Where"
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
349 for bp in bdb.Breakpoint.bpbynumber:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
350 if bp:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
351 bp.bpprint(self.stdout)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
352 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
353 # parse arguments; comma has lowest precedence
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
354 # and cannot occur in filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
355 filename = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
356 lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
357 cond = None
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
358 comma = arg.find(',')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
359 if comma > 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
360 # parse stuff after comma: "condition"
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
361 cond = arg[comma+1:].lstrip()
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
362 arg = arg[:comma].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
363 # parse stuff before comma: [filename:]lineno | function
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
364 colon = arg.rfind(':')
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
365 funcname = None
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
366 if colon >= 0:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
367 filename = arg[:colon].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
368 f = self.lookupmodule(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
369 if not f:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
370 print >>self.stdout, '*** ', repr(filename),
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
371 print >>self.stdout, 'not found from sys.path'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
372 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
373 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
374 filename = f
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
375 arg = arg[colon+1:].lstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
376 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
377 lineno = int(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
378 except ValueError, msg:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
379 print >>self.stdout, '*** Bad lineno:', arg
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
380 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
381 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
382 # no colon; can be lineno or function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
383 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
384 lineno = int(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
385 except ValueError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
386 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
387 func = eval(arg,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
388 self.curframe.f_globals,
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
389 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
390 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
391 func = arg
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
392 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
393 if hasattr(func, 'im_func'):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
394 func = func.im_func
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
395 code = func.func_code
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
396 #use co_name to identify the bkpt (function names
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
397 #could be aliased, but co_name is invariant)
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
398 funcname = code.co_name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
399 lineno = code.co_firstlineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
400 filename = code.co_filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
401 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
402 # last thing to try
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
403 (ok, filename, ln) = self.lineinfo(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
404 if not ok:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
405 print >>self.stdout, '*** The specified object',
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
406 print >>self.stdout, repr(arg),
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
407 print >>self.stdout, 'is not a function'
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
408 print >>self.stdout, 'or was not found along sys.path.'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
409 return
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
410 funcname = ok # ok contains a function name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
411 lineno = int(ln)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
412 if not filename:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
413 filename = self.defaultFile()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
414 # Check for reasonable breakpoint
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
415 line = self.checkline(filename, lineno)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
416 if line:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
417 # now set the break point
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
418 err = self.set_break(filename, line, temporary, cond, funcname)
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
419 if err: print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
420 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
421 bp = self.get_breaks(filename, line)[-1]
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
422 print >>self.stdout, "Breakpoint %d at %s:%d" % (bp.number,
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
423 bp.file,
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
424 bp.line)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
425
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
426 # To be overridden in derived debuggers
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
427 def defaultFile(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
428 """Produce a reasonable default."""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
429 filename = self.curframe.f_code.co_filename
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
430 if filename == '<string>' and self.mainpyfile:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
431 filename = self.mainpyfile
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
432 return filename
5767
03a57af72218 Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
433
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
434 do_b = do_break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
435
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
436 def do_tbreak(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
437 self.do_break(arg, 1)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
438
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
439 def lineinfo(self, identifier):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
440 failed = (None, None, None)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
441 # Input is identifier, may be in single quotes
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
442 idstring = identifier.split("'")
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
443 if len(idstring) == 1:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
444 # not in single quotes
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
445 id = idstring[0].strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
446 elif len(idstring) == 3:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
447 # quoted
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
448 id = idstring[1].strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
449 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
450 return failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
451 if id == '': return failed
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
452 parts = id.split('.')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
453 # Protection for derived debuggers
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
454 if parts[0] == 'self':
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
455 del parts[0]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
456 if len(parts) == 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
457 return failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
458 # Best first guess at file to look at
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
459 fname = self.defaultFile()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
460 if len(parts) == 1:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
461 item = parts[0]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
462 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
463 # More than one part.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
464 # First is module, second is method/class
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
465 f = self.lookupmodule(parts[0])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
466 if f:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
467 fname = f
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
468 item = parts[1]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
469 answer = find_function(item, fname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
470 return answer or failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
471
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
472 def checkline(self, filename, lineno):
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
473 """Check whether specified line seems to be executable.
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
474
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
475 Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
476 line or EOF). Warning: testing is not comprehensive.
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
477 """
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
478 # this method should be callable before starting debugging, so default
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
479 # to "no globals" if there is no current frame
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
480 globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
481 line = linecache.getline(filename, lineno, globs)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
482 if not line:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
483 print >>self.stdout, 'End of file'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
484 return 0
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
485 line = line.strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
486 # Don't allow setting breakpoint at a blank line
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
487 if (not line or (line[0] == '#') or
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
488 (line[:3] == '"""') or line[:3] == "'''"):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
489 print >>self.stdout, '*** Blank or comment'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
490 return 0
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
491 return lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
492
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
493 def do_enable(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
494 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
495 for i in args:
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
496 try:
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
497 i = int(i)
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
498 except ValueError:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
499 print >>self.stdout, 'Breakpoint index %r is not a number' % i
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
500 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
501
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
502 if not (0 <= i < len(bdb.Breakpoint.bpbynumber)):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
503 print >>self.stdout, 'No breakpoint numbered', i
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
504 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
505
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
506 bp = bdb.Breakpoint.bpbynumber[i]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
507 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
508 bp.enable()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
509
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
510 def do_disable(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
511 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
512 for i in args:
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
513 try:
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
514 i = int(i)
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
515 except ValueError:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
516 print >>self.stdout, 'Breakpoint index %r is not a number' % i
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
517 continue
29488
5143cfe7cc75 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 29208
diff changeset
518
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
519 if not (0 <= i < len(bdb.Breakpoint.bpbynumber)):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
520 print >>self.stdout, 'No breakpoint numbered', i
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
521 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
522
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
523 bp = bdb.Breakpoint.bpbynumber[i]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
524 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
525 bp.disable()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
526
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
527 def do_condition(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
528 # arg is breakpoint number and condition
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
529 args = arg.split(' ', 1)
40697
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
530 try:
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
531 bpnum = int(args[0].strip())
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
532 except ValueError:
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
533 # something went wrong
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
534 print >>self.stdout, \
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
535 'Breakpoint index %r is not a number' % args[0]
41109
c9b40b0aa303 Add missing "return" statements in exception handler.
Georg Brandl <georg@python.org>
parents: 40697
diff changeset
536 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
537 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
538 cond = args[1]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
539 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
540 cond = None
41113
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
541 try:
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
542 bp = bdb.Breakpoint.bpbynumber[bpnum]
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
543 except IndexError:
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
544 print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
545 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
546 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
547 bp.cond = cond
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
548 if not cond:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
549 print >>self.stdout, 'Breakpoint', bpnum,
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
550 print >>self.stdout, 'is now unconditional.'
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
551
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
552 def do_ignore(self,arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
553 """arg is bp number followed by ignore count."""
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
554 args = arg.split()
40697
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
555 try:
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
556 bpnum = int(args[0].strip())
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
557 except ValueError:
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
558 # something went wrong
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
559 print >>self.stdout, \
29b8b65bae3f Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39208
diff changeset
560 'Breakpoint index %r is not a number' % args[0]
41109
c9b40b0aa303 Add missing "return" statements in exception handler.
Georg Brandl <georg@python.org>
parents: 40697
diff changeset
561 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
562 try:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
563 count = int(args[1].strip())
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
564 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
565 count = 0
41113
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
566 try:
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
567 bp = bdb.Breakpoint.bpbynumber[bpnum]
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
568 except IndexError:
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
569 print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
d7044465b743 Patch #1192590: Fix pdb's "ignore" and "condition" commands so they trap the IndexError caused by passing in an invalid breakpoint number.
Collin Winter <collinw@gmail.com>
parents: 41109
diff changeset
570 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
571 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
572 bp.ignore = count
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
573 if count > 0:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
574 reply = 'Will ignore next '
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
575 if count > 1:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
576 reply = reply + '%d crossings' % count
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
577 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
578 reply = reply + '1 crossing'
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
579 print >>self.stdout, reply + ' of breakpoint %d.' % bpnum
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
580 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
581 print >>self.stdout, 'Will stop next time breakpoint',
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
582 print >>self.stdout, bpnum, 'is reached.'
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
583
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
584 def do_clear(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
585 """Three possibilities, tried in this order:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
586 clear -> clear all breaks, ask for confirmation
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
587 clear file:lineno -> clear all breaks at file:lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
588 clear bpno bpno ... -> clear breakpoints by number"""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
589 if not arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
590 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
591 reply = raw_input('Clear all breaks? ')
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
592 except EOFError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
593 reply = 'no'
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
594 reply = reply.strip().lower()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
595 if reply in ('y', 'yes'):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
596 self.clear_all_breaks()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
597 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
598 if ':' in arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
599 # Make sure it works for "clear C:\foo\bar.py:12"
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
600 i = arg.rfind(':')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
601 filename = arg[:i]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
602 arg = arg[i+1:]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
603 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
604 lineno = int(arg)
38105
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
605 except ValueError:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
606 err = "Invalid line number (%s)" % arg
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
607 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
608 err = self.clear_break(filename, lineno)
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
609 if err: print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
610 return
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
611 numberlist = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
612 for i in numberlist:
38105
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
613 try:
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
614 i = int(i)
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
615 except ValueError:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
616 print >>self.stdout, 'Breakpoint index %r is not a number' % i
38105
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
617 continue
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
618
35414
156abda4e457 backport bug [ 1192315 ] 'clear -1' in pdb
Georg Brandl <georg@python.org>
parents: 33924
diff changeset
619 if not (0 <= i < len(bdb.Breakpoint.bpbynumber)):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
620 print >>self.stdout, 'No breakpoint numbered', i
35414
156abda4e457 backport bug [ 1192315 ] 'clear -1' in pdb
Georg Brandl <georg@python.org>
parents: 33924
diff changeset
621 continue
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
622 err = self.clear_bpbynumber(i)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
623 if err:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
624 print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
625 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
626 print >>self.stdout, 'Deleted breakpoint', i
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
627 do_cl = do_clear # 'c' is already an abbreviation for 'continue'
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
628
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
629 def do_where(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
630 self.print_stack_trace()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
631 do_w = do_where
16068
4db664389415 I've been using gdb a lot lately -- I'm missing 'bt' as a command in
Guido van Rossum <guido@python.org>
parents: 15870
diff changeset
632 do_bt = do_where
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
633
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
634 def do_up(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
635 if self.curindex == 0:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
636 print >>self.stdout, '*** Oldest frame'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
637 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
638 self.curindex = self.curindex - 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
639 self.curframe = self.stack[self.curindex][0]
52706
35c3e1d7cfdf Fix test_doctest, missed two assignments to curframe.
Georg Brandl <georg@python.org>
parents: 52693
diff changeset
640 self.curframe_locals = self.curframe.f_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
641 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
642 self.lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
643 do_u = do_up
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
644
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
645 def do_down(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
646 if self.curindex + 1 == len(self.stack):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
647 print >>self.stdout, '*** Newest frame'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
648 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
649 self.curindex = self.curindex + 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
650 self.curframe = self.stack[self.curindex][0]
52706
35c3e1d7cfdf Fix test_doctest, missed two assignments to curframe.
Georg Brandl <georg@python.org>
parents: 52693
diff changeset
651 self.curframe_locals = self.curframe.f_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
652 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
653 self.lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
654 do_d = do_down
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
655
46882
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
656 def do_until(self, arg):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
657 self.set_until(self.curframe)
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
658 return 1
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
659 do_unt = do_until
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
660
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
661 def do_step(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
662 self.set_step()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
663 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
664 do_s = do_step
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
665
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
666 def do_next(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
667 self.set_next(self.curframe)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
668 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
669 do_n = do_next
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
670
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
671 def do_run(self, arg):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
672 """Restart program by raising an exception to be caught in the main
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
673 debugger loop. If arguments were given, set them in sys.argv."""
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
674 if arg:
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
675 import shlex
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
676 argv0 = sys.argv[0:1]
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
677 sys.argv = shlex.split(arg)
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
678 sys.argv[:0] = argv0
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
679 raise Restart
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
680
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
681 do_restart = do_run
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
682
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
683 def do_return(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
684 self.set_return(self.curframe)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
685 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
686 do_r = do_return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
687
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
688 def do_continue(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
689 self.set_continue()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
690 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
691 do_c = do_cont = do_continue
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
692
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
693 def do_jump(self, arg):
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
694 if self.curindex + 1 != len(self.stack):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
695 print >>self.stdout, "*** You can only jump within the bottom frame"
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
696 return
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
697 try:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
698 arg = int(arg)
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
699 except ValueError:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
700 print >>self.stdout, "*** The 'jump' command requires a line number."
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
701 else:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
702 try:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
703 # Do the jump, fix up our copy of the stack, and display the
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
704 # new position
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
705 self.curframe.f_lineno = arg
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
706 self.stack[self.curindex] = self.stack[self.curindex][0], arg
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
707 self.print_stack_entry(self.stack[self.curindex])
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
708 except ValueError, e:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
709 print >>self.stdout, '*** Jump failed:', e
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
710 do_j = do_jump
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
711
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
712 def do_debug(self, arg):
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
713 sys.settrace(None)
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
714 globals = self.curframe.f_globals
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
715 locals = self.curframe_locals
45312
18c76af4f364 In the recursive debug command, pass Pdb arguments (completekey, stdin, stdout)
Guido van Rossum <guido@python.org>
parents: 43832
diff changeset
716 p = Pdb(self.completekey, self.stdin, self.stdout)
28561
21f7cff1790f Detabified.
Guido van Rossum <guido@python.org>
parents: 28556
diff changeset
717 p.prompt = "(%s) " % self.prompt.strip()
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
718 print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
28561
21f7cff1790f Detabified.
Guido van Rossum <guido@python.org>
parents: 28556
diff changeset
719 sys.call_tracing(p.run, (arg, globals, locals))
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
720 print >>self.stdout, "LEAVING RECURSIVE DEBUGGER"
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
721 sys.settrace(self.trace_dispatch)
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
722 self.lastcmd = p.lastcmd
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
723
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
724 def do_quit(self, arg):
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
725 self._user_requested_quit = 1
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
726 self.set_quit()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
727 return 1
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
728
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
729 do_q = do_quit
23036
8f645180534d Add exit as alias for quit, as the easiest way to address SF bug
Guido van Rossum <guido@python.org>
parents: 16545
diff changeset
730 do_exit = do_quit
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
731
27236
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
732 def do_EOF(self, arg):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
733 print >>self.stdout
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
734 self._user_requested_quit = 1
27236
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
735 self.set_quit()
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
736 return 1
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
737
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
738 def do_args(self, arg):
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
739 co = self.curframe.f_code
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
740 dict = self.curframe_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
741 n = co.co_argcount
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
742 if co.co_flags & 4: n = n+1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
743 if co.co_flags & 8: n = n+1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
744 for i in range(n):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
745 name = co.co_varnames[i]
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
746 print >>self.stdout, name, '=',
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
747 if name in dict: print >>self.stdout, dict[name]
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
748 else: print >>self.stdout, "*** undefined ***"
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
749 do_a = do_args
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
750
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
751 def do_retval(self, arg):
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
752 if '__return__' in self.curframe_locals:
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
753 print >>self.stdout, self.curframe_locals['__return__']
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
754 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
755 print >>self.stdout, '*** Not yet returned!'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
756 do_rv = do_retval
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
757
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
758 def _getval(self, arg):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
759 try:
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
760 return eval(arg, self.curframe.f_globals,
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
761 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
762 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
763 t, v = sys.exc_info()[:2]
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
764 if isinstance(t, str):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
765 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
766 else: exc_type_name = t.__name__
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
767 print >>self.stdout, '***', exc_type_name + ':', repr(v)
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
768 raise
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
769
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
770 def do_p(self, arg):
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
771 try:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
772 print >>self.stdout, repr(self._getval(arg))
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
773 except:
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
774 pass
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
775
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
776 def do_pp(self, arg):
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
777 try:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
778 pprint.pprint(self._getval(arg), self.stdout)
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
779 except:
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
780 pass
1331
07900834cc97 * pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents: 1317
diff changeset
781
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
782 def do_list(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
783 self.lastcmd = 'list'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
784 last = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
785 if arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
786 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
787 x = eval(arg, {}, {})
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
788 if type(x) == type(()):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
789 first, last = x
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
790 first = int(first)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
791 last = int(last)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
792 if last < first:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
793 # Assume it's a count
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
794 last = first + last
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
795 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
796 first = max(1, int(x) - 5)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
797 except:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
798 print >>self.stdout, '*** Error in argument:', repr(arg)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
799 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
800 elif self.lineno is None:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
801 first = max(1, self.curframe.f_lineno - 5)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
802 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
803 first = self.lineno + 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
804 if last is None:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
805 last = first + 10
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
806 filename = self.curframe.f_code.co_filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
807 breaklist = self.get_file_breaks(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
808 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
809 for lineno in range(first, last+1):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
810 line = linecache.getline(filename, lineno,
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
811 self.curframe.f_globals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
812 if not line:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
813 print >>self.stdout, '[EOF]'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
814 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
815 else:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29488
diff changeset
816 s = repr(lineno).rjust(3)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
817 if len(s) < 4: s = s + ' '
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
818 if lineno in breaklist: s = s + 'B'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
819 else: s = s + ' '
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
820 if lineno == self.curframe.f_lineno:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
821 s = s + '->'
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
822 print >>self.stdout, s + '\t' + line,
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
823 self.lineno = lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
824 except KeyboardInterrupt:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
825 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
826 do_l = do_list
1261
2c515f07367a Added whatis command (third try -- filesystem was full, rcs lock failed)
Guido van Rossum <guido@python.org>
parents: 1110
diff changeset
827
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
828 def do_whatis(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
829 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
830 value = eval(arg, self.curframe.f_globals,
52693
1b8d68dae572 Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Georg Brandl <georg@python.org>
parents: 52687
diff changeset
831 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
832 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
833 t, v = sys.exc_info()[:2]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
834 if type(t) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
835 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
836 else: exc_type_name = t.__name__
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
837 print >>self.stdout, '***', exc_type_name + ':', repr(v)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
838 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
839 code = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
840 # Is it a function?
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
841 try: code = value.func_code
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
842 except: pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
843 if code:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
844 print >>self.stdout, 'Function', code.co_name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
845 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
846 # Is it an instance method?
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
847 try: code = value.im_func.func_code
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
848 except: pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
849 if code:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
850 print >>self.stdout, 'Method', code.co_name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
851 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
852 # None of the above...
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
853 print >>self.stdout, type(value)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
854
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
855 def do_alias(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
856 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
857 if len(args) == 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
858 keys = self.aliases.keys()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
859 keys.sort()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
860 for alias in keys:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
861 print >>self.stdout, "%s = %s" % (alias, self.aliases[alias])
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
862 return
24213
0867da5e8548 Fix SF bug 579701 (Fernando Pérez); an input line consisting of one or
Guido van Rossum <guido@python.org>
parents: 23620
diff changeset
863 if args[0] in self.aliases and len(args) == 1:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
864 print >>self.stdout, "%s = %s" % (args[0], self.aliases[args[0]])
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
865 else:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
866 self.aliases[args[0]] = ' '.join(args[1:])
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
867
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
868 def do_unalias(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
869 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
870 if len(args) == 0: return
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23036
diff changeset
871 if args[0] in self.aliases:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
872 del self.aliases[args[0]]
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
873
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
874 #list of all the commands making the program resume execution.
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
875 commands_resuming = ['do_continue', 'do_step', 'do_next', 'do_return',
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
876 'do_quit', 'do_jump']
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
877
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
878 # Print a traceback starting at the top stack frame.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
879 # The most recently entered frame is printed last;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
880 # this is different from dbx and gdb, but consistent with
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
881 # the Python interpreter's stack trace.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
882 # It is also consistent with the up/down commands (which are
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
883 # compatible with dbx and gdb: up moves towards 'main()'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
884 # and down moves towards the most recent stack frame).
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
885
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
886 def print_stack_trace(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
887 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
888 for frame_lineno in self.stack:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
889 self.print_stack_entry(frame_lineno)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
890 except KeyboardInterrupt:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
891 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
892
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
893 def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
894 frame, lineno = frame_lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
895 if frame is self.curframe:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
896 print >>self.stdout, '>',
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
897 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
898 print >>self.stdout, ' ',
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
899 print >>self.stdout, self.format_stack_entry(frame_lineno,
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
900 prompt_prefix)
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
901
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
902
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
903 # Help methods (derived from pdb.doc)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
904
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
905 def help_help(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
906 self.help_h()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
907
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
908 def help_h(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
909 print >>self.stdout, """h(elp)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
910 Without argument, print the list of available commands.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
911 With a command name as argument, print help about that command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
912 "help pdb" pipes the full documentation file to the $PAGER
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
913 "help exec" gives help on the ! command"""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
914
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
915 def help_where(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
916 self.help_w()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
917
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
918 def help_w(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
919 print >>self.stdout, """w(here)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
920 Print a stack trace, with the most recent frame at the bottom.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
921 An arrow indicates the "current frame", which determines the
16068
4db664389415 I've been using gdb a lot lately -- I'm missing 'bt' as a command in
Guido van Rossum <guido@python.org>
parents: 15870
diff changeset
922 context of most commands. 'bt' is an alias for this command."""
4db664389415 I've been using gdb a lot lately -- I'm missing 'bt' as a command in
Guido van Rossum <guido@python.org>
parents: 15870
diff changeset
923
4db664389415 I've been using gdb a lot lately -- I'm missing 'bt' as a command in
Guido van Rossum <guido@python.org>
parents: 15870
diff changeset
924 help_bt = help_w
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
925
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
926 def help_down(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
927 self.help_d()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
928
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
929 def help_d(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
930 print >>self.stdout, """d(own)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
931 Move the current frame one level down in the stack trace
33130
8a282797895f bug #989672: pdb.doc and the help messages for the help_d and help_u methods
Johannes Gijsbers <jlg@dds.nl>
parents: 31515
diff changeset
932 (to a newer frame)."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
933
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
934 def help_up(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
935 self.help_u()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
936
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
937 def help_u(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
938 print >>self.stdout, """u(p)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
939 Move the current frame one level up in the stack trace
33130
8a282797895f bug #989672: pdb.doc and the help messages for the help_d and help_u methods
Johannes Gijsbers <jlg@dds.nl>
parents: 31515
diff changeset
940 (to an older frame)."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
941
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
942 def help_break(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
943 self.help_b()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
944
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
945 def help_b(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
946 print >>self.stdout, """b(reak) ([file:]lineno | function) [, condition]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
947 With a line number argument, set a break there in the current
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
948 file. With a function name, set a break at first executable line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
949 of that function. Without argument, list all breaks. If a second
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
950 argument is present, it is a string specifying an expression
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
951 which must evaluate to true before the breakpoint is honored.
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
952
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
953 The line number may be prefixed with a filename and a colon,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
954 to specify a breakpoint in another file (probably one that
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
955 hasn't been loaded yet). The file is searched for on sys.path;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
956 the .py suffix may be omitted."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
957
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
958 def help_clear(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
959 self.help_cl()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
960
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
961 def help_cl(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
962 print >>self.stdout, "cl(ear) filename:lineno"
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
963 print >>self.stdout, """cl(ear) [bpnumber [bpnumber...]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
964 With a space separated list of breakpoint numbers, clear
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
965 those breakpoints. Without argument, clear all breaks (but
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
966 first ask confirmation). With a filename:lineno argument,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
967 clear all breaks at that line in that file.
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
968
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
969 Note that the argument is different from previous versions of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
970 the debugger (in python distributions 1.5.1 and before) where
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
971 a linenumber was used instead of either filename:lineno or
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
972 breakpoint numbers."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
973
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
974 def help_tbreak(self):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
975 print >>self.stdout, """tbreak same arguments as break, but breakpoint
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
976 is removed when first hit."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
977
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
978 def help_enable(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
979 print >>self.stdout, """enable bpnumber [bpnumber ...]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
980 Enables the breakpoints given as a space separated list of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
981 bp numbers."""
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
982
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
983 def help_disable(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
984 print >>self.stdout, """disable bpnumber [bpnumber ...]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
985 Disables the breakpoints given as a space separated list of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
986 bp numbers."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
987
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
988 def help_ignore(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
989 print >>self.stdout, """ignore bpnumber count
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
990 Sets the ignore count for the given breakpoint number. A breakpoint
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
991 becomes active when the ignore count is zero. When non-zero, the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
992 count is decremented each time the breakpoint is reached and the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
993 breakpoint is not disabled and any associated condition evaluates
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
994 to true."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
995
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
996 def help_condition(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
997 print >>self.stdout, """condition bpnumber str_condition
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
998 str_condition is a string specifying an expression which
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
999 must evaluate to true before the breakpoint is honored.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1000 If str_condition is absent, any existing condition is removed;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1001 i.e., the breakpoint is made unconditional."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1002
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1003 def help_step(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1004 self.help_s()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1005
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1006 def help_s(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1007 print >>self.stdout, """s(tep)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1008 Execute the current line, stop at the first possible occasion
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1009 (either in a function that is called or in the current function)."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1010
46882
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1011 def help_until(self):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1012 self.help_unt()
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1013
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1014 def help_unt(self):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1015 print """unt(il)
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1016 Continue execution until the line with a number greater than the current
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1017 one is reached or until the current frame returns"""
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1018
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1019 def help_next(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1020 self.help_n()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1021
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1022 def help_n(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1023 print >>self.stdout, """n(ext)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1024 Continue execution until the next line in the current function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1025 is reached or it returns."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1026
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1027 def help_return(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1028 self.help_r()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1029
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1030 def help_r(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1031 print >>self.stdout, """r(eturn)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1032 Continue execution until the current function returns."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1033
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1034 def help_continue(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1035 self.help_c()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1036
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1037 def help_cont(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1038 self.help_c()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1039
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1040 def help_c(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1041 print >>self.stdout, """c(ont(inue))
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1042 Continue execution, only stop when a breakpoint is encountered."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1043
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1044 def help_jump(self):
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1045 self.help_j()
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1046
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1047 def help_j(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1048 print >>self.stdout, """j(ump) lineno
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1049 Set the next line that will be executed."""
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1050
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1051 def help_debug(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1052 print >>self.stdout, """debug code
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1053 Enter a recursive debugger that steps through the code argument
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1054 (which is an arbitrary expression or statement to be executed
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1055 in the current environment)."""
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1056
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1057 def help_list(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1058 self.help_l()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1059
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1060 def help_l(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1061 print >>self.stdout, """l(ist) [first [,last]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1062 List source code for the current file.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1063 Without arguments, list 11 lines around the current line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1064 or continue the previous listing.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1065 With one argument, list 11 lines starting at that line.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1066 With two arguments, list the given range;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1067 if the second argument is less than the first, it is a count."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1068
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1069 def help_args(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1070 self.help_a()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1071
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1072 def help_a(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1073 print >>self.stdout, """a(rgs)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1074 Print the arguments of the current function."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1075
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1076 def help_p(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1077 print >>self.stdout, """p expression
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1078 Print the value of the expression."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1079
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
1080 def help_pp(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1081 print >>self.stdout, """pp expression
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
1082 Pretty-print the value of the expression."""
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
1083
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1084 def help_exec(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1085 print >>self.stdout, """(!) statement
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1086 Execute the (one-line) statement in the context of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1087 the current stack frame.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1088 The exclamation point can be omitted unless the first word
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1089 of the statement resembles a debugger command.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1090 To assign to a global variable you must always prefix the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1091 command with a 'global' command, e.g.:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1092 (Pdb) global list_options; list_options = ['-l']
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1093 (Pdb)"""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1094
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1095 def help_run(self):
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1096 print """run [args...]
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1097 Restart the debugged python program. If a string is supplied, it is
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1098 splitted with "shlex" and the result is used as the new sys.argv.
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1099 History, breakpoints, actions and debugger options are preserved.
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1100 "restart" is an alias for "run"."""
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1101
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1102 help_restart = help_run
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1103
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1104 def help_quit(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1105 self.help_q()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1106
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1107 def help_q(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1108 print >>self.stdout, """q(uit) or exit - Quit from the debugger.
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1109 The program being executed is aborted."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1110
23036
8f645180534d Add exit as alias for quit, as the easiest way to address SF bug
Guido van Rossum <guido@python.org>
parents: 16545
diff changeset
1111 help_exit = help_q
8f645180534d Add exit as alias for quit, as the easiest way to address SF bug
Guido van Rossum <guido@python.org>
parents: 16545
diff changeset
1112
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1113 def help_whatis(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1114 print >>self.stdout, """whatis arg
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1115 Prints the type of the argument."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1116
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1117 def help_EOF(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1118 print >>self.stdout, """EOF
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1119 Handles the receipt of EOF as a command."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1120
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1121 def help_alias(self):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1122 print >>self.stdout, """alias [name [command [parameter parameter ...]]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1123 Creates an alias called 'name' the executes 'command'. The command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1124 must *not* be enclosed in quotes. Replaceable parameters are
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1125 indicated by %1, %2, and so on, while %* is replaced by all the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1126 parameters. If no command is given, the current alias for name
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1127 is shown. If no name is given, all aliases are listed.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1128
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1129 Aliases may be nested and can contain anything that can be
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1130 legally typed at the pdb prompt. Note! You *can* override
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1131 internal pdb commands with aliases! Those internal commands
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1132 are then hidden until the alias is removed. Aliasing is recursively
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1133 applied to the first word of the command line; all other words
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1134 in the line are left alone.
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1135
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1136 Some useful aliases (especially when placed in the .pdbrc file) are:
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1137
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1138 #Print instance variables (usage "pi classInst")
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1139 alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1140
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1141 #Print instance variables in self
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1142 alias ps pi self
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1143 """
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1144
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1145 def help_unalias(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1146 print >>self.stdout, """unalias name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1147 Deletes the specified alias."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1148
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1149 def help_commands(self):
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
1150 print >>self.stdout, """commands [bpnumber]
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1151 (com) ...
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1152 (com) end
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1153 (Pdb)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1154
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1155 Specify a list of commands for breakpoint number bpnumber. The
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1156 commands themselves appear on the following lines. Type a line
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1157 containing just 'end' to terminate the commands.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1158
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1159 To remove all commands from a breakpoint, type commands and
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1160 follow it immediately with end; that is, give no commands.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1161
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1162 With no bpnumber argument, commands refers to the last
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1163 breakpoint set.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1164
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1165 You can use breakpoint commands to start your program up again.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1166 Simply use the continue command, or step, or any other
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1167 command that resumes execution.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1168
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1169 Specifying any command resuming execution (currently continue,
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1170 step, next, return, jump, quit and their abbreviations) terminates
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1171 the command list (as if that command was immediately followed by end).
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1172 This is because any time you resume execution
37805
efe749225bae Remove bogus character.
Martin v. Löwis <martin@v.loewis.de>
parents: 37803
diff changeset
1173 (even with a simple next or step), you may encounter
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1174 another breakpoint--which could have its own command list, leading to
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1175 ambiguities about which list to execute.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1176
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1177 If you use the 'silent' command in the command list, the
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1178 usual message about stopping at a breakpoint is not printed. This may
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1179 be desirable for breakpoints that are to print a specific message and
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1180 then continue. If none of the other commands print anything, you
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1181 see no sign that the breakpoint was reached.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1182 """
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1183
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1184 def help_pdb(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1185 help()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1186
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1187 def lookupmodule(self, filename):
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1188 """Helper function for break/clear parsing -- may be overridden.
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1189
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1190 lookupmodule() translates (possibly incomplete) file or module name
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1191 into an absolute file name.
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1192 """
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1193 if os.path.isabs(filename) and os.path.exists(filename):
33731
53c468d0955b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33728
diff changeset
1194 return filename
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1195 f = os.path.join(sys.path[0], filename)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1196 if os.path.exists(f) and self.canonic(f) == self.mainpyfile:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1197 return f
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1198 root, ext = os.path.splitext(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1199 if ext == '':
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1200 filename = filename + '.py'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1201 if os.path.isabs(filename):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1202 return filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1203 for dirname in sys.path:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1204 while os.path.islink(dirname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1205 dirname = os.readlink(dirname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1206 fullname = os.path.join(dirname, filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1207 if os.path.exists(fullname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1208 return fullname
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1209 return None
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
1210
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1211 def _runscript(self, filename):
41173
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1212 # The script has to run in __main__ namespace (or imports from
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1213 # __main__ will break).
41532
4b9fa8092e82 Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents: 41173
diff changeset
1214 #
41173
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1215 # So we clear up the __main__ and set several special variables
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1216 # (this gets rid of pdb's globals and cleans old variables on restarts).
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1217 import __main__
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1218 __main__.__dict__.clear()
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1219 __main__.__dict__.update({"__name__" : "__main__",
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1220 "__file__" : filename,
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1221 "__builtins__": __builtins__,
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1222 })
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1223
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1224 # When bdb sets tracing, a number of call and line events happens
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1225 # BEFORE debugger even reaches user's code (and the exact sequence of
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1226 # events depends on python version). So we take special measures to
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1227 # avoid stopping before we reach the main script (see user_line and
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1228 # user_call for details).
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1229 self._wait_for_mainpyfile = 1
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1230 self.mainpyfile = self.canonic(filename)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1231 self._user_requested_quit = 0
73601
f7dd5178f36a PDB now will properly escape backslashes in the names of modules it executes. Fixes #7750
Jason R. Coombs <jaraco@jaraco.com>
parents: 68256
diff changeset
1232 statement = 'execfile(%r)' % filename
41532
4b9fa8092e82 Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents: 41173
diff changeset
1233 self.run(statement)
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1234
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1235 # Simplified interface
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1236
2437
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 2280
diff changeset
1237 def run(statement, globals=None, locals=None):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1238 Pdb().run(statement, globals, locals)
2437
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 2280
diff changeset
1239
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 2280
diff changeset
1240 def runeval(expression, globals=None, locals=None):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1241 return Pdb().runeval(expression, globals, locals)
600
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1242
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1243 def runctx(statement, globals, locals):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1244 # B/W compatibility
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1245 run(statement, globals, locals)
600
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1246
33823
db8710f13650 SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents: 33731
diff changeset
1247 def runcall(*args, **kwds):
db8710f13650 SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents: 33731
diff changeset
1248 return Pdb().runcall(*args, **kwds)
1006
903071377d29 Added a _v21 def to FL.py and added two new input field types
Guido van Rossum <guido@python.org>
parents: 649
diff changeset
1249
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1250 def set_trace():
33924
662c155106e4 Bug #1055168: calling pdb.set_trace() calls Bdb.set_trace, which made
Johannes Gijsbers <jlg@dds.nl>
parents: 33823
diff changeset
1251 Pdb().set_trace(sys._getframe().f_back)
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1252
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1253 # Post-Mortem interface
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1254
45716
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1255 def post_mortem(t=None):
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1256 # handling the default
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1257 if t is None:
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1258 # sys.exc_info() returns (type, value, traceback) if an exception is
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1259 # being handled, otherwise it returns None
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1260 t = sys.exc_info()[2]
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1261 if t is None:
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1262 raise ValueError("A valid traceback must be passed if no "
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1263 "exception is being handled")
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1264
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1265 p = Pdb()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1266 p.reset()
49572
c6c32842e71d Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48120
diff changeset
1267 p.interaction(None, t)
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1268
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1269 def pm():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1270 post_mortem(sys.last_traceback)
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1271
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1272
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1273 # Main program for testing
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1274
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
1275 TESTCMD = 'import x; x.main()'
600
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1276
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1277 def test():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1278 run(TESTCMD)
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1279
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1280 # print help
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1281 def help():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1282 for dirname in sys.path:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1283 fullname = os.path.join(dirname, 'pdb.doc')
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1284 if os.path.exists(fullname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1285 sts = os.system('${PAGER-more} '+fullname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1286 if sts: print '*** Pager exit status:', sts
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1287 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1288 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1289 print 'Sorry, can\'t find the help file "pdb.doc"',
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1290 print 'along the Python search path'
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
1291
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1292 def main():
46105
6ea41d5239e0 Added help options to PDB
Benjamin Peterson <benjamin@python.org>
parents: 45716
diff changeset
1293 if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1294 print "usage: pdb.py scriptfile [arg] ..."
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1295 sys.exit(2)
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
1296
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1297 mainpyfile = sys.argv[1] # Get script filename
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1298 if not os.path.exists(mainpyfile):
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1299 print 'Error:', mainpyfile, 'does not exist'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1300 sys.exit(1)
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1301
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1302 del sys.argv[0] # Hide "pdb.py" from argument list
4262
67d258edd3d9 Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents: 3822
diff changeset
1303
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1304 # Replace pdb's dir with script's dir in front of module search path.
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1305 sys.path[0] = os.path.dirname(mainpyfile)
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
1306
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1307 # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1308 # modified by the script being debugged. It's a bad idea when it was
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1309 # changed by the user from the command line. There is a "restart" command
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1310 # which allows explicit specification of command line arguments.
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1311 pdb = Pdb()
63509
5fd09e410d36 Merged revisions 83429,83436 via svnmerge from
Georg Brandl <georg@python.org>
parents: 56830
diff changeset
1312 while True:
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1313 try:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1314 pdb._runscript(mainpyfile)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1315 if pdb._user_requested_quit:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1316 break
33731
53c468d0955b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33728
diff changeset
1317 print "The program finished and will be restarted"
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1318 except Restart:
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1319 print "Restarting", mainpyfile, "with arguments:"
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1320 print "\t" + " ".join(sys.argv[1:])
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1321 except SystemExit:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1322 # In most cases SystemExit does not warrant a post-mortem session.
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1323 print "The program exited via sys.exit(). Exit status: ",
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1324 print sys.exc_info()[1]
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1325 except:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1326 traceback.print_exc()
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1327 print "Uncaught exception. Entering post mortem debugging"
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1328 print "Running 'cont' or 'step' will restart the program"
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1329 t = sys.exc_info()[2]
49572
c6c32842e71d Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48120
diff changeset
1330 pdb.interaction(None, t)
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1331 print "Post mortem debugger finished. The " + mainpyfile + \
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1332 " will be restarted"
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1333
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1334
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1335 # When invoked as main program, invoke the debugger on a script
41173
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1336 if __name__ == '__main__':
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1337 import pdb
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1338 pdb.main()