From 2df2a6bfc5e6706c2bc09ec82b95e6ab69bbc662 Mon Sep 17 00:00:00 2001 From: Peace Lee Date: Wed, 4 Oct 2023 00:09:48 +0900 Subject: [PATCH] readelf: Add .gnu_debuglink family sections Signed-off-by: Peace Lee --- guider/guider.py | 78 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/guider/guider.py b/guider/guider.py index f6acd0e1..7e98d024 100755 --- a/guider/guider.py +++ b/guider/guider.py @@ -7,7 +7,7 @@ __credits__ = "Peace Lee" __license__ = "GPLv2" __version__ = "3.9.8" -__revision__ = "231002" +__revision__ = "231003" __maintainer__ = "Peace Lee" __email__ = "iipeace5@gmail.com" __repository__ = "https://github.com/iipeace/guider" @@ -85708,9 +85708,10 @@ def getCallStatsFile(logFile, verb=False): elif context is None: continue - # split line # + # split a line # sline = line.split("|") + # last call # if len(sline) == 2: per = sline[0].strip() if not per[0].isdigit(): @@ -85743,8 +85744,8 @@ def getCallStatsFile(logFile, verb=False): mainCnt = long(last[1].strip().replace(",", "")[:-1]) main = stack + # backtrace # elif line.lstrip().startswith("<-"): - # parse backtraces # last = line.split("7} | {1:<144}{2:1}".format( - "%.1f%%" % per, filename, suffix + "%.1f%%" % per, filename + addVal, suffix ) ) @@ -98934,6 +98936,8 @@ def _printStrSect(sh_name, strtab): e_shdbgdata = -1 e_shdbgframe = -1 e_shdbginfo = -1 + e_shdbglink = -1 + e_shdbgaltlink = -1 e_shdbgloc = -1 e_shdbgranges = -1 e_shdbgline = -1 @@ -99167,6 +99171,10 @@ def _printStrSect(sh_name, strtab): e_shehframehdr = i elif symbol == ".gnu_debugdata": e_shdbgdata = i + elif symbol == ".gnu_debuglink": + e_shdbglink = i + elif symbol == ".gnu_debugaltlink": + e_shdbgaltlink = i elif symbol.startswith(".note."): e_shnotelist.setdefault(symbol, i) elif stype == "GNU_versym": @@ -102981,6 +102989,44 @@ def _addEntryOldState(cmd, args, isExtended=False): except: SysMgr.printErr("failed to parse .gnu_debugdata", True) + # print gnu_debuglink section # + for secName, secIdx in ( + (".gnu_debuglink", e_shdbglink), + (".gnu_debugaltlink", e_shdbgaltlink), + ): + try: + if secIdx < 0 or not secName in self.attr["sectionHeader"]: + continue + + vals = self.attr["sectionHeader"][secName] + doffset = vals["offset"] + dsize = vals["size"] + + # read section # + ddata = SysMgr.readFile(path, dsize, byte=True, offset=doffset) + + # get path and checksum # + dpath = ddata.split(b"\x00")[0].decode("utf-8") + + if printable: + printer("\n[%s Section]\n%s" % (secName, twoLineLoc)) + printer("Debug info file: %s" % dpath) + if secName == ".gnu_debuglink": + dchecksum = ddata[len(dpath.encode("utf-8")) + 1 :][ + -4: + ] + printer("CRC value: 0x%s" % dchecksum[::-1].hex()) + elif secName == ".gnu_debugaltlink": + dbuildid = UtilMgr.convStr2Bytes( + ddata[len(dpath.encode("utf-8")) + 1 :] + ) + printer("Build-ID: 0x%s" % dbuildid) + printer(oneLineLoc) + except SystemExit: + sys.exit(0) + except: + SysMgr.printErr("failed to parse %s" % secName, True) + # check dynamic section # if e_shdynamic < 0: return None @@ -103082,7 +103128,7 @@ def _addEntryOldState(cmd, args, isExtended=False): if nrPrint == 0 and isTarget: printer(" None") - printer("%s\n\n\n" % oneLineLoc) + printer("%s\n" % oneLineLoc) class TaskAnalyzer(object): @@ -113516,28 +113562,28 @@ def printResourceUsage(self): runtimeStats = UtilMgr.convList2Histo( self.statData["runtime"], mult=1000000 ) - UtilMgr.printHist(runtimeStats, "sched_runtime", "us") + UtilMgr.printHist(runtimeStats, "Sched_runtime", "us") # print histo stats for preemption # if "prttime" in self.statData: prttimeStats = UtilMgr.convList2Histo( self.statData["prttime"], mult=1000000 ) - UtilMgr.printHist(prttimeStats, "sched_preempted", "us") + UtilMgr.printHist(prttimeStats, "Sched_preempted", "us") # print histo stats for latency # if "schedlat" in self.statData: latStats = UtilMgr.convList2Histo( self.statData["schedlat"], mult=1000000 ) - UtilMgr.printHist(latStats, "sched_latency", "us") + UtilMgr.printHist(latStats, "Sched_latency", "us") # print histo stats for block # if "schedblock" in self.statData: latStats = UtilMgr.convList2Histo( self.statData["schedblock"], mult=1000000 ) - UtilMgr.printHist(latStats, "sched_block", "us") + UtilMgr.printHist(latStats, "Sched_block", "us") # prepare to draw graph # if not SysMgr.isRecordMode() and SysMgr.graphEnable: