Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / examples / python / disassembly_mode.py
blob2cc2b5f3179f63863d493476d106f7db08cf6b1a
1 """ Adds the 'toggle-disassembly' command to switch you into a disassembly only mode """
2 import lldb
5 class DisassemblyMode:
6 def __init__(self, debugger, unused):
7 self.dbg = debugger
8 self.interp = debugger.GetCommandInterpreter()
9 self.store_state()
10 self.mode_off = True
12 def store_state(self):
13 self.dis_count = self.get_string_value("stop-disassembly-count")
14 self.dis_display = self.get_string_value("stop-disassembly-display")
15 self.before_count = self.get_string_value("stop-line-count-before")
16 self.after_count = self.get_string_value("stop-line-count-after")
18 def get_string_value(self, setting):
19 result = lldb.SBCommandReturnObject()
20 self.interp.HandleCommand("settings show " + setting, result)
21 value = result.GetOutput().split(" = ")[1].rstrip("\n")
22 return value
24 def set_value(self, setting, value):
25 result = lldb.SBCommandReturnObject()
26 self.interp.HandleCommand("settings set " + setting + " " + value, result)
28 def __call__(self, debugger, command, exe_ctx, result):
29 if self.mode_off:
30 self.mode_off = False
31 self.store_state()
32 self.set_value("stop-disassembly-display", "always")
33 self.set_value("stop-disassembly-count", "8")
34 self.set_value("stop-line-count-before", "0")
35 self.set_value("stop-line-count-after", "0")
36 result.AppendMessage("Disassembly mode on.")
37 else:
38 self.mode_off = True
39 self.set_value("stop-disassembly-display", self.dis_display)
40 self.set_value("stop-disassembly-count", self.dis_count)
41 self.set_value("stop-line-count-before", self.before_count)
42 self.set_value("stop-line-count-after", self.after_count)
43 result.AppendMessage("Disassembly mode off.")
45 def get_short_help(self):
46 return "Toggles between a disassembly only mode and normal source mode\n"
49 def __lldb_init_module(debugger, unused):
50 debugger.HandleCommand(
51 "command script add -o -c disassembly_mode.DisassemblyMode toggle-disassembly"