1990-08-31 18:22:53 +00:00
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <out.h>
|
|
|
|
#include <stb.h>
|
|
|
|
|
|
|
|
#include "position.h"
|
|
|
|
#include "scope.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "idf.h"
|
|
|
|
#include "symbol.h"
|
1993-11-10 15:11:28 +00:00
|
|
|
#include "misc.h"
|
1990-08-31 18:22:53 +00:00
|
|
|
|
|
|
|
extern FILE *db_out;
|
|
|
|
|
1992-07-02 11:15:18 +00:00
|
|
|
static struct outname *f_start, *f_end;
|
1990-08-31 18:22:53 +00:00
|
|
|
|
|
|
|
/* extern p_position get_position_from_addr(t_addr t);
|
|
|
|
Returns a pointer to a structure containing the source position of the code
|
|
|
|
at address 't'. 0 is returned if no source position could be found.
|
|
|
|
*/
|
|
|
|
p_position
|
|
|
|
get_position_from_addr(t)
|
|
|
|
t_addr t;
|
|
|
|
{
|
|
|
|
static t_position retval;
|
1992-07-02 11:15:18 +00:00
|
|
|
register struct outname *p;
|
|
|
|
register int i,j;
|
1990-08-31 18:22:53 +00:00
|
|
|
|
1992-07-02 11:15:18 +00:00
|
|
|
if (! f_start) return 0;
|
1990-08-31 18:22:53 +00:00
|
|
|
i = 0;
|
1992-07-02 11:15:18 +00:00
|
|
|
j = f_end - f_start;
|
1990-08-31 18:22:53 +00:00
|
|
|
do {
|
1992-07-02 11:15:18 +00:00
|
|
|
p = &f_start[((i + j) >> 1) + ((i + j) & 1)];
|
|
|
|
while ((p->on_type >> 8) != N_SLINE) p++;
|
|
|
|
if (p->on_valu > t) {
|
|
|
|
p--;
|
|
|
|
while (p > &f_start[i] && (p->on_type >> 8) != N_SLINE) p--;
|
|
|
|
j = p-f_start;
|
1990-08-31 18:22:53 +00:00
|
|
|
}
|
1992-07-02 11:15:18 +00:00
|
|
|
else i = p-f_start;
|
1990-08-31 18:22:53 +00:00
|
|
|
} while (i < j);
|
1992-07-02 11:15:18 +00:00
|
|
|
retval.lineno = f_start[j].on_desc;
|
|
|
|
p = &f_start[j-1];
|
|
|
|
while ((i = p->on_type >> 8) != N_SOL && i != N_SO) p--;
|
|
|
|
retval.filename = p->on_mptr;
|
1990-08-31 18:22:53 +00:00
|
|
|
return &retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extern t_addr get_addr_from_position(p_position p);
|
|
|
|
Returns the address of the code at position 'p', or ILL_ADDR if it could
|
|
|
|
not be found. If there is no symbolic information for the filename in
|
|
|
|
position 'p', an error message will be given.
|
|
|
|
*/
|
|
|
|
t_addr
|
|
|
|
get_addr_from_position(p)
|
|
|
|
p_position p;
|
|
|
|
{
|
|
|
|
register p_symbol sym = Lookup(findidf(p->filename), PervasiveScope, FILESYM);
|
|
|
|
|
|
|
|
if (sym) {
|
|
|
|
register unsigned int i;
|
|
|
|
register p_file map = sym->sy_file;
|
|
|
|
|
|
|
|
for (i = p->lineno; i > 0; i--) {
|
|
|
|
register struct outname *n = map->f_line_addr[HASH(i)];
|
|
|
|
|
|
|
|
while (n) {
|
|
|
|
if (n->on_desc == i) return (t_addr) n->on_valu;
|
|
|
|
n = next_outname(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ILL_ADDR;
|
|
|
|
}
|
|
|
|
error("no symbolic information for file %s", p->filename);
|
|
|
|
return ILL_ADDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* extern add_position_addr(char *filename, struct outname *n);
|
|
|
|
Adds the ('filename','lineno'),'t' pair to the mapping information.
|
|
|
|
*/
|
|
|
|
add_position_addr(filename, n)
|
|
|
|
char *filename;
|
|
|
|
register struct outname *n;
|
|
|
|
{
|
|
|
|
static char *lastfile = 0;
|
|
|
|
static p_file lastmap = 0;
|
|
|
|
register p_file map = lastmap;
|
|
|
|
|
|
|
|
if (filename != lastfile) { /* new file ... */
|
|
|
|
register p_symbol sym;
|
|
|
|
|
|
|
|
lastfile = filename;
|
|
|
|
if (! filename) { /* last call */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sym = Lookup(findidf(filename), PervasiveScope, FILESYM);
|
|
|
|
if (sym) map = sym->sy_file;
|
|
|
|
else {
|
|
|
|
sym = add_file(filename);
|
|
|
|
map = sym->sy_file;
|
|
|
|
map->f_scope = FileScope;
|
|
|
|
}
|
|
|
|
lastmap = map;
|
1992-07-02 11:15:18 +00:00
|
|
|
if (! f_start) f_start = n;
|
1990-08-31 18:22:53 +00:00
|
|
|
}
|
|
|
|
else map = lastmap;
|
1990-10-11 08:42:07 +00:00
|
|
|
if (map) {
|
1992-07-02 11:15:18 +00:00
|
|
|
f_end = n;
|
1990-10-11 08:42:07 +00:00
|
|
|
setnext_outname(n, map->f_line_addr[HASH(n->on_desc)]);
|
|
|
|
map->f_line_addr[HASH(n->on_desc)] = n;
|
|
|
|
}
|
1990-08-31 18:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* extern p_position print_position(t_addr a, int print_function);
|
|
|
|
Prints position 'a' and returns it. If 'print_function' is set,
|
|
|
|
an attempt is made to print the function name as well.
|
|
|
|
*/
|
|
|
|
p_position
|
|
|
|
print_position(a, print_function)
|
|
|
|
t_addr a;
|
|
|
|
int print_function;
|
|
|
|
{
|
|
|
|
register p_position pos = get_position_from_addr(a);
|
|
|
|
|
1990-11-12 13:46:31 +00:00
|
|
|
if (print_function) {
|
|
|
|
register p_scope sc = base_scope(get_scope_from_addr(a));
|
|
|
|
if (sc) fprintf(db_out, "in %s ", sc->sc_definedby->sy_idf->id_text);
|
1990-08-31 18:22:53 +00:00
|
|
|
}
|
|
|
|
if (pos) fprintf(db_out, "at \"%s\":%u", pos->filename, pos->lineno);
|
|
|
|
return pos;
|
|
|
|
}
|