annotate agent/src/share/classes/sun/jvm/hotspot/debugger/win32/coff/TestParser.java @ 1552:c18cbe5936b8

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