2019-03-21 16:42:47 +00:00
|
|
|
"""Parses the cc65 .dbg output to extract symbol addresses."""
|
|
|
|
|
2019-03-21 22:41:05 +00:00
|
|
|
from typing import Dict, TextIO
|
2019-02-27 12:10:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SymbolTable:
|
|
|
|
"""Parse cc65 debug file to extract symbol table."""
|
|
|
|
|
|
|
|
def __init__(self, debugfile: str = None):
|
2019-03-21 22:41:05 +00:00
|
|
|
self.debugfile = debugfile # type: str
|
2019-02-27 12:10:14 +00:00
|
|
|
|
2019-03-21 22:41:05 +00:00
|
|
|
def parse(self, iostream: TextIO = None) -> Dict:
|
|
|
|
"""
|
|
|
|
|
|
|
|
:param iostream:
|
|
|
|
:return:
|
|
|
|
"""
|
2019-02-27 12:10:14 +00:00
|
|
|
syms = {}
|
|
|
|
|
|
|
|
if not iostream:
|
|
|
|
iostream = open(self.debugfile, "r")
|
|
|
|
|
|
|
|
with iostream as f:
|
|
|
|
for line in f.read().split("\n"):
|
|
|
|
if not line.startswith("sym"):
|
|
|
|
continue
|
|
|
|
|
|
|
|
sym = {}
|
|
|
|
data = line.split()[1].split(",")
|
|
|
|
for kv in data:
|
|
|
|
k, v = kv.split("=")
|
|
|
|
sym[k] = v
|
|
|
|
|
|
|
|
name = sym["name"]
|
|
|
|
|
|
|
|
syms[name] = sym
|
|
|
|
|
|
|
|
return syms
|