Mercurial > hg > truffle
comparison mx/commands.py @ 6958:abbe4faaf0c1
added support for dumping an address to symbol map (with -G:+PrintAddressMap) to translate addresses in disassembled output (via new '-m' option to the hcfdis command)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Fri, 16 Nov 2012 12:39:26 +0100 |
parents | cce59a7ee92c |
children | 5d0bb7d52783 |
comparison
equal
deleted
inserted
replaced
6957:158e0c9645c5 | 6958:abbe4faaf0c1 |
---|---|
24 # or visit www.oracle.com if you need additional information or have any | 24 # or visit www.oracle.com if you need additional information or have any |
25 # questions. | 25 # questions. |
26 # | 26 # |
27 # ---------------------------------------------------------------------------------------------------- | 27 # ---------------------------------------------------------------------------------------------------- |
28 | 28 |
29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing | 29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess, multiprocessing, types |
30 from os.path import join, exists, dirname, basename | 30 from os.path import join, exists, dirname, basename |
31 from argparse import ArgumentParser, REMAINDER | 31 from argparse import ArgumentParser, REMAINDER |
32 from threading import Thread | 32 from threading import Thread |
33 import mx | 33 import mx |
34 import sanitycheck | 34 import sanitycheck |
1009 def hcfdis(args): | 1009 def hcfdis(args): |
1010 """disassemble HexCodeFiles embedded in text files | 1010 """disassemble HexCodeFiles embedded in text files |
1011 | 1011 |
1012 Run a tool over the input files to convert all embedded HexCodeFiles | 1012 Run a tool over the input files to convert all embedded HexCodeFiles |
1013 to a disassembled format.""" | 1013 to a disassembled format.""" |
1014 | |
1015 parser = ArgumentParser(prog='mx hcfdis'); | |
1016 parser.add_argument('-m', '--map', help='address to symbol map applied to disassembler output') | |
1017 parser.add_argument('files', nargs=REMAINDER, metavar='files...') | |
1018 | |
1019 args = parser.parse_args(args) | |
1020 | |
1014 path = join(_graal_home, 'lib', 'hcfdis-1.jar') | 1021 path = join(_graal_home, 'lib', 'hcfdis-1.jar') |
1015 if not exists(path): | 1022 if not exists(path): |
1016 mx.download(path, ['http://lafo.ssw.uni-linz.ac.at/hcfdis-1.jar']) | 1023 mx.download(path, ['http://lafo.ssw.uni-linz.ac.at/hcfdis-1.jar']) |
1017 mx.run_java(['-jar', path] + args) | 1024 mx.run_java(['-jar', path] + args.files) |
1025 | |
1026 if args.map is not None: | |
1027 addressRE = re.compile(r'0[xX]([A-Fa-f0-9]+)') | |
1028 with open(args.map) as fp: | |
1029 lines = fp.read().splitlines() | |
1030 symbols = dict() | |
1031 for l in lines: | |
1032 addressAndSymbol = l.split(' ', 1) | |
1033 if len(addressAndSymbol) == 2: | |
1034 address, symbol = addressAndSymbol; | |
1035 if address.startswith('0x'): | |
1036 address = long(address, 16) | |
1037 symbols[address] = symbol | |
1038 for f in args.files: | |
1039 with open(f) as fp: | |
1040 lines = fp.read().splitlines() | |
1041 updated = False | |
1042 for i in range(0, len(lines)): | |
1043 l = lines[i] | |
1044 for m in addressRE.finditer(l): | |
1045 sval = m.group(0) | |
1046 val = long(sval, 16) | |
1047 sym = symbols.get(val) | |
1048 if sym: | |
1049 l = l.replace(sval, sym) | |
1050 updated = True | |
1051 lines[i] = l | |
1052 if updated: | |
1053 mx.log('updating ' + f) | |
1054 with open('new_' + f, "w") as fp: | |
1055 for l in lines: | |
1056 print >> fp, l | |
1018 | 1057 |
1019 def jacocoreport(args): | 1058 def jacocoreport(args): |
1020 """create a JaCoCo coverage report | 1059 """create a JaCoCo coverage report |
1021 | 1060 |
1022 Creates the report from the 'jacoco.exec' file in the current directory. | 1061 Creates the report from the 'jacoco.exec' file in the current directory. |