annotate Lib/pdb.py @ 58925:eecf1bef052d 2.6

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