Skip to content

Commit 19e0759

Browse files
committed
"info lines" filters by name now
Add RsT documentation for "info lines" Blacken some buffers
1 parent 6367796 commit 19e0759

6 files changed

Lines changed: 130 additions & 67 deletions

File tree

docs/commands/info.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Type `info` for a list of info subcommands and what they do. Type help
2323
info/frame
2424
info/globals
2525
info/line
26+
info/lines
2627
info/locals
2728
info/macro
2829
info/pc

docs/commands/info/lines.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. index:: info; lines
2+
.. _info_lines:
3+
4+
Info Lines
5+
-----------
6+
7+
**info lines** [**-n** *function-or-module*]
8+
9+
Show line - function/offset information.
10+
Use **-n** *function-or-module* to filter results.
11+
12+
13+
Examples
14+
++++++++
15+
16+
::
17+
18+
(trepan3k) info lines
19+
Line - (fn, start offset) table for test/example/gcd.py
20+
10: <module> @0 21: check_args() @84 36: gcd() @30
21+
11: <module> @4 22: check_args() @106 37: gcd() @50
22+
13: <module> @12 23: check_args() @116 38: gcd() @54
23+
14: check_args() @0 24: check_args() @122 40: <module> @28
24+
16: check_args() @14 26: <module> @20 41: <module> @36
25+
17: check_args() @22 30: gcd() @0 43: <module> @42
26+
18: check_args() @36 31: gcd() @8 44: <module> @60
27+
19: check_args() @38 34: gcd() @18 45: <module> @84
28+
20: check_args() @70 35: gcd() @26
29+
(trepan3k) info lines -n <module>
30+
10: <module> @0 11: <module> @4 13: <module> @12
31+
40: <module> @28 26: <module> @20 41: <module> @36
32+
43: <module> @42 44: <module> @60 45: <module> @84
33+
(trepan3k) info lines -n gcd
34+
30: gcd() @0 31: gcd() @8 34: gcd() @18
35+
35: gcd() @26 36: gcd() @30 37: gcd() @50
36+
38: gcd() @54
37+
38+
.. seealso::
39+
40+
:ref:`info program <info_line>`, :ref:`info program <info_program>`, :ref:`info pc <info_pc>`, :ref:`info frame <info_frame>`

trepan/lib/format.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -229,57 +229,51 @@ def reflow_text(self, text, ttype, color):
229229
self.write_nl()
230230
self.last_was_nl = True
231231
return
232-
elif self.verbatim == "colon-verbatim" and ttype == Token.Text and text == "\n":
232+
elif self.verbatim == 'colon-verbatim' and ttype == Token.Text and text == '\n':
233233
self.write_nl()
234234
self.last_was_nl = False
235235
return
236236
last_last_nl = self.last_was_nl
237-
if text == "":
237+
if text == '':
238238
pass
239-
elif text[-1] == "\n":
239+
elif text[-1] == '\n':
240240
if self.last_was_nl:
241241
self.write_nl()
242242
self.write_nl()
243243
text = text[:-1]
244244
elif self.verbatim:
245245
self.write_verbatim(text)
246246
self.column = 0
247-
self.verbatim = len(text) >= 2 and text[-2] == "\n"
247+
self.verbatim = len(text) >=2 and text[-2] == '\n'
248248
self.last_was_nl = True
249249
return
250250
else:
251-
self.write(" ", color)
251+
self.write(' ', color)
252252
text = text[:-1]
253253
pass
254254
self.last_was_nl = True
255-
if "" == text:
256-
return
257-
while text[-1] == "\n":
255+
if '' == text: return
256+
while text[-1] == '\n':
258257
self.write_nl()
259258
text = text[:-1]
260-
if "" == text:
261-
return
259+
if '' == text: return
262260
pass
263261
pass
264262
else:
265263
self.last_was_nl = False
266264
pass
267265
self.in_list = False
268266
if last_last_nl:
269-
if " * " == text[0:3]:
270-
self.in_list = True
271-
elif " " == text[0:2]:
272-
self.verbatim = self.verbatim or True
267+
if ' * ' == text[0:3]: self.in_list = True
268+
elif ' ' == text[0:2]: self.verbatim = self.verbatim or True
273269
pass
274270

275271
# FIXME: there may be nested lists, tables and so on.
276272
if self.verbatim:
277273
self.write_verbatim(text)
278274
elif self.in_list:
279275
# FIXME:
280-
self.write(
281-
text, color,
282-
)
276+
self.write(text, color,)
283277
else:
284278
words = re.compile("[ \t]+").split(text)
285279
for word in words[:-1]:

