~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/tools/leaky/coff.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/
 
5
//
 
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.
 
10
//
 
11
// The Initial Developer of the Original Code is Kipp E.B. Hickman.
 
12
 
 
13
#include "leaky.h"
 
14
 
 
15
#ifdef USE_COFF
 
16
 
 
17
#define LANGUAGE_C
 
18
#include <sym.h>
 
19
#include <cmplrs/stsupport.h>
 
20
#include <symconst.h>
 
21
#include <filehdr.h>
 
22
#include <ldfcn.h>
 
23
#include <string.h>
 
24
#include <stdlib.h>
 
25
 
 
26
#ifdef IRIX4
 
27
extern "C" {
 
28
    extern char *demangle(char const* in);
 
29
};
 
30
#else
 
31
#include <dem.h>
 
32
#endif
 
33
 
 
34
static char *Demangle(char *rawName)
 
35
{
 
36
#ifdef IRIX4
 
37
    return strdup(demangle(rawName));
 
38
#else
 
39
    char namebuf[4000];
 
40
    demangle(rawName, namebuf);
 
41
    return strdup(namebuf);
 
42
#endif
 
43
}
 
44
 
 
45
void leaky::readSymbols(const char *fileName)
 
46
{
 
47
    LDFILE *ldptr;
 
48
 
 
49
    ldptr = ldopen(fileName, NULL);
 
50
    if (!ldptr) {
 
51
        fprintf(stderr, "%s: unable to open \"%s\"\n", applicationName,
 
52
                fileName);
 
53
        exit(-1);
 
54
    }
 
55
    if (PSYMTAB(ldptr) == 0) {
 
56
        fprintf(stderr, "%s: \"%s\": has no symbol table\n", applicationName,
 
57
                fileName);
 
58
        exit(-1);
 
59
    }
 
60
 
 
61
    long isymMax = SYMHEADER(ldptr).isymMax;
 
62
    long iextMax = SYMHEADER(ldptr).iextMax;
 
63
    long iMax = isymMax + iextMax;
 
64
 
 
65
    long alloced = 10000;
 
66
    Symbol* syms = (Symbol*) malloc(sizeof(Symbol) * 10000);
 
67
    Symbol* sp = syms;
 
68
    Symbol* last = syms + alloced;
 
69
    SYMR symr;
 
70
 
 
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,
 
74
                    isym);
 
75
            exit(-1);
 
76
        }
 
77
        if (isym < isymMax) {
 
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;
 
86
                sp++;
 
87
                if (sp >= last) {
 
88
                    long n = alloced + 10000;
 
89
                    syms = (Symbol*)
 
90
                        realloc(syms, (size_t) (sizeof(Symbol) * n));
 
91
                    last = syms + n;
 
92
                    sp = syms + alloced;
 
93
                    alloced = n;
 
94
                }
 
95
            }
 
96
        }
 
97
    }
 
98
 
 
99
    int interesting = sp - syms;
 
100
    if (!quiet) {
 
101
        printf("Total of %d symbols\n", interesting);
 
102
    }
 
103
    usefulSymbols = interesting;
 
104
    externalSymbols = syms;
 
105
}
 
106
 
 
107
#endif /* USE_COFF */