From 3c29f50292a7f185508f0069f3b4b836b672ffff Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Mon, 19 Nov 2012 15:35:45 +0100 Subject: No more pain with backtraces in bugzilla. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- gdb-bt-reformat | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 gdb-bt-reformat diff --git a/gdb-bt-reformat b/gdb-bt-reformat new file mode 100755 index 0000000..6b3fb84 --- /dev/null +++ b/gdb-bt-reformat @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +__author__ = "Jan Pokorny " +__license__ = "GPLv2" + +from sys import stdin, stderr +import re +import textwrap + +DEF_IDENT = '[A-Za-z_][A-Za-z0-9_]*' +DEF_HEX = '0x[0-9A-Za-z]+' +DEF_MSG = '[<][ A-Za-z0-9_]+[>]' +DEF_PATH = '[A-Za-z0-9._/]+' +RE_BT = re.compile(\ + '(?P^\#[0-9]+\s+)'\ + '(?:(?P%(DEF_HEX)s) in )?'\ + '(?P%(DEF_IDENT)s(?:(?: |::)%(DEF_IDENT)s)*)'\ + ' (?P[(](?:(?<=[( ])%(DEF_IDENT)s=(?:%(DEF_IDENT)s|%(DEF_MSG)s|%(DEF_HEX)s)(?:, )?)*[)])'\ + ' at (?P%(DEF_PATH)s):(?P[1-9][0-9]*)' + % locals()) + + +def main(): + space = None + line = '__init__' + while line: + line = stdin.readline() + found = RE_BT.search(line) + if found: + found = found.groupdict() + if not space: + space = '\n' + ' ' * len(found['init']) + args = textwrap.wrap(found['args'], subsequent_indent=space[1:]) + res = found['init'] + found['where'] + res += (args[0] == '()' and '()' or space + '\n'.join(args)) + res += space + 'at ' + found['path'] + ':' + found['line'] + '\n' + print res + else: + space = None + print >>stderr, "bad line:", line + +if __name__ == '__main__': + main() -- cgit