def fetchSome(self): firstMeetFuncInfo=None funcInfoStr='' funcInfo = None ignore=False blockOfNormalLines=[] i=self.i-1 #======================================================================= # print "========" # for line in self.lines: # print line # print "========" #======================================================================= if abs(i)>len(self.lines): print "OH" while abs(i)<=len(self.lines): line=self.lines[i] if self.should_ignore_and_ingore_following(line): ignore=True #=========================================================== # rfx_free (ptr=0x81c3900) at mem.c:10 # 10 { # 11 if(!ptr) # 13 free(ptr); # __GI___libc_free (mem=0x81c3900) at malloc.c:2912 # 2912 malloc.c: No such file or directory. # 2917 in malloc.c # ... # 2946 in malloc.c # _int_free (av=0xb7fa7420 <main_arena>, p=0x81c38f8, have_lock=0) at malloc.c:3814 # 3814 in malloc.c # ... # 3827 in malloc.c # rfx_free (ptr=0x81c3900) at mem.c:14 <---------this line should also be removed # 14 } #=========================================================== i-=1 continue #if self.hexHeadPattern.match(line): #return True if ignore: #if headInfoPattern.match(line): if ('a'<=line[0] and line[0]<='z') or ('A'<=line[0] and line[0]<'Z') or line[0]=='_': if not self.singleStepPattern.match(line): ignore=False if '0x'==line[0:2]:#hex head line (optimization) if self.singleStepPattern.match(self.lines[i+1]): ignore=False i-=1 continue if re.search(r"^[0-9][1-9]*$",line.strip()):#null line i-=1 continue if self.isNormalLine(line):#normal line blockOfNormalLines.append(line) #LOG INFO print "find normal line:",line if "785" in line: print "HEY!" print self.lines[0] else:#func info line #if headInfoPattern.match(line): if ('a'<=line[0] and line[0]<='z') or ('A'<=line[0] and line[0]<'Z') or line[0]=='_': if i-1<len(self.lines):#look ahead if abs(i)!=len(self.lines) and self.should_ignore_and_ingore_following(self.lines[i-1]): #=========================================================== # 3827 in malloc.c # rfx_free (ptr=0x81c3900) at mem.c:14 <---------this line should also be removed # 14 } #=========================================================== ignore=True i-=1 continue else: ignore=False funcInfoStr=line.strip()+funcInfoStr print funcInfoStr funcInfo=FunctionCallInfo(funcInfoStr) self.l[0:0]=[LineOfCode(aline,funcInfo) for aline in blockOfNormalLines[::-1]] self.l.insert(0, funcInfo) if abs(i)==len(self.lines): break blockOfNormalLines=[] if firstMeetFuncInfo is None or funcInfo.get_func_name()==firstMeetFuncInfo.get_func_name(): if self.isNormalLine(self.lines[i-1]): callsite=LineOfCode(self.lines[i-1], None) print callsite funcname=funcInfo.get_func_name().split("::")[-1] if self.isObviousCallSite(funcname, callsite.codestr): #=============================================================================== # positive example #=============================================================================== # 515 if (jobs & FEDTJ_CALLBACK) # 516 callback(self, buf, advance, num, fid, fontsize, x, y, &color);<--------------callsite # textcallback (self=0xbfffe6a8, glyphs=0xbfffde40, advance=0xbfffe240, nr=15, fontid=5, fontsize=960, startx=0, starty=1053, color=0xbfffde14) at swfstrings.c:115 # 115 SWFFONT*font = 0; #=============================================================================== # negative example #=============================================================================== # 43 return mFirst = mLast = new ListItem<T>( data, NULL, user_data );<--------------not callsite # SWF::Header::parse (this=0x83c7ab0, r=0x83c7a98, end=32780, ctx=0xbfffe724) # at gSWFParser.cpp:423 # 423 if( r->getPosition() < myend || (r->getPosition()==myend && r->getBits() )) #=============================================================================== break else: filename=self.fetch_callsite_filename(i-1) if self.isMacroCall(callsite,filename,line): break if firstMeetFuncInfo is None: firstMeetFuncInfo=funcInfo elif 'main' in line: funcInfoStr=line.strip()+funcInfoStr funcInfo=FunctionCallInfo(funcInfoStr) ns=[LineOfCode(aline,funcInfo) for aline in blockOfNormalLines[::-1]] #ns = self.fixBlock(ns) self.l[0:0]=ns self.l.insert(0, funcInfo) blockOfNormalLines=[] else: print 1/0#ERROR IMPOSSIBLE funcInfoStr='' #LOG INFO print "find head info line:",line else: #Tail function call stack info funcInfoStr=line.strip()+funcInfoStr #LOG INFO print "find tail info line:",line if "_ctx=_ctx@entry=0xbfffe724, filesize=filesize@entry=505) at SWFFile.cpp:34" in line: print "HEY!" i-=1 self.i=i return self.l
def parse(self,log_file_path='../gdb.txt'): now0 = datetime.datetime.now() logFile=file(log_file_path, 'r') lines = logFile.readlines() normalLinePattern = re.compile(r'^[0-9]+\s+.*\n') headInfoPattern = re.compile(r'^[A-Za-z_][A-Za-z0-9_]+.*\n') nullLinePattern = re.compile(r'^\s*\n') valueReturnLinePattern=re.compile(r'^(Value returned is |Run till exit from ).*') no_such_file_or_directory=r'No such file or directory.' hexHeadPattern=re.compile(r'^0x[0-9a-f]+ in .*$') #singleStepPattern=re.compile(r'^Single stepping until exit from function .*$') nullLineNum = 0 l = [] isFuncInfo=True funcInfoStr='' funcInfo = None #errorInfo=[] meetBreakPoint = True ignore=False ignoreNext=False last_ignore=False blockOfNormalLines=[] for line in lines: if line[0]=='V' or line[0]=='R': if line[0:3]=='Val' or line[0:3]=='Run': if valueReturnLinePattern.match(line): ignore=False continue if ignore: #if headInfoPattern.match(line): if ('a'<=line[0] and line[0]<='z') or ('A'<=line[0] and line[0]<'Z') or line[0]=='_': ignore=False last_ignore=True #the this line should also be removed as #=========================================================== # rfx_free (ptr=0x81c3900) at mem.c:10 # 10 { # 11 if(!ptr) # 13 free(ptr); # __GI___libc_free (mem=0x81c3900) at malloc.c:2912 # 2912 malloc.c: No such file or directory. # 2917 in malloc.c # ... # 2946 in malloc.c # _int_free (av=0xb7fa7420 <main_arena>, p=0x81c38f8, have_lock=0) at malloc.c:3814 # 3814 in malloc.c # ... # 3827 in malloc.c # rfx_free (ptr=0x81c3900) at mem.c:14 <---------this line should also be removed # 14 } #=========================================================== else: continue if ignoreNext: #if normalLinePattern.match(line): if re.search(r'[1-9][0-9]',line[0:2]) or re.search(r'[1-9]\s',line[0:2]) :#normal line ignoreNext=False else: continue #if hexHeadPattern.match(line): if '0x'==line[0:2]:#hex head line ignoreNext=True continue #if nullLinePattern.match(line): if line.strip()=='':#null line nullLineNum+=1 elif nullLineNum == 1: #trace content #if normalLinePattern.match(line): if re.search(r'[1-9][0-9]',line[0:2]) or re.search(r'[1-9]\s',line[0:2]) :#normal line if isFuncInfo: isFuncInfo = False funcInfo=FunctionCallInfo(funcInfoStr) l.append(funcInfo) funcInfoStr='' blockOfNormalLines.append(LineOfCode(line,funcInfo)) #LOG INFO print "find normal line:",line else: #if headInfoPattern.match(line): if ('a'<=line[0] and line[0]<='z') or ('A'<=line[0] and line[0]<'Z') or line[0]=='_': if lines.index(line)+1<len(lines): if re.search(no_such_file_or_directory,lines[lines.index(line)+1]): ignore=True continue elif last_ignore: last_ignore=False continue #BUG #listOfLines = fixBlock(blockOfNormalLines) listOfLines = blockOfNormalLines l.extend(listOfLines) blockOfNormalLines=[] if not meetBreakPoint: for aline in listOfLines: aline.set_func_call_info(funcInfo) funcInfo.addLines(listOfLines) #Head function call stack info if meetBreakPoint: line = line.strip('Breakpoint 1, ') meetBreakPoint=False funcInfoStr = line.strip('\n') isFuncInfo=True #LOG INFO print "find head info line:",line else: #Tail function call stack info funcInfoStr+=line.strip() #LOG INFO print "find tail info line:",line elif nullLineNum == 2: #Error info #FIXME #listOfLines = fixBlock(blockOfNormalLines) listOfLines = blockOfNormalLines l.extend(listOfLines) blockOfNormalLines=[] #errorInfo.append(line) print 'ALL PARSED\n============================================' fixer=RedundancyFixer(l,self.redundant_level) now1 = datetime.datetime.now() print "initial parse time:",now1-now0 l=fixer.fix() now2 = datetime.datetime.now() print "filter complains time:",now2-now1 write2File("trace.txt", l) now3 = datetime.datetime.now() print "write2File time:",now3-now2 return l