* Copyright (c) 1982, 1993
* The Regents of the University of California. All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)readobj.c 8.1 (Berkeley) 6/6/93";
* Read in the namelist from the obj file.
#include "mappings/filetab.h"
#include "mappings/linetab.h"
LOCAL SYM
*sym
[MAXSYMNO
];
if ((fp
= fopen(file
, "r")) == NIL
) {
panic("can't open %s", file
);
if (hdr
.magicnum
!= MAGICNUM
) {
fseek(fp
, (long) (HEADER_BYTES
- sizeof(struct pxhdr
)), 0);
if (hdr
.magicnum
!= MAGICNUM
) {
fatal("%s is not a Pascal object file", file
);
if (hdr
.symtabsize
== 0) {
fatal("%s doesn't have symbolic information", file
);
fseek(fp
, (long) objsize
, 1);
if (get(fp
, nlhdr
) != 1) {
panic("can't read nlhdr");
printf("\nHeader information:\n");
printf("\tobject size %d\n", objsize
);
printf("\tsymtab size %d\n", hdr
.symtabsize
);
printf("\tstringsize %d\n", nlhdr
.stringsize
);
printf("\tnsyms %d\n", nlhdr
.nsyms
);
printf("\tnfiles %d\n", nlhdr
.nfiles
);
printf("\tnlines %d\n", nlhdr
.nlines
);
stringtab
= alloc(nlhdr
.stringsize
, char);
fread(stringtab
, sizeof(char), nlhdr
.stringsize
, fp
);
* Allocate and read in file name information table.
filetab
= alloc(nlhdr
.nfiles
, FILETAB
);
for (i
= 0; i
< nlhdr
.nfiles
; i
++) {
fread(&temp
, sizeof(FILETAB
), 1, fp
);
if (temp
.addr
!= prevaddr
) {
ftp
->filename
+= (int) stringtab
;
nlhdr
.nfiles
= (ftp
- &filetab
[0]) + 1;
skimsource(filetab
[0].filename
);
dotpfile
= filetab
[0].filename
;
* Allocate and read in line number information table.
linetab
= alloc(nlhdr
.nlines
, LINETAB
);
for (lp
= &linetab
[0]; lp
< &linetab
[nlhdr
.nlines
]; lp
++) {
for (ftp
= &filetab
[0]; ftp
< &filetab
[nlhdr
.nfiles
]; ftp
++) {
if (ftp
->lineindex
< nlhdr
.nlines
) {
linetab
[ftp
->lineindex
].line
= ftp
->line
;
for (lp
= &linetab
[0]; lp
< &linetab
[nlhdr
.nlines
]; lp
++) {
info
.together
= getw(fp
);
oline
+= info
.separate
.lineincr
;
oaddr
+= info
.separate
.addrincr
;
symtab
= st_creat(nlhdr
.nsyms
);
for (i
= 0; i
< nlhdr
.nsyms
; i
++) {
panic("symbol number too large (%d)", symno
);
sym
[symno
] = readsym(fp
);
panic("patchlist not empty after reading namelist");
typedef struct patchinfo
{
struct patchinfo
*next_patch
;
* Go through patchlist looking for symbol numbers for which the
* sym array now has a non-NIL entry.
* Afterwards, zap the sym array.
register PATCH
*p
, *last
, *next
;
for (p
= phead
; p
!= NIL
; p
= next
) {
if ((s
= sym
[(int) *t
]) != NIL
) {
for (t
= &sym
[0]; t
< &sym
[MAXSYMNO
]; t
++) {
* Check to see if the given pointer (really symbol number) should
* be added to the patch list. The argument is double indirect
* to do call by reference passing.
if ((t
= sym
[(int) s
]) != NIL
) {
patch
->next_patch
= phead
;
* Free all the object information.
for (i
= 0; i
< MAXSYMNO
; i
++) {