Created
December 22, 2016 11:10
-
-
Save moshev/75e437431e77f1a01743fa7c5905be6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vim: ft=gdb | |
add-auto-load-safe-path /home/moshev/Projects/tools/moshev/gdb | |
set non-stop on | |
set print address on | |
set print array on | |
set pagination on | |
set print pretty on | |
set print object on | |
set print vtbl on | |
set breakpoint pending on | |
set logging overwrite on | |
set logging off | |
python | |
import gdb | |
import subprocess | |
class AttachOnClick(gdb.Command): | |
def __init__(self): | |
super(AttachOnClick, self).__init__('attach_onclick', gdb.COMMAND_RUNNING, gdb.COMPLETE_NONE) | |
def invoke(self, arg, from_tty): | |
if not from_tty: | |
print('Only supported in interactive mode (from tty)') | |
return | |
if arg: | |
print('No arguments supported') | |
return | |
xprop = subprocess.Popen(['xprop'], stdout=subprocess.PIPE) | |
awk = subprocess.Popen(['awk', '/^_NET_WM_PID/{print $3}'], stdin=xprop.stdout, stdout=subprocess.PIPE) | |
xprop.stdout.close() | |
try: | |
bpid = awk.communicate(timeout=60)[0] | |
except subprocess.TimeoutExpired: | |
print('No click within 60 seconds, giving up') | |
xprop.terminate() | |
awk.terminate() | |
awk.wait(1) | |
xprop.wait(1) | |
return | |
awk.wait(1) | |
xprop.wait(1) | |
spid = bpid.decode('ASCII').strip() | |
if not spid: | |
print('No pid could be obtained') | |
return | |
cmd = 'attach ' + spid | |
gdb.execute(cmd, True) | |
AttachOnClick() | |
end | |
source /home/moshev/Projects/tools/moshev/gdb/vraypp.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- python2 -*- | |
# coding=utf-8 | |
# Functions to pretty-print certain kinds of values in gdb | |
import gdb.printing | |
import functools | |
from functools import partial | |
import itertools | |
from itertools import starmap | |
import operator | |
from operator import getitem | |
class VUtilsColorPrinter(object): | |
'''Print a VUtils::Color''' | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
return 'VUtils::Color (%f %f %f)' % (self.val['r'], self.val['g'], self.val['b']) | |
class VectorPrinter(object): | |
'''Print a Vector-like''' | |
def __init__(self, tag, elts, val): | |
self.tag = tag | |
self.elts = elts | |
self.val = val | |
self.fmtstr = '%s (' + ' '.join(['%f'] * len(elts)) + ')' | |
def to_string(self): | |
return self.fmtstr % ((self.tag,) + | |
tuple (self.val[e] for e in self.elts)) | |
class VUtilsMatrixPrinter(object): | |
'''Print a VUtils::Matrix''' | |
def __init__(self, tag, val): | |
self.tag = tag | |
self.val = val | |
def to_string(self): | |
f = self.val['f'] | |
return ( | |
'%s' | |
'\n⎛% 12g % 12g % 12g⎞' | |
'\n⎜% 12g % 12g % 12g⎟' | |
'\n⎝% 12g % 12g % 12g⎠' | |
) % ( | |
self.tag, | |
f[0]['x'], f[1]['x'], f[2]['x'], | |
f[0]['y'], f[1]['y'], f[2]['y'], | |
f[0]['z'], f[1]['z'], f[2]['z'], | |
) | |
class VUtilsCharStringPrinter(object): | |
'''Print a VUtils::CharString''' | |
def __init__(self, val): | |
self.val = val | |
def to_string(self): | |
buf = self.val['buf'] | |
def build_pretty_printer(): | |
pp = gdb.printing.RegexpCollectionPrettyPrinter("vray") | |
pp.add_printer('Vector', '^VUtils::Vector$', | |
partial(VectorPrinter, 'VUtils::Vector', 'xyz')) | |
pp.add_printer('TracePoint', '^VUtils::TracePoint$', | |
partial(VectorPrinter, 'VUtils::TracePoint', 'xyz')) | |
pp.add_printer('Color', '^VUtils::Color$', | |
partial(VectorPrinter, 'VUtils::Color', 'rgb')) | |
pp.add_printer('Matrix', '^VUtils::Matrix$', | |
partial(VUtilsMatrixPrinter, 'VUtils::Matrix')) | |
return pp | |
gdb.printing.register_pretty_printer(gdb.current_objfile(), build_pretty_printer()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment