def save_ureport(self, db, db_report, ureport, flush=False, count=1): crashframe = ureport["stacktrace"][0] if "special_function" in crashframe: crashfn = "<{0}>".format(crashframe["special_function"]) else: crashfn = crashframe["function_name"] if not db_report.errname: db_report.errname = ureport["exception_name"] elif ureport["exception_name"] and (ureport["exception_name"][0] in ascii_uppercase or "." in ureport["exception_name"]): # Only overwrite errname if the new one begins with an uppercase # letter or contains a ".", i.e. is probably a valid exception type db_report.errname = ureport["exception_name"] db_reportexe = get_reportexe(db, db_report, crashframe["file_name"]) if db_reportexe is None: db_reportexe = ReportExecutable() db_reportexe.report = db_report db_reportexe.path = crashframe["file_name"] db_reportexe.count = 0 db.session.add(db_reportexe) db_reportexe.count += count bthash = self._hash_traceback(ureport["stacktrace"]) if not db_report.backtraces: db_backtrace = ReportBacktrace() db_backtrace.report = db_report db_backtrace.crashfn = crashfn db.session.add(db_backtrace) db_bthash = ReportBtHash() db_bthash.type = "NAMES" db_bthash.hash = bthash db_bthash.backtrace = db_backtrace db_thread = ReportBtThread() db_thread.backtrace = db_backtrace db_thread.crashthread = True db.session.add(db_thread) new_symbols = {} new_symbolsources = {} i = 0 for frame in ureport["stacktrace"]: i += 1 if "special_function" in frame: function_name = "<{0}>".format(frame["special_function"]) else: function_name = frame["function_name"] if "special_file" in frame: file_name = "<{0}>".format(frame["special_file"]) else: file_name = frame["file_name"] norm_path = get_libname(file_name) db_symbol = get_symbol_by_name_path(db, function_name, norm_path) if db_symbol is None: key = (function_name, norm_path) if key in new_symbols: db_symbol = new_symbols[key] else: db_symbol = Symbol() db_symbol.name = function_name db_symbol.normalized_path = norm_path db.session.add(db_symbol) new_symbols[key] = db_symbol db_symbolsource = get_symbolsource(db, db_symbol, file_name, frame["file_line"]) if db_symbolsource is None: key = (function_name, file_name, frame["file_line"]) if key in new_symbolsources: db_symbolsource = new_symbolsources[key] else: db_symbolsource = SymbolSource() db_symbolsource.path = file_name db_symbolsource.offset = frame["file_line"] db_symbolsource.source_path = file_name db_symbolsource.symbol = db_symbol if "line_contents" in frame: db_symbolsource.srcline = frame["line_contents"] if "file_line" in frame: db_symbolsource.line_number = frame["file_line"] db.session.add(db_symbolsource) new_symbolsources[key] = db_symbolsource db_frame = ReportBtFrame() db_frame.order = i db_frame.inlined = False db_frame.symbolsource = db_symbolsource db_frame.thread = db_thread db.session.add(db_frame) if flush: db.session.flush()
def save_ureport(self, db, db_report, ureport, flush=False, count=1): db_report.errname = str(ureport["signal"]) db_reportexe = get_reportexe(db, db_report, ureport["executable"]) if db_reportexe is None: db_reportexe = ReportExecutable() db_reportexe.path = ureport["executable"] db_reportexe.report = db_report db_reportexe.count = 0 db.session.add(db_reportexe) db_reportexe.count += count bthashes = self._hash_backtrace(ureport["stacktrace"]) if not bthashes: raise FafError("Unable to get backtrace hash") if not db_report.backtraces: new_symbols = {} new_symbolsources = {} db_backtrace = ReportBacktrace() db_backtrace.report = db_report db.session.add(db_backtrace) for bthash in bthashes: db_bthash = ReportBtHash() db_bthash.backtrace = db_backtrace db_bthash.type = "NAMES" db_bthash.hash = bthash db.session.add(db_bthash) tid = 0 for thread in ureport["stacktrace"]: tid += 1 crash = "crash_thread" in thread and thread["crash_thread"] db_thread = ReportBtThread() db_thread.backtrace = db_backtrace db_thread.number = tid db_thread.crashthread = crash db.session.add(db_thread) fid = 0 for frame in thread["frames"]: # OK, this is totally ugly. # Frames may contain inlined functions, that would normally # require shifting all frames by 1 and inserting a new one. # There is no way to do this efficiently with SQL Alchemy # (you need to go one by one and flush after each) so # creating a space for additional frames is a huge speed # optimization. fid += 10 if "build_id" in frame: build_id = frame["build_id"] else: build_id = None if "fingerprint" in frame: fingerprint = frame["fingerprint"] else: fingerprint = None path = os.path.abspath(frame["file_name"]) offset = frame["build_id_offset"] db_symbol = None if "function_name" in frame: norm_path = get_libname(path) db_symbol = \ get_symbol_by_name_path(db, frame["function_name"], norm_path) if db_symbol is None: key = (frame["function_name"], norm_path) if key in new_symbols: db_symbol = new_symbols[key] else: db_symbol = Symbol() db_symbol.name = frame["function_name"] db_symbol.normalized_path = norm_path db.session.add(db_symbol) new_symbols[key] = db_symbol db_symbolsource = get_ssource_by_bpo( db, build_id, path, offset) if db_symbolsource is None: key = (build_id, path, offset) if key in new_symbolsources: db_symbolsource = new_symbolsources[key] else: db_symbolsource = SymbolSource() db_symbolsource.symbol = db_symbol db_symbolsource.build_id = build_id db_symbolsource.path = path db_symbolsource.offset = offset db_symbolsource.hash = fingerprint db.session.add(db_symbolsource) new_symbolsources[key] = db_symbolsource db_frame = ReportBtFrame() db_frame.thread = db_thread db_frame.order = fid db_frame.symbolsource = db_symbolsource db_frame.inlined = False db.session.add(db_frame) if flush: db.session.flush()
def save_ureport(self, db, db_report, ureport, flush=False): db_report.errname = str(ureport["signal"]) db_reportexe = get_reportexe(db, db_report, ureport["executable"]) if db_reportexe is None: db_reportexe = ReportExecutable() db_reportexe.path = ureport["executable"] db_reportexe.report = db_report db_reportexe.count = 0 db.session.add(db_reportexe) db_reportexe.count += 1 bthashes = self._hash_backtrace(ureport["stacktrace"]) if len(bthashes) < 1: raise FafError("Unable to get backtrace hash") bts = filter(None, set(get_backtrace_by_hash(db, b) for b in bthashes)) if len(bts) > 1: raise FafError("Unable to reliably identify backtrace by hash") if len(bts) == 1: db_backtrace = bts.pop() else: new_symbols = {} new_symbolsources = {} db_backtrace = ReportBacktrace() db_backtrace.report = db_report db.session.add(db_backtrace) for bthash in bthashes: db_bthash = ReportBtHash() db_bthash.backtrace = db_backtrace db_bthash.type = "NAMES" db_bthash.hash = bthash db.session.add(db_bthash) tid = 0 for thread in ureport["stacktrace"]: tid += 1 crash = "crash_thread" in thread and thread["crash_thread"] db_thread = ReportBtThread() db_thread.backtrace = db_backtrace db_thread.number = tid db_thread.crashthread = crash db.session.add(db_thread) fid = 0 for frame in thread["frames"]: # OK, this is totally ugly. # Frames may contain inlined functions, that would normally # require shifting all frames by 1 and inserting a new one. # There is no way to do this efficiently with SQL Alchemy # (you need to go one by one and flush after each) so # creating a space for additional frames is a huge speed # optimization. fid += 10 if "build_id" in frame: build_id = frame["build_id"] else: build_id = None if "fingerprint" in frame: fingerprint = frame["fingerprint"] else: fingerprint = None path = os.path.abspath(frame["file_name"]) offset = frame["build_id_offset"] db_symbol = None if "function_name" in frame: norm_path = get_libname(path) db_symbol = \ get_symbol_by_name_path(db, frame["function_name"], norm_path) if db_symbol is None: key = (frame["function_name"], norm_path) if key in new_symbols: db_symbol = new_symbols[key] else: db_symbol = Symbol() db_symbol.name = frame["function_name"] db_symbol.normalized_path = norm_path db.session.add(db_symbol) new_symbols[key] = db_symbol db_symbolsource = get_ssource_by_bpo(db, build_id, path, offset) if db_symbolsource is None: key = (build_id, path, offset) if key in new_symbolsources: db_symbolsource = new_symbolsources[key] else: db_symbolsource = SymbolSource() db_symbolsource.symbol = db_symbol db_symbolsource.build_id = build_id db_symbolsource.path = path db_symbolsource.offset = offset db_symbolsource.hash = fingerprint db.session.add(db_symbolsource) new_symbolsources[key] = db_symbolsource db_frame = ReportBtFrame() db_frame.thread = db_thread db_frame.order = fid db_frame.symbolsource = db_symbolsource db_frame.inlined = False db.session.add(db_frame) if flush: db.session.flush()
def save_ureport(self, db, db_report, ureport, flush=False, count=1): crashframe = ureport["stacktrace"][0] if "special_function" in crashframe: crashfn = "<{0}>".format(crashframe["special_function"]) else: crashfn = crashframe["function_name"] db_report.errname = ureport["exception_name"] db_reportexe = get_reportexe(db, db_report, crashframe["file_name"]) if db_reportexe is None: db_reportexe = ReportExecutable() db_reportexe.report = db_report db_reportexe.path = crashframe["file_name"] db_reportexe.count = 0 db.session.add(db_reportexe) db_reportexe.count += count bthash = self._hash_traceback(ureport["stacktrace"]) if len(db_report.backtraces) < 1: db_backtrace = ReportBacktrace() db_backtrace.report = db_report db_backtrace.crashfn = crashfn db.session.add(db_backtrace) db_bthash = ReportBtHash() db_bthash.type = "NAMES" db_bthash.hash = bthash db_bthash.backtrace = db_backtrace db_thread = ReportBtThread() db_thread.backtrace = db_backtrace db_thread.crashthread = True db.session.add(db_thread) new_symbols = {} new_symbolsources = {} i = 0 for frame in ureport["stacktrace"]: i += 1 if "special_function" in frame: function_name = "<{0}>".format(frame["special_function"]) else: function_name = frame["function_name"] if "special_file" in frame: file_name = "<{0}>".format(frame["special_file"]) else: file_name = frame["file_name"] norm_path = get_libname(file_name) db_symbol = get_symbol_by_name_path(db, function_name, norm_path) if db_symbol is None: key = (function_name, norm_path) if key in new_symbols: db_symbol = new_symbols[key] else: db_symbol = Symbol() db_symbol.name = function_name db_symbol.normalized_path = norm_path db.session.add(db_symbol) new_symbols[key] = db_symbol db_symbolsource = get_symbolsource(db, db_symbol, file_name, frame["file_line"]) if db_symbolsource is None: key = (function_name, file_name, frame["file_line"]) if key in new_symbolsources: db_symbolsource = new_symbolsources[key] else: db_symbolsource = SymbolSource() db_symbolsource.path = file_name db_symbolsource.offset = frame["file_line"] db_symbolsource.source_path = file_name db_symbolsource.symbol = db_symbol if "line_contents" in frame: db_symbolsource.srcline = frame["line_contents"] if "file_line" in frame: db_symbolsource.line_number = frame["file_line"] db.session.add(db_symbolsource) new_symbolsources[key] = db_symbolsource db_frame = ReportBtFrame() db_frame.order = i db_frame.inlined = False db_frame.symbolsource = db_symbolsource db_frame.thread = db_thread db.session.add(db_frame) if flush: db.session.flush()