[Lldb-commits] [lldb] r300902 - Add an example command to toggle between disassembly-only and source mode.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 21 10:40:36 PDT 2017


This was the first time I'd used Enrico's class-based command interface.  It is much handier than the one-at-a time way of doing things.

We need to figure out a better way to package up and advertise these commands.  It would be nice to have a way for the broader community to be able to contribute their little niceties like this.  But I think we need to hook into some package manager that you could query what's available and add it selectively.  I don't want to just slam everything into the default command set that you see when you start lldb, that will make it more difficult to figure out how to do ordinary things.

Jim

> On Apr 21, 2017, at 1:32 AM, Pavel Labath <labath at google.com> wrote:
> 
> This is cool, I just did some assembly debugging yesterday, and wished it was easier :)
> 
> On 20 April 2017 at 22:51, Jim Ingham via lldb-commits <lldb-commits at lists.llvm.org> wrote:
> Author: jingham
> Date: Thu Apr 20 16:51:27 2017
> New Revision: 300902
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=300902&view=rev
> Log:
> Add an example command to toggle between disassembly-only and source mode.
> 
> Sometimes you are debugging in source, but you really only want to see
> the disassembly.  That's easy to do but you have to set a few variables.
> This command toggles between your old values, and a disassembly only mode.
> 
> Added:
>     lldb/trunk/examples/python/disassembly_mode.py
> 
> Added: lldb/trunk/examples/python/disassembly_mode.py
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/examples/python/disassembly_mode.py?rev=300902&view=auto
> ==============================================================================
> --- lldb/trunk/examples/python/disassembly_mode.py (added)
> +++ lldb/trunk/examples/python/disassembly_mode.py Thu Apr 20 16:51:27 2017
> @@ -0,0 +1,48 @@
> +""" Adds the 'toggle-disassembly' command to switch you into a disassembly only mode """
> +import lldb
> +
> +class DisassemblyMode:
> +    def __init__(self, debugger, unused):
> +        self.dbg = debugger
> +        self.interp = debugger.GetCommandInterpreter()
> +        self.store_state()
> +        self.mode_off = True
> +
> +    def store_state(self):
> +        self.dis_count = self.get_string_value("stop-disassembly-count")
> +        self.dis_display = self.get_string_value("stop-disassembly-display")
> +        self.before_count = self.get_string_value("stop-line-count-before")
> +        self.after_count = self.get_string_value("stop-line-count-after")
> +
> +    def get_string_value(self, setting):
> +        result = lldb.SBCommandReturnObject()
> +        self.interp.HandleCommand("settings show " + setting, result)
> +        value = result.GetOutput().split(" = ")[1].rstrip("\n")
> +        return value
> +
> +    def set_value(self, setting, value):
> +        result = lldb.SBCommandReturnObject()
> +        self.interp.HandleCommand("settings set " + setting + " " + value, result)
> +
> +    def __call__(self, debugger, command, exe_ctx, result):
> +        if self.mode_off:
> +            self.mode_off = False
> +            self.store_state()
> +            self.set_value("stop-disassembly-display","always")
> +            self.set_value("stop-disassembly-count", "8")
> +            self.set_value("stop-line-count-before", "0")
> +            self.set_value("stop-line-count-after", "0")
> +            result.AppendMessage("Disassembly mode on.")
> +        else:
> +            self.mode_off = True
> +            self.set_value("stop-disassembly-display",self.dis_display)
> +            self.set_value("stop-disassembly-count", self.dis_count)
> +            self.set_value("stop-line-count-before", self.before_count)
> +            self.set_value("stop-line-count-after", self.after_count)
> +            result.AppendMessage("Disassembly mode off.")
> +
> +    def get_short_help(self):
> +        return "Toggles between a disassembly only mode and normal source mode\n"
> +
> +def __lldb_init_module(debugger, unused):
> +    debugger.HandleCommand("command script add -c disassembly_mode.DisassemblyMode toggle-disassembly")
> 
> 
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
> 



More information about the lldb-commits mailing list