Skip to content

Commit

Permalink
readelf: Add .gnu_debuglink family sections
Browse files Browse the repository at this point in the history
Signed-off-by: Peace Lee <[email protected]>
  • Loading branch information
iipeace committed Oct 3, 2023
1 parent 3e4ab74 commit 2df2a6b
Showing 1 changed file with 62 additions and 16 deletions.
78 changes: 62 additions & 16 deletions guider/guider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__credits__ = "Peace Lee"
__license__ = "GPLv2"
__version__ = "3.9.8"
__revision__ = "231002"
__revision__ = "231003"
__maintainer__ = "Peace Lee"
__email__ = "[email protected]"
__repository__ = "https://github.com/iipeace/guider"
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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("<Cnt: ")
if len(last) == 2:
stack = "%s %s" % (stack, last[0].strip())
Expand All @@ -85755,12 +85756,11 @@ def getCallStatsFile(logFile, verb=False):
else:
stack = "%s %s" % (stack, last[0].strip())

else:
# no backtrace call #
if not onlybt and stack:
samples.setdefault(stack, 0)
samples[stack] += mainCnt
stack = ""
# no backtrace #
elif not onlybt and stack:
samples.setdefault(stack, 0)
samples[stack] += mainCnt
stack = ""

return samples, title

Expand Down Expand Up @@ -93306,7 +93306,7 @@ def _printSystemStat():
# print histo stats for elapsed time #
if elapsedTable:
elapsedTable = UtilMgr.convList2Histo(elapsedTable, mult=1000000)
UtilMgr.printHist(elapsedTable, "elapsed", "us")
UtilMgr.printHist(elapsedTable, "Elapsed", "us")

# print file table #
if fileTable:
Expand Down Expand Up @@ -93351,9 +93351,11 @@ def _printSystemStat():
except:
break

addVal = " <Cnt: %s>" % convert(value["cnt"])

SysMgr.printPipe(
"{0:>7} | {1:<144}{2:1}".format(
"%.1f%%" % per, filename, suffix
"%.1f%%" % per, filename + addVal, suffix
)
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2df2a6b

Please sign in to comment.