Fix line number info.

line number info is now 1 based rather than 0 based (to better detect when
a function does not have line number info).
This commit is contained in:
Bill Currie 2011-03-05 15:40:08 +09:00
parent 1dea86a3e4
commit 97b1ceceb0
3 changed files with 29 additions and 13 deletions

View File

@ -582,6 +582,9 @@ linker_begin (void)
for (i = 0; i < qfo_num_spaces; i++)
work->spaces[i].id = i;
work->lines = calloc (1, sizeof (pr_lineno_t));
work->num_lines = 1;
if (!options.partial_link) {
for (i = 0; i < num_builtins; i++) {
builtin_sym_t *bi = builtin_symbols + i;
@ -752,7 +755,8 @@ process_funcs (qfo_t *qfo)
func->code += work_base[qfo_code_space];
func->def = qfo->defs[func->def].offset; // defref index
func->locals_space = qfo->spaces[func->locals_space].id;
func->line_info += work->num_lines; //FIXME order dependent
if (func->line_info)
func->line_info += work->num_lines - 1; //FIXME order dependent
func->relocs = add_relocs (qfo, func->relocs, func->num_relocs,
func - work->funcs);
}
@ -764,10 +768,12 @@ process_lines (qfo_t *qfo)
int size;
pr_lineno_t *line;
size = work->num_lines + qfo->num_lines;
if (!qfo->num_lines)
return;
size = work->num_lines + qfo->num_lines - 1;
work->lines = realloc (work->lines, size * sizeof (pr_lineno_t));
memcpy (work->lines + work->num_lines, qfo->lines,
qfo->num_lines * sizeof (pr_lineno_t));
memcpy (work->lines + work->num_lines, qfo->lines + 1,
(qfo->num_lines - 1) * sizeof (pr_lineno_t));
while (work->num_lines < size) {
line = work->lines + work->num_lines++;
if (line->line)

View File

@ -912,6 +912,7 @@ qfo_to_sym (qfo_t *qfo, int *size)
pr_debug_header_t *sym;
int i, j;
pr_auxfunction_t *auxfuncs;
pr_auxfunction_t *aux;
pr_lineno_t *linenos;
ddef_t *locals, *ld;
@ -947,7 +948,7 @@ qfo_to_sym (qfo_t *qfo, int *size)
ld = locals;
for (i = 0; i < qfo->num_funcs; i++) {
for (i = 0, aux = auxfuncs; i < qfo->num_funcs; i++) {
qfo_func_t *func = qfo->funcs + i;
qfo_def_t *def = 0;
int num_locals = 0;
@ -959,20 +960,22 @@ qfo_to_sym (qfo_t *qfo, int *size)
}
if (!func->line_info && !num_locals)
continue;
memset (auxfuncs, 0, sizeof (*auxfuncs));
auxfuncs->function = i;
auxfuncs->source_line = func->line;
auxfuncs->line_info = func->line_info;
memset (aux, 0, sizeof (*aux));
aux->function = i + 1;
aux->source_line = func->line;
aux->line_info = func->line_info;
if (func->line_info)
qfo->lines[func->line_info].fa.func = aux - auxfuncs;
if (num_locals) {
auxfuncs->local_defs = ld - locals;
aux->local_defs = ld - locals;
for (j = 0; j < num_locals; j++)
convert_def (qfo, def++, ld++);
}
auxfuncs->num_locals = num_locals;
aux->num_locals = num_locals;
//FIXME check type
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, func->type);
auxfuncs->return_type = type->t.func.return_type;
auxfuncs++;
aux->return_type = type->t.func.return_type;
aux++;
}
memcpy (linenos, qfo->lines, qfo->num_lines * sizeof (pr_lineno_t));
return sym;

View File

@ -124,6 +124,8 @@ fix_backslash (char *path)
static void
InitData (void)
{
pr_lineno_t *line;
if (pr.code) {
codespace_delete (pr.code);
strpool_delete (pr.strings);
@ -136,6 +138,11 @@ InitData (void)
pr.strings = strpool_new ();
pr.num_functions = 1;
pr.num_linenos = 0;
line = new_lineno ();
line->fa.func = -1;
line->line = -1;
pr.data = defspace_new ();
pr.far_data = defspace_new ();