trepan/processor/command/base_cmd.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727

2828
from trepan.lib import format as Mformat
2929

30-
__all__ = ['DebuggerCommand']
30+
__all__ = ["DebuggerCommand"]
3131

3232

3333
class DebuggerCommand:
3434
"""Base Class for Debugger commands. We pull in some helper
3535
functions for command from module cmdfns."""
3636

37-
category = 'misc'
37+
category = "misc"
3838

3939
@staticmethod
40-
def setup(l, category="misc", min_args=0, max_args=None,
41-
need_stack=False):
42-
l["name"] =l["__module__"].split(".")[-1]
40+
def setup(l, category="misc", min_args=0, max_args=None, need_stack=False):
41+
l["name"] = l["__module__"].split(".")[-1]
4342
l["category"] = category
4443
l["min_args"] = min_args
4544
l["max_args"] = max_args
@@ -57,20 +56,19 @@ def __init__(self, proc):
5756
# execution like errmsg(), msg(), and msg_nocr() might. (See
5857
# the note below on these latter 3 methods.)
5958
#
60-
self.core = proc.core
59+
self.core = proc.core
6160
self.debugger = proc.debugger
6261
self.settings = self.debugger.settings
6362
return
6463

6564
aliases = ()
66-
name = 'YourCommandName'
65+
name = "YourCommandName"
6766

6867
def columnize_commands(self, commands):
6968
"""List commands arranged in an aligned columns"""
7069
commands.sort()
71-
width = self.debugger.settings['width']
72-
return columnize.columnize(commands, displaywidth=width,
73-
lineprefix=' ')
70+
width = self.debugger.settings["width"]
71+
return columnize.columnize(commands, displaywidth=width, lineprefix=" ")
7472

7573
def confirm(self, msg, default=False):
7674
""" Convenience short-hand for self.debugger.intf[-1].confirm """
@@ -85,7 +83,7 @@ def confirm(self, msg, default=False):
8583
def errmsg(self, msg, opts={}):
8684
""" Convenience short-hand for self.debugger.intf[-1].errmsg """
8785
try:
88-
return(self.debugger.intf[-1].errmsg(msg))
86+
return self.debugger.intf[-1].errmsg(msg)
8987
except EOFError:
9088
# FIXME: what do we do here?
9189
pass
@@ -94,7 +92,7 @@ def errmsg(self, msg, opts={}):
9492
def msg(self, msg, opts={}):
9593
""" Convenience short-hand for self.debugger.intf[-1].msg """
9694
try:
97-
return(self.debugger.intf[-1].msg(msg))
95+
return self.debugger.intf[-1].msg(msg)
9896
except EOFError:
9997
# FIXME: what do we do here?
10098
pass
@@ -103,17 +101,19 @@ def msg(self, msg, opts={}):
103101
def msg_nocr(self, msg, opts={}):
104102
""" Convenience short-hand for self.debugger.intf[-1].msg_nocr """
105103
try:
106-
return(self.debugger.intf[-1].msg_nocr(msg))
104+
return self.debugger.intf[-1].msg_nocr(msg)
107105
except EOFError:
108106
# FIXME: what do we do here?
109107
pass
110108
return None
111109

112110
def rst_msg(self, text, opts={}):
113111
"""Convert ReStructuredText and run through msg()"""
114-
text = Mformat.rst_text(text,
115-
'plain' == self.debugger.settings['highlight'],
116-
self.debugger.settings['width'])
112+
text = Mformat.rst_text(
113+
text,
114+
"plain" == self.debugger.settings["highlight"],
115+
self.debugger.settings["width"],
116+
)
117117
return self.msg(text)
118118

119119
def run(self, args):
@@ -125,15 +125,17 @@ def run(self, args):
125125
pass
126126

127127
def section(self, message, opts={}):
128-
if 'plain' != self.settings['highlight']:
129-
message = colorize('bold', message)
128+
if "plain" != self.settings["highlight"]:
129+
message = colorize("bold", message)
130130
else:
131-
message += "\n" + '-' * len(message)
131+
message += "\n" + "-" * len(message)
132132
pass
133133
self.msg(message)
134134

135-
if __name__ == '__main__':
135+
136+
if __name__ == "__main__":
136137
from trepan.processor.command import mock
138+
137139
d, cp = mock.dbg_setup()
138140
dd = DebuggerCommand(cp)
139141
dd.msg("hi")

trepan/processor/command/condition.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import os
18-
1917
from trepan.processor.command.base_cmd import DebuggerCommand
2018
from trepan.processor.complete import complete_bpnumber
2119

