llvm-project
52 строки · 2.1 Кб
1""" Adds the 'toggle-disassembly' command to switch you into a disassembly only mode """
2import lldb3
4
5class DisassemblyMode:6def __init__(self, debugger, unused):7self.dbg = debugger8self.interp = debugger.GetCommandInterpreter()9self.store_state()10self.mode_off = True11
12def store_state(self):13self.dis_count = self.get_string_value("stop-disassembly-count")14self.dis_display = self.get_string_value("stop-disassembly-display")15self.before_count = self.get_string_value("stop-line-count-before")16self.after_count = self.get_string_value("stop-line-count-after")17
18def get_string_value(self, setting):19result = lldb.SBCommandReturnObject()20self.interp.HandleCommand("settings show " + setting, result)21value = result.GetOutput().split(" = ")[1].rstrip("\n")22return value23
24def set_value(self, setting, value):25result = lldb.SBCommandReturnObject()26self.interp.HandleCommand("settings set " + setting + " " + value, result)27
28def __call__(self, debugger, command, exe_ctx, result):29if self.mode_off:30self.mode_off = False31self.store_state()32self.set_value("stop-disassembly-display", "always")33self.set_value("stop-disassembly-count", "8")34self.set_value("stop-line-count-before", "0")35self.set_value("stop-line-count-after", "0")36result.AppendMessage("Disassembly mode on.")37else:38self.mode_off = True39self.set_value("stop-disassembly-display", self.dis_display)40self.set_value("stop-disassembly-count", self.dis_count)41self.set_value("stop-line-count-before", self.before_count)42self.set_value("stop-line-count-after", self.after_count)43result.AppendMessage("Disassembly mode off.")44
45def get_short_help(self):46return "Toggles between a disassembly only mode and normal source mode\n"47
48
49def __lldb_init_module(debugger, unused):50debugger.HandleCommand(51"command script add -o -c disassembly_mode.DisassemblyMode toggle-disassembly"52)53