Bug 597811: Make mozJSComponentLoader use JSVERSION_LATEST. (r=sayrer)
[mozilla-central.git] / tools / leaky / coff.cpp
bloba20ab3e83e54c07ce5ae6cee5b303228f24e653a
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is Kipp E.B. Hickman.
17 * Portions created by the Initial Developer are Copyright (C) 1999
18 * the Initial Developer. All Rights Reserved.
20 * Contributor(s):
22 * Alternatively, the contents of this file may be used under the terms of
23 * either the GNU General Public License Version 2 or later (the "GPL"), or
24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25 * in which case the provisions of the GPL or the LGPL are applicable instead
26 * of those above. If you wish to allow use of your version of this file only
27 * under the terms of either the GPL or the LGPL, and not to allow others to
28 * use your version of this file under the terms of the MPL, indicate your
29 * decision by deleting the provisions above and replace them with the notice
30 * and other provisions required by the GPL or the LGPL. If you do not delete
31 * the provisions above, a recipient may use your version of this file under
32 * the terms of any one of the MPL, the GPL or the LGPL.
34 * ***** END LICENSE BLOCK ***** */
36 #include "leaky.h"
38 #ifdef USE_COFF
40 #define LANGUAGE_C
41 #include <sym.h>
42 #include <cmplrs/stsupport.h>
43 #include <symconst.h>
44 #include <filehdr.h>
45 #include <ldfcn.h>
46 #include <string.h>
47 #include <stdlib.h>
49 #ifdef IRIX4
50 extern "C" {
51 extern char *demangle(char const* in);
53 #else
54 #include <dem.h>
55 #endif
57 static char *Demangle(char *rawName)
59 #ifdef IRIX4
60 return strdup(demangle(rawName));
61 #else
62 char namebuf[4000];
63 demangle(rawName, namebuf);
64 return strdup(namebuf);
65 #endif
68 void leaky::readSymbols(const char *fileName)
70 LDFILE *ldptr;
72 ldptr = ldopen(fileName, NULL);
73 if (!ldptr) {
74 fprintf(stderr, "%s: unable to open \"%s\"\n", applicationName,
75 fileName);
76 exit(-1);
78 if (PSYMTAB(ldptr) == 0) {
79 fprintf(stderr, "%s: \"%s\": has no symbol table\n", applicationName,
80 fileName);
81 exit(-1);
84 long isymMax = SYMHEADER(ldptr).isymMax;
85 long iextMax = SYMHEADER(ldptr).iextMax;
86 long iMax = isymMax + iextMax;
88 long alloced = 10000;
89 Symbol* syms = (Symbol*) malloc(sizeof(Symbol) * 10000);
90 Symbol* sp = syms;
91 Symbol* last = syms + alloced;
92 SYMR symr;
94 for (long isym = 0; isym < iMax; isym++) {
95 if (ldtbread(ldptr, isym, &symr) != SUCCESS) {
96 fprintf(stderr, "%s: can't read symbol #%d\n", applicationName,
97 isym);
98 exit(-1);
100 if (isym < isymMax) {
101 if ((symr.st == stStaticProc)
102 || ((symr.st == stProc) &&
103 ((symr.sc == scText) || (symr.sc == scAbs)))
104 || ((symr.st == stBlock) &&
105 (symr.sc == scText))) {
106 // Text symbol. Set name field to point to the symbol name
107 sp->name = Demangle(ldgetname(ldptr, &symr));
108 sp->address = symr.value;
109 sp++;
110 if (sp >= last) {
111 long n = alloced + 10000;
112 syms = (Symbol*)
113 realloc(syms, (size_t) (sizeof(Symbol) * n));
114 last = syms + n;
115 sp = syms + alloced;
116 alloced = n;
122 int interesting = sp - syms;
123 if (!quiet) {
124 printf("Total of %d symbols\n", interesting);
126 usefulSymbols = interesting;
127 externalSymbols = syms;
130 #endif /* USE_COFF */