1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
11 # include <cmplrs/stsupport.h>
12 # include <symconst.h>
20 extern char* demangle(char const* in
);
26 static char* Demangle(char* rawName
) {
28 return strdup(demangle(rawName
));
31 demangle(rawName
, namebuf
);
32 return strdup(namebuf
);
36 void leaky::readSymbols(const char* fileName
) {
39 ldptr
= ldopen(fileName
, nullptr);
41 fprintf(stderr
, "%s: unable to open \"%s\"\n", applicationName
, fileName
);
44 if (PSYMTAB(ldptr
) == 0) {
45 fprintf(stderr
, "%s: \"%s\": has no symbol table\n", applicationName
,
50 long isymMax
= SYMHEADER(ldptr
).isymMax
;
51 long iextMax
= SYMHEADER(ldptr
).iextMax
;
52 long iMax
= isymMax
+ iextMax
;
55 Symbol
* syms
= (Symbol
*)malloc(sizeof(Symbol
) * 10000);
57 Symbol
* last
= syms
+ alloced
;
60 for (long isym
= 0; isym
< iMax
; isym
++) {
61 if (ldtbread(ldptr
, isym
, &symr
) != SUCCESS
) {
62 fprintf(stderr
, "%s: can't read symbol #%d\n", applicationName
, isym
);
66 if ((symr
.st
== stStaticProc
) ||
67 ((symr
.st
== stProc
) &&
68 ((symr
.sc
== scText
) || (symr
.sc
== scAbs
))) ||
69 ((symr
.st
== stBlock
) && (symr
.sc
== scText
))) {
70 // Text symbol. Set name field to point to the symbol name
71 sp
->name
= Demangle(ldgetname(ldptr
, &symr
));
72 sp
->address
= symr
.value
;
75 long n
= alloced
+ 10000;
76 syms
= (Symbol
*)realloc(syms
, (size_t)(sizeof(Symbol
) * n
));
85 int interesting
= sp
- syms
;
87 printf("Total of %d symbols\n", interesting
);
89 usefulSymbols
= interesting
;
90 externalSymbols
= syms
;