1 /* $Id: position.c,v 1.7 1994/06/24 11:00:41 ceriel Exp $ */
18 static struct outname *f_start, *f_end;
20 /* extern p_position get_position_from_addr(t_addr t);
21 Returns a pointer to a structure containing the source position of the code
22 at address 't'. 0 is returned if no source position could be found.
25 get_position_from_addr(t)
28 static t_position retval;
29 register struct outname *p;
32 if (! f_start) return 0;
36 p = &f_start[((i + j) >> 1) + ((i + j) & 1)];
37 while ((p->on_type >> 8) != N_SLINE) p++;
40 while (p > &f_start[i] && (p->on_type >> 8) != N_SLINE) p--;
45 retval.lineno = f_start[j].on_desc;
47 while ((i = p->on_type >> 8) != N_SOL && i != N_SO) p--;
48 retval.filename = p->on_mptr;
52 /* extern t_addr get_addr_from_position(p_position p);
53 Returns the address of the code at position 'p', or ILL_ADDR if it could
54 not be found. If there is no symbolic information for the filename in
55 position 'p', an error message will be given.
58 get_addr_from_position(p)
61 register p_symbol sym = Lookup(findidf(p->filename), PervasiveScope, FILESYM);
64 register unsigned int i;
65 register p_file map = sym->sy_file;
67 for (i = p->lineno; i > 0; i--) {
68 register struct outname *n = map->f_line_addr[HASH(i)];
71 if (n->on_desc == i) return (t_addr) n->on_valu;
77 error("no symbolic information for file %s", p->filename);
81 /* extern add_position_addr(char *filename, struct outname *n);
82 Adds the ('filename','lineno'),'t' pair to the mapping information.
84 add_position_addr(filename, n)
86 register struct outname *n;
88 static char *lastfile = 0;
89 static p_file lastmap = 0;
90 register p_file map = lastmap;
92 if (filename != lastfile) { /* new file ... */
93 register p_symbol sym;
96 if (! filename) { /* last call */
99 sym = Lookup(findidf(filename), PervasiveScope, FILESYM);
100 if (sym) map = sym->sy_file;
102 sym = add_file(filename);
104 map->f_scope = FileScope;
107 if (! f_start) f_start = n;
112 setnext_outname(n, map->f_line_addr[HASH(n->on_desc)]);
113 map->f_line_addr[HASH(n->on_desc)] = n;
117 /* extern p_position print_position(t_addr a, int print_function);
118 Prints position 'a' and returns it. If 'print_function' is set,
119 an attempt is made to print the function name as well.
122 print_position(a, print_function)
126 register p_position pos = get_position_from_addr(a);
128 if (print_function) {
129 register p_scope sc = base_scope(get_scope_from_addr(a));
130 if (sc) fprintf(db_out, "in %s ", sc->sc_definedby->sy_idf->id_text);
132 if (pos) fprintf(db_out, "at \"%s\":%u", pos->filename, pos->lineno);