trepan/processor/command/info_subcmd/lines.py

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@
1414
# You should have received a copy of the GNU General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
import sys
18+
from getopt import getopt, GetoptError
19+
1720
# Our local modules
1821
from trepan.processor.command.base_subcmd import DebuggerSubcommand
1922
from trepan.misc import pretty_modfunc_name
2023
from pyficache import cache_code_lines
2124

2225

2326
class InfoOffsets(DebuggerSubcommand):
24-
"""**info lines** [*function-file-or-module*]
25-
26-
Show line - function/offste information for a function, module, or a file.
27+
"""**info lines** [-n *function-or-module*]
2728
28-
If no location is given, use the the current frame.
29+
Show line - function/offset information
30+
Use -n *function-or-module* to filter results.
2931
30-
Example
31-
-------
32+
Examples
33+
--------
3234
3335
(trepan3k) info lines
3436
Line - (fn, start offset) table for test/example/gcd.py
@@ -41,6 +43,14 @@ class InfoOffsets(DebuggerSubcommand):
4143
18: check_args() @36 31: gcd() @8 44: <module> @60
4244
19: check_args() @38 34: gcd() @18 45: <module> @84
4345
20: check_args() @70 35: gcd() @26
46+
(trepan3k) info lines -n <module>
47+
10: <module> @0 11: <module> @4 13: <module> @12
48+
40: <module> @28 26: <module> @20 41: <module> @36
49+
43: <module> @42 44: <module> @60 45: <module> @84
50+
(trepan3k) info lines -n gcd
51+
30: gcd() @0 31: gcd() @8 34: gcd() @18
52+
35: gcd() @26 36: gcd() @30 37: gcd() @50
53+
38: gcd() @54
4454
4555
See also:
4656
---------
@@ -54,42 +64,60 @@ class InfoOffsets(DebuggerSubcommand):
5464
def run(self, args):
5565
"""Current line number in source file"""
5666
# info line <loc>
57-
if len(args) == 0:
58-
curframe = self.proc.curframe
59-
if not curframe:
60-
self.errmsg("No line number information available.")
67+
try:
68+
opts, args = getopt(args, "hn:", ["help", "name"],)
69+
except GetoptError:
70+
# print help information and exit:
71+
self.errmsg(
72+
str(sys.exc_info()[1])
73+
) # will print something like "option -a not recognized"
74+
return
75+
76+
name = None
77+
for o, a in opts:
78+
if o in ("-h", "--help"):
79+
self.proc.commands["help"].run(["help", "info", "lines"])
6180
return
81+
elif o in ("-n", "--name"):
82+
name = a
83+
else:
84+
self.errmsg("unhandled option '%s'" % o)
85+
pass
86+
pass
6287

63-
# No line number. Use current frame line number
64-
filename = curframe.f_code.co_filename
65-
file_info = cache_code_lines(
66-
filename, toplevel_only=False, include_offsets=True
67-
)
68-
if file_info:
69-
self.section("Line - (fn, start offset) table for %s" % filename)
70-
lines = []
71-
for line_number, line_info in file_info.line_numbers.items():
88+
curframe = self.proc.curframe
89+
if not curframe:
90+
self.errmsg("No line number information available.")
91+
return
92+
93+
# No line number. Use current frame line number
94+
filename = curframe.f_code.co_filename
95+
file_info = cache_code_lines(
96+
filename, toplevel_only=False, include_offsets=True
97+
)
98+
if file_info:
99+
self.section("Line - (fn, start offset) table for %s" % filename)
100+
lines = []
101+
for line_number, line_info in file_info.line_numbers.items():
102+
if not name or any(li.name == name for li in line_info):
72103
lines.append(
73104
"%4d: %s"
74105
% (
75106
line_number,
76107
", ".join(
77108
[
78109
"%s @%d" % (pretty_modfunc_name(li.name), li.offsets[0])
79-
for li in line_info
110+
for li in line_info if not name or li.name == name
80111
]
81112
),
82113
)
83114
)
84-
m = self.columnize_commands(list(sorted(lines)))
85-
self.msg(m)
86-
else:
87-
self.errmsg("haven't recorded info for offset file %s" % filename)
88-
pass
89-
pass
115+
m = self.columnize_commands(list(sorted(lines)))
116+
self.msg(m)
90117
else:
91-
self.errmsg("Passing a filename, function, or module not completed yet...")
92-
return
118+
self.errmsg("haven't recorded info for offset file %s" % filename)
119+
pass
120+
pass
93121

94122
pass
95123

0 commit comments

Comments
 (0)