diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2012-11-19 15:35:45 +0100 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2012-11-19 15:36:14 +0100 |
commit | 3c29f50292a7f185508f0069f3b4b836b672ffff (patch) | |
tree | ea0e42fbb73f9c341d8ab17b00ce15fd2820a3c8 | |
download | gdb-bt-reformat-3c29f50292a7f185508f0069f3b4b836b672ffff.tar.gz gdb-bt-reformat-3c29f50292a7f185508f0069f3b4b836b672ffff.tar.xz gdb-bt-reformat-3c29f50292a7f185508f0069f3b4b836b672ffff.zip |
No more pain with backtraces in bugzilla.
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-x | gdb-bt-reformat | 43 |
1 files changed, 43 insertions, 0 deletions
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 <jpokorny at redhat dot com>" +__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<init>^\#[0-9]+\s+)'\ + '(?:(?P<hex>%(DEF_HEX)s) in )?'\ + '(?P<where>%(DEF_IDENT)s(?:(?: |::)%(DEF_IDENT)s)*)'\ + ' (?P<args>[(](?:(?<=[( ])%(DEF_IDENT)s=(?:%(DEF_IDENT)s|%(DEF_MSG)s|%(DEF_HEX)s)(?:, )?)*[)])'\ + ' at (?P<path>%(DEF_PATH)s):(?P<line>[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() |