annotate Lib/pdb.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents 4c63670639ec
children 7a3ed1b43410
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
47221
9fbc41abdd4b Revert the renaming of repr to reprlib.
Brett Cannon <bcannon@gmail.com>
parents: 47085
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."""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
186 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
187 print >>self.stdout, '--Return--'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
188 self.interaction(frame, None)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
189
48120
0d2d26ffe20e Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents: 47221
diff changeset
190 def user_exception(self, frame, exc_info):
0d2d26ffe20e Remove use of tuple unpacking and dict.has_key() so as to silence
Brett Cannon <bcannon@gmail.com>
parents: 47221
diff changeset
191 exc_type, exc_value, exc_traceback = exc_info
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
192 """This function is called if an exception occurs,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
193 but only if we are to stop at or just below this level."""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
194 frame.f_locals['__exception__'] = exc_type, exc_value
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
195 if type(exc_type) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
196 exc_type_name = exc_type
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
197 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
198 print >>self.stdout, exc_type_name + ':', _saferepr(exc_value)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
199 self.interaction(frame, exc_traceback)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
200
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
201 # General interaction function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
202
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
203 def interaction(self, frame, traceback):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
204 self.setup(frame, traceback)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
205 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
206 self.cmdloop()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
207 self.forget()
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
208
52687
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
209 def displayhook(self, obj):
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
210 """Custom displayhook for the exec in default(), which prevents
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
211 assignment of the _ variable in the builtins.
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
212 """
52736
c801a67ce292 Actually the displayhook should print the repr.
Georg Brandl <georg@python.org>
parents: 52706
diff changeset
213 print repr(obj)
52687
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
214
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
215 def default(self, line):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
216 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
217 locals = self.curframe_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
218 globals = self.curframe.f_globals
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
219 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
220 code = compile(line + '\n', '<stdin>', 'single')
44698
f302cf999633 test_doctest fails since r59984.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44694
diff changeset
221 save_stdout = sys.stdout
f302cf999633 test_doctest fails since r59984.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 44694
diff changeset
222 save_stdin = sys.stdin
52687
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
223 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
224 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
225 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
226 sys.stdout = self.stdout
52687
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
227 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
228 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
229 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
230 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
231 sys.stdin = save_stdin
52687
e3a1969fdbe5 In Pdb, stop assigning values to __builtin__._ which interferes with the one commonly installed by gettext.
Georg Brandl <georg@python.org>
parents: 52683
diff changeset
232 sys.displayhook = save_displayhook
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
233 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
234 t, v = sys.exc_info()[:2]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
235 if type(t) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
236 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
237 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
238 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
239
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
240 def precmd(self, line):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
241 """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
242 if not line.strip():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
243 return line
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
244 args = line.split()
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23036
diff changeset
245 while args[0] in self.aliases:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
246 line = self.aliases[args[0]]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
247 ii = 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
248 for tmpArg in args[1:]:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
249 line = line.replace("%" + str(ii),
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
250 tmpArg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
251 ii = ii + 1
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
252 line = line.replace("%*", ' '.join(args[1:]))
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
253 args = line.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
254 # split into ';;' separated commands
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
255 # unless it's an alias command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
256 if args[0] != 'alias':
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
257 marker = line.find(';;')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
258 if marker >= 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
259 # queue up everything after marker
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
260 next = line[marker+2:].lstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
261 self.cmdqueue.append(next)
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
262 line = line[:marker].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
263 return line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
264
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
265 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
266 """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
267 to the prompt.
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
268
39205
8ca3068ea343 Reformat docstring; fix typo
Andrew M. Kuchling <amk@amk.ca>
parents: 38147
diff changeset
269 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
270 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
271 """
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
272 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
273 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
274 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
275 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
276
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
277 def handle_command_def(self,line):
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
278 """ Handles one command line during command list definition. """
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
279 cmd, arg, line = self.parseline(line)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
280 if cmd == 'silent':
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
281 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
282 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
283 elif cmd == 'end':
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
284 self.cmdqueue = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
285 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
286 cmdlist = self.commands[self.commands_bnum]
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
287 if (arg):
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
288 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
289 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
290 cmdlist.append(cmd)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
291 # 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
292 try:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
293 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
294 except AttributeError:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
295 func = self.default
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
296 # one of the resuming commands
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
297 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
298 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
299 self.cmdqueue = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
300 return 1
37806
df9ecacb0bf6 Reindent.
Martin v. Löwis <martin@v.loewis.de>
parents: 37805
diff changeset
301 return
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
302
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
303 # Command definitions, called by cmdloop()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
304 # The argument is the remaining string on the command line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
305 # Return true to exit from the command loop
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
306
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
307 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
308
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
309 def do_commands(self, arg):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
310 """Defines a list of commands associated to a breakpoint.
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
311
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
312 Those commands will be executed whenever the breakpoint causes
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
313 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
314 if not arg:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
315 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
316 else:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
317 try:
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
318 bnum = int(arg)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
319 except:
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
320 print >>self.stdout, "Usage : commands [bnum]\n ..." \
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
321 "\n end"
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
322 return
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
323 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
324 self.commands[bnum] = []
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
325 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
326 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
327 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
328 self.prompt = '(com) '
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
329 self.commands_defining = True
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
330 self.cmdloop()
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
331 self.commands_defining = False
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
332 self.prompt = prompt_back
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
333
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
334 def do_break(self, arg, temporary = 0):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
335 # break [ ([filename:]lineno | function) [, "condition"] ]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
336 if not arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
337 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
338 print >>self.stdout, "Num Type Disp Enb Where"
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
339 for bp in bdb.Breakpoint.bpbynumber:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
340 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
341 bp.bpprint(self.stdout)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
342 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
343 # parse arguments; comma has lowest precedence
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
344 # and cannot occur in filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
345 filename = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
346 lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
347 cond = None
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
348 comma = arg.find(',')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
349 if comma > 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
350 # parse stuff after comma: "condition"
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
351 cond = arg[comma+1:].lstrip()
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
352 arg = arg[:comma].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
353 # parse stuff before comma: [filename:]lineno | function
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
354 colon = arg.rfind(':')
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
355 funcname = None
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
356 if colon >= 0:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
357 filename = arg[:colon].rstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
358 f = self.lookupmodule(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
359 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
360 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
361 print >>self.stdout, 'not found from sys.path'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
362 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
363 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
364 filename = f
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
365 arg = arg[colon+1:].lstrip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
366 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
367 lineno = int(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
368 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
369 print >>self.stdout, '*** Bad lineno:', arg
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
370 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
371 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
372 # no colon; can be lineno or function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
373 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
374 lineno = int(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
375 except ValueError:
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 func = eval(arg,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
378 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
379 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
380 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
381 func = arg
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
382 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
383 if hasattr(func, 'im_func'):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
384 func = func.im_func
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
385 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
386 #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
387 #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
388 funcname = code.co_name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
389 lineno = code.co_firstlineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
390 filename = code.co_filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
391 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
392 # last thing to try
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
393 (ok, filename, ln) = self.lineinfo(arg)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
394 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
395 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
396 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
397 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
398 print >>self.stdout, 'or was not found along sys.path.'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
399 return
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
400 funcname = ok # ok contains a function name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
401 lineno = int(ln)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
402 if not filename:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
403 filename = self.defaultFile()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
404 # Check for reasonable breakpoint
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
405 line = self.checkline(filename, lineno)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
406 if line:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
407 # 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
408 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
409 if err: print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
410 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
411 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
412 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
413 bp.file,
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
414 bp.line)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
415
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
416 # To be overridden in derived debuggers
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
417 def defaultFile(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
418 """Produce a reasonable default."""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
419 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
420 if filename == '<string>' and self.mainpyfile:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
421 filename = self.mainpyfile
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
422 return filename
5767
03a57af72218 Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents: 4573
diff changeset
423
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
424 do_b = do_break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
425
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
426 def do_tbreak(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
427 self.do_break(arg, 1)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
428
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
429 def lineinfo(self, identifier):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
430 failed = (None, None, None)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
431 # Input is identifier, may be in single quotes
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
432 idstring = identifier.split("'")
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
433 if len(idstring) == 1:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
434 # not in single quotes
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
435 id = idstring[0].strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
436 elif len(idstring) == 3:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
437 # quoted
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
438 id = idstring[1].strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
439 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
440 return failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
441 if id == '': return failed
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
442 parts = id.split('.')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
443 # Protection for derived debuggers
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
444 if parts[0] == 'self':
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
445 del parts[0]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
446 if len(parts) == 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
447 return failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
448 # Best first guess at file to look at
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
449 fname = self.defaultFile()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
450 if len(parts) == 1:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
451 item = parts[0]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
452 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
453 # More than one part.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
454 # First is module, second is method/class
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
455 f = self.lookupmodule(parts[0])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
456 if f:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
457 fname = f
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
458 item = parts[1]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
459 answer = find_function(item, fname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
460 return answer or failed
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
461
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
462 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
463 """Check whether specified line seems to be executable.
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
464
33334
04245ef53949 Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents: 33130
diff changeset
465 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
466 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
467 """
50162
4264cf00a75c Merged revisions 67750-67751 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 49572
diff changeset
468 line = linecache.getline(filename, lineno, self.curframe.f_globals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
469 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
470 print >>self.stdout, 'End of file'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
471 return 0
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
472 line = line.strip()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
473 # 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
474 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
475 (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
476 print >>self.stdout, '*** Blank or comment'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
477 return 0
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
478 return lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
479
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
480 def do_enable(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
481 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
482 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
483 try:
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
484 i = int(i)
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
485 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
486 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
487 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
488
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
489 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
490 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
491 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
492
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
493 bp = bdb.Breakpoint.bpbynumber[i]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
494 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
495 bp.enable()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
496
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
497 def do_disable(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
498 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
499 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
500 try:
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
501 i = int(i)
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
502 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
503 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
504 continue
29488
5143cfe7cc75 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 29208
diff changeset
505
29208
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
506 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
507 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
508 continue
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
509
ff9ba3d1e280 [Bug #741171] pdb crashes when enabling a non-existing breakpoint
Andrew M. Kuchling <amk@amk.ca>
parents: 28561
diff changeset
510 bp = bdb.Breakpoint.bpbynumber[i]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
511 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
512 bp.disable()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
513
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
514 def do_condition(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
515 # arg is breakpoint number and condition
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
516 args = arg.split(' ', 1)
40696
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
517 try:
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
518 bpnum = int(args[0].strip())
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
519 except ValueError:
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
520 # something went wrong
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
521 print >>self.stdout, \
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
522 'Breakpoint index %r is not a number' % args[0]
41108
f118aadc1120 Add missing "return" statements in exception handler.
Georg Brandl <georg@python.org>
parents: 40696
diff changeset
523 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
524 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
525 cond = args[1]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
526 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
527 cond = None
41111
5ab7dc8e731a 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: 41108
diff changeset
528 try:
5ab7dc8e731a 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: 41108
diff changeset
529 bp = bdb.Breakpoint.bpbynumber[bpnum]
5ab7dc8e731a 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: 41108
diff changeset
530 except IndexError:
5ab7dc8e731a 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: 41108
diff changeset
531 print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
5ab7dc8e731a 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: 41108
diff changeset
532 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
533 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
534 bp.cond = cond
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
535 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
536 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
537 print >>self.stdout, 'is now unconditional.'
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
538
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
539 def do_ignore(self,arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
540 """arg is bp number followed by ignore count."""
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
541 args = arg.split()
40696
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
542 try:
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
543 bpnum = int(args[0].strip())
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
544 except ValueError:
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
545 # something went wrong
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
546 print >>self.stdout, \
081ca6080ff1 Bug #1627316: handle error in condition/ignore pdb commands more gracefully.
Georg Brandl <georg@python.org>
parents: 39767
diff changeset
547 'Breakpoint index %r is not a number' % args[0]
41108
f118aadc1120 Add missing "return" statements in exception handler.
Georg Brandl <georg@python.org>
parents: 40696
diff changeset
548 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
549 try:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
550 count = int(args[1].strip())
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
551 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
552 count = 0
41111
5ab7dc8e731a 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: 41108
diff changeset
553 try:
5ab7dc8e731a 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: 41108
diff changeset
554 bp = bdb.Breakpoint.bpbynumber[bpnum]
5ab7dc8e731a 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: 41108
diff changeset
555 except IndexError:
5ab7dc8e731a 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: 41108
diff changeset
556 print >>self.stdout, 'Breakpoint index %r is not valid' % args[0]
5ab7dc8e731a 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: 41108
diff changeset
557 return
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
558 if bp:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
559 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
560 if count > 0:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
561 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
562 if count > 1:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
563 reply = reply + '%d crossings' % count
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
564 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
565 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
566 print >>self.stdout, reply + ' of breakpoint %d.' % bpnum
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
567 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
568 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
569 print >>self.stdout, bpnum, 'is reached.'
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
570
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
571 def do_clear(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
572 """Three possibilities, tried in this order:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
573 clear -> clear all breaks, ask for confirmation
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
574 clear file:lineno -> clear all breaks at file:lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
575 clear bpno bpno ... -> clear breakpoints by number"""
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
576 if not arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
577 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
578 reply = raw_input('Clear all breaks? ')
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
579 except EOFError:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
580 reply = 'no'
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
581 reply = reply.strip().lower()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
582 if reply in ('y', 'yes'):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
583 self.clear_all_breaks()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
584 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
585 if ':' in arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
586 # 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
587 i = arg.rfind(':')
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
588 filename = arg[:i]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
589 arg = arg[i+1:]
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 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
592 except ValueError:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
593 err = "Invalid line number (%s)" % arg
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
594 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
595 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
596 if err: print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
597 return
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
598 numberlist = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
599 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
600 try:
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
601 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
602 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
603 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
604 continue
8c383ef78198 Bug #1472191: convert breakpoint indices to ints before comparing them to ints
Georg Brandl <georg@python.org>
parents: 37806
diff changeset
605
35414
156abda4e457 backport bug [ 1192315 ] 'clear -1' in pdb
Georg Brandl <georg@python.org>
parents: 33924
diff changeset
606 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
607 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
608 continue
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
609 err = self.clear_bpbynumber(i)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
610 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
611 print >>self.stdout, '***', err
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
612 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
613 print >>self.stdout, 'Deleted breakpoint', i
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
614 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
615
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
616 def do_where(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
617 self.print_stack_trace()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
618 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
619 do_bt = do_where
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
620
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
621 def do_up(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
622 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
623 print >>self.stdout, '*** Oldest frame'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
624 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
625 self.curindex = self.curindex - 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
626 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
627 self.curframe_locals = self.curframe.f_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
628 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
629 self.lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
630 do_u = do_up
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
631
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
632 def do_down(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
633 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
634 print >>self.stdout, '*** Newest frame'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
635 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
636 self.curindex = self.curindex + 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
637 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
638 self.curframe_locals = self.curframe.f_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
639 self.print_stack_entry(self.stack[self.curindex])
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
640 self.lineno = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
641 do_d = do_down
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
642
46882
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
643 def do_until(self, arg):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
644 self.set_until(self.curframe)
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
645 return 1
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
646 do_unt = do_until
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
647
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
648 def do_step(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
649 self.set_step()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
650 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
651 do_s = do_step
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
652
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
653 def do_next(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
654 self.set_next(self.curframe)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
655 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
656 do_n = do_next
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
657
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
658 def do_run(self, arg):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
659 """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
660 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
661 if arg:
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
662 import shlex
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
663 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
664 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
665 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
666 raise Restart
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
667
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
668 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
669
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
670 def do_return(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
671 self.set_return(self.curframe)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
672 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
673 do_r = do_return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
674
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
675 def do_continue(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
676 self.set_continue()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
677 return 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
678 do_c = do_cont = do_continue
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
679
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
680 def do_jump(self, arg):
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
681 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
682 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
683 return
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
684 try:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
685 arg = int(arg)
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
686 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
687 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
688 else:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
689 try:
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
690 # 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
691 # new position
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
692 self.curframe.f_lineno = arg
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
693 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
694 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
695 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
696 print >>self.stdout, '*** Jump failed:', e
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
697 do_j = do_jump
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
698
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
699 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
700 sys.settrace(None)
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
701 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
702 locals = self.curframe_locals
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
703 p = Pdb(self.completekey, self.stdin, self.stdout)
28561
21f7cff1790f Detabified.
Guido van Rossum <guido@python.org>
parents: 28556
diff changeset
704 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
705 print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
28561
21f7cff1790f Detabified.
Guido van Rossum <guido@python.org>
parents: 28556
diff changeset
706 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
707 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
708 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
709 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
710
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
711 def do_quit(self, arg):
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
712 self._user_requested_quit = 1
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
713 self.set_quit()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
714 return 1
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
715
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
716 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
717 do_exit = do_quit
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
718
27236
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
719 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
720 print >>self.stdout
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
721 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
722 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
723 return 1
3ede90d6e1cf Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents: 26686
diff changeset
724
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
725 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
726 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
727 dict = self.curframe_locals
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
728 n = co.co_argcount
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
729 if co.co_flags & 4: n = n+1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
730 if co.co_flags & 8: n = n+1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
731 for i in range(n):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
732 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
733 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
734 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
735 else: print >>self.stdout, "*** undefined ***"
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
736 do_a = do_args
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
737
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
738 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
739 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
740 print >>self.stdout, self.curframe_locals['__return__']
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
741 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
742 print >>self.stdout, '*** Not yet returned!'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
743 do_rv = do_retval
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
744
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
745 def _getval(self, arg):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
746 try:
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
747 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
748 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
749 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
750 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
751 if isinstance(t, str):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
752 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
753 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
754 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
755 raise
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
756
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
757 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
758 try:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
759 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
760 except:
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
761 pass
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
762
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
763 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
764 try:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
765 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
766 except:
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
767 pass
1331
07900834cc97 * pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents: 1317
diff changeset
768
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
769 def do_list(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
770 self.lastcmd = 'list'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
771 last = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
772 if arg:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
773 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
774 x = eval(arg, {}, {})
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
775 if type(x) == type(()):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
776 first, last = x
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
777 first = int(first)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
778 last = int(last)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
779 if last < first:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
780 # Assume it's a count
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
781 last = first + last
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
782 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
783 first = max(1, int(x) - 5)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
784 except:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
785 print >>self.stdout, '*** Error in argument:', repr(arg)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
786 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
787 elif self.lineno is None:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
788 first = max(1, self.curframe.f_lineno - 5)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
789 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
790 first = self.lineno + 1
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
791 if last is None:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
792 last = first + 10
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
793 filename = self.curframe.f_code.co_filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
794 breaklist = self.get_file_breaks(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
795 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
796 for lineno in range(first, last+1):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
797 line = linecache.getline(filename, lineno,
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
798 self.curframe.f_globals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
799 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
800 print >>self.stdout, '[EOF]'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
801 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
802 else:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 29488
diff changeset
803 s = repr(lineno).rjust(3)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
804 if len(s) < 4: s = s + ' '
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
805 if lineno in breaklist: s = s + 'B'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
806 else: s = s + ' '
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
807 if lineno == self.curframe.f_lineno:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
808 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
809 print >>self.stdout, s + '\t' + line,
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
810 self.lineno = lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
811 except KeyboardInterrupt:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
812 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
813 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
814
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
815 def do_whatis(self, arg):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
816 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
817 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
818 self.curframe_locals)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
819 except:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
820 t, v = sys.exc_info()[:2]
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
821 if type(t) == type(''):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
822 exc_type_name = t
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
823 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
824 print >>self.stdout, '***', exc_type_name + ':', repr(v)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
825 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
826 code = None
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
827 # Is it a function?
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
828 try: code = value.func_code
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
829 except: pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
830 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
831 print >>self.stdout, 'Function', code.co_name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
832 return
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
833 # Is it an instance method?
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
834 try: code = value.im_func.func_code
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
835 except: pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
836 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
837 print >>self.stdout, 'Method', code.co_name
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 # 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
840 print >>self.stdout, type(value)
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
841
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
842 def do_alias(self, arg):
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
843 args = arg.split()
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
844 if len(args) == 0:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
845 keys = self.aliases.keys()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
846 keys.sort()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
847 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
848 print >>self.stdout, "%s = %s" % (alias, self.aliases[alias])
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
849 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
850 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
851 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
852 else:
16491
a4c6e401ee18 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 16474
diff changeset
853 self.aliases[args[0]] = ' '.join(args[1:])
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_unalias(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: return
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23036
diff changeset
858 if args[0] in self.aliases:
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
859 del self.aliases[args[0]]
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
860
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
861 #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
862 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
863 '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
864
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
865 # Print a traceback starting at the top stack frame.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
866 # The most recently entered frame is printed last;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
867 # this is different from dbx and gdb, but consistent with
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
868 # the Python interpreter's stack trace.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
869 # It is also consistent with the up/down commands (which are
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
870 # compatible with dbx and gdb: up moves towards 'main()'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
871 # and down moves towards the most recent stack frame).
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
872
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
873 def print_stack_trace(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
874 try:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
875 for frame_lineno in self.stack:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
876 self.print_stack_entry(frame_lineno)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
877 except KeyboardInterrupt:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
878 pass
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
879
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
880 def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
881 frame, lineno = frame_lineno
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
882 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
883 print >>self.stdout, '>',
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
884 else:
38147
7fe49dbcbbda Patch #721464: pdb.Pdb instances can now be given explicit stdin and
Georg Brandl <georg@python.org>
parents: 38105
diff changeset
885 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
886 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
887 prompt_prefix)
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
888
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
889
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
890 # 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
891
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
892 def help_help(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
893 self.help_h()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
894
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
895 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
896 print >>self.stdout, """h(elp)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
897 Without argument, print the list of available commands.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
898 With a command name as argument, print help about that command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
899 "help pdb" pipes the full documentation file to the $PAGER
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
900 "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
901
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
902 def help_where(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
903 self.help_w()
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_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
906 print >>self.stdout, """w(here)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
907 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
908 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
909 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
910
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
911 help_bt = help_w
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
912
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
913 def help_down(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
914 self.help_d()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
915
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
916 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
917 print >>self.stdout, """d(own)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
918 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
919 (to a newer frame)."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
920
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
921 def help_up(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
922 self.help_u()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
923
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
924 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
925 print >>self.stdout, """u(p)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
926 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
927 (to an older frame)."""
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_break(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
930 self.help_b()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
931
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
932 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
933 print >>self.stdout, """b(reak) ([file:]lineno | function) [, condition]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
934 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
935 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
936 of that function. Without argument, list all breaks. If a second
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
937 argument is present, it is a string specifying an expression
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
938 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
939
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
940 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
941 to specify a breakpoint in another file (probably one that
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
942 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
943 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
944
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
945 def help_clear(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
946 self.help_cl()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
947
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
948 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
949 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
950 print >>self.stdout, """cl(ear) [bpnumber [bpnumber...]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
951 With a space separated list of breakpoint numbers, clear
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
952 those breakpoints. Without argument, clear all breaks (but
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
953 first ask confirmation). With a filename:lineno argument,
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
954 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
955
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
956 Note that the argument is different from previous versions of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
957 the debugger (in python distributions 1.5.1 and before) where
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
958 a linenumber was used instead of either filename:lineno or
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
959 breakpoint numbers."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
960
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
961 def help_tbreak(self):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
962 print >>self.stdout, """tbreak same arguments as break, but breakpoint
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
963 is removed when first hit."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
964
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
965 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
966 print >>self.stdout, """enable bpnumber [bpnumber ...]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
967 Enables the breakpoints given as a space separated list of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
968 bp numbers."""
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
969
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
970 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
971 print >>self.stdout, """disable bpnumber [bpnumber ...]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
972 Disables the breakpoints given as a space separated list of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
973 bp numbers."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
974
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
975 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
976 print >>self.stdout, """ignore bpnumber count
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
977 Sets the ignore count for the given breakpoint number. A breakpoint
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
978 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
979 count is decremented each time the breakpoint is reached and the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
980 breakpoint is not disabled and any associated condition evaluates
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
981 to true."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
982
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
983 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
984 print >>self.stdout, """condition bpnumber str_condition
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
985 str_condition is a string specifying an expression which
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
986 must evaluate to true before the breakpoint is honored.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
987 If str_condition is absent, any existing condition is removed;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
988 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
989
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
990 def help_step(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
991 self.help_s()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
992
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
993 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
994 print >>self.stdout, """s(tep)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
995 Execute the current line, stop at the first possible occasion
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
996 (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
997
46882
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
998 def help_until(self):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
999 self.help_unt()
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1000
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1001 def help_unt(self):
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1002 print """unt(il)
a73e87f15ffa Add the "until" command to pdb
Benjamin Peterson <benjamin@python.org>
parents: 46105
diff changeset
1003 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
1004 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
1005
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1006 def help_next(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1007 self.help_n()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1008
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1009 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
1010 print >>self.stdout, """n(ext)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1011 Continue execution until the next line in the current function
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1012 is reached or it returns."""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1013
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1014 def help_return(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1015 self.help_r()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1016
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1017 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
1018 print >>self.stdout, """r(eturn)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1019 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
1020
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1021 def help_continue(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1022 self.help_c()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1023
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1024 def help_cont(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1025 self.help_c()
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_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
1028 print >>self.stdout, """c(ont(inue))
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1029 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
1030
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1031 def help_jump(self):
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1032 self.help_j()
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1033
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1034 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
1035 print >>self.stdout, """j(ump) lineno
26686
ad3f66e7fb10 This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents: 26061
diff changeset
1036 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
1037
28556
78395e5b4782 - New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents: 28089
diff changeset
1038 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
1039 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
1040 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
1041 (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
1042 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
1043
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1044 def help_list(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1045 self.help_l()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1046
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1047 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
1048 print >>self.stdout, """l(ist) [first [,last]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1049 List source code for the current file.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1050 Without arguments, list 11 lines around the current line
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1051 or continue the previous listing.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1052 With one argument, list 11 lines starting at that line.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1053 With two arguments, list the given range;
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1054 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
1055
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1056 def help_args(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1057 self.help_a()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1058
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1059 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
1060 print >>self.stdout, """a(rgs)
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1061 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
1062
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1063 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
1064 print >>self.stdout, """p expression
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1065 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
1066
26061
9b5b7da362a5 Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents: 25195
diff changeset
1067 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
1068 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
1069 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
1070
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1071 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
1072 print >>self.stdout, """(!) statement
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1073 Execute the (one-line) statement in the context of
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1074 the current stack frame.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1075 The exclamation point can be omitted unless the first word
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1076 of the statement resembles a debugger command.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1077 To assign to a global variable you must always prefix the
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1078 command with a 'global' command, e.g.:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1079 (Pdb) global list_options; list_options = ['-l']
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1080 (Pdb)"""
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1081
41170
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1082 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
1083 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
1084 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
1085 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
1086 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
1087 "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
1088
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1089 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
1090
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1091 def help_quit(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1092 self.help_q()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1093
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1094 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
1095 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
1096 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
1097
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
1098 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
1099
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1100 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
1101 print >>self.stdout, """whatis arg
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1102 Prints the type of the argument."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1103
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1104 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
1105 print >>self.stdout, """EOF
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1106 Handles the receipt of EOF as a command."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1107
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1108 def help_alias(self):
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1109 print >>self.stdout, """alias [name [command [parameter parameter ...]]]
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1110 Creates an alias called 'name' the executes 'command'. The command
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1111 must *not* be enclosed in quotes. Replaceable parameters are
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1112 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
1113 parameters. If no command is given, the current alias for name
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1114 is shown. If no name is given, all aliases are listed.
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1115
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1116 Aliases may be nested and can contain anything that can be
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1117 legally typed at the pdb prompt. Note! You *can* override
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1118 internal pdb commands with aliases! Those internal commands
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1119 are then hidden until the alias is removed. Aliasing is recursively
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1120 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
1121 in the line are left alone.
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1122
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1123 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
1124
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1125 #Print instance variables (usage "pi classInst")
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1126 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
1127
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1128 #Print instance variables in self
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1129 alias ps pi self
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1130 """
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1131
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1132 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
1133 print >>self.stdout, """unalias name
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1134 Deletes the specified alias."""
9091
556927d868d8 Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents: 8697
diff changeset
1135
37803
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1136 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
1137 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
1138 (com) ...
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1139 (com) end
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1140 (Pdb)
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1141
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1142 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
1143 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
1144 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
1145
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1146 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
1147 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
1148
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1149 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
1150 breakpoint set.
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1151
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1152 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
1153 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
1154 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
1155
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1156 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
1157 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
1158 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
1159 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
1160 (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
1161 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
1162 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
1163
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1164 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
1165 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
1166 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
1167 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
1168 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
1169 """
19d2477c1283 Patch #790710: Add breakpoint command lists in pdb.
Martin v. Löwis <martin@v.loewis.de>
parents: 35414
diff changeset
1170
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1171 def help_pdb(self):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1172 help()
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1173
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1174 def lookupmodule(self, filename):
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1175 """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
1176
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1177 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
1178 into an absolute file name.
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1179 """
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1180 if os.path.isabs(filename) and os.path.exists(filename):
33731
53c468d0955b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33728
diff changeset
1181 return filename
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1182 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
1183 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
1184 return f
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1185 root, ext = os.path.splitext(filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1186 if ext == '':
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1187 filename = filename + '.py'
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1188 if os.path.isabs(filename):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1189 return filename
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1190 for dirname in sys.path:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1191 while os.path.islink(dirname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1192 dirname = os.readlink(dirname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1193 fullname = os.path.join(dirname, filename)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1194 if os.path.exists(fullname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1195 return fullname
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1196 return None
8690
a0477bc820b2 Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents: 7485
diff changeset
1197
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1198 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
1199 # 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
1200 # __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
1201 #
41173
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1202 # 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
1203 # (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
1204 import __main__
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1205 __main__.__dict__.clear()
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1206 __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
1207 "__file__" : filename,
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1208 "__builtins__": __builtins__,
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1209 })
41532
4b9fa8092e82 Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents: 41173
diff changeset
1210
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1211 # 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
1212 # 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
1213 # 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
1214 # 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
1215 # user_call for details).
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1216 self._wait_for_mainpyfile = 1
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1217 self.mainpyfile = self.canonic(filename)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1218 self._user_requested_quit = 0
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1219 statement = 'execfile( "%s")' % filename
41532
4b9fa8092e82 Whitespace normalization. Ugh, we really need to do this more often.
Neal Norwitz <nnorwitz@gmail.com>
parents: 41173
diff changeset
1220 self.run(statement)
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1221
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1222 # Simplified interface
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1223
2437
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 2280
diff changeset
1224 def run(statement, globals=None, locals=None):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1225 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
1226
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 2280
diff changeset
1227 def runeval(expression, globals=None, locals=None):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1228 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
1229
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1230 def runctx(statement, globals, locals):
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1231 # B/W compatibility
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1232 run(statement, globals, locals)
600
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1233
33823
db8710f13650 SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents: 33731
diff changeset
1234 def runcall(*args, **kwds):
db8710f13650 SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents: 33731
diff changeset
1235 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
1236
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
1237 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
1238 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
1239
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1240 # Post-Mortem interface
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1241
45716
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1242 def post_mortem(t=None):
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1243 # handling the default
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1244 if t is None:
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1245 # 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
1246 # 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
1247 t = sys.exc_info()[2]
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1248 if t is None:
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1249 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
1250 "exception is being handled")
506547822b8d Issue 1106316. post_mortem()'s parameter, traceback, is now
Facundo Batista <facundobatista@gmail.com>
parents: 44698
diff changeset
1251
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1252 p = Pdb()
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1253 p.reset()
49572
c6c32842e71d Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48120
diff changeset
1254 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
1255
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1256 def pm():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1257 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
1258
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1259
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 1006
diff changeset
1260 # 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
1261
649
da5b1433467c Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents: 601
diff changeset
1262 TESTCMD = 'import x; x.main()'
600
d49b6a6725bd Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents: 583
diff changeset
1263
566
5a1f9ade1512 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1264 def test():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1265 run(TESTCMD)
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1266
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1267 # print help
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
1268 def help():
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1269 for dirname in sys.path:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1270 fullname = os.path.join(dirname, 'pdb.doc')
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1271 if os.path.exists(fullname):
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1272 sts = os.system('${PAGER-more} '+fullname)
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1273 if sts: print '*** Pager exit status:', sts
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1274 break
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1275 else:
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1276 print 'Sorry, can\'t find the help file "pdb.doc"',
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1277 print 'along the Python search path'
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
1278
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1279 def main():
46105
6ea41d5239e0 Added help options to PDB
Benjamin Peterson <benjamin@python.org>
parents: 45716
diff changeset
1280 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
1281 print "usage: pdb.py scriptfile [arg] ..."
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1282 sys.exit(2)
3822
db4ea3abf891 Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents: 2922
diff changeset
1283
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1284 mainpyfile = sys.argv[1] # Get script filename
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1285 if not os.path.exists(mainpyfile):
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1286 print 'Error:', mainpyfile, 'does not exist'
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1287 sys.exit(1)
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1288
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 15866
diff changeset
1289 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
1290
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1291 # 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
1292 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
1293
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1294 # 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
1295 # 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
1296 # 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
1297 # 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
1298 pdb = Pdb()
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1299 while 1:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1300 try:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1301 pdb._runscript(mainpyfile)
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1302 if pdb._user_requested_quit:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1303 break
33731
53c468d0955b Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 33728
diff changeset
1304 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
1305 except Restart:
226d9fcf9d59 Patch #1393667: pdb now has a "run" command which restarts the debugged
Georg Brandl <georg@python.org>
parents: 41111
diff changeset
1306 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
1307 print "\t" + " ".join(sys.argv[1:])
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1308 except SystemExit:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1309 # 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
1310 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
1311 print sys.exc_info()[1]
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1312 except:
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1313 traceback.print_exc()
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1314 print "Uncaught exception. Entering post mortem debugging"
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1315 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
1316 t = sys.exc_info()[2]
49572
c6c32842e71d Merged revisions 67000 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents: 48120
diff changeset
1317 pdb.interaction(None, t)
53778
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1318 print "Post mortem debugger finished. The " + mainpyfile + \
4c63670639ec Fix overlong lines.
Georg Brandl <georg@python.org>
parents: 53776
diff changeset
1319 " will be restarted"
33728
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1320
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1321
a01be350ed61 Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents: 33334
diff changeset
1322 # 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
1323 if __name__ == '__main__':
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1324 import pdb
eafbfa8a2b30 Patch #1429539: pdb now correctly initializes the __main__ module for
Georg Brandl <georg@python.org>
parents: 41170
diff changeset
1325 pdb.main()