def fixStackTraces(inputFilename, isZipped, opener): # This append() call is needed to make the import statements work when this # script is installed as a symlink. sys.path.append(os.path.dirname(__file__)) bpsyms = os.environ.get("BREAKPAD_SYMBOLS_PATH", None) sysname = platform.system() if bpsyms and os.path.exists(bpsyms): import fix_stack_using_bpsyms as fixModule fix = lambda line: fixModule.fixSymbols(line, bpsyms) elif sysname == "Linux": import fix_linux_stack as fixModule fix = lambda line: fixModule.fixSymbols(line) elif sysname == "Darwin": import fix_macosx_stack as fixModule fix = lambda line: fixModule.fixSymbols(line) else: fix = None # there is no fix script for Windows if fix: # Fix stacks, writing output to a temporary file, and then # overwrite the original file. tmpFile = tempfile.NamedTemporaryFile(delete=False) # If the input is gzipped, then the output (written initially to # |tmpFile|) should be gzipped as well. # # And we want to set its pre-gzipped filename to '' rather than the # name of the temporary file, so that programs like the Unix 'file' # utility don't say that it was called 'tmp6ozTxE' (or something like # that) before it was zipped. So that explains the |filename=''| # parameter. # # But setting the filename like that clobbers |tmpFile.name|, so we # must get that now in order to move |tmpFile| at the end. tmpFilename = tmpFile.name if isZipped: tmpFile = gzip.GzipFile(filename="", fileobj=tmpFile) with opener(inputFilename, "rb") as inputFile: for line in inputFile: tmpFile.write(fix(line)) tmpFile.close() shutil.move(tmpFilename, inputFilename)
def fixStackTraces(inputFilename, isZipped, opener): # This append() call is needed to make the import statements work when this # script is installed as a symlink. sys.path.append(os.path.dirname(__file__)) bpsyms = os.environ.get('BREAKPAD_SYMBOLS_PATH', None) sysname = platform.system() if bpsyms and os.path.exists(bpsyms): import fix_stack_using_bpsyms as fixModule fix = lambda line: fixModule.fixSymbols(line, bpsyms) elif sysname == 'Linux': import fix_linux_stack as fixModule fix = lambda line: fixModule.fixSymbols(line) elif sysname == 'Darwin': import fix_macosx_stack as fixModule fix = lambda line: fixModule.fixSymbols(line) else: fix = None # there is no fix script for Windows if fix: # Fix stacks, writing output to a temporary file, and then # overwrite the original file. tmpFile = tempfile.NamedTemporaryFile(delete=False) # If the input is gzipped, then the output (written initially to # |tmpFile|) should be gzipped as well. # # And we want to set its pre-gzipped filename to '' rather than the # name of the temporary file, so that programs like the Unix 'file' # utility don't say that it was called 'tmp6ozTxE' (or something like # that) before it was zipped. So that explains the |filename=''| # parameter. # # But setting the filename like that clobbers |tmpFile.name|, so we # must get that now in order to move |tmpFile| at the end. tmpFilename = tmpFile.name if isZipped: tmpFile = gzip.GzipFile(filename='', fileobj=tmpFile) with opener(inputFilename, 'rb') as inputFile: for line in inputFile: tmpFile.write(fix(line)) tmpFile.close() shutil.move(tmpFilename, inputFilename)
def fixSymbol(address): addr = ((int(address, 0) - self.start + self.offset) & ~1) - 1 # the 'x' in '0x' must be lower case, all others must be upper case addr_str = "0x{:X}".format(addr) libname = os.path.basename(self.host_name) line = "[" + libname + " +" + addr_str + "]" symbol = fixSymbols(line, self.bp_symbols_path) if symbol == line: return "??" if symbol[-1] == "\n": symbol = symbol[:-1] return symbol.split()[0] + " (in " + self.target_name + ")"
def test_fix_Symbols_missing_symbol(): line = '#01: foobar[{:s}foo.{:s} +0xfc258]\n' result = '#01: foo.{:s} + 0xfc258\n' if platform.system() == "Windows": line = line.format('C:\\application\\firefox\\', 'dll') result = result.format('dll') else: line = line.format('/home/firerox/', 'so', '') result = result.format('so') output = fixSymbols(line, '.') assert output == result
def fixSymbol(address): addr = fixupAddress(self, address) # the 'x' in '0x' must be lower case, all others must be upper case addr_str = formatAddress(addr) libname = os.path.basename(self.host_name) line = "[" + libname + " +" + addr_str + "]" symbol = fixSymbols(line, self.symbols_path) if symbol == line: return "??" if symbol[-1] == "\n": symbol = symbol[:-1] # Absolute source path ends up in a long string, # take only the source file with line number. # When the symbol is resolved with source path, # the symbol format is: # <function-name> [<source-path>:<line>] match = symbol_path_matcher.match(symbol) if match: symbol, source_path = match.group(1, 2) source_file = os.path.basename(source_path) symbol += " @ " + source_file return symbol + " (in " + self.target_name + ")"
def fix(line): return fixModule.fixSymbols(line)
def waitForFinish(self, proc, utilityPath, timeout, maxTime, startTime, debuggerInfo, symbolsPath): """ Look for timeout or crashes and return the status after the process terminates """ stackFixerFunction = None didTimeout = False hitMaxTime = False if proc.stdout is None: self.log.info("TEST-INFO: Not logging stdout or stderr due to debugger connection") else: logsource = proc.stdout if self.IS_DEBUG_BUILD and symbolsPath and os.path.exists(symbolsPath): # Run each line through a function in fix_stack_using_bpsyms.py (uses breakpad symbol files) # This method is preferred for Tinderbox builds, since native symbols may have been stripped. sys.path.insert(0, utilityPath) import fix_stack_using_bpsyms as stackFixerModule stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line, symbolsPath) del sys.path[0] elif self.IS_DEBUG_BUILD and self.IS_MAC: # Run each line through a function in fix_macosx_stack.py (uses atos) sys.path.insert(0, utilityPath) import fix_macosx_stack as stackFixerModule stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line) del sys.path[0] elif self.IS_DEBUG_BUILD and self.IS_LINUX: # Run each line through a function in fix_linux_stack.py (uses addr2line) # This method is preferred for developer machines, so we don't have to run "make buildsymbols". sys.path.insert(0, utilityPath) import fix_linux_stack as stackFixerModule stackFixerFunction = lambda line: stackFixerModule.fixSymbols(line) del sys.path[0] # With metro browser runs this script launches the metro test harness which launches the browser. # The metro test harness hands back the real browser process id via log output which we need to # pick up on and parse out. This variable tracks the real browser process id if we find it. browserProcessId = -1 (line, didTimeout) = self.readWithTimeout(logsource, timeout) while line != "" and not didTimeout: if stackFixerFunction: line = stackFixerFunction(line) self.log.info(line.rstrip().decode("UTF-8", "ignore")) if "TEST-START" in line and "|" in line: self.lastTestSeen = line.split("|")[1].strip() if not debuggerInfo and "TEST-UNEXPECTED-FAIL" in line and "Test timed out" in line: self.dumpScreen(utilityPath) (line, didTimeout) = self.readWithTimeout(logsource, timeout) if not hitMaxTime and maxTime and datetime.now() - startTime > timedelta(seconds=maxTime): # Kill the application. hitMaxTime = True self.log.info( "TEST-UNEXPECTED-FAIL | %s | application ran for longer than allowed maximum time of %d seconds", self.lastTestSeen, int(maxTime), ) self.killAndGetStack(proc.pid, utilityPath, debuggerInfo) if didTimeout: if line: self.log.info(line.rstrip().decode("UTF-8", "ignore")) self.log.info( "TEST-UNEXPECTED-FAIL | %s | application timed out after %d seconds with no output", self.lastTestSeen, int(timeout), ) if browserProcessId == -1: browserProcessId = proc.pid self.killAndGetStack(browserProcessId, utilityPath, debuggerInfo) status = proc.wait() automationutils.printstatus(status, "Main app process") if status == 0: self.lastTestSeen = "Main app process exited normally" if status != 0 and not didTimeout and not hitMaxTime: self.log.info("TEST-UNEXPECTED-FAIL | %s | Exited with code %d during test run", self.lastTestSeen, status) return status
def fix(line): return fixModule.fixSymbols(line, jsonEscape=True) else:
def fix(line): return fixModule.fixSymbols(line, jsonEscape=True) elif sysname == 'Darwin':
def fix(line): return fixModule.fixSymbols(line, bpsyms, jsonEscape=True)
def fix(line): return fixModule.fixSymbols(line, jsonMode=True)
def fix(line): return fixModule.fixSymbols(line) elif sysname == 'Darwin':
def fix(line): return fixModule.fixSymbols(line, bpsyms) elif sysname == 'Linux':
def test_fixSymbols_non_stack_line(): line = 'foobar\n' res = fixSymbols(line, '.') assert res == line