'''
Crash Information

Represents information about a crash. Specific subclasses implement
different crash data supported by the implementation.

@author:     Christian Holler (:decoder)

@license:

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

@contact:    choller@mozilla.com
'''

from abc import ABCMeta, abstractmethod

class CrashInfo():
    '''
    Abstract base class that provides a method to instantiate the right sub class.
    It also supports generating a CrashSignature based on the stored information.
    '''
    __metaclass__ = ABCMeta
    
    backtrace = []
    stdout = []
    stderr = []
    registers = {}
    crashAddress = None
    crashInstruction = None
    os = None
    product = None
    platform = None
    
    @staticmethod
    def fromRawCrashData(stdout, stderr, crashData=None, platform=None, product=None, os=None):
        if (crashData == None):
            pass
    
    def createCrashSignature(self, forceCrashAddress=False, forceCrashInstruction=False, numFrames=8):
        pass # TODO: Implement
    
    
class ASanCrashInfo(CrashInfo):
    def __init__(self, stdout, stderr, crashData=None, platform=None, product=None, os=None):
        self.stdout.extend(stdout)
        self.stderr.extend(stderr)
        self.platform = platform
        self.product = product
        self.os = os
        #TODO: Implement ASan parsing here
        # backtrace
        # crashAddress =
        
class GDBCrashInfo(CrashInfo):
    def __init__(self, stdout, stderr, crashData=None, platform=None, product=None, os=None):
        self.stdout.extend(stdout)
        self.stderr.extend(stderr)
        self.platform = platform
        self.product = product
        self.os = os
        #TODO: Implement GDB parsing here
        # backtrace
        # crashAddress =
        # crashInstruction =
        # registers
        
    @staticmethod
    def calculateCrashAddress(crashInstruction, registerMap):
        #TODO: Port this code from Java. It's complicated ^.^
        pass
        

@@ -984,32 +984,876 @@
 None, os=None):%0A
+        '''%0A        Create appropriate CrashInfo instance from raw crash data%0A        %0A        @type stdout: List of strings%0A        @param stdout: List of lines as they appeared on stdout%0A        @type stderr: List of strings%0A        @param stderr: List of lines as they appeared on stderr%0A        @type crashData: List of strings%0A        @param crashData: Optional crash output (e.g. GDB). If not specified, assumed to be on stderr.%0A        @type platform: string%0A        @param platform: Optional platform to match the signature platform attribute%0A        @type product: string%0A        @param product: Optional product to match the signature product attribute%0A        @type os: string%0A        @param os: Optional OS to match the signature OS attribute%0A        %0A        @rtype: CrashInfo%0A        @return: Crash information object%0A        '''%0A
         if (cras
@@ -1864,24 +1864,24 @@
 a == None):%0A
-
             
@@ -2152,32 +2152,144 @@
 None, os=None):%0A
+        '''%0A        Private constructor, called by CrashInfo.fromRawCrashData. Do not use directly.%0A        '''%0A
         self.std
@@ -2641,32 +2641,144 @@
 None, os=None):%0A
+        '''%0A        Private constructor, called by CrashInfo.fromRawCrashData. Do not use directly.%0A        '''%0A
         self.std
@@ -3071,32 +3071,32 @@
   @staticmethod%0A
-
     def calculat
@@ -3141,16 +3141,428 @@
 erMap):%0A
+        '''%0A        Calculate the crash address given the crash instruction and register contents%0A        %0A        @type crashInstruction: string%0A        @param crashInstruction: Crash instruction string as provided by GDB%0A        @type registerMap: Map from string to long%0A        @param registerMap: Map of register names to values%0A        @rtype: long%0A        @return The calculated crash address%0A        '''%0A
         

Add documentation to CrashInfo class