This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PCH] fix dbx debug output
- From: Geoffrey Keating <gkeating at apple dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 25 Nov 2002 19:26:37 -0800 (PST)
- Subject: [PCH] fix dbx debug output
This fixes all the dbx debugging PCH testcase failures but one.
Bootstrapped & tested on powerpc-darwin with gcac checking.
--
- Geoffrey Keating <geoffk@apple.com>
===File ~/patches/pchbranch-dbxggc.patch====================
2002-11-22 Geoffrey Keating <geoffk@apple.com>
* dbxout.c: Include gt-dbxout.h.
(lastfile): Mark for PCH/GGC.
(cwd): Likewise.
(struct typeinfo): Likewise.
(typevec): Likewise.
(typevec_len): Likewise.
(next_type_number): Likewise.
(struct dbx_file): Likewise.
(current_file): Likewise.
(next_file_number): Likewise.
(dbxout_init): Allocate typevec, struct dbx_file with GGC.
(dbxout_start_source_file): Allocate struct dbx_file with GGC.
(dbxout_end_source_file): Don't free struct dbx_file.
(dbxout_type): Use GGC to allocate typevec.
* Makefile.in (dbxout.o): Depend on gt-dbxout.h, $(GGC_H).
(GTFILES): Add dbxout.c.
(gt-dbxout.h): New rule.
* Makefile.in (c-pch.o): Add debug.h as dependency.
* c-pch.c: Include debug.h.
(pch_init): Call start_source_file to keep nesting right.
(c_common_read_pch): Add orig_name parameter. Call
start_source_file debug hook. Call end_source_file debug hook.
* c-common.h (c_common_read_pch): Update prototype.
* cpplib.h (struct cpp_callbacks): Add fourth field to read_pch
callback.
* cppfiles.c (struct include_file): Add new field `header_name'.
(find_or_create_entry): Default it to `name'.
(open_file_pch): Set it to the original header file searched for.
(stack_include_file): Don't stack an empty buffer, just handle
PCH files immediately. Pass header_name field to read_pch callback.
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.822.2.38
diff -u -p -u -p -r1.822.2.38 Makefile.in
--- Makefile.in 16 Nov 2002 03:44:19 -0000 1.822.2.38
+++ Makefile.in 25 Nov 2002 19:08:37 -0000
@@ -1253,7 +1253,7 @@ c-semantics.o : c-semantics.c $(CONFIG_H
c-dump.o : c-dump.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) tree-dump.h
c-pch.o : c-pch.c $(CONFIG_H) $(SYSTEM_H) $(CPPLIB_H) $(TREE_H) c-common.h \
- output.h toplev.h c-pragma.h $(GGC_H)
+ output.h toplev.h c-pragma.h $(GGC_H) debug.h
# Language-independent files.
@@ -1447,7 +1447,8 @@ optabs.o : optabs.c $(CONFIG_H) $(SYSTEM
toplev.h $(GGC_H) real.h $(TM_P_H) except.h gt-optabs.h
dbxout.o : dbxout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h \
$(REGS_H) debug.h $(TM_P_H) $(TARGET_H) function.h langhooks.h \
- insn-config.h reload.h gstab.h xcoffout.h output.h dbxout.h toplev.h
+ insn-config.h reload.h gstab.h xcoffout.h output.h dbxout.h toplev.h \
+ $(GGC_H) gt-dbxout.h
debug.o : debug.c debug.h $(CONFIG_H) $(SYSTEM_H)
sdbout.o : sdbout.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) flags.h \
function.h $(EXPR_H) output.h hard-reg-set.h $(REGS_H) real.h \
@@ -1846,7 +1847,7 @@ GTFILES = $(GCONFIG_H) \
$(srcdir)/basic-block.h $(srcdir)/location.h \
$(srcdir)/c-common.h $(srcdir)/c-tree.h \
$(srcdir)/alias.c $(srcdir)/bitmap.c $(srcdir)/cselib.c \
- $(srcdir)/dwarf2out.c $(srcdir)/dwarf2asm.c \
+ $(srcdir)/dbxout.c $(srcdir)/dwarf2out.c $(srcdir)/dwarf2asm.c \
$(srcdir)/emit-rtl.c $(srcdir)/except.c $(srcdir)/explow.c $(srcdir)/expr.c \
$(srcdir)/fold-const.c $(srcdir)/function.c \
$(srcdir)/gcse.c $(srcdir)/integrate.c $(srcdir)/lists.c $(srcdir)/optabs.c \
@@ -1867,7 +1868,7 @@ gt-integrate.h gt-stmt.h gt-tree.h gt-va
gt-explow.h gt-stor-layout.h gt-regclass.h gt-lists.h : s-gtype; @true
gt-alias.h gt-cselib.h gt-fold-const.h gt-gcse.h gt-profile.h : s-gtype; @true
gt-expr.h gt-sdbout.h gt-optabs.h gt-bitmap.h gt-dwarf2out.h : s-gtype ; @true
-gt-ra-build.h gt-reg-stack.h gt-dwarf2asm.h : s-gtype ; @true
+gt-ra-build.h gt-reg-stack.h gt-dwarf2asm.h gt-dbxout.h : s-gtype ; @true
gt-c-common.h gt-c-decl.h gt-c-parse.h gt-c-pragma.h : s-gtype; @true
gt-c-objc-common.h gtype-c.h gt-location.h gt-stringpool.h : s-gtype ; @true
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.112.4.21
diff -u -p -u -p -r1.112.4.21 c-common.h
--- c-common.h 14 Nov 2002 17:46:23 -0000 1.112.4.21
+++ c-common.h 25 Nov 2002 19:08:37 -0000
@@ -1272,7 +1272,8 @@ extern int c_common_valid_pch PARAMS (
int fd));
extern void c_common_read_pch PARAMS ((cpp_reader *pfile,
const char *name,
- int fd));
+ int fd,
+ const char *orig));
extern void c_common_write_pch PARAMS ((void));
#endif /* ! GCC_C_COMMON_H */
Index: c-pch.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-pch.c,v
retrieving revision 1.1.2.5
diff -u -p -u -p -r1.1.2.5 c-pch.c
--- c-pch.c 9 Nov 2002 01:12:21 -0000 1.1.2.5
+++ c-pch.c 25 Nov 2002 19:08:37 -0000
@@ -25,6 +25,7 @@ Boston, MA 02111-1307, USA. */
#include "c-common.h"
#include "output.h"
#include "toplev.h"
+#include "debug.h"
#include "c-pragma.h"
#include "ggc.h"
@@ -47,6 +48,10 @@ pch_init ()
if (pch_file)
{
+ /* We're precompiling a header file, so when it's actually used,
+ it'll be at least one level deep. */
+ (*debug_hooks->start_source_file) (lineno, input_filename);
+
f = fopen (pch_file, "w+b");
if (f == NULL)
fatal_io_error ("can't open %s", pch_file);
@@ -163,10 +168,11 @@ c_common_valid_pch (pfile, name, fd)
}
void
-c_common_read_pch (pfile, name, fd)
+c_common_read_pch (pfile, name, fd, orig_name)
cpp_reader *pfile;
const char *name;
int fd;
+ const char *orig_name;
{
FILE *f;
struct c_pch_header h;
@@ -174,6 +180,10 @@ c_common_read_pch (pfile, name, fd)
unsigned long written;
struct save_macro_data *smd;
+ /* Before we wrote the file, we started a source file, so we have to start
+ one here to match. */
+ (*debug_hooks->start_source_file) (lineno, orig_name);
+
f = fdopen (fd, "rb");
if (f == NULL)
{
@@ -210,4 +220,6 @@ c_common_read_pch (pfile, name, fd)
return;
fclose (f);
+
+ (*debug_hooks->end_source_file) (lineno);
}
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.143.2.10
diff -u -p -u -p -r1.143.2.10 cppfiles.c
--- cppfiles.c 10 Nov 2002 07:16:49 -0000 1.143.2.10
+++ cppfiles.c 25 Nov 2002 19:08:37 -0000
@@ -80,6 +80,7 @@ Foundation, 59 Temple Place - Suite 330,
struct include_file
{
const char *name; /* actual path name of file */
+ const char *header_name; /* the original header found */
const cpp_hashnode *cmacro; /* macro, if any, preventing reinclusion. */
const struct search_path *foundhere;
/* location in search path where file was
@@ -215,6 +216,7 @@ find_or_create_entry (pfile, fname)
{
file = xcnew (struct include_file);
file->name = name;
+ file->header_name = name;
file->err_no = errno;
node = splay_tree_insert (pfile->all_include_files,
(splay_tree_key) file->name,
@@ -330,6 +332,8 @@ open_file_pch (pfile, filename)
{
if ((file->pch & 2) == 0)
file->pch = pfile->cb.valid_pch (pfile, pchname, file->fd);
+ file->header_name = xstrdup (filename);
+ _cpp_simplify_pathname (file->header_name);
if (INCLUDE_PCH_P (file))
return file;
close (file->fd);
@@ -365,47 +369,40 @@ stack_include_file (pfile, inc)
deps_add_dep (pfile->deps, inc->name);
}
- /* PCH files get dealt with immediately.
- We stack a zero-sized buffer below.
- The reason for this is that reading a PCH directly into memory
- will approximately double the memory consumption of the compiler. */
+ /* PCH files get dealt with immediately. */
if (INCLUDE_PCH_P (inc))
{
- pfile->cb.read_pch (pfile, inc->name, inc->fd);
+ pfile->cb.read_pch (pfile, inc->name, inc->fd, inc->header_name);
close (inc->fd);
inc->fd = -1;
-
- fp = cpp_push_buffer (pfile, (unsigned char *)"", 0, 0, 0);
+ return false;
}
- else
+
+ /* Not in cache? */
+ if (! inc->buffer)
{
- /* Not in cache? */
- if (! inc->buffer)
+ if (read_include_file (pfile, inc))
{
- if (read_include_file (pfile, inc))
- {
- /* If an error occurs, do not try to read this file again. */
- _cpp_never_reread (inc);
- return false;
- }
- /* Mark a regular, zero-length file never-reread. We read it,
- NUL-terminate it, and stack it once, so preprocessing a main
- file of zero length does not raise an error. */
- if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
- _cpp_never_reread (inc);
- close (inc->fd);
- inc->fd = -1;
+ /* If an error occurs, do not try to read this file again. */
+ _cpp_never_reread (inc);
+ return false;
}
-
- if (pfile->buffer)
- /* We don't want MI guard advice for the main file. */
- inc->include_count++;
-
- /* Push a buffer. */
- fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size,
- /* from_stage3 */ CPP_OPTION (pfile, preprocessed),
- 0);
+ /* Mark a regular, zero-length file never-reread. We read it,
+ NUL-terminate it, and stack it once, so preprocessing a main
+ file of zero length does not raise an error. */
+ if (S_ISREG (inc->st.st_mode) && inc->st.st_size == 0)
+ _cpp_never_reread (inc);
+ close (inc->fd);
+ inc->fd = -1;
}
+
+ if (pfile->buffer)
+ /* We don't want MI guard advice for the main file. */
+ inc->include_count++;
+
+ /* Push a buffer. */
+ fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size,
+ /* from_stage3 */ CPP_OPTION (pfile, preprocessed), 0);
fp->inc = inc;
fp->inc->refcnt++;
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.199.4.14
diff -u -p -u -p -r1.199.4.14 cpplib.h
--- cpplib.h 14 Nov 2002 17:46:24 -0000 1.199.4.14
+++ cpplib.h 25 Nov 2002 19:08:37 -0000
@@ -427,7 +427,7 @@ struct cpp_callbacks
built-ins with cpp_define() and cpp_assert(). */
void (*register_builtins) PARAMS ((cpp_reader *));
int (*valid_pch) PARAMS ((cpp_reader *, const char *, int));
- void (*read_pch) PARAMS ((cpp_reader *, const char *, int));
+ void (*read_pch) PARAMS ((cpp_reader *, const char *, int, const char *));
};
/* Name under which this program was invoked. */
Index: cpppch.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cpppch.c,v
retrieving revision 1.1.4.4
diff -u -p -u -p -r1.1.4.4 cpppch.c
--- cpppch.c 15 Nov 2002 18:21:58 -0000 1.1.4.4
+++ cpppch.c 25 Nov 2002 19:08:37 -0000
@@ -563,6 +563,7 @@ cpp_read_state (r, name, f, data)
struct lexer_state old_state;
struct save_macro_data *d;
size_t i;
+ int saved_line = r->line;
/* First, erase all the existing hashtable entries for macros. At
this point, they're all from the PCH file, and their pointers
@@ -639,6 +640,7 @@ cpp_read_state (r, name, f, data)
}
r->state = old_state;
+ r->line = saved_line;
free (defn);
defn = NULL;
Index: dbxout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/dbxout.c,v
retrieving revision 1.114.4.8
diff -u -p -u -p -r1.114.4.8 dbxout.c
--- dbxout.c 10 Nov 2002 07:16:50 -0000 1.114.4.8
+++ dbxout.c 25 Nov 2002 19:08:37 -0000
@@ -135,64 +135,13 @@ Software Foundation, 59 Temple Place - S
#define STABS_GCC_MARKER "gcc2_compiled."
#endif
-/* Typical USG systems don't have stab.h, and they also have
- no use for DBX-format debugging info. */
-
-#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
-
-/* Nonzero if we have actually used any of the GDB extensions
- to the debugging format. The idea is that we use them for the
- first time only if there's a strong reason, but once we have done that,
- we use them whenever convenient. */
-
-static int have_used_extensions = 0;
-
-/* Number for the next N_SOL filename stabs label. The number 0 is reserved
- for the N_SO filename stabs label. */
-
-#if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
-static int source_label_number = 1;
-#endif
-
-#ifdef DEBUG_SYMS_TEXT
-#define FORCE_TEXT function_section (current_function_decl);
-#else
-#define FORCE_TEXT
-#endif
-
-#include "gstab.h"
-
-#define STAB_CODE_TYPE enum __stab_debug_code
-
-/* 1 if PARM is passed to this function in memory. */
-
-#define PARM_PASSED_IN_MEMORY(PARM) \
- (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
-
-/* A C expression for the integer offset value of an automatic variable
- (N_LSYM) having address X (an RTX). */
-#ifndef DEBUGGER_AUTO_OFFSET
-#define DEBUGGER_AUTO_OFFSET(X) \
- (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
-#endif
-
-/* A C expression for the integer offset value of an argument (N_PSYM)
- having address X (an RTX). The nominal offset is OFFSET. */
-#ifndef DEBUGGER_ARG_OFFSET
-#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
-#endif
-
-/* Stream for writing to assembler file. */
-
-static FILE *asmfile;
-
/* Last source file name mentioned in a NOTE insn. */
-static const char *lastfile;
+static GTY(()) const char *lastfile;
/* Current working directory. */
-static const char *cwd;
+static GTY(()) const char *cwd;
enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
@@ -203,13 +152,11 @@ enum typestatus {TYPE_UNSEEN, TYPE_XREF,
The file_number and type_number elements are used if DBX_USE_BINCL
is defined. */
-struct typeinfo
+struct typeinfo GTY(())
{
enum typestatus status;
-#ifdef DBX_USE_BINCL
int file_number;
int type_number;
-#endif
};
/* Vector recording information about C data types.
@@ -217,25 +164,23 @@ struct typeinfo
we assign it a number using next_type_number.
That is its index in this vector. */
-struct typeinfo *typevec;
+static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
/* Number of elements of space allocated in `typevec'. */
-static int typevec_len;
+static GTY(()) int typevec_len;
/* In dbx output, each type gets a unique number.
This is the number for the next type output.
The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
-static int next_type_number;
-
-#ifdef DBX_USE_BINCL
+static GTY(()) int next_type_number;
/* When using N_BINCL in dbx output, each type number is actually a
pair of the file number and the type number within the file.
This is a stack of input files. */
-struct dbx_file
+struct dbx_file GTY(())
{
struct dbx_file *next;
int file_number;
@@ -244,13 +189,62 @@ struct dbx_file
/* This is the top of the stack. */
-static struct dbx_file *current_file;
+static GTY(()) struct dbx_file *current_file;
/* This is the next file number to use. */
-static int next_file_number;
+static GTY(()) int next_file_number;
+
+/* Typical USG systems don't have stab.h, and they also have
+ no use for DBX-format debugging info. */
+
+#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
+
+/* Nonzero if we have actually used any of the GDB extensions
+ to the debugging format. The idea is that we use them for the
+ first time only if there's a strong reason, but once we have done that,
+ we use them whenever convenient. */
+
+static int have_used_extensions = 0;
+
+/* Number for the next N_SOL filename stabs label. The number 0 is reserved
+ for the N_SO filename stabs label. */
+
+#if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
+static int source_label_number = 1;
+#endif
+
+#ifdef DEBUG_SYMS_TEXT
+#define FORCE_TEXT function_section (current_function_decl);
+#else
+#define FORCE_TEXT
+#endif
+
+#include "gstab.h"
+
+#define STAB_CODE_TYPE enum __stab_debug_code
+
+/* 1 if PARM is passed to this function in memory. */
+
+#define PARM_PASSED_IN_MEMORY(PARM) \
+ (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
-#endif /* DBX_USE_BINCL */
+/* A C expression for the integer offset value of an automatic variable
+ (N_LSYM) having address X (an RTX). */
+#ifndef DEBUGGER_AUTO_OFFSET
+#define DEBUGGER_AUTO_OFFSET(X) \
+ (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
+#endif
+
+/* A C expression for the integer offset value of an argument (N_PSYM)
+ having address X (an RTX). The nominal offset is OFFSET. */
+#ifndef DEBUGGER_ARG_OFFSET
+#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
+#endif
+
+/* Stream for writing to assembler file. */
+
+static FILE *asmfile;
/* These variables are for dbxout_symbol to communicate to
dbxout_finish_symbol.
@@ -422,7 +416,7 @@ dbxout_init (input_file_name)
asmfile = asm_out_file;
typevec_len = 100;
- typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
+ typevec = (struct typeinfo *) ggc_calloc (typevec_len, sizeof typevec[0]);
/* Convert Ltext into the appropriate format for local labels in case
the system doesn't insert underscores in front of user generated
@@ -481,7 +475,7 @@ dbxout_init (input_file_name)
next_type_number = 1;
#ifdef DBX_USE_BINCL
- current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
+ current_file = (struct dbx_file *) ggc_alloc (sizeof *current_file);
current_file->next = NULL;
current_file->file_number = 0;
current_file->next_type_number = 1;
@@ -538,7 +532,7 @@ dbxout_start_source_file (line, filename
const char *filename ATTRIBUTE_UNUSED;
{
#ifdef DBX_USE_BINCL
- struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
+ struct dbx_file *n = (struct dbx_file *) ggc_alloc (sizeof *n);
n->next = current_file;
n->file_number = next_file_number++;
@@ -557,12 +551,8 @@ dbxout_end_source_file (line)
unsigned int line ATTRIBUTE_UNUSED;
{
#ifdef DBX_USE_BINCL
- struct dbx_file *next;
-
fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
- next = current_file->next;
- free (current_file);
- current_file = next;
+ current_file = current_file->next;
#endif
}
@@ -1091,8 +1081,9 @@ dbxout_type (type, full)
if (next_type_number == typevec_len)
{
typevec
- = (struct typeinfo *) xrealloc (typevec,
- typevec_len * 2 * sizeof typevec[0]);
+ = (struct typeinfo *) ggc_realloc (typevec,
+ (typevec_len * 2
+ * sizeof typevec[0]));
memset ((char *) (typevec + typevec_len), 0,
typevec_len * sizeof typevec[0]);
typevec_len *= 2;
@@ -2950,3 +2941,5 @@ dbxout_begin_function (decl)
#endif /* DBX_DEBUGGING_INFO */
#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
+
+#include "gt-dbxout.h"
Index: gengtype.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gengtype.c,v
retrieving revision 1.1.2.39
diff -u -p -u -p -r1.1.2.39 gengtype.c
--- gengtype.c 10 Nov 2002 07:16:59 -0000 1.1.2.39
+++ gengtype.c 25 Nov 2002 19:08:38 -0000
@@ -2676,6 +2676,7 @@ write_array (f, v, wtd)
oprintf (f, "}\n\n");
}
+ d.opt = v->opt;
oprintf (f, "static void gt_%sa_%s PARAMS ((void *));\n",
wtd->prefix, v->name);
oprintf (f, "static void\ngt_%sa_%s (x_p)\n",
============================================================