|
38 | 38 | import nativeaot.rehydration.MetadataRehydrator; |
39 | 39 | import nativeaot.rehydration.MetadataRehydratorNet80; |
40 | 40 | import nativeaot.rehydration.PointerScanResult; |
41 | | -import nativeaot.rtr.ReadyToRunDirectory; |
42 | | -import nativeaot.rtr.ReadyToRunLocator; |
43 | | -import nativeaot.rtr.ReadyToRunSection; |
44 | | -import nativeaot.rtr.SymbolReadyToRunLocator; |
| 41 | +import nativeaot.rtr.*; |
45 | 42 |
|
46 | 43 | /** |
47 | 44 | * Provide class-level documentation that describes what this analyzer does. |
48 | 45 | */ |
49 | 46 | public class NativeAotAnalyzer extends AbstractAnalyzer { |
50 | 47 |
|
51 | 48 | public static final String MARKUP_REHYDRATION_CODE = "Markup rehydration code"; |
| 49 | + private static final ReadyToRunLocator[] READY_TO_RUN_LOCATORS = new ReadyToRunLocator[] { |
| 50 | + new SymbolReadyToRunLocator(), |
| 51 | + new SignatureReadyToRunLocator(), |
| 52 | + }; |
52 | 53 |
|
53 | 54 | private boolean _markupRehydrationCode = false; |
54 | 55 |
|
@@ -93,14 +94,9 @@ public void optionsChanged(Options options, Program program) { |
93 | 94 | } |
94 | 95 |
|
95 | 96 | @Override |
96 | | - public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) |
97 | | - throws CancelledException { |
98 | | - |
99 | | - // TODO: make configurable which locator is used.. |
100 | | - ReadyToRunLocator locator = new SymbolReadyToRunLocator(); |
101 | | - |
102 | | - var moduleHeaders = locator.locateModules(program, monitor, log); |
103 | | - |
| 97 | + public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log) throws CancelledException { |
| 98 | + // Locate modules. |
| 99 | + var moduleHeaders = locateModules(program, monitor, log); |
104 | 100 | if (moduleHeaders.length == 0) { |
105 | 101 | log.appendMsg(Constants.TAG, String.format( |
106 | 102 | "Symbols `%s` or `%s` and `%s` not found.", |
@@ -129,16 +125,26 @@ public boolean added(Program program, AddressSetView set, TaskMonitor monitor, M |
129 | 125 | return true; |
130 | 126 | } |
131 | 127 |
|
| 128 | + private Address[] locateModules(Program program, TaskMonitor monitor, MessageLog log) throws CancelledException { |
| 129 | + for (var locator : READY_TO_RUN_LOCATORS) { |
| 130 | + var moduleHeaders = locator.locateModules(program, monitor, log); |
| 131 | + if (moduleHeaders.length > 0) { |
| 132 | + return moduleHeaders; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + return new Address[0]; |
| 137 | + } |
| 138 | + |
132 | 139 | private void processModule(Program program, Address moduleHeader, TaskMonitor monitor, MessageLog log) throws Exception { |
133 | 140 | ReadyToRunDirectory directory; |
134 | 141 | try { |
135 | 142 | directory = readRtrDirectory(program, moduleHeader); |
136 | 143 | } catch (Exception ex) { |
137 | | - throw new Exception("Failed to read rtr directory.", ex); |
| 144 | + throw new Exception("Failed to read RTR directory at %s.".formatted(moduleHeader), ex); |
138 | 145 | } |
139 | 146 |
|
140 | | - // NOTE: Method table managers should be changed if the file format changes per rtr version. |
141 | | - var manager = new MethodTableManagerNet80(program); |
| 147 | + var manager = createMethodTableManagerForDirectory(program, directory); |
142 | 148 |
|
143 | 149 | // Restore first from DB to allow for the analyzer to be run multiple times. |
144 | 150 | manager.restoreFromDB(); |
@@ -208,6 +214,11 @@ private ReadyToRunDirectory readRtrDirectory(Program program, Address moduleHead |
208 | 214 | return directory; |
209 | 215 | } |
210 | 216 |
|
| 217 | + private static MethodTableManagerNet80 createMethodTableManagerForDirectory(Program program, ReadyToRunDirectory directory) { |
| 218 | + // NOTE: Method table managers should be changed if the file format changes per RTR version. |
| 219 | + return new MethodTableManagerNet80(program); |
| 220 | + } |
| 221 | + |
211 | 222 | private PointerScanResult rehydrateData(Program program, ReadyToRunSection rehydratedData, MetadataRehydrator rehydrator, TaskMonitor monitor, MessageLog log) throws Exception { |
212 | 223 | var symbolTable = program.getSymbolTable(); |
213 | 224 |
|
@@ -241,10 +252,7 @@ private PointerScanResult scanForPointers(Program program, Address moduleHeader, |
241 | 252 | } |
242 | 253 |
|
243 | 254 | // We use the block containing the module header as the scanning range |
244 | | - var scanningRange = new AddressRangeImpl( |
245 | | - moduleBlock.getStart(), |
246 | | - moduleBlock.getEnd() |
247 | | - ); |
| 255 | + var scanningRange = moduleBlock.getAddressRange(); |
248 | 256 |
|
249 | 257 | monitor.setMessage(Constants.TAG + ": Scanning for pointers..."); |
250 | 258 | monitor.setMaximum(moduleBlock.getSize()); |
|
0 commit comments