Skip to content

Instantly share code, notes, and snippets.

@Dragorn421
Last active July 14, 2021 16:22
Show Gist options
  • Save Dragorn421/d5017fc0f8df4d4caee2fe31c9e86d6f to your computer and use it in GitHub Desktop.
Save Dragorn421/d5017fc0f8df4d4caee2fe31c9e86d6f to your computer and use it in GitHub Desktop.
stackTraceStr = """
8022cf50
8022cca8
8022cb40
80030a40
800bdae8
800bf14c
800c4054
800c5808
800c5ea0
"""
overlaysStr = """
8022c860-8022d500 TestActor
"""
# This is free and unencumbered software released into the public domain.
# For more information, please refer to <http://unlicense.org/>
import os, subprocess
def sym_info(address):
symInfoPyPath = 'sym_info.py'
for i in range(2):
if not os.path.isfile(symInfoPyPath):
symInfoPyPath = '../' + symInfoPyPath
return subprocess.run(['python3', symInfoPyPath, hex(address)], stdout=subprocess.PIPE).stdout.decode().rstrip('\n')
stackTrace = [int(l, 16) for l in stackTraceStr.splitlines() if l]
overlays = []
for l in overlaysStr.splitlines():
if not l:
continue
dashIdx = l.index('-')
spaceIdx = l.index(' ')
if dashIdx < 0:
print(f'malformatted line in overlaysStr: {l} (expected "<startHex>-<endHex> <name>", eg "8022c860-8022d500 TestActor"')
continue
overlays.append((int(l[:dashIdx], 16), int(l[dashIdx+1:spaceIdx], 16), l[spaceIdx+1:]))
for stackTraceAddr in stackTrace:
symInfoRes = sym_info(stackTraceAddr)
print(symInfoRes)
inOverlays = [ovl for ovl in overlays if ovl[0] <= stackTraceAddr and stackTraceAddr < ovl[1]]
if len(inOverlays) > 1:
print('\tWeird, found several overlays where this address belongs:')
print(f'\t{inOverlays}')
if 'gSystemHeap' in symInfoRes:
if not inOverlays:
print('\tThis address does not belong in the listed overlays')
else:
inOvl = inOverlays[0]
mapPath = 'build/z64.map'
for i in range(2):
if not os.path.isfile(mapPath):
mapPath = '../' + mapPath
searchSymbol = f'_ovl_{inOvl[2]}SegmentStart'
with open(mapPath) as mapF:
matches = [l for l in mapF if searchSymbol in l]
if len(matches) != 1:
print(f'Found not exactly 1 match when searching {searchSymbol} in the map:')
print(matches)
if matches:
m = matches[0]
hexAddrStartIdx = m.index('0x')
hexAddrEndIdx = m.index(' ', hexAddrStartIdx)
ovlVaddr = int(m[hexAddrStartIdx+2:hexAddrEndIdx], 16)
symInfoRes2 = sym_info(stackTraceAddr - inOvl[0] + ovlVaddr)
print(f'\t{symInfoRes2}')
elif inOverlays:
print('\tWeird, this address is not in gSystemHeap but belongs in the listed overlays:')
print(f'\t{inOverlays}')
@Dragorn421
Copy link
Author

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment