Mercurial > cpython-lru_cache-weakref
annotate Lib/pdb.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 3c9232a684ae |
| children | 708586792eec 01a25f638c83 |
| rev | line source |
|---|---|
|
59522
fcfe324663a6
convert shebang lines: python -> python3
Benjamin Peterson <benjamin@python.org>
parents:
56888
diff
changeset
|
1 #! /usr/bin/env python3 |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
2 |
|
63073
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
3 """ |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
4 The Python Debugger Pdb |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
5 ======================= |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
6 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
7 To use the debugger in its simplest form: |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
8 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
9 >>> import pdb |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
10 >>> pdb.run('<a statement>') |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
11 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
12 The debugger's prompt is '(Pdb) '. This will stop in the first |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
13 function call in <a statement>. |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
14 |
|
63073
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
15 Alternatively, if a statement terminated with an unhandled exception, |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
16 you can use pdb's post-mortem facility to inspect the contents of the |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
17 traceback: |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
18 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
19 >>> <a statement> |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
20 <exception traceback> |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
21 >>> import pdb |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
22 >>> pdb.pm() |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
23 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
24 The commands recognized by the debugger are listed in the next |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
25 section. Most can be abbreviated as indicated; e.g., h(elp) means |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
26 that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel', |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
27 nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
28 square brackets. Alternatives in the command syntax are separated |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
29 by a vertical bar (|). |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
30 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
31 A blank line repeats the previous command literally, except for |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
32 'list', where it lists the next 11 lines. |
| 583 | 33 |
|
63073
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
34 Commands that the debugger doesn't recognize are assumed to be Python |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
35 statements and are executed in the context of the program being |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
36 debugged. Python statements can also be prefixed with an exclamation |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
37 point ('!'). This is a powerful way to inspect the program being |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
38 debugged; it is even possible to change variables or call functions. |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
39 When an exception occurs in such a statement, the exception name is |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
40 printed but the debugger's state is not changed. |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
41 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
42 The debugger supports aliases, which can save typing. And aliases can |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
43 have parameters (see the alias help entry) which allows one a certain |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
44 level of adaptability to the context under examination. |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
45 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
46 Multiple commands may be entered on a single line, separated by the |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
47 pair ';;'. No intelligence is applied to separating the commands; the |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
48 input is split at the first ';;', even if it is in the middle of a |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
49 quoted string. |
| 566 | 50 |
|
63073
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
51 If a file ".pdbrc" exists in your home directory or in the current |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
52 directory, it is read in and executed as if it had been typed at the |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
53 debugger prompt. This is particularly useful for aliases. If both |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
54 files exist, the one in the home directory is read first and aliases |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
55 defined there can be overriden by the local file. |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
56 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
57 Aside from aliases, the debugger is not directly programmable; but it |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
58 is implemented as a class from which you can derive your own debugger |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
59 class, which you can make as fancy as you like. |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
60 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
61 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
62 Debugger commands |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
63 ================= |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
64 |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
65 """ |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
66 # NOTE: the actual command documentation is collected from docstrings of the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
67 # commands and is appended to __doc__ after the class has been defined. |
| 566 | 68 |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
69 import os |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
70 import re |
| 566 | 71 import sys |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
72 import cmd |
|
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
73 import bdb |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
74 import dis |
|
66691
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
75 import code |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
76 import pprint |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
77 import signal |
|
66691
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
78 import inspect |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
79 import traceback |
|
66691
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
80 import linecache |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
81 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
82 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
83 class Restart(Exception): |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
84 """Causes a debugger to be restarted for the debugged python program.""" |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
85 pass |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
86 |
| 16474 | 87 __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", |
| 88 "post_mortem", "help"] | |
| 89 | |
|
11269
2e087539da60
Pdb.lineinfo(): Don't use os.popen('egrep ...') to find the line in
Barry Warsaw <barry@python.org>
parents:
10824
diff
changeset
|
90 def find_function(funcname, filename): |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
39782
diff
changeset
|
91 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
|
92 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
93 fp = open(filename) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
94 except IOError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
95 return None |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
96 # consumer of this info expects the first line to be 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
97 lineno = 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
98 answer = None |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
99 while True: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
100 line = fp.readline() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
101 if line == '': |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
102 break |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
103 if cre.match(line): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
104 answer = funcname, filename, lineno |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
105 break |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
106 lineno += 1 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
107 fp.close() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
108 return answer |
| 566 | 109 |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
110 def getsourcelines(obj): |
|
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
111 lines, lineno = inspect.findsource(obj) |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
112 if inspect.isframe(obj) and obj.f_globals is obj.f_locals: |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
113 # must be a module frame: do not try to cut a block out of it |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
114 return lines, 1 |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
115 elif inspect.ismodule(obj): |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
116 return lines, 1 |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
117 return inspect.getblock(lines[lineno:]), lineno+1 |
| 566 | 118 |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
119 def lasti2lineno(code, lasti): |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
120 linestarts = list(dis.findlinestarts(code)) |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
121 linestarts.reverse() |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
122 for i, lineno in linestarts: |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
123 if lasti >= i: |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
124 return lineno |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
125 return 0 |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
126 |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
127 |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
128 class _rstr(str): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
129 """String that doesn't quote its repr.""" |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
130 def __repr__(self): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
131 return self |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
132 |
| 566 | 133 |
|
1999
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
134 # 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
|
135 # 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
|
136 # 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
|
137 # command "pdb.line_prefix = '\n% '". |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
138 # line_prefix = ': ' # Use this to get the old situation back |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
139 line_prefix = '\n-> ' # Probably a better default |
|
1999
c5a514f8f3e3
improved prompt format
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
140 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
141 class Pdb(bdb.Bdb, cmd.Cmd): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
142 |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
143 def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None, |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
144 nosigint=False): |
|
53777
58574288a5bf
Merged revisions 72322 via svnmerge from
Georg Brandl <georg@python.org>
parents:
52892
diff
changeset
|
145 bdb.Bdb.__init__(self, skip=skip) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
146 cmd.Cmd.__init__(self, completekey, stdin, stdout) |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
147 if stdout: |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
148 self.use_rawinput = 0 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
149 self.prompt = '(Pdb) ' |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
150 self.aliases = {} |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
151 self.displaying = {} |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
152 self.mainpyfile = '' |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
153 self._wait_for_mainpyfile = False |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
154 self.tb_lineno = {} |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
155 # Try to load readline if it exists |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
156 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
157 import readline |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
158 except ImportError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
159 pass |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
160 self.allow_kbdint = False |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
161 self.nosigint = nosigint |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
162 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
163 # Read $HOME/.pdbrc and ./.pdbrc |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
164 self.rcLines = [] |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23036
diff
changeset
|
165 if 'HOME' in os.environ: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
166 envHome = os.environ['HOME'] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
167 try: |
|
64405
06e5fd4959e8
Use a context manager for some file objects.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63339
diff
changeset
|
168 with open(os.path.join(envHome, ".pdbrc")) as rcFile: |
|
06e5fd4959e8
Use a context manager for some file objects.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63339
diff
changeset
|
169 self.rcLines.extend(rcFile) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
170 except IOError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
171 pass |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
172 try: |
|
64405
06e5fd4959e8
Use a context manager for some file objects.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63339
diff
changeset
|
173 with open(".pdbrc") as rcFile: |
|
06e5fd4959e8
Use a context manager for some file objects.
Florent Xicluna <florent.xicluna@gmail.com>
parents:
63339
diff
changeset
|
174 self.rcLines.extend(rcFile) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
175 except IOError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
176 pass |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
177 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
178 self.commands = {} # associates a command list to breakpoint numbers |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
179 self.commands_doprompt = {} # for each bp num, tells if the prompt |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
180 # must be disp. after execing the cmd list |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
181 self.commands_silent = {} # for each bp num, tells if the stack trace |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
182 # must be disp. after execing the cmd list |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
183 self.commands_defining = False # True while in the process of defining |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
184 # a command list |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
185 self.commands_bnum = None # The breakpoint number for which we are |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
186 # defining a list |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
187 |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
188 def sigint_handler(self, signum, frame): |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
189 if self.allow_kbdint: |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
190 raise KeyboardInterrupt |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
191 self.message("\nProgram interrupted. (Use 'cont' to resume).") |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
192 self.set_step() |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
193 self.set_trace(frame) |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
194 # restore previous signal handler |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
195 signal.signal(signal.SIGINT, self._previous_sigint_handler) |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
196 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
197 def reset(self): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
198 bdb.Bdb.reset(self) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
199 self.forget() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
200 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
201 def forget(self): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
202 self.lineno = None |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
203 self.stack = [] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
204 self.curindex = 0 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
205 self.curframe = None |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
206 self.tb_lineno.clear() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
207 |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
208 def setup(self, f, tb): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
209 self.forget() |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
210 self.stack, self.curindex = self.get_stack(f, tb) |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
211 while tb: |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
212 # when setting up post-mortem debugging with a traceback, save all |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
213 # the original line numbers to be displayed along the current line |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
214 # numbers (which can be different, e.g. due to finally clauses) |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
215 lineno = lasti2lineno(tb.tb_frame.f_code, tb.tb_lasti) |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
216 self.tb_lineno[tb.tb_frame] = lineno |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
217 tb = tb.tb_next |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
218 self.curframe = self.stack[self.curindex][0] |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
219 # The f_locals dictionary is updated from the actual frame |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
220 # locals whenever the .f_locals accessor is called, so we |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
221 # cache it here to ensure that modifications are not overwritten. |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
222 self.curframe_locals = self.curframe.f_locals |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
223 return self.execRcLines() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
224 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
225 # Can be executed earlier than 'setup' if desired |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
226 def execRcLines(self): |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
227 if not self.rcLines: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
228 return |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
229 # local copy because of recursion |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
230 rcLines = self.rcLines |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
231 rcLines.reverse() |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
232 # execute every line only once |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
233 self.rcLines = [] |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
234 while rcLines: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
235 line = rcLines.pop().strip() |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
236 if line and line[0] != '#': |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
237 if self.onecmd(line): |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
238 # if onecmd returns True, the command wants to exit |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
239 # from the interaction, save leftover rc lines |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
240 # to execute before next interaction |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
241 self.rcLines += reversed(rcLines) |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
242 return True |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
243 |
|
25003
c744144c4049
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24844
diff
changeset
|
244 # Override Bdb methods |
| 24844 | 245 |
| 246 def user_call(self, frame, argument_list): | |
| 247 """This method is called when there is the remote possibility | |
| 248 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
|
249 if self._wait_for_mainpyfile: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
250 return |
| 27556 | 251 if self.stop_here(frame): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
252 self.message('--Call--') |
| 27556 | 253 self.interaction(frame, None) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
254 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
255 def user_line(self, frame): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
256 """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
|
257 if self._wait_for_mainpyfile: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
258 if (self.mainpyfile != self.canonic(frame.f_code.co_filename) |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
259 or frame.f_lineno <= 0): |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
260 return |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
261 self._wait_for_mainpyfile = False |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
262 if self.bp_commands(frame): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
263 self.interaction(frame, None) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
264 |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
265 def bp_commands(self, frame): |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
266 """Call every command that was set for the current active breakpoint |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
267 (if there is one). |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
268 |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
269 Returns True if the normal interaction function must be called, |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
270 False otherwise.""" |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
271 # self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
272 if getattr(self, "currentbp", False) and \ |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
273 self.currentbp in self.commands: |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
274 currentbp = self.currentbp |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
275 self.currentbp = 0 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
276 lastcmd_back = self.lastcmd |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
277 self.setup(frame, None) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
278 for line in self.commands[currentbp]: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
279 self.onecmd(line) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
280 self.lastcmd = lastcmd_back |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
281 if not self.commands_silent[currentbp]: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
282 self.print_stack_entry(self.stack[self.curindex]) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
283 if self.commands_doprompt[currentbp]: |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
284 self._cmdloop() |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
285 self.forget() |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
286 return |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
287 return 1 |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
288 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
289 def user_return(self, frame, return_value): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
290 """This function is called when a return trap is set here.""" |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
291 if self._wait_for_mainpyfile: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
292 return |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
293 frame.f_locals['__return__'] = return_value |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
294 self.message('--Return--') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
295 self.interaction(frame, None) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
296 |
|
41717
9ad84070b22d
Merged revisions 55328-55341 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
297 def user_exception(self, frame, exc_info): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
298 """This function is called if an exception occurs, |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
299 but only if we are to stop at or just below this level.""" |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
300 if self._wait_for_mainpyfile: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
301 return |
|
41717
9ad84070b22d
Merged revisions 55328-55341 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
302 exc_type, exc_value, exc_traceback = exc_info |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
303 frame.f_locals['__exception__'] = exc_type, exc_value |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
304 self.message(traceback.format_exception_only(exc_type, |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
305 exc_value)[-1].strip()) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
306 self.interaction(frame, exc_traceback) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
307 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
308 # General interaction function |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
309 def _cmdloop(self): |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
310 while True: |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
311 try: |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
312 # keyboard interrupts allow for an easy way to cancel |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
313 # the current command, so allow them during interactive input |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
314 self.allow_kbdint = True |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
315 self.cmdloop() |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
316 self.allow_kbdint = False |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
317 break |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
318 except KeyboardInterrupt: |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
319 self.message('--KeyboardInterrupt--') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
320 |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
321 # Called before loop, handles display expressions |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
322 def preloop(self): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
323 displaying = self.displaying.get(self.curframe) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
324 if displaying: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
325 for expr, oldvalue in displaying.items(): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
326 newvalue = self._getval_except(expr) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
327 # check for identity first; this prevents custom __eq__ to |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
328 # be called at every loop, and also prevents instances whose |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
329 # fields are changed to be displayed |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
330 if newvalue is not oldvalue and newvalue != oldvalue: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
331 displaying[expr] = newvalue |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
332 self.message('display %s: %r [old: %r]' % |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
333 (expr, newvalue, oldvalue)) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
334 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
335 def interaction(self, frame, traceback): |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
336 if self.setup(frame, traceback): |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
337 # no interaction desired at this time (happens if .pdbrc contains |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
338 # a command like "continue") |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
339 self.forget() |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
340 return |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
341 self.print_stack_entry(self.stack[self.curindex]) |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
342 self._cmdloop() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
343 self.forget() |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
344 |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
345 def displayhook(self, obj): |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
346 """Custom displayhook for the exec in default(), which prevents |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
347 assignment of the _ variable in the builtins. |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
348 """ |
|
56888
021d3a38bd36
Merged revisions 74609,74627,74634,74645,74651,74738,74840,75016,75316-75317,75323-75324,75326,75328,75330,75338,75340-75341,75343,75352-75353,75355,75357,75359 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55908
diff
changeset
|
349 # reproduce the behavior of the standard displayhook, not printing None |
|
021d3a38bd36
Merged revisions 74609,74627,74634,74645,74651,74738,74840,75016,75316-75317,75323-75324,75326,75328,75330,75338,75340-75341,75343,75352-75353,75355,75357,75359 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55908
diff
changeset
|
350 if obj is not None: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
351 self.message(repr(obj)) |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
352 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
353 def default(self, line): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
354 if line[:1] == '!': line = line[1:] |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
355 locals = self.curframe_locals |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
356 globals = self.curframe.f_globals |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
357 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
358 code = compile(line + '\n', '<stdin>', 'single') |
|
44742
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44699
diff
changeset
|
359 save_stdout = sys.stdout |
|
14d4104976fc
Merged revisions 59985-60000,60002,60005-60007,60009-60042 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44699
diff
changeset
|
360 save_stdin = sys.stdin |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
361 save_displayhook = sys.displayhook |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
362 try: |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
363 sys.stdin = self.stdin |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
364 sys.stdout = self.stdout |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
365 sys.displayhook = self.displayhook |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
366 exec(code, globals, locals) |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
367 finally: |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
368 sys.stdout = save_stdout |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
369 sys.stdin = save_stdin |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
370 sys.displayhook = save_displayhook |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
371 except: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
372 exc_info = sys.exc_info()[:2] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
373 self.error(traceback.format_exception_only(*exc_info)[-1].strip()) |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
374 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
375 def precmd(self, line): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
376 """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
|
377 if not line.strip(): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
378 return line |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
379 args = line.split() |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23036
diff
changeset
|
380 while args[0] in self.aliases: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
381 line = self.aliases[args[0]] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
382 ii = 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
383 for tmpArg in args[1:]: |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
384 line = line.replace("%" + str(ii), |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
385 tmpArg) |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
386 ii += 1 |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
387 line = line.replace("%*", ' '.join(args[1:])) |
|
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
388 args = line.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
389 # split into ';;' separated commands |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
390 # unless it's an alias command |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
391 if args[0] != 'alias': |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
392 marker = line.find(';;') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
393 if marker >= 0: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
394 # queue up everything after marker |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
395 next = line[marker+2:].lstrip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
396 self.cmdqueue.append(next) |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
397 line = line[:marker].rstrip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
398 return line |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
399 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
400 def onecmd(self, line): |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
401 """Interpret the argument as though it had been typed in response |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
402 to the prompt. |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
403 |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
404 Checks whether this line is typed at the normal prompt or in |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
38453
diff
changeset
|
405 a breakpoint command list definition. |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
406 """ |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
407 if not self.commands_defining: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
408 return cmd.Cmd.onecmd(self, line) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
409 else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
410 return self.handle_command_def(line) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
411 |
|
63339
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
412 def handle_command_def(self, line): |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
413 """Handles one command line during command list definition.""" |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
414 cmd, arg, line = self.parseline(line) |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
415 if not cmd: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
416 return |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
417 if cmd == 'silent': |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
418 self.commands_silent[self.commands_bnum] = True |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
419 return # continue to handle other cmd def in the cmd list |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
420 elif cmd == 'end': |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
421 self.cmdqueue = [] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
422 return 1 # end of cmd list |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
423 cmdlist = self.commands[self.commands_bnum] |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
424 if arg: |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
425 cmdlist.append(cmd+' '+arg) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
426 else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
427 cmdlist.append(cmd) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
428 # Determine if we must stop |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
429 try: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
430 func = getattr(self, 'do_' + cmd) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
431 except AttributeError: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
432 func = self.default |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
433 # one of the resuming commands |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
434 if func.__name__ in self.commands_resuming: |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
435 self.commands_doprompt[self.commands_bnum] = False |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
436 self.cmdqueue = [] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
437 return 1 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
438 return |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
439 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
440 # interface abstraction functions |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
441 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
442 def message(self, msg): |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
443 print(msg, file=self.stdout) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
444 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
445 def error(self, msg): |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
446 print('***', msg, file=self.stdout) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
447 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
448 # Command definitions, called by cmdloop() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
449 # The argument is the remaining string on the command line |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
450 # Return true to exit from the command loop |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
451 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
452 def do_commands(self, arg): |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
453 """commands [bpnumber] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
454 (com) ... |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
455 (com) end |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
456 (Pdb) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
457 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
458 Specify a list of commands for breakpoint number bpnumber. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
459 The commands themselves are entered on the following lines. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
460 Type a line containing just 'end' to terminate the commands. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
461 The commands are executed when the breakpoint is hit. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
462 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
463 To remove all commands from a breakpoint, type commands and |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
464 follow it immediately with end; that is, give no commands. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
465 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
466 With no bpnumber argument, commands refers to the last |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
467 breakpoint set. |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
468 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
469 You can use breakpoint commands to start your program up |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
470 again. Simply use the continue command, or step, or any other |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
471 command that resumes execution. |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
472 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
473 Specifying any command resuming execution (currently continue, |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
474 step, next, return, jump, quit and their abbreviations) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
475 terminates the command list (as if that command was |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
476 immediately followed by end). This is because any time you |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
477 resume execution (even with a simple next or step), you may |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
478 encounter another breakpoint -- which could have its own |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
479 command list, leading to ambiguities about which list to |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
480 execute. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
481 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
482 If you use the 'silent' command in the command list, the usual |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
483 message about stopping at a breakpoint is not printed. This |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
484 may be desirable for breakpoints that are to print a specific |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
485 message and then continue. If none of the other commands |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
486 print anything, you will see no sign that the breakpoint was |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
487 reached. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
488 """ |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
489 if not arg: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
490 bnum = len(bdb.Breakpoint.bpbynumber) - 1 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
491 else: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
492 try: |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
493 bnum = int(arg) |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
494 except: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
495 self.error("Usage: commands [bnum]\n ...\n end") |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
496 return |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
497 self.commands_bnum = bnum |
|
63339
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
498 # Save old definitions for the case of a keyboard interrupt. |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
499 if bnum in self.commands: |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
500 old_command_defs = (self.commands[bnum], |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
501 self.commands_doprompt[bnum], |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
502 self.commands_silent[bnum]) |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
503 else: |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
504 old_command_defs = None |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
505 self.commands[bnum] = [] |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
506 self.commands_doprompt[bnum] = True |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
507 self.commands_silent[bnum] = False |
|
63339
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
508 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
509 prompt_back = self.prompt |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
510 self.prompt = '(com) ' |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
511 self.commands_defining = True |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
512 try: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
513 self.cmdloop() |
|
63339
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
514 except KeyboardInterrupt: |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
515 # Restore old definitions. |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
516 if old_command_defs: |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
517 self.commands[bnum] = old_command_defs[0] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
518 self.commands_doprompt[bnum] = old_command_defs[1] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
519 self.commands_silent[bnum] = old_command_defs[2] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
520 else: |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
521 del self.commands[bnum] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
522 del self.commands_doprompt[bnum] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
523 del self.commands_silent[bnum] |
|
7c4a77604027
Part of #7245: when KeyboardInterrupt is raised while defining commands, restore the old commands instead of producing a traceback.
Georg Brandl <georg@python.org>
parents:
63334
diff
changeset
|
524 self.error('command definition aborted, old commands restored') |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
525 finally: |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
526 self.commands_defining = False |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
527 self.prompt = prompt_back |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
528 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
529 def do_break(self, arg, temporary = 0): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
530 """b(reak) [ ([filename:]lineno | function) [, condition] ] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
531 Without argument, list all breaks. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
532 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
533 With a line number argument, set a break at this line in the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
534 current file. With a function name, set a break at the first |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
535 executable line of that function. If a second argument is |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
536 present, it is a string specifying an expression which must |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
537 evaluate to true before the breakpoint is honored. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
538 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
539 The line number may be prefixed with a filename and a colon, |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
540 to specify a breakpoint in another file (probably one that |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
541 hasn't been loaded yet). The file is searched for on |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
542 sys.path; the .py suffix may be omitted. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
543 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
544 if not arg: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
545 if self.breaks: # There's at least one |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
546 self.message("Num Type Disp Enb Where") |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
547 for bp in bdb.Breakpoint.bpbynumber: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
548 if bp: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
549 self.message(bp.bpformat()) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
550 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
551 # parse arguments; comma has lowest precedence |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
552 # and cannot occur in filename |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
553 filename = None |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
554 lineno = None |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
555 cond = None |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
556 comma = arg.find(',') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
557 if comma > 0: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
558 # parse stuff after comma: "condition" |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
559 cond = arg[comma+1:].lstrip() |
|
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
560 arg = arg[:comma].rstrip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
561 # parse stuff before comma: [filename:]lineno | function |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
562 colon = arg.rfind(':') |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
33130
diff
changeset
|
563 funcname = None |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
564 if colon >= 0: |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
565 filename = arg[:colon].rstrip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
566 f = self.lookupmodule(filename) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
567 if not f: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
568 self.error('%r not found from sys.path' % filename) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
569 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
570 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
571 filename = f |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
572 arg = arg[colon+1:].lstrip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
573 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
574 lineno = int(arg) |
| 65293 | 575 except ValueError: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
576 self.error('Bad lineno: %s' % arg) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
577 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
578 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
579 # no colon; can be lineno or function |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
580 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
581 lineno = int(arg) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
582 except ValueError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
583 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
584 func = eval(arg, |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
585 self.curframe.f_globals, |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
586 self.curframe_locals) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
587 except: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
588 func = arg |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
589 try: |
|
44026
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
43352
diff
changeset
|
590 if hasattr(func, '__func__'): |
|
48af6375207e
Removed the API to create unbound methods and simplified the API for bound methods. The signature is PyMethod_New(func, instance).
Christian Heimes <christian@cheimes.de>
parents:
43352
diff
changeset
|
591 func = func.__func__ |
|
40910
eaaee785eb86
Change all the function attributes from func_* -> __*__. This gets rid
Neal Norwitz <nnorwitz@gmail.com>
parents:
40792
diff
changeset
|
592 code = func.__code__ |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
33130
diff
changeset
|
593 #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
|
594 #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
|
595 funcname = code.co_name |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
596 lineno = code.co_firstlineno |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
597 filename = code.co_filename |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
598 except: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
599 # last thing to try |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
600 (ok, filename, ln) = self.lineinfo(arg) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
601 if not ok: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
602 self.error('The specified object %r is not a function ' |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
603 'or was not found along sys.path.' % arg) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
604 return |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
33130
diff
changeset
|
605 funcname = ok # ok contains a function name |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
606 lineno = int(ln) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
607 if not filename: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
608 filename = self.defaultFile() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
609 # Check for reasonable breakpoint |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
610 line = self.checkline(filename, lineno) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
611 if line: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
612 # 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
|
613 err = self.set_break(filename, line, temporary, cond, funcname) |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
614 if err: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
615 self.error(err, file=self.stdout) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
616 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
617 bp = self.get_breaks(filename, line)[-1] |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
618 self.message("Breakpoint %d at %s:%d" % |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
619 (bp.number, bp.file, bp.line)) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
620 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
621 # To be overridden in derived debuggers |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
622 def defaultFile(self): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
623 """Produce a reasonable default.""" |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
624 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
|
625 if filename == '<string>' and self.mainpyfile: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
626 filename = self.mainpyfile |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
627 return filename |
|
5767
03a57af72218
Support for conditional breakpoints (Jim Fulton, with some changes).
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
628 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
629 do_b = do_break |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
630 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
631 def do_tbreak(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
632 """tbreak [ ([filename:]lineno | function) [, condition] ] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
633 Same arguments as break, but sets a temporary breakpoint: it |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
634 is automatically deleted when first hit. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
635 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
636 self.do_break(arg, 1) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
637 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
638 def lineinfo(self, identifier): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
639 failed = (None, None, None) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
640 # Input is identifier, may be in single quotes |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
641 idstring = identifier.split("'") |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
642 if len(idstring) == 1: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
643 # not in single quotes |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
644 id = idstring[0].strip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
645 elif len(idstring) == 3: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
646 # quoted |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
647 id = idstring[1].strip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
648 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
649 return failed |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
650 if id == '': return failed |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
651 parts = id.split('.') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
652 # Protection for derived debuggers |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
653 if parts[0] == 'self': |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
654 del parts[0] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
655 if len(parts) == 0: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
656 return failed |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
657 # Best first guess at file to look at |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
658 fname = self.defaultFile() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
659 if len(parts) == 1: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
660 item = parts[0] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
661 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
662 # More than one part. |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
663 # First is module, second is method/class |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
664 f = self.lookupmodule(parts[0]) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
665 if f: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
666 fname = f |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
667 item = parts[1] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
668 answer = find_function(item, fname) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
669 return answer or failed |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
670 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
671 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
|
672 """Check whether specified line seems to be executable. |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
673 |
|
33334
04245ef53949
Patch #1003640: replace checkline() function parsing with new breakpoint logic:
Johannes Gijsbers <jlg@dds.nl>
parents:
33130
diff
changeset
|
674 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
|
675 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
|
676 """ |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
677 # this method should be callable before starting debugging, so default |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
678 # to "no globals" if there is no current frame |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
679 globs = self.curframe.f_globals if hasattr(self, 'curframe') else None |
|
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
680 line = linecache.getline(filename, lineno, globs) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
681 if not line: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
682 self.message('End of file') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
683 return 0 |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
684 line = line.strip() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
685 # 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
|
686 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
|
687 (line[:3] == '"""') or line[:3] == "'''"): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
688 self.error('Blank or comment') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
689 return 0 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
690 return lineno |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
691 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
692 def do_enable(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
693 """enable bpnumber [bpnumber ...] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
694 Enables the breakpoints given as a space separated list of |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
695 breakpoint numbers. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
696 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
697 args = arg.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
698 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
|
699 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
700 bp = self.get_bpbynumber(i) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
701 except ValueError as err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
702 self.error(err) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
703 else: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
704 bp.enable() |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
705 self.message('Enabled %s' % bp) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
706 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
707 def do_disable(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
708 """disable bpnumber [bpnumber ...] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
709 Disables the breakpoints given as a space separated list of |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
710 breakpoint numbers. Disabling a breakpoint means it cannot |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
711 cause the program to stop execution, but unlike clearing a |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
712 breakpoint, it remains in the list of breakpoints and can be |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
713 (re-)enabled. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
714 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
715 args = arg.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
716 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
|
717 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
718 bp = self.get_bpbynumber(i) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
719 except ValueError as err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
720 self.error(err) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
721 else: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
722 bp.disable() |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
723 self.message('Disabled %s' % bp) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
724 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
725 def do_condition(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
726 """condition bpnumber [condition] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
727 Set a new condition for the breakpoint, an expression which |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
728 must evaluate to true before the breakpoint is honored. If |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
729 condition is absent, any existing condition is removed; i.e., |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
730 the breakpoint is made unconditional. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
731 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
732 args = arg.split(' ', 1) |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40587
diff
changeset
|
733 try: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
734 cond = args[1] |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
735 except IndexError: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
736 cond = None |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
737 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
738 bp = self.get_bpbynumber(args[0].strip()) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
739 except ValueError as err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
740 self.error(err) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
741 else: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
742 bp.cond = cond |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
743 if not cond: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
744 self.message('Breakpoint %d is now unconditional.' % bp.number) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
745 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
746 self.message('New condition set for breakpoint %d.' % bp.number) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
747 |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
748 def do_ignore(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
749 """ignore bpnumber [count] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
750 Set the ignore count for the given breakpoint number. If |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
751 count is omitted, the ignore count is set to 0. A breakpoint |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
752 becomes active when the ignore count is zero. When non-zero, |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
753 the count is decremented each time the breakpoint is reached |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
754 and the breakpoint is not disabled and any associated |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
755 condition evaluates to true. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
756 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
757 args = arg.split() |
|
40737
6ebad2a6b990
Merged revisions 53451-53537 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
40587
diff
changeset
|
758 try: |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
759 count = int(args[1].strip()) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
760 except: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
761 count = 0 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
762 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
763 bp = self.get_bpbynumber(args[0].strip()) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
764 except ValueError as err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
765 self.error(err) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
766 else: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
767 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
|
768 if count > 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
|
769 if count > 1: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
770 countstr = '%d crossings' % count |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
771 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
772 countstr = '1 crossing' |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
773 self.message('Will ignore next %s of breakpoint %d.' % |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
774 (countstr, bp.number)) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
775 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
776 self.message('Will stop next time breakpoint %d is reached.' |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
777 % bp.number) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
778 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
779 def do_clear(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
780 """cl(ear) filename:lineno\ncl(ear) [bpnumber [bpnumber...]] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
781 With a space separated list of breakpoint numbers, clear |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
782 those breakpoints. Without argument, clear all breaks (but |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
783 first ask confirmation). With a filename:lineno argument, |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
784 clear all breaks at that line in that file. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
785 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
786 if not arg: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
787 try: |
|
41892
c3287e195a1d
Use input(), not our own fake raw input (in one place).
Guido van Rossum <guido@python.org>
parents:
41717
diff
changeset
|
788 reply = input('Clear all breaks? ') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
789 except EOFError: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
790 reply = 'no' |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
791 reply = reply.strip().lower() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
792 if reply in ('y', 'yes'): |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
793 bplist = [bp for bp in bdb.Breakpoint.bpbynumber if bp] |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
794 self.clear_all_breaks() |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
795 for bp in bplist: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
796 self.message('Deleted %s' % bp) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
797 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
798 if ':' in arg: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
799 # 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
|
800 i = arg.rfind(':') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
801 filename = arg[:i] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
802 arg = arg[i+1:] |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
803 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
804 lineno = int(arg) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
805 except ValueError: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
806 err = "Invalid line number (%s)" % arg |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
807 else: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
808 bplist = self.get_breaks(filename, lineno) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
809 err = self.clear_break(filename, lineno) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
810 if err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
811 self.error(err) |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
812 else: |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
813 for bp in bplist: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
814 self.message('Deleted %s' % bp) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
815 return |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
816 numberlist = arg.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
817 for i in numberlist: |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
818 try: |
|
63318
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
819 bp = self.get_bpbynumber(i) |
|
40d6a7c15836
#809887: improve pdb feedback for breakpoint-related actions. Also add a functional test for these commands.
Georg Brandl <georg@python.org>
parents:
63313
diff
changeset
|
820 except ValueError as err: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
821 self.error(err) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
822 else: |
|
66534
e5fcb4226b42
Fix #10561 - Fix pdb behavior. Delete the breakpoints by breakpoint number.
Senthil Kumaran <orsenthil@gmail.com>
parents:
65293
diff
changeset
|
823 self.clear_bpbynumber(i) |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
824 self.message('Deleted %s' % bp) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
825 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
|
826 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
827 def do_where(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
828 """w(here) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
829 Print a stack trace, with the most recent frame at the bottom. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
830 An arrow indicates the "current frame", which determines the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
831 context of most commands. 'bt' is an alias for this command. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
832 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
833 self.print_stack_trace() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
834 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
|
835 do_bt = do_where |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
836 |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
837 def _select_frame(self, number): |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
838 assert 0 <= number < len(self.stack) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
839 self.curindex = number |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
840 self.curframe = self.stack[self.curindex][0] |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
841 self.curframe_locals = self.curframe.f_locals |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
842 self.print_stack_entry(self.stack[self.curindex]) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
843 self.lineno = None |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
844 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
845 def do_up(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
846 """u(p) [count] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
847 Move the current frame count (default one) levels up in the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
848 stack trace (to an older frame). |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
849 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
850 if self.curindex == 0: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
851 self.error('Oldest frame') |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
852 return |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
853 try: |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
854 count = int(arg or 1) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
855 except ValueError: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
856 self.error('Invalid frame count (%s)' % arg) |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
857 return |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
858 if count < 0: |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
859 newframe = 0 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
860 else: |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
861 newframe = max(0, self.curindex - count) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
862 self._select_frame(newframe) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
863 do_u = do_up |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
864 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
865 def do_down(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
866 """d(own) [count] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
867 Move the current frame count (default one) levels down in the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
868 stack trace (to a newer frame). |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
869 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
870 if self.curindex + 1 == len(self.stack): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
871 self.error('Newest frame') |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
872 return |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
873 try: |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
874 count = int(arg or 1) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
875 except ValueError: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
876 self.error('Invalid frame count (%s)' % arg) |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
877 return |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
878 if count < 0: |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
879 newframe = len(self.stack) - 1 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
880 else: |
|
62531
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
881 newframe = min(len(self.stack) - 1, self.curindex + count) |
|
547e65db4d38
#9064: accept number of frames for "up" and "down" commands in pdb.
Georg Brandl <georg@python.org>
parents:
59522
diff
changeset
|
882 self._select_frame(newframe) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
883 do_d = do_down |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
884 |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46978
diff
changeset
|
885 def do_until(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
886 """unt(il) [lineno] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
887 Without argument, continue execution until the line with a |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
888 number greater than the current one is reached. With a line |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
889 number, continue execution until a line with a number greater |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
890 or equal to that is reached. In both cases, also stop when |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
891 the current frame returns. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
892 """ |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
893 if arg: |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
894 try: |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
895 lineno = int(arg) |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
896 except ValueError: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
897 self.error('Error in argument: %r' % arg) |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
898 return |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
899 if lineno <= self.curframe.f_lineno: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
900 self.error('"until" line number is smaller than current ' |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
901 'line number') |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
902 return |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
903 else: |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
904 lineno = None |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
905 self.set_until(self.curframe, lineno) |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46978
diff
changeset
|
906 return 1 |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46978
diff
changeset
|
907 do_unt = do_until |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46978
diff
changeset
|
908 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
909 def do_step(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
910 """s(tep) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
911 Execute the current line, stop at the first possible occasion |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
912 (either in a function that is called or in the current |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
913 function). |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
914 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
915 self.set_step() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
916 return 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
917 do_s = do_step |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
918 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
919 def do_next(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
920 """n(ext) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
921 Continue execution until the next line in the current function |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
922 is reached or it returns. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
923 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
924 self.set_next(self.curframe) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
925 return 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
926 do_n = do_next |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
927 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
928 def do_run(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
929 """run [args...] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
930 Restart the debugged python program. If a string is supplied |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
931 it is splitted with "shlex", and the result is used as the new |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
932 sys.argv. History, breakpoints, actions and debugger options |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
933 are preserved. "restart" is an alias for "run". |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
934 """ |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
935 if arg: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
936 import shlex |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
937 argv0 = sys.argv[0:1] |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
938 sys.argv = shlex.split(arg) |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
939 sys.argv[:0] = argv0 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
940 # this is caught in the main debugger loop |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
941 raise Restart |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
942 |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
943 do_restart = do_run |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
944 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
945 def do_return(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
946 """r(eturn) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
947 Continue execution until the current function returns. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
948 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
949 self.set_return(self.curframe) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
950 return 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
951 do_r = do_return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
952 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
953 def do_continue(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
954 """c(ont(inue)) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
955 Continue execution, only stop when a breakpoint is encountered. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
956 """ |
|
66711
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
957 if not self.nosigint: |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
958 self._previous_sigint_handler = \ |
|
c2ca867cdd1a
#7245: Add a SIGINT handler on continue in pdb that allows to break a program again by pressing Ctrl-C.
Georg Brandl <georg@python.org>
parents:
66691
diff
changeset
|
959 signal.signal(signal.SIGINT, self.sigint_handler) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
960 self.set_continue() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
961 return 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
962 do_c = do_cont = do_continue |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
963 |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
964 def do_jump(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
965 """j(ump) lineno |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
966 Set the next line that will be executed. Only available in |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
967 the bottom-most frame. This lets you jump back and execute |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
968 code again, or jump forward to skip code that you don't want |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
969 to run. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
970 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
971 It should be noted that not all jumps are allowed -- for |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
972 instance it is not possible to jump into the middle of a |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
973 for loop or out of a finally clause. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
974 """ |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
975 if self.curindex + 1 != len(self.stack): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
976 self.error('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
|
977 return |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
978 try: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
979 arg = int(arg) |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
980 except ValueError: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
981 self.error("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
|
982 else: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
983 try: |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
984 # 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
|
985 # new position |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
986 self.curframe.f_lineno = arg |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
987 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
|
988 self.print_stack_entry(self.stack[self.curindex]) |
|
40587
6b18a095c2e7
SF patch 1631942 by Collin Winter:
Guido van Rossum <guido@python.org>
parents:
40450
diff
changeset
|
989 except ValueError as e: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
990 self.error('Jump failed: %s' % e) |
|
26686
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
991 do_j = do_jump |
|
ad3f66e7fb10
This is Richie Hindle's patch
Michael W. Hudson <mwh@python.net>
parents:
26061
diff
changeset
|
992 |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28089
diff
changeset
|
993 def do_debug(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
994 """debug code |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
995 Enter a recursive debugger that steps through the code |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
996 argument (which is an arbitrary expression or statement to be |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
997 executed in the current environment). |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
998 """ |
|
28556
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28089
diff
changeset
|
999 sys.settrace(None) |
|
78395e5b4782
- New function sys.call_tracing() allows pdb to debug code
Guido van Rossum <guido@python.org>
parents:
28089
diff
changeset
|
1000 globals = self.curframe.f_globals |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
1001 locals = self.curframe_locals |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44498
diff
changeset
|
1002 p = Pdb(self.completekey, self.stdin, self.stdout) |
| 28561 | 1003 p.prompt = "(%s) " % self.prompt.strip() |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1004 self.message("ENTERING RECURSIVE DEBUGGER") |
| 28561 | 1005 sys.call_tracing(p.run, (arg, globals, locals)) |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1006 self.message("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
|
1007 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
|
1008 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
|
1009 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1010 def do_quit(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1011 """q(uit)\nexit |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1012 Quit from the debugger. The program being executed is aborted. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1013 """ |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
1014 self._user_requested_quit = True |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1015 self.set_quit() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1016 return 1 |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1017 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1018 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
|
1019 do_exit = do_quit |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1020 |
|
27236
3ede90d6e1cf
Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents:
26686
diff
changeset
|
1021 def do_EOF(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1022 """EOF |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1023 Handles the receipt of EOF as a command. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1024 """ |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1025 self.message('') |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
1026 self._user_requested_quit = True |
|
27236
3ede90d6e1cf
Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents:
26686
diff
changeset
|
1027 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
|
1028 return 1 |
|
3ede90d6e1cf
Duh. The do_EOF() implementation was bogus. Make it more like
Guido van Rossum <guido@python.org>
parents:
26686
diff
changeset
|
1029 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1030 def do_args(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1031 """a(rgs) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1032 Print the argument list of the current function. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1033 """ |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
1034 co = self.curframe.f_code |
|
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
1035 dict = self.curframe_locals |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1036 n = co.co_argcount |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1037 if co.co_flags & 4: n = n+1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1038 if co.co_flags & 8: n = n+1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1039 for i in range(n): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1040 name = co.co_varnames[i] |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1041 if name in dict: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1042 self.message('%s = %r' % (name, dict[name])) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1043 else: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1044 self.message('%s = *** undefined ***' % (name,)) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1045 do_a = do_args |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1046 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1047 def do_retval(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1048 """retval |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1049 Print the return value for the last return of a function. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1050 """ |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
1051 if '__return__' in self.curframe_locals: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1052 self.message(repr(self.curframe_locals['__return__'])) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1053 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1054 self.error('Not yet returned!') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1055 do_rv = do_retval |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1056 |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1057 def _getval(self, arg): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1058 try: |
|
52892
792bb885029f
Merged revisions 70712,70714,70764-70765,70769-70771,70773,70776-70777,70788-70789,70824,70828,70832,70836,70842,70851,70855,70857,70866-70872,70883,70885,70893-70894,70896-70897,70903,70905-70907,70915,70927,70933,70951,70960,70962-70964,70998,71001,71006,71008,71010-71011,71019,71037,71056,71094,71101-71103,71106,71119,71123,71149-71150,71203,71212,71214-71217,71221,71240 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
50164
diff
changeset
|
1059 return eval(arg, self.curframe.f_globals, self.curframe_locals) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1060 except: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1061 exc_info = sys.exc_info()[:2] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1062 self.error(traceback.format_exception_only(*exc_info)[-1].strip()) |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1063 raise |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1064 |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1065 def _getval_except(self, arg, frame=None): |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1066 try: |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1067 if frame is None: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1068 return eval(arg, self.curframe.f_globals, self.curframe_locals) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1069 else: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1070 return eval(arg, frame.f_globals, frame.f_locals) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1071 except: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1072 exc_info = sys.exc_info()[:2] |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1073 err = traceback.format_exception_only(*exc_info)[-1].strip() |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1074 return _rstr('** raised %s **' % err) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1075 |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1076 def do_p(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1077 """p(rint) expression |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1078 Print the value of the expression. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1079 """ |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1080 try: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1081 self.message(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
|
1082 except: |
|
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1083 pass |
|
43218
428d921804fa
Add "print" command to pdb, "print s" previously invoked the print statement.
Georg Brandl <georg@python.org>
parents:
42552
diff
changeset
|
1084 # make "print" an alias of "p" since print isn't a Python statement anymore |
|
428d921804fa
Add "print" command to pdb, "print s" previously invoked the print statement.
Georg Brandl <georg@python.org>
parents:
42552
diff
changeset
|
1085 do_print = do_p |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1086 |
|
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1087 def do_pp(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1088 """pp expression |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1089 Pretty-print the value of the expression. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1090 """ |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1091 try: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1092 self.message(pprint.pformat(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
|
1093 except: |
|
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1094 pass |
|
1331
07900834cc97
* pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents:
1317
diff
changeset
|
1095 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1096 def do_list(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1097 """l(ist) [first [,last] | .] |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1098 |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1099 List source code for the current file. Without arguments, |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1100 list 11 lines around the current line or continue the previous |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1101 listing. With . as argument, list 11 lines around the current |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1102 line. With one argument, list 11 lines starting at that line. |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1103 With two arguments, list the given range; if the second |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1104 argument is less than the first, it is a count. |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1105 |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1106 The current line in the current frame is indicated by "->". |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1107 If an exception is being debugged, the line where the |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1108 exception was originally raised or propagated is indicated by |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1109 ">>", if it differs from the current line. |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1110 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1111 self.lastcmd = 'list' |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1112 last = None |
|
63304
cb18bc8dd469
#4179: In pdb, allow "list ." as a command to return to the currently debugged line.
Georg Brandl <georg@python.org>
parents:
63087
diff
changeset
|
1113 if arg and arg != '.': |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1114 try: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1115 if ',' in arg: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1116 first, last = arg.split(',') |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1117 first = int(first.strip()) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1118 last = int(last.strip()) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1119 if last < first: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1120 # assume it's a count |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1121 last = first + last |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1122 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1123 first = int(arg.strip()) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1124 first = max(1, first - 5) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1125 except ValueError: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1126 self.error('Error in argument: %r' % arg) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1127 return |
|
63304
cb18bc8dd469
#4179: In pdb, allow "list ." as a command to return to the currently debugged line.
Georg Brandl <georg@python.org>
parents:
63087
diff
changeset
|
1128 elif self.lineno is None or arg == '.': |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1129 first = max(1, self.curframe.f_lineno - 5) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1130 else: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1131 first = self.lineno + 1 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1132 if last is None: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1133 last = first + 10 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1134 filename = self.curframe.f_code.co_filename |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1135 breaklist = self.get_file_breaks(filename) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1136 try: |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1137 lines = linecache.getlines(filename, self.curframe.f_globals) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1138 self._print_lines(lines[first-1:last], first, breaklist, |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1139 self.curframe) |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1140 self.lineno = min(last, len(lines)) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1141 if len(lines) < last: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1142 self.message('[EOF]') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1143 except KeyboardInterrupt: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1144 pass |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1145 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
|
1146 |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1147 def do_longlist(self, arg): |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1148 """longlist | ll |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1149 List the whole source code for the current function or frame. |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1150 """ |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1151 filename = self.curframe.f_code.co_filename |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1152 breaklist = self.get_file_breaks(filename) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1153 try: |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
1154 lines, lineno = getsourcelines(self.curframe) |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1155 except IOError as err: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1156 self.error(err) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1157 return |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1158 self._print_lines(lines, lineno, breaklist, self.curframe) |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1159 do_ll = do_longlist |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1160 |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1161 def do_source(self, arg): |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1162 """source expression |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1163 Try to get source code for the given object and display it. |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1164 """ |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1165 try: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1166 obj = self._getval(arg) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1167 except: |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1168 return |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1169 try: |
|
63332
c3b673b94612
Fix source finding if the given frame is a module-level frame.
Georg Brandl <georg@python.org>
parents:
63329
diff
changeset
|
1170 lines, lineno = getsourcelines(obj) |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1171 except (IOError, TypeError) as err: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1172 self.error(err) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1173 return |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1174 self._print_lines(lines, lineno) |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1175 |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1176 def _print_lines(self, lines, start, breaks=(), frame=None): |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1177 """Print a range of lines.""" |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1178 if frame: |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1179 current_lineno = frame.f_lineno |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1180 exc_lineno = self.tb_lineno.get(frame, -1) |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1181 else: |
|
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1182 current_lineno = exc_lineno = -1 |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1183 for lineno, line in enumerate(lines, start): |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1184 s = str(lineno).rjust(3) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1185 if len(s) < 4: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1186 s += ' ' |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1187 if lineno in breaks: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1188 s += 'B' |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1189 else: |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1190 s += ' ' |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1191 if lineno == current_lineno: |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1192 s += '->' |
|
63334
670d4cbf1464
Show the traceback line numbers as well as the current line numbers if an exception is being debugged. Courtesy of pdb++ by Antonio Cuni. Also document -> and >> markers for "list".
Georg Brandl <georg@python.org>
parents:
63332
diff
changeset
|
1193 elif lineno == exc_lineno: |
|
63329
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1194 s += '>>' |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1195 self.message(s + '\t' + line.rstrip()) |
|
46d2ec78ef79
Add "longlist" and "source" commands, ideas borrowed from pdb++ by Antonio Cuni.
Georg Brandl <georg@python.org>
parents:
63328
diff
changeset
|
1196 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1197 def do_whatis(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1198 """whatis arg |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1199 Print the type of the argument. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1200 """ |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1201 try: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1202 value = self._getval(arg) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1203 except: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1204 # _getval() already printed the error |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1205 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1206 code = None |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1207 # Is it a function? |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1208 try: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1209 code = value.__code__ |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1210 except Exception: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1211 pass |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1212 if code: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1213 self.message('Function %s' % code.co_name) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1214 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1215 # Is it an instance method? |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1216 try: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1217 code = value.__func__.__code__ |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1218 except Exception: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1219 pass |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1220 if code: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1221 self.message('Method %s' % code.co_name) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1222 return |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1223 # Is it a class? |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1224 if value.__class__ is type: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1225 self.message('Class %s.%s' % (value.__module__, value.__name__)) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1226 return |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1227 # None of the above... |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1228 self.message(type(value)) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
1229 |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1230 def do_display(self, arg): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1231 """display [expression] |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1232 |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1233 Display the value of the expression if it changed, each time execution |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1234 stops in the current frame. |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1235 |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1236 Without expression, list all display expressions for the current frame. |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1237 """ |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1238 if not arg: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1239 self.message('Currently displaying:') |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1240 for item in self.displaying.get(self.curframe, {}).items(): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1241 self.message('%s: %r' % item) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1242 else: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1243 val = self._getval_except(arg) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1244 self.displaying.setdefault(self.curframe, {})[arg] = val |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1245 self.message('display %s: %r' % (arg, val)) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1246 |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1247 def do_undisplay(self, arg): |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1248 """undisplay [expression] |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1249 |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1250 Do not display the expression any more in the current frame. |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1251 |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1252 Without expression, clear all display expressions for the current frame. |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1253 """ |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1254 if arg: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1255 try: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1256 del self.displaying.get(self.curframe, {})[arg] |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1257 except KeyError: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1258 self.error('not displaying %s' % arg) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1259 else: |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1260 self.displaying.pop(self.curframe, None) |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1261 |
|
66691
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1262 def do_interact(self, arg): |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1263 """interact |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1264 |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1265 Start an interative interpreter whose global namespace |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1266 contains all the (global and local) names found in the current scope. |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1267 """ |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1268 ns = self.curframe.f_globals.copy() |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1269 ns.update(self.curframe_locals) |
|
c2578a68879d
Add the "interact" pdb command from pdb++.
Georg Brandl <georg@python.org>
parents:
66543
diff
changeset
|
1270 code.interact("*interactive*", local=ns) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
1271 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1272 def do_alias(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1273 """alias [name [command [parameter parameter ...] ]] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1274 Create an alias called 'name' that executes 'command'. The |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1275 command must *not* be enclosed in quotes. Replaceable |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1276 parameters can be indicated by %1, %2, and so on, while %* is |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1277 replaced by all the parameters. If no command is given, the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1278 current alias for name is shown. If no name is given, all |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1279 aliases are listed. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1280 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1281 Aliases may be nested and can contain anything that can be |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1282 legally typed at the pdb prompt. Note! You *can* override |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1283 internal pdb commands with aliases! Those internal commands |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1284 are then hidden until the alias is removed. Aliasing is |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1285 recursively applied to the first word of the command line; all |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1286 other words in the line are left alone. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1287 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1288 As an example, here are two useful aliases (especially when |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1289 placed in the .pdbrc file): |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1290 |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1291 # Print instance variables (usage "pi classInst") |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1292 alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1293 # Print instance variables in self |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1294 alias ps pi self |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1295 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
1296 args = arg.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1297 if len(args) == 0: |
|
55908
0f6db002b3a1
Merged revisions 74741 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
55576
diff
changeset
|
1298 keys = sorted(self.aliases.keys()) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1299 for alias in keys: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1300 self.message("%s = %s" % (alias, self.aliases[alias])) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1301 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
|
1302 if args[0] in self.aliases and len(args) == 1: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1303 self.message("%s = %s" % (args[0], self.aliases[args[0]])) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1304 else: |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
1305 self.aliases[args[0]] = ' '.join(args[1:]) |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
1306 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1307 def do_unalias(self, arg): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1308 """unalias name |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1309 Delete the specified alias. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1310 """ |
|
16491
a4c6e401ee18
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16474
diff
changeset
|
1311 args = arg.split() |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1312 if len(args) == 0: return |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
23036
diff
changeset
|
1313 if args[0] in self.aliases: |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1314 del self.aliases[args[0]] |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
1315 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1316 # List of all the commands making the program resume execution. |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1317 commands_resuming = ['do_continue', 'do_step', 'do_next', 'do_return', |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
1318 'do_quit', 'do_jump'] |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1319 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1320 # Print a traceback starting at the top stack frame. |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1321 # The most recently entered frame is printed last; |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1322 # this is different from dbx and gdb, but consistent with |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1323 # the Python interpreter's stack trace. |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1324 # It is also consistent with the up/down commands (which are |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1325 # compatible with dbx and gdb: up moves towards 'main()' |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1326 # and down moves towards the most recent stack frame). |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1327 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1328 def print_stack_trace(self): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1329 try: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1330 for frame_lineno in self.stack: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1331 self.print_stack_entry(frame_lineno) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1332 except KeyboardInterrupt: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1333 pass |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1334 |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1335 def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1336 frame, lineno = frame_lineno |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1337 if frame is self.curframe: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1338 prefix = '> ' |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1339 else: |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1340 prefix = ' ' |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1341 self.message(prefix + |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1342 self.format_stack_entry(frame_lineno, prompt_prefix)) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
1343 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1344 # Provide help |
|
9091
556927d868d8
Richard Wolff's changes:
Guido van Rossum <guido@python.org>
parents:
8697
diff
changeset
|
1345 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1346 def do_help(self, arg): |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1347 """h(elp) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1348 Without argument, print the list of available commands. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1349 With a command name as argument, print help about that command. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1350 "help pdb" shows the full pdb documentation. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1351 "help exec" gives help on the ! command. |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1352 """ |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1353 if not arg: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1354 return cmd.Cmd.do_help(self, arg) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1355 try: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1356 try: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1357 topic = getattr(self, 'help_' + arg) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1358 return topic() |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1359 except AttributeError: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1360 command = getattr(self, 'do_' + arg) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1361 except AttributeError: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1362 self.error('No help for %r' % arg) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1363 else: |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1364 if sys.flags.optimize >= 2: |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1365 self.error('No help for %r; please do not run Python with -OO ' |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1366 'if you need command help' % arg) |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1367 return |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1368 self.message(command.__doc__.rstrip()) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
1369 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1370 do_h = do_help |
|
26061
9b5b7da362a5
Implement a `pp' command, which is like `p' except that it
Barry Warsaw <barry@python.org>
parents:
25195
diff
changeset
|
1371 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1372 def help_exec(self): |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1373 """(!) statement |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1374 Execute the (one-line) statement in the context of the current |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1375 stack frame. The exclamation point can be omitted unless the |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1376 first word of the statement resembles a debugger command. To |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1377 assign to a global variable you must always prefix the command |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1378 with a 'global' command, e.g.: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1379 (Pdb) global list_options; list_options = ['-l'] |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1380 (Pdb) |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1381 """ |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1382 self.message((self.help_exec.__doc__ or '').strip()) |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
37045
diff
changeset
|
1383 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1384 def help_pdb(self): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1385 help() |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
1386 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1387 # other helper functions |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1388 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1389 def lookupmodule(self, filename): |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1390 """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
|
1391 |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1392 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
|
1393 into an absolute file name. |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1394 """ |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1395 if os.path.isabs(filename) and os.path.exists(filename): |
|
33731
53c468d0955b
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
33728
diff
changeset
|
1396 return filename |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1397 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
|
1398 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
|
1399 return f |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1400 root, ext = os.path.splitext(filename) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1401 if ext == '': |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1402 filename = filename + '.py' |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1403 if os.path.isabs(filename): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1404 return filename |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1405 for dirname in sys.path: |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1406 while os.path.islink(dirname): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1407 dirname = os.readlink(dirname) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1408 fullname = os.path.join(dirname, filename) |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1409 if os.path.exists(fullname): |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1410 return fullname |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1411 return None |
|
8690
a0477bc820b2
Added support for specifying a filename for a breakpoint, roughly
Guido van Rossum <guido@python.org>
parents:
7485
diff
changeset
|
1412 |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1413 def _runscript(self, filename): |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1414 # The script has to run in __main__ namespace (or imports from |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1415 # __main__ will break). |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1416 # |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1417 # So we clear up the __main__ and set several special variables |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1418 # (this gets rid of pdb's globals and cleans old variables on restarts). |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1419 import __main__ |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1420 __main__.__dict__.clear() |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1421 __main__.__dict__.update({"__name__" : "__main__", |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1422 "__file__" : filename, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1423 "__builtins__": __builtins__, |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1424 }) |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1425 |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1426 # 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
|
1427 # 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
|
1428 # 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
|
1429 # 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
|
1430 # user_call for details). |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
1431 self._wait_for_mainpyfile = True |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1432 self.mainpyfile = self.canonic(filename) |
|
66543
e7392ffee071
Use booleans where applicable.
Georg Brandl <georg@python.org>
parents:
66537
diff
changeset
|
1433 self._user_requested_quit = False |
|
55576
4a1ab2d70385
Merged revisions 74366 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55182
diff
changeset
|
1434 with open(filename, "rb") as fp: |
|
4a1ab2d70385
Merged revisions 74366 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55182
diff
changeset
|
1435 statement = "exec(compile(%r, %r, 'exec'))" % \ |
|
4a1ab2d70385
Merged revisions 74366 via svnmerge from
Georg Brandl <georg@python.org>
parents:
55182
diff
changeset
|
1436 (fp.read(), self.mainpyfile) |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1437 self.run(statement) |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1438 |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1439 # Collect all command help into docstring, if not run with -OO |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1440 |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1441 if __doc__ is not None: |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1442 # unfortunately we can't guess this order from the class definition |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1443 _help_order = [ |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1444 'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable', |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1445 'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until', |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1446 'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist', |
|
66713
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1447 'args', 'print', 'pp', 'whatis', 'source', 'display', 'undisplay', |
|
0fd6ae0a8567
Add display/undisplay pdb commands.
Georg Brandl <georg@python.org>
parents:
66711
diff
changeset
|
1448 'interact', 'alias', 'unalias', 'debug', 'quit', |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1449 ] |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1450 |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1451 for _command in _help_order: |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1452 __doc__ += getattr(Pdb, 'do_' + _command).__doc__.strip() + '\n\n' |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1453 __doc__ += Pdb.help_exec.__doc__ |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1454 |
|
65292
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1455 del _help_order, _command |
|
6ab0f9219660
#9964: fix pdb failure to import under -OO. Warn the user that help is simply not available in this case.
Georg Brandl <georg@python.org>
parents:
64405
diff
changeset
|
1456 |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1457 |
|
1041
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1458 # Simplified interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1459 |
|
2437
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
1460 def run(statement, globals=None, locals=None): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1461 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
|
1462 |
|
62ebbcfea827
handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents:
2280
diff
changeset
|
1463 def runeval(expression, globals=None, locals=None): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1464 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
|
1465 |
|
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
1466 def runctx(statement, globals, locals): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1467 # B/W compatibility |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1468 run(statement, globals, locals) |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
1469 |
|
33823
db8710f13650
SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents:
33731
diff
changeset
|
1470 def runcall(*args, **kwds): |
|
db8710f13650
SF bug #1052503: pdb runcall should accept keyword arguments
Raymond Hettinger <python@rcn.com>
parents:
33731
diff
changeset
|
1471 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
|
1472 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1435
diff
changeset
|
1473 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
|
1474 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
|
1475 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1476 # Post-Mortem interface |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1477 |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1478 def post_mortem(t=None): |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1479 # handling the default |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1480 if t is None: |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1481 # sys.exc_info() returns (type, value, traceback) if an exception is |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1482 # being handled, otherwise it returns None |
|
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1483 t = sys.exc_info()[2] |
|
63328
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1484 if t is None: |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1485 raise ValueError("A valid traceback must be passed if no " |
|
2c9a8e6112b3
Several enhancements to pdb and its test suite.
Georg Brandl <georg@python.org>
parents:
63318
diff
changeset
|
1486 "exception is being handled") |
|
45773
832c820e9d14
Merged revisions 61239-61249,61252-61257,61260-61264,61269-61275,61278-61279,61285-61286,61288-61290,61298,61303-61305,61312-61314,61317,61329,61332,61344,61350-61351,61363-61376,61378-61379,61382-61383,61387-61388,61392,61395-61396,61402-61403 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44742
diff
changeset
|
1487 |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1488 p = Pdb() |
|
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1489 p.reset() |
|
49587
f66688e69f66
Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47088
diff
changeset
|
1490 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
|
1491 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1492 def pm(): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1493 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
|
1494 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1495 |
|
3dac204b74fa
Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents:
1006
diff
changeset
|
1496 # 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
|
1497 |
|
649
da5b1433467c
Rewritten to use bdb.Bdb as base class.
Guido van Rossum <guido@python.org>
parents:
601
diff
changeset
|
1498 TESTCMD = 'import x; x.main()' |
|
600
d49b6a6725bd
Moved documentation out to pdb.doc file.
Guido van Rossum <guido@python.org>
parents:
583
diff
changeset
|
1499 |
| 566 | 1500 def test(): |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1501 run(TESTCMD) |
|
1357
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
1502 |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
1503 # print help |
|
2fac209e1c3f
* profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents:
1331
diff
changeset
|
1504 def help(): |
|
63073
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
1505 import pydoc |
|
978683fde820
#9279: remove the pdb.doc file, put its contents in pdb.__doc__. Also sync this and the pdb docs, introduce a new directive for pdb commands and a role to link to them.
Georg Brandl <georg@python.org>
parents:
62531
diff
changeset
|
1506 pydoc.pager(__doc__) |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
1507 |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1508 _usage = """\ |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1509 usage: pdb.py [-c command] ... pyfile [arg] ... |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1510 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1511 Debug the Python program given by pyfile. |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1512 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1513 Initial commands are read from .pdbrc files in your home directory |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1514 and in the current directory, if they exist. Commands supplied with |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1515 -c are executed after commands from .pdbrc files. |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1516 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1517 To let the script run until an exception occurs, use "-c continue". |
|
63307
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
1518 To let the script run up to a given line X in the debugged file, use |
|
48557db0eeea
Allow giving an explicit line number to "until".
Georg Brandl <georg@python.org>
parents:
63306
diff
changeset
|
1519 "-c 'until X'".""" |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
1520 |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1521 def main(): |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1522 import getopt |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1523 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1524 opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['--help', '--command=']) |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1525 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1526 if not args: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1527 print(_usage) |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1528 sys.exit(2) |
|
3822
db4ea3abf891
Two changes suggested by Andrew Kuchling:
Guido van Rossum <guido@python.org>
parents:
2922
diff
changeset
|
1529 |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1530 commands = [] |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1531 for opt, optarg in opts: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1532 if opt in ['-h', '--help']: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1533 print(_usage) |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1534 sys.exit() |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1535 elif opt in ['-c', '--command']: |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1536 commands.append(optarg) |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1537 |
|
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1538 mainpyfile = args[0] # Get script filename |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1539 if not os.path.exists(mainpyfile): |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1540 print('Error:', mainpyfile, 'does not exist') |
|
15870
010d03853546
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
15866
diff
changeset
|
1541 sys.exit(1) |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1542 |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1543 sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list |
|
4262
67d258edd3d9
Correct sys.path[0] when used stand-alone
Guido van Rossum <guido@python.org>
parents:
3822
diff
changeset
|
1544 |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1545 # 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
|
1546 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
|
1547 |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1548 # 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
|
1549 # modified by the script being debugged. It's a bad idea when it was |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
1550 # changed by the user from the command line. There is a "restart" command |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
1551 # which allows explicit specification of command line arguments. |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1552 pdb = Pdb() |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1553 pdb.rcLines.extend(commands) |
|
63453
4903e7577454
Merged revisions 83259,83261,83264-83265,83268-83269,83271-83272,83281 via svnmerge from
Georg Brandl <georg@python.org>
parents:
56888
diff
changeset
|
1554 while True: |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1555 try: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1556 pdb._runscript(mainpyfile) |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1557 if pdb._user_requested_quit: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1558 break |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1559 print("The program finished and will be restarted") |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1560 except Restart: |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1561 print("Restarting", mainpyfile, "with arguments:") |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1562 print("\t" + " ".join(args)) |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1563 except SystemExit: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1564 # In most cases SystemExit does not warrant a post-mortem session. |
|
63306
0f6a1e476d31
#1437051: allow "continue"/"next"/etc. in .pdbrc, also add pdb -c option to give these commands. This allows to run a script until an exception occurs.
Georg Brandl <georg@python.org>
parents:
63305
diff
changeset
|
1565 print("The program exited via sys.exit(). Exit status:", end=' ') |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1566 print(sys.exc_info()[1]) |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1567 except: |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1568 traceback.print_exc() |
|
40775
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1569 print("Uncaught exception. Entering post mortem debugging") |
|
4cdf21a0dbbc
Fix most trivially-findable print statements.
Guido van Rossum <guido@python.org>
parents:
40737
diff
changeset
|
1570 print("Running 'cont' or 'step' will restart the program") |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1571 t = sys.exc_info()[2] |
|
49587
f66688e69f66
Merged revisions 66974,66977,66984,66989,66992,66994-66996,66998-67000,67007,67015 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
47088
diff
changeset
|
1572 pdb.interaction(None, t) |
|
53779
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
1573 print("Post mortem debugger finished. The " + mainpyfile + |
|
58aa0ad77253
Merged revisions 72324 via svnmerge from
Georg Brandl <georg@python.org>
parents:
53777
diff
changeset
|
1574 " will be restarted") |
|
33728
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1575 |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1576 |
|
a01be350ed61
Improvements when running pdb as a script.
Johannes Gijsbers <jlg@dds.nl>
parents:
33334
diff
changeset
|
1577 # When invoked as main program, invoke the debugger on a script |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1578 if __name__ == '__main__': |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1579 import pdb |
|
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
40910
diff
changeset
|
1580 pdb.main() |
