|
| 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 |
0 commit comments