Paste P171

Get more detailed stack dump from kritacrash.log generated by Dr. MinGW
ActivePublic

Authored by alvinhochun on Feb 26 2018, 2:37 PM.
import fileinput
import glob
import re
import subprocess
import pefile
ADDR2LINE_EXE = "D:\\dev\compilers\\mingw64\\x86_64-7.1.0-posix-seh\\bin\\addr2line.exe"
PACKAGE_BASE_PATH = "C:\\Users\\Alvin\\Downloads\\krita-v4.0.0.51-343-gf6f83a2a5f-dirty"
INPUT_PER_LINE = False
def addr2lineFromText(moduleFile, offsetFromTextSection):
res = subprocess.run([
ADDR2LINE_EXE,
"-e", moduleFile,
"-j", ".text",
"-fCisp",
"0x%x" % offsetFromTextSection
], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
if res.returncode != 0:
return False
if "??" in res.stdout:
return False
return res.stdout
def addr2line(moduleFile, offsetFromImageBase):
if not type(offsetFromImageBase) is int:
offsetFromImageBase = int(offsetFromImageBase, base=16)
pe = pefile.PE(moduleFile, fast_load=True)
#print("baseOfCode %d" % pe.OPTIONAL_HEADER.BaseOfCode)
offset = offsetFromImageBase - pe.OPTIONAL_HEADER.BaseOfCode
pe.close()
return addr2lineFromText(moduleFile, offset)
LINE_REGEX = re.compile(r"^(?:(?:[0-9A-Fa-f]{8}){1,2} ){4} ([A-Za-z0-9._\-]+)!(0x[0-9A-Fa-f]+)(.*)$")
def parseStackDumpLine(line):
result = LINE_REGEX.match(line)
if not result:
print("?? %s" % line)
return
module = result.group(1)
foundFiles = glob.glob(PACKAGE_BASE_PATH + "/**/" + module, recursive=True)
pre = "%s!%s" % (result.group(1), result.group(2))
if not foundFiles:
print("%-30s%s" % (pre, result.group(3)))
return
offset = int(result.group(2), base=16)
output = addr2line(foundFiles[0], offset - 1)
if not output:
print("%-30s%s" % (pre, result.group(3)))
return
lines = output.split("\n")
for line in lines:
if not line:
continue
print("%-30s %s" % (pre, line))
def main():
if INPUT_PER_LINE:
for line in fileinput.input():
parseStackDumpLine(line)
else:
lines = []
for line in fileinput.input():
lines.append(line)
for line in lines:
parseStackDumpLine(line)
if __name__ == '__main__':
main()
alvinhochun created this object in space S1 KDE Community.
alvinhochun changed the title of this paste from Get more detailed stack dump from kritacrash.log generated by DrMingw to Get more detailed stack dump from kritacrash.log generated by Dr. MinGW.Feb 26 2018, 2:42 PM
alvinhochun edited the content of this paste. (Show Details)