1
// The contents of this file are subject to the Mozilla Public License
2
// Version 1.1 (the "License"); you may not use this file except in
3
// compliance with the License. You may obtain a copy of the License
4
// at http://www.mozilla.org/MPL/
6
// Software distributed under the License is distributed on an "AS IS"
7
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8
// the License for the specific language governing rights and
9
// limitations under the License.
11
// The Initial Developer of the Original Code is Kipp E.B. Hickman.
19
#include <cmplrs/stsupport.h>
28
extern char *demangle(char const* in);
34
static char *Demangle(char *rawName)
37
return strdup(demangle(rawName));
40
demangle(rawName, namebuf);
41
return strdup(namebuf);
45
void leaky::readSymbols(const char *fileName)
49
ldptr = ldopen(fileName, NULL);
51
fprintf(stderr, "%s: unable to open \"%s\"\n", applicationName,
55
if (PSYMTAB(ldptr) == 0) {
56
fprintf(stderr, "%s: \"%s\": has no symbol table\n", applicationName,
61
long isymMax = SYMHEADER(ldptr).isymMax;
62
long iextMax = SYMHEADER(ldptr).iextMax;
63
long iMax = isymMax + iextMax;
66
Symbol* syms = (Symbol*) malloc(sizeof(Symbol) * 10000);
68
Symbol* last = syms + alloced;
71
for (long isym = 0; isym < iMax; isym++) {
72
if (ldtbread(ldptr, isym, &symr) != SUCCESS) {
73
fprintf(stderr, "%s: can't read symbol #%d\n", applicationName,
78
if ((symr.st == stStaticProc)
79
|| ((symr.st == stProc) &&
80
((symr.sc == scText) || (symr.sc == scAbs)))
81
|| ((symr.st == stBlock) &&
82
(symr.sc == scText))) {
83
// Text symbol. Set name field to point to the symbol name
84
sp->name = Demangle(ldgetname(ldptr, &symr));
85
sp->address = symr.value;
88
long n = alloced + 10000;
90
realloc(syms, (size_t) (sizeof(Symbol) * n));
99
int interesting = sp - syms;
101
printf("Total of %d symbols\n", interesting);
103
usefulSymbols = interesting;
104
externalSymbols = syms;
107
#endif /* USE_COFF */