mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-22 07:41:16 +00:00
reccmp: add basic logging + optional debug
This commit is contained in:
parent
f3ed31ed60
commit
3d7b08e3e6
@ -6,6 +6,7 @@
|
|||||||
import difflib
|
import difflib
|
||||||
import struct
|
import struct
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import colorama
|
import colorama
|
||||||
@ -24,8 +25,14 @@
|
|||||||
parser.add_argument('--svg-icon', metavar='icon', help='Icon to use in SVG (PNG)')
|
parser.add_argument('--svg-icon', metavar='icon', help='Icon to use in SVG (PNG)')
|
||||||
parser.add_argument('--print-rec-addr', action='store_true', help='Print addresses of recompiled functions too')
|
parser.add_argument('--print-rec-addr', action='store_true', help='Print addresses of recompiled functions too')
|
||||||
|
|
||||||
|
parser.set_defaults(loglevel=logging.INFO)
|
||||||
|
parser.add_argument('--debug', action='store_const', const=logging.DEBUG, dest='loglevel', help='Print script debug information')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
logging.basicConfig(level=args.loglevel, format='[%(levelname)s] %(message)s')
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
colorama.init()
|
colorama.init()
|
||||||
|
|
||||||
verbose = None
|
verbose = None
|
||||||
@ -61,6 +68,7 @@
|
|||||||
# to file addresses
|
# to file addresses
|
||||||
class Bin:
|
class Bin:
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
|
logger.debug('Parsing headers of "%s"... ', filename)
|
||||||
self.file = open(filename, 'rb')
|
self.file = open(filename, 'rb')
|
||||||
|
|
||||||
#HACK: Strictly, we should be parsing the header, but we know where
|
#HACK: Strictly, we should be parsing the header, but we know where
|
||||||
@ -77,6 +85,7 @@ def __init__(self, filename):
|
|||||||
# Read .text PointerToRawData
|
# Read .text PointerToRawData
|
||||||
self.file.seek(0x18C)
|
self.file.seek(0x18C)
|
||||||
self.textraw = struct.unpack('i', self.file.read(4))[0]
|
self.textraw = struct.unpack('i', self.file.read(4))[0]
|
||||||
|
logger.debug('... Parsing finished')
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self.file:
|
if self.file:
|
||||||
@ -141,12 +150,14 @@ def __init__(self, pdb, file, wine_path_converter):
|
|||||||
else:
|
else:
|
||||||
call.append(pdb)
|
call.append(pdb)
|
||||||
|
|
||||||
print('Parsing %s...' % pdb)
|
logger.info('Parsing %s ...', pdb)
|
||||||
|
logger.debug('Command = %r', call)
|
||||||
line_dump = subprocess.check_output(call).decode('utf-8').split('\r\n')
|
line_dump = subprocess.check_output(call).decode('utf-8').split('\r\n')
|
||||||
|
|
||||||
current_section = None
|
current_section = None
|
||||||
|
|
||||||
|
logger.debug('Parsing output of cvdump.exe ...')
|
||||||
|
|
||||||
for i, line in enumerate(line_dump):
|
for i, line in enumerate(line_dump):
|
||||||
if line.startswith('***'):
|
if line.startswith('***'):
|
||||||
current_section = line[4:]
|
current_section = line[4:]
|
||||||
@ -154,8 +165,6 @@ def __init__(self, pdb, file, wine_path_converter):
|
|||||||
if current_section == 'SYMBOLS' and 'S_GPROC32' in line:
|
if current_section == 'SYMBOLS' and 'S_GPROC32' in line:
|
||||||
addr = int(line[26:34], 16)
|
addr = int(line[26:34], 16)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
info = RecompiledInfo()
|
info = RecompiledInfo()
|
||||||
info.addr = addr + recompfile.imagebase + recompfile.textvirt
|
info.addr = addr + recompfile.imagebase + recompfile.textvirt
|
||||||
|
|
||||||
@ -200,11 +209,13 @@ def __init__(self, pdb, file, wine_path_converter):
|
|||||||
|
|
||||||
j += 1
|
j += 1
|
||||||
|
|
||||||
|
logger.debug('... Parsing output of cvdump.exe finished')
|
||||||
|
|
||||||
def get_recompiled_address(self, filename, line):
|
def get_recompiled_address(self, filename, line):
|
||||||
addr = None
|
addr = None
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
#print('Looking for ' + filename + ' line ' + str(line))
|
logger.debug('Looking for %s:%d', filename, line)
|
||||||
|
|
||||||
for fn in self.lines:
|
for fn in self.lines:
|
||||||
# Sometimes a PDB is compiled with a relative path while we always have
|
# Sometimes a PDB is compiled with a relative path while we always have
|
||||||
@ -222,9 +233,9 @@ def get_recompiled_address(self, filename, line):
|
|||||||
if addr in self.funcs:
|
if addr in self.funcs:
|
||||||
return self.funcs[addr]
|
return self.funcs[addr]
|
||||||
else:
|
else:
|
||||||
print('Failed to find function symbol with address: %s' % hex(addr))
|
logger.error('Failed to find function symbol with address: 0x%x', addr)
|
||||||
else:
|
else:
|
||||||
print('Failed to find function symbol with filename and line: %s:%s' % (filename, str(line)))
|
logger.error('Failed to find function symbol with filename and line: %s:%d', filename, line)
|
||||||
|
|
||||||
wine_path_converter = None
|
wine_path_converter = None
|
||||||
if os.name != 'nt':
|
if os.name != 'nt':
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user