2001-09-28 07:09:38 +00:00
|
|
|
/*
|
2002-10-22 14:53:18 +00:00
|
|
|
debug.c
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
debug info support
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Copyright (C) 2001 Bill Currie <bill@taniwha.org>
|
2001-09-28 07:09:38 +00:00
|
|
|
|
2002-10-22 14:53:18 +00:00
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2001/7/14
|
2001-09-28 07:09:38 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2002-06-01 04:41:25 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
2011-01-06 05:57:40 +00:00
|
|
|
#include <ctype.h>
|
2002-06-01 04:41:25 +00:00
|
|
|
|
2012-12-06 11:52:53 +00:00
|
|
|
#include "QF/alloc.h"
|
2002-06-04 21:23:39 +00:00
|
|
|
#include "QF/pr_comp.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
2011-01-24 12:54:57 +00:00
|
|
|
#include "diagnostic.h"
|
2011-01-06 05:57:40 +00:00
|
|
|
#include "expr.h"
|
2002-07-17 14:19:30 +00:00
|
|
|
#include "qfcc.h"
|
2011-01-24 12:31:32 +00:00
|
|
|
#include "strpool.h"
|
2011-03-22 03:24:39 +00:00
|
|
|
#include "value.h"
|
2001-07-14 01:16:07 +00:00
|
|
|
|
2011-02-09 00:59:43 +00:00
|
|
|
int lineno_base;
|
|
|
|
|
2011-01-06 05:57:40 +00:00
|
|
|
static srcline_t *free_srclines;
|
|
|
|
|
2012-12-04 03:48:52 +00:00
|
|
|
static void
|
2011-01-06 05:57:40 +00:00
|
|
|
push_source_file (void)
|
|
|
|
{
|
|
|
|
srcline_t *srcline;
|
|
|
|
ALLOC (16, srcline_t, srclines, srcline);
|
|
|
|
srcline->source_file = pr.source_file;
|
|
|
|
srcline->source_line = pr.source_line;
|
|
|
|
srcline->next = pr.srcline_stack;
|
|
|
|
pr.srcline_stack = srcline;
|
|
|
|
}
|
|
|
|
|
2012-12-04 03:48:52 +00:00
|
|
|
static void
|
2011-01-06 05:57:40 +00:00
|
|
|
pop_source_file (void)
|
|
|
|
{
|
|
|
|
srcline_t *tmp;
|
|
|
|
|
|
|
|
if (!pr.srcline_stack) {
|
|
|
|
notice (0, "unbalanced #includes. bug in preprocessor?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmp = pr.srcline_stack;
|
|
|
|
pr.srcline_stack = tmp->next;
|
2012-12-04 04:23:31 +00:00
|
|
|
FREE (srclines, tmp);
|
2011-01-06 05:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
line_info (char *text)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
char *s;
|
|
|
|
const char *str;
|
|
|
|
int line;
|
|
|
|
int flags;
|
|
|
|
|
|
|
|
p = text;
|
|
|
|
line = strtol (p, &s, 10);
|
|
|
|
p = s;
|
|
|
|
while (isspace ((unsigned char)*p))
|
|
|
|
p++;
|
|
|
|
if (!*p)
|
|
|
|
error (0, "Unexpected end of file");
|
|
|
|
str = make_string (p, &s); // grab the filename
|
|
|
|
p = s;
|
|
|
|
while (isspace ((unsigned char) *p))
|
|
|
|
p++;
|
|
|
|
flags = strtol (p, &s, 10);
|
|
|
|
switch (flags) {
|
|
|
|
case 1:
|
|
|
|
push_source_file ();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pop_source_file ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (*p && *p != '\n') // ignore rest
|
|
|
|
p++;
|
|
|
|
pr.source_line = line - 1;
|
|
|
|
pr.source_file = ReuseString (strip_path (str));
|
|
|
|
}
|
|
|
|
|
2001-07-14 01:16:07 +00:00
|
|
|
pr_lineno_t *
|
|
|
|
new_lineno (void)
|
|
|
|
{
|
2002-07-17 14:19:30 +00:00
|
|
|
if (pr.num_linenos == pr.linenos_size) {
|
|
|
|
pr.linenos_size += 1024;
|
|
|
|
pr.linenos = realloc (pr.linenos,
|
|
|
|
pr.linenos_size * sizeof (pr_lineno_t));
|
2001-07-14 01:16:07 +00:00
|
|
|
}
|
2002-07-17 14:19:30 +00:00
|
|
|
memset (&pr.linenos[pr.num_linenos], 0, sizeof (pr_lineno_t));
|
|
|
|
return &pr.linenos[pr.num_linenos++];
|
2001-07-14 01:16:07 +00:00
|
|
|
}
|