From 681ded937532774d8272c25efc5bf192e995c41f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 9 Feb 2011 09:59:43 +0900 Subject: [PATCH] Fix debug line number information. --- tools/qfcc/include/debug.h | 2 ++ tools/qfcc/include/expr.h | 2 -- tools/qfcc/source/debug.c | 2 ++ tools/qfcc/source/emit.c | 11 +++++++++++ tools/qfcc/source/expr.c | 1 - tools/qfcc/source/function.c | 2 ++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/qfcc/include/debug.h b/tools/qfcc/include/debug.h index 056c5dbb6..cf4d02900 100644 --- a/tools/qfcc/include/debug.h +++ b/tools/qfcc/include/debug.h @@ -41,4 +41,6 @@ pr_auxfunction_t *new_auxfunction (void); pr_lineno_t *new_lineno (void); struct ddef_s *new_local (void); +extern int lineno_base; + #endif//__debug_h diff --git a/tools/qfcc/include/expr.h b/tools/qfcc/include/expr.h index 92ae685fc..d61ad60cf 100644 --- a/tools/qfcc/include/expr.h +++ b/tools/qfcc/include/expr.h @@ -558,8 +558,6 @@ void init_elements (struct def_s *def, expr_t *eles); const char *get_op_string (int op); -extern int lineno_base; - struct keywordarg_s; struct class_type_s; expr_t *selector_expr (struct keywordarg_s *selector); diff --git a/tools/qfcc/source/debug.c b/tools/qfcc/source/debug.c index 682744c47..c7c6cd5b3 100644 --- a/tools/qfcc/source/debug.c +++ b/tools/qfcc/source/debug.c @@ -52,6 +52,8 @@ static __attribute__ ((used)) const char rcsid[] = #include "qfcc.h" #include "strpool.h" +int lineno_base; + static srcline_t *free_srclines; void diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c index 6ba68d969..32d72fcab 100644 --- a/tools/qfcc/source/emit.c +++ b/tools/qfcc/source/emit.c @@ -162,6 +162,17 @@ emit_statement (statement_t *statement) if (!op) internal_error (statement->expr, "ice ice baby"); + if (options.code.debug && current_func->aux) { + expr_t *e = statement->expr; + pr_uint_t line = (e ? e->line : pr.source_line) - lineno_base; + + if (line != pr.linenos[pr.num_linenos - 1].line) { + pr_lineno_t *lineno = new_lineno (); + + lineno->line = line; + lineno->fa.addr = pr.code->size; + } + } s = codespace_newstatement (pr.code); s->op = op->opcode; s->a = def_a ? def_a->offset : 0; diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index ddfa12f70..769226dad 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -67,7 +67,6 @@ static __attribute__ ((used)) const char rcsid[] = #include "qc-parse.h" static expr_t *free_exprs; -int lineno_base; type_t *ev_types[ev_type_count] = { &type_void, diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 20499614f..aa3e2bf62 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -646,6 +646,8 @@ emit_function (function_t *f, expr_t *e) sblock_t *sblock; f->code = pr.code->size; + if (f->aux) + lineno_base = f->aux->source_line; sblock = make_statements (e); emit_statements (sblock); }