Mercurial > hg > graal-jvmci-8
comparison agent/src/share/classes/sun/jvm/hotspot/debugger/win32/coff/TestParser.java @ 0:a61af66fc99e jdk7-b24
Initial load
author | duke |
---|---|
date | Sat, 01 Dec 2007 00:00:00 +0000 |
parents | |
children | c18cbe5936b8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a61af66fc99e |
---|---|
1 /* | |
2 * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 package sun.jvm.hotspot.debugger.win32.coff; | |
26 | |
27 public class TestParser { | |
28 public static void main(String[] args) { | |
29 if (args.length != 1) { | |
30 System.err.println("usage: java TestParser [file name]"); | |
31 System.err.println("File name may be an .exe, .dll or .obj"); | |
32 System.exit(1); | |
33 } | |
34 | |
35 try { | |
36 COFFFile file = COFFFileParser.getParser().parse(args[0]); | |
37 if (file.isImage()) { | |
38 System.out.println("PE Image detected."); | |
39 } else { | |
40 System.out.println("PE Image NOT detected, assuming object file."); | |
41 } | |
42 COFFHeader header = file.getHeader(); | |
43 int numSections = header.getNumberOfSections(); | |
44 System.out.println(numSections + " sections detected."); | |
45 for (int i = 0; i < numSections; i++) { | |
46 SectionHeader secHeader = header.getSectionHeader(1 + i); | |
47 System.out.println(secHeader.getName()); | |
48 } | |
49 | |
50 // FIXME: the DLL exports are not contained in the COFF symbol | |
51 // table. Instead, they are in the Export Table, one of the | |
52 // Optional Header Data Directories available from the Optional | |
53 // Header. Must implement that next. | |
54 | |
55 /* | |
56 int numSymbols = header.getNumberOfSymbols(); | |
57 System.out.println(numSymbols + " symbols detected."); | |
58 System.out.println("Symbol dump:"); | |
59 for (int i = 0; i < header.getNumberOfSymbols(); i++) { | |
60 COFFSymbol sym = header.getCOFFSymbol(i); | |
61 System.out.println(" " + sym.getName()); | |
62 } | |
63 */ | |
64 | |
65 // OK, let's give the exported symbols a shot | |
66 OptionalHeader optHdr = header.getOptionalHeader(); | |
67 OptionalHeaderDataDirectories ddirs = optHdr.getDataDirectories(); | |
68 ExportDirectoryTable exports = ddirs.getExportDirectoryTable(); | |
69 System.out.println("Export flags (should be 0): " + exports.getExportFlags()); | |
70 System.out.println("DLL name (from export directory table): " + | |
71 exports.getDLLName()); | |
72 int numSymbols = exports.getNumberOfNamePointers(); | |
73 System.out.println(numSymbols + " exported symbols detected:"); | |
74 for (int i = 0; i < numSymbols; i++) { | |
75 System.out.println(" " + exports.getExportName(i)); | |
76 } | |
77 } catch (Exception e) { | |
78 e.printStackTrace(); | |
79 } | |
80 } | |
81 } |