Skip to content

Commit 9206c5d

Browse files
committed
Add set/show autodisasm
1 parent ad202b0 commit 9206c5d

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

trepan/lib/default.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
# Format style to use in showing disassembly
5959
"disasmflavor": "extended",
6060

61+
# Run 'disassemble' command every time we enter the debugger?
62+
"autodisasm": False,
63+
6164
# Eval as Python the unrecognized debugger commands?
6265
"autoeval": True,
6366

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2026 Rocky Bernstein
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# Our local modules
18+
from trepan.processor.command.base_subcmd import DebuggerSetBoolSubcommand
19+
from trepan.processor.cmdfns import run_set_bool, run_show_bool
20+
21+
22+
class SetAutoDisasm(DebuggerSetBoolSubcommand):
23+
"""**set autodisasm** [ **on** | **off** ]
24+
25+
Run the `disasm` command every time we enter the debugger.
26+
27+
See also:
28+
---------
29+
30+
`show autodisasm`"""
31+
32+
in_list = True
33+
min_abbrev = len("autod")
34+
35+
list_cmd = None
36+
37+
def run(self, args):
38+
run_set_bool(self, args)
39+
if self.settings["autodisasm"]:
40+
if self.list_cmd is None:
41+
self.list_cmd = self.proc.commands["disassemble"].run
42+
pass
43+
self.proc.add_preloop_hook(self.run_list, 0)
44+
45+
else:
46+
self.proc.remove_preloop_hook(self.run_list)
47+
pass
48+
run_show_bool(self, "Show `disasm` on debugger entry")
49+
return
50+
51+
def run_list(self, args):
52+
# Check if there is a "file" to show. Right now we just
53+
# handle the case of a string.
54+
# FIXME: generalize this so for other kinds of missing "files"
55+
# are not shown.
56+
self.list_cmd(["disasm"])
57+
return
58+
59+
pass
60+
61+
62+
if __name__ == "__main__":
63+
from trepan.processor.command.show_subcmd.__demo_helper__ import demo_run
64+
65+
demo_run(SetAutoDisasm)
66+
pass
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright (C) 2026 Rocky Bernstein
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# Our local modules
18+
from trepan.processor.command.base_subcmd import DebuggerShowBoolSubcommand
19+
20+
21+
class ShowAutoDisasm(DebuggerShowBoolSubcommand):
22+
"""**show autodisasm**
23+
24+
Show debugger `list` command automatically on entry.
25+
26+
See also:
27+
---------
28+
29+
`set autolist`"""
30+
31+
min_abbrev = len("autod")
32+
short_help = "Show `disassemble` on debugger entry"
33+
pass
34+
35+
36+
if __name__ == "__main__":
37+
from trepan.processor.command.show_subcmd.__demo_helper__ import demo_run
38+
39+
demo_run(ShowAutoDisasm)
40+
pass

0 commit comments

Comments
 (0)