diff options
author | David Malcolm <dmalcolm@redhat.com> | 2009-12-03 13:16:48 -0500 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2009-12-03 13:16:48 -0500 |
commit | a96cfb0a19b5c7b450d459f198442365a08f69ca (patch) | |
tree | b74c018b896212c9915de0c4fb206bf4c29c2d7c | |
parent | f1cfaa78d80f41800fab911442f20e0400576d1e (diff) | |
download | triage-a96cfb0a19b5c7b450d459f198442365a08f69ca.tar.gz triage-a96cfb0a19b5c7b450d459f198442365a08f69ca.tar.xz triage-a96cfb0a19b5c7b450d459f198442365a08f69ca.zip |
Move the various backtrace-parsing classes into a new file: backtrace.py
-rwxr-xr-x | abrt-triage.py | 81 | ||||
-rw-r--r-- | backtrace.py | 97 |
2 files changed, 98 insertions, 80 deletions
diff --git a/abrt-triage.py b/abrt-triage.py index 70e8279..86e3876 100755 --- a/abrt-triage.py +++ b/abrt-triage.py @@ -2,86 +2,7 @@ from pprint import pprint import re -class Frame(object): - def __init__(self, index, address, function, info): - self.index = index - self.address = address - self.function = function - self.info = info - -class Thread(object): - def __init__(self, index, pid): - self.index = index - self.pid = pid - self.frames = {} - self.framelist = [] - -class Backtrace(object): - def __init__(self, string): - debug = False - self._string = string - if debug: - print string - self._crash_site = None - self._thread = None - self._threads = {} - self._frame = None - for line in string.splitlines(): - if debug: - print repr(line) - m = re.match('^Thread ([0-9]+) \(Thread ([0-9]+)\):$', line) - if m: - if debug: - print 'THREAD START:', m.groups() - self._thread = Thread(int(m.group(1)), - int(m.group(2))) - self._threads[self._thread.index] = self._thread - self._frame = None - continue - - m = re.match('^#([0-9]+)\s+(?:0x([0-9a-f]+) in)? (\S+) (.*)$', line) - if m: - if debug: - print 'STACK FRAME:', m.groups() - #print m.groups() - if m.group(2): - address = int(m.group(2), 16) - else: - address = None - f = Frame(int(m.group(1)), - address, - m.group(3), - m.group(4)) - - if self._thread is None: - self._crash_site = f - self._frame = None - continue - else: - self._thread.frames[f.index] = f - self._thread.framelist.append(f) - self._frame = f - continue - - if line.startswith(' '): - if self._frame: - self._frame.info += '\n' + line - - #pprint(self._threads[5].frames[6].__dict__) - - def get_crash_site(self): - '''Get a (Thread, Frame) pair for where the crash happened (or None)''' - debug = False - if debug: - print self._crash_site.__dict__ - for t in self._threads.values(): - if debug: - print t - if 0 in t.frames: - if debug: - print t.frames[0].__dict__ - if t.frames[0].address == self._crash_site.address: - return (t, t.frames[0]) +from backtrace import Backtrace class Bug(object): def __init__(self, bz, id): diff --git a/backtrace.py b/backtrace.py new file mode 100644 index 0000000..8d33577 --- /dev/null +++ b/backtrace.py @@ -0,0 +1,97 @@ +''' +Support for parsing strings containing gdb backtraces, turning them into classes +''' +import re + +class Frame(object): + ''' + Class representing a stack frame of a thread within a backtrace + ''' + def __init__(self, index, address, function, info): + self.index = index + self.address = address + self.function = function + self.info = info + +class Thread(object): + ''' + Class representing a thread within a backtrace + ''' + def __init__(self, index, pid): + self.index = index + self.pid = pid + self.frames = {} + self.framelist = [] + +class Backtrace(object): + ''' + Class representing a parsed backtrace + ''' + def __init__(self, string): + ''' + Parse the given string (from gdb) + ''' + debug = False + self._string = string + if debug: + print string + self._crash_site = None + self._thread = None + self._threads = {} + self._frame = None + for line in string.splitlines(): + if debug: + print repr(line) + m = re.match('^Thread ([0-9]+) \(Thread ([0-9]+)\):$', line) + if m: + if debug: + print 'THREAD START:', m.groups() + self._thread = Thread(int(m.group(1)), + int(m.group(2))) + self._threads[self._thread.index] = self._thread + self._frame = None + continue + + m = re.match('^#([0-9]+)\s+(?:0x([0-9a-f]+) in)? (\S+) (.*)$', line) + if m: + if debug: + print 'STACK FRAME:', m.groups() + #print m.groups() + if m.group(2): + address = int(m.group(2), 16) + else: + address = None + f = Frame(int(m.group(1)), + address, + m.group(3), + m.group(4)) + + if self._thread is None: + self._crash_site = f + self._frame = None + continue + else: + self._thread.frames[f.index] = f + self._thread.framelist.append(f) + self._frame = f + continue + + if line.startswith(' '): + if self._frame: + self._frame.info += '\n' + line + + #pprint(self._threads[5].frames[6].__dict__) + + def get_crash_site(self): + '''Get a (Thread, Frame) pair for where the crash happened (or None)''' + debug = False + if debug: + print self._crash_site.__dict__ + for t in self._threads.values(): + if debug: + print t + if 0 in t.frames: + if debug: + print t.frames[0].__dict__ + if t.frames[0].address == self._crash_site.address: + return (t, t.frames[0]) |