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
14 * The Original Code is jprof.
16 * The Initial Developer of the Original Code is Kipp E.B. Hickman.
17 * Portions created by the Initial Developer are Copyright (C) 1998
18 * the Initial Developer. All Rights Reserved.
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 ***** */
42 #include <cmplrs/stsupport.h>
51 extern char *demangle(char const* in
);
57 static char *Demangle(char *rawName
)
60 return strdup(demangle(rawName
));
63 demangle(rawName
, namebuf
);
64 return strdup(namebuf
);
68 void leaky::readSymbols(const char *fileName
)
72 ldptr
= ldopen(fileName
, NULL
);
74 fprintf(stderr
, "%s: unable to open \"%s\"\n", applicationName
,
78 if (PSYMTAB(ldptr
) == 0) {
79 fprintf(stderr
, "%s: \"%s\": has no symbol table\n", applicationName
,
84 long isymMax
= SYMHEADER(ldptr
).isymMax
;
85 long iextMax
= SYMHEADER(ldptr
).iextMax
;
86 long iMax
= isymMax
+ iextMax
;
89 Symbol
* syms
= (Symbol
*) malloc(sizeof(Symbol
) * 10000);
91 Symbol
* last
= syms
+ alloced
;
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
,
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
;
111 long n
= alloced
+ 10000;
113 realloc(syms
, (size_t) (sizeof(Symbol
) * n
));
122 int interesting
= sp
- syms
;
124 printf("Total of %d symbols\n", interesting
);
126 usefulSymbols
= interesting
;
127 externalSymbols
= syms
;
130 #endif /* USE_COFF */