/* Copyright (c) 1982 Regents of the University of California */
static char sccsid
[] = "@(#)mappings.c 1.2 %G%";
* Source-to-object and vice versa mappings.
Lineno lineindex
; /* index to first linetab entry */
#define NOADDR ((Address) -1) /* no address for line or procedure */
* Get the source file name associated with a given address.
public String
srcfilename(addr
)
register Address i
, j
, k
;
if (nlhdr
.nfiles
!= 0 and addr
>= filetab
[0].addr
) {
if (addr
>= filetab
[i
].addr
) {
s
= filetab
[i
-1].filename
;
* Find the line associated with the given address.
* If the second parameter is true, then the address must match
* a source line exactly. Otherwise the nearest source line
* below the given address is returned. In any case, if no suitable
* line exists, 0 is returned.
private Lineno
findline(addr
, exact
)
register Address i
, j
, k
;
if (nlhdr
.nlines
== 0 or addr
< linetab
[0].addr
) {
if (addr
== linetab
[i
].addr
) {
} else if (addr
== linetab
[j
].addr
) {
} else if (addr
> linetab
[j
].addr
) {
r
= exact
? 0 : linetab
[j
].line
;
} else if (addr
> linetab
[i
].addr
) {
* Lookup the source line number nearest from below to an address.
public Lineno
srcline(addr
)
return findline(addr
, false);
* Look for a line exactly corresponding to the given address.
public Lineno
linelookup(addr
)
return findline(addr
, true);
* Lookup the object address of a given line from the named file.
* Potentially all files in the file table need to be checked
* until the line is found since a particular file name may appear
* more than once in the file table (caused by includes).
public Address
objaddr(line
, name
)
for (ftp
= &filetab
[0]; ftp
< &filetab
[nlhdr
.nfiles
]; ftp
++) {
if (streq(ftp
->filename
, name
)) {
if (ftp
== &filetab
[nlhdr
.nfiles
-1]) {
j
= (ftp
+ 1)->lineindex
;
if (linetab
[i
].line
== line
) {
error("unknown source file \"%s\"", name
);
* Table for going from object addresses to the functions in which they belong.
#define MAXNFUNCS 1001 /* maximum number of functions allowed */
private Symbol functab
[MAXNFUNCS
];
* Insert a new function into the table.
* The table is ordered by object address.
if (nfuncs
>= MAXNFUNCS
) {
panic("too many procedures/functions");
* Return the function that begins at the given address.
public Symbol
whatblock(addr
)
if (addr
< codeloc(functab
[i
])) {
} else if (addr
== codeloc(functab
[i
])) {
} else if (addr
>= codeloc(functab
[j
])) {
if (addr
> codeloc(functab
[i
])) {
private int cmpfunc(f1
, f2
)
return ( (a1
< a2
) ? -1 : ( (a1
== a2
) ? 0 : 1 ) );
qsort(functab
, nfuncs
, sizeof(Symbol
), cmpfunc
);
* Clear out the functab, used when re-reading the object information.