Thursday, May 26, 2011

GDB: Disassembly Syntax highlighting + CPP demangle

Here is a little GDB Skript, which enables syntax highlighting for disassemblings and demangles cpp-names:

shell mkfifo /tmp/colorPipe

define hook-disassemble
echo \n
shell cat /tmp/colorPipe | c++filt | highlight --syntax=asm -Oxterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end

define hookpost-disassemble
set logging off
set logging redirect off
shell sleep 0.1s
end

define hook-quit
shell rm /tmp/colorPipe
end


It uses highlight and c++filt and is based on Expermintal GDB syntax highlighting by Michael Kelleher

SessionManager for gdb

I had written today a simple SessionManager for GDB via GDB's Python-API
You need to place the following python lines in /usr/share/gdb/python/session.py
import os.path

def gettargetname():
    target = gdb.execute("info target", False, True).strip()
    target = target.splitlines()

    if len(target) > 2 and target[1].count("Local") > 0:
        name = target[2].strip().split(',')[0]
        name = os.path.basename(name.replace("`", "").replace("'", ""))
        return name
    return None


class SessionManager(gdb.Command):
    """Save and Loads gdb Sessions
    session save - saves session
    session load - loads session"""

    def __init__(self):
        super(SessionManager, self).__init__("session", gdb.COMMAND_SUPPORT)
        print "[+] Registered command 'session'"
    
    def save(self):
        name = gettargetname()
        breakpoints = gdb.breakpoints()
        if not breakpoints:
            return

        print "[*] write to %s.gdbsession" % name
        gdb.execute("save breakpoints %s.gdbsession" % name)
        print "done"


    def invoke(self, arg, from_tty):
        if arg == "save":
            self.save()
        elif arg == "load":
            name = gettargetname()
            gdb.execute("source %s.gdbsession" % name)
        else:
            print "Invalid argument. see 'help session' for details"
SessionManager()

Now you can add the following lines to your .gdbinit
source session.py
session load

define hook-quit
    session save
end
Have fun with automated breakpoint saving/loading :-)

Greetz,
bluec0re

Wednesday, April 20, 2011

How to git svn dcommit with uncommited changes

If you want to send your commits to a svn backend, you can do this with:

> git svn dcommit

Sometimes git ends with the error messge 'file.xy: needs update'. This happens if you have uncommited changes in your working directory. But often you won't commit these changes to the repository yet. A workaround would be the following:

> git stash
> git stash list # if you want to check the stashed changes
> git svn rebase # get the remote changes
> git svn dcommit
> git stash apply
> git stash drop # clean up the stash list if everything went fine
A shortcut for stash apply + stash drop also exists:
> git stash pop
I created a shortcut for this:
> git alias.svn-update '!git stash && git svn rebase && git stash pop'
> git svn-update