This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
dwarf2 file handling
- To: gcc-patches at gcc dot gnu dot org
- Subject: dwarf2 file handling
- From: Richard Henderson <rth at redhat dot com>
- Date: Sat, 25 Nov 2000 16:14:31 -0800
The file tables for .debug_info and .debug_line are emitted
separately. This patch separates the two in dwarf2out.c so
that we don't emit more that we'll need into .debug_line.
r~
* dwarf2out.c (file_table, file_table_allocated): Remove.
(file_table_allocated): Remove.
(struct file_table): New.
(decl_file_table, line_file_table): New.
(print_dwarf_line_table): Use them.
(size_of_line_prolog): Likewise.
(output_line_info): Likewise.
(add_src_coords_attributes): Likewise.
(gen_subprogram_die): Likewise.
(gen_variable_die): Likewise.
(dwarf2out_add_library_unit_info): Likewise.
(dwarf2out_line): Likewise.
(lookup_filename): Take a struct file_table argument.
(init_file_table): New.
(dwarf2out_init): Use it.
Index: dwarf2out.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/dwarf2out.c,v
retrieving revision 1.221
diff -c -p -d -r1.221 dwarf2out.c
*** dwarf2out.c 2000/11/20 01:25:59 1.221
--- dwarf2out.c 2000/11/26 00:09:09
*************** static dw_die_ref comp_unit_die;
*** 3173,3193 ****
/* A list of DIEs with a NULL parent waiting to be relocated. */
static limbo_die_node *limbo_die_list = 0;
! /* Pointer to an array of filenames referenced by this compilation unit. */
! static char **file_table;
!
! /* Total number of entries in the table (i.e. array) pointed to by
! `file_table'. This is the *total* and includes both used and unused
! slots. */
! static unsigned file_table_allocated;
!
! /* Number of entries in the file_table which are actually in use. */
! static unsigned file_table_in_use;
/* Size (in elements) of increments by which we may expand the filename
table. */
#define FILE_TABLE_INCREMENT 64
/* Local pointer to the name of the main input file. Initialized in
dwarf2out_init. */
static const char *primary_filename;
--- 3173,3197 ----
/* A list of DIEs with a NULL parent waiting to be relocated. */
static limbo_die_node *limbo_die_list = 0;
! /* Structure used by lookup_filename to manage sets of filenames. */
! struct file_table
! {
! char **table;
! unsigned allocated;
! unsigned in_use;
! unsigned last_lookup_index;
! };
/* Size (in elements) of increments by which we may expand the filename
table. */
#define FILE_TABLE_INCREMENT 64
+ /* Filenames referenced by declarations this compilation unit. */
+ static struct file_table decl_file_table;
+
+ /* Filenames referenced by line numbers in this compilation unit. */
+ static struct file_table line_file_table;
+
/* Local pointer to the name of the main input file. Initialized in
dwarf2out_init. */
static const char *primary_filename;
*************** static void gen_block_die PARAMS ((tree
*** 3516,3522 ****
static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
static int is_redundant_typedef PARAMS ((tree));
static void gen_decl_die PARAMS ((tree, dw_die_ref));
! static unsigned lookup_filename PARAMS ((const char *));
static void add_incomplete_type PARAMS ((tree));
static void retry_incomplete_types PARAMS ((void));
static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
--- 3520,3528 ----
static void decls_for_scope PARAMS ((tree, dw_die_ref, int));
static int is_redundant_typedef PARAMS ((tree));
static void gen_decl_die PARAMS ((tree, dw_die_ref));
! static unsigned lookup_filename PARAMS ((struct file_table *,
! const char *));
! static void init_file_table PARAMS ((struct file_table *));
static void add_incomplete_type PARAMS ((tree));
static void retry_incomplete_types PARAMS ((void));
static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref));
*************** print_dwarf_line_table (outfile)
*** 4978,4984 ****
{
line_info = &line_info_table[i];
fprintf (outfile, "%5d: ", i);
! fprintf (outfile, "%-20s", file_table[line_info->dw_file_num]);
fprintf (outfile, "%6ld", line_info->dw_line_num);
fprintf (outfile, "\n");
}
--- 4984,4990 ----
{
line_info = &line_info_table[i];
fprintf (outfile, "%5d: ", i);
! fprintf (outfile, "%-20s", line_file_table.table[line_info->dw_file_num]);
fprintf (outfile, "%6ld", line_info->dw_line_num);
fprintf (outfile, "\n");
}
*************** size_of_line_prolog ()
*** 5662,5671 ****
null byte used to terminate the table. */
size += 1;
! for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
{
/* File name entry. */
! size += size_of_string (file_table[ft_index]);
/* Include directory index. */
size += size_of_uleb128 (0);
--- 5668,5677 ----
null byte used to terminate the table. */
size += 1;
! for (ft_index = 1; ft_index < decl_file_table.in_use; ++ft_index)
{
/* File name entry. */
! size += size_of_string (decl_file_table.table[ft_index]);
/* Include directory index. */
size += size_of_uleb128 (0);
*************** output_line_info ()
*** 6482,6500 ****
if (flag_debug_asm)
fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
! for (ft_index = 1; ft_index < file_table_in_use; ++ft_index)
{
if (flag_debug_asm)
{
! ASM_OUTPUT_DWARF_STRING (asm_out_file, file_table[ft_index]);
fprintf (asm_out_file, "%s File Entry: 0x%lx",
ASM_COMMENT_START, ft_index);
}
else
{
ASM_OUTPUT_ASCII (asm_out_file,
! file_table[ft_index],
! (int) strlen (file_table[ft_index]) + 1);
}
fputc ('\n', asm_out_file);
--- 6488,6507 ----
if (flag_debug_asm)
fprintf (asm_out_file, "%s File Name Table\n", ASM_COMMENT_START);
! for (ft_index = 1; ft_index < line_file_table.in_use; ++ft_index)
{
if (flag_debug_asm)
{
! ASM_OUTPUT_DWARF_STRING (asm_out_file,
! line_file_table.table[ft_index]);
fprintf (asm_out_file, "%s File Entry: 0x%lx",
ASM_COMMENT_START, ft_index);
}
else
{
ASM_OUTPUT_ASCII (asm_out_file,
! line_file_table.table[ft_index],
! (int) strlen (line_file_table.table[ft_index]) + 1);
}
fputc ('\n', asm_out_file);
*************** output_line_info ()
*** 6595,6601 ****
fputc ('\n', asm_out_file);
output_uleb128 (current_file);
if (flag_debug_asm)
! fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
fputc ('\n', asm_out_file);
}
--- 6602,6609 ----
fputc ('\n', asm_out_file);
output_uleb128 (current_file);
if (flag_debug_asm)
! fprintf (asm_out_file, " (\"%s\")",
! line_file_table.table[current_file]);
fputc ('\n', asm_out_file);
}
*************** output_line_info ()
*** 6767,6773 ****
fputc ('\n', asm_out_file);
output_uleb128 (current_file);
if (flag_debug_asm)
! fprintf (asm_out_file, " (\"%s\")", file_table[current_file]);
fputc ('\n', asm_out_file);
}
--- 6775,6782 ----
fputc ('\n', asm_out_file);
output_uleb128 (current_file);
if (flag_debug_asm)
! fprintf (asm_out_file, " (\"%s\")",
! line_file_table.table[current_file]);
fputc ('\n', asm_out_file);
}
*************** add_src_coords_attributes (die, decl)
*** 8770,8776 ****
register dw_die_ref die;
register tree decl;
{
! register unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl));
add_AT_unsigned (die, DW_AT_decl_file, file_index);
add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
--- 8779,8786 ----
register dw_die_ref die;
register tree decl;
{
! register unsigned file_index = lookup_filename (&decl_file_table,
! DECL_SOURCE_FILE (decl));
add_AT_unsigned (die, DW_AT_decl_file, file_index);
add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl));
*************** gen_subprogram_die (decl, context_die)
*** 9507,9513 ****
else if (old_die)
{
register unsigned file_index
! = lookup_filename (DECL_SOURCE_FILE (decl));
if (get_AT_flag (old_die, DW_AT_declaration) != 1)
{
--- 9517,9523 ----
else if (old_die)
{
register unsigned file_index
! = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
if (get_AT_flag (old_die, DW_AT_declaration) != 1)
{
*************** gen_variable_die (decl, context_die)
*** 9764,9770 ****
if (DECL_NAME (decl))
{
register unsigned file_index
! = lookup_filename (DECL_SOURCE_FILE (decl));
if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
--- 9774,9780 ----
if (DECL_NAME (decl))
{
register unsigned file_index
! = lookup_filename (&decl_file_table, DECL_SOURCE_FILE (decl));
if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index)
add_AT_unsigned (var_die, DW_AT_decl_file, file_index);
*************** dwarf2out_add_library_unit_info (filenam
*** 10799,10805 ****
TREE_PUBLIC (context_list_decl) = TRUE;
add_name_attribute (unit_die, context_list);
! file_index = lookup_filename (filename);
add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
add_pubname (context_list_decl, unit_die);
}
--- 10809,10815 ----
TREE_PUBLIC (context_list_decl) = TRUE;
add_name_attribute (unit_die, context_list);
! file_index = lookup_filename (&decl_file_table, filename);
add_AT_unsigned (unit_die, DW_AT_decl_file, file_index);
add_pubname (context_list_decl, unit_die);
}
*************** dwarf2out_ignore_block (block)
*** 10973,11013 ****
was looked up last. This handles the majority of all searches. */
static unsigned
! lookup_filename (file_name)
const char *file_name;
{
- static unsigned last_file_lookup_index = 0;
register unsigned i;
! /* Check to see if the file name that was searched on the previous call
! matches this file name. If so, return the index. */
! if (last_file_lookup_index != 0)
! if (strcmp (file_name, file_table[last_file_lookup_index]) == 0)
! return last_file_lookup_index;
/* Didn't match the previous lookup, search the table */
! for (i = 1; i < file_table_in_use; ++i)
! if (strcmp (file_name, file_table[i]) == 0)
{
! last_file_lookup_index = i;
return i;
}
/* Prepare to add a new table entry by making sure there is enough space in
the table to do so. If not, expand the current table. */
! if (file_table_in_use == file_table_allocated)
{
! file_table_allocated += FILE_TABLE_INCREMENT;
! file_table
! = (char **) xrealloc (file_table,
! file_table_allocated * sizeof (char *));
}
/* Add the new entry to the end of the filename table. */
! file_table[file_table_in_use] = xstrdup (file_name);
! last_file_lookup_index = file_table_in_use++;
! return last_file_lookup_index;
}
/* Output a label to mark the beginning of a source code line entry
--- 10983,11036 ----
was looked up last. This handles the majority of all searches. */
static unsigned
! lookup_filename (t, file_name)
! struct file_table *t;
const char *file_name;
{
register unsigned i;
! /* Check to see if the file name that was searched on the previous
! call matches this file name. If so, return the index. */
! if (t->last_lookup_index != 0)
! if (strcmp (file_name, t->table[t->last_lookup_index]) == 0)
! return t->last_lookup_index;
/* Didn't match the previous lookup, search the table */
! for (i = 1; i < t->in_use; ++i)
! if (strcmp (file_name, t->table[i]) == 0)
{
! t->last_lookup_index = i;
return i;
}
/* Prepare to add a new table entry by making sure there is enough space in
the table to do so. If not, expand the current table. */
! if (i == t->allocated)
{
! t->allocated = i + FILE_TABLE_INCREMENT;
! t->table = (char **)
! xrealloc (t->table, t->allocated * sizeof (char *));
}
/* Add the new entry to the end of the filename table. */
! t->table[i] = xstrdup (file_name);
! t->in_use = i + 1;
! t->last_lookup_index = i;
! return i;
! }
!
! static void
! init_file_table (t)
! struct file_table *t;
! {
! /* Allocate the initial hunk of the file_table. */
! t->table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
! t->allocated = FILE_TABLE_INCREMENT;
!
! /* Skip the first entry - file numbers begin at 1. */
! t->in_use = 1;
! t->last_lookup_index = 0;
}
/* Output a label to mark the beginning of a source code line entry
*************** dwarf2out_line (filename, line)
*** 11025,11040 ****
if (DWARF2_ASM_LINE_DEBUG_INFO)
{
! static const char *lastfile;
/* Emit the .file and .loc directives understood by GNU as. */
! if (lastfile == 0 || strcmp (filename, lastfile))
{
fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
- lastfile = filename;
}
-
fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
/* Indicate that line number info exists. */
++line_info_table_in_use;
--- 11048,11073 ----
if (DWARF2_ASM_LINE_DEBUG_INFO)
{
! unsigned old_in_use = line_file_table.in_use;
! unsigned file_num = lookup_filename (&line_file_table, filename);
/* Emit the .file and .loc directives understood by GNU as. */
! #if 0
! /* ??? As of 2000-11-25, gas has a bug in which it doesn't
! actually use the file number argument. It merely remembers
! the last .file directive emitted. */
! if (file_num >= old_in_use)
! fprintf (asm_out_file, "\t.file %d \"%s\"\n", file_num, filename);
! fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line);
! #else
! static int last_file_num;
! if (file_num != last_file_num)
{
+ last_file_num = file_num;
fprintf (asm_out_file, "\t.file 0 \"%s\"\n", filename);
}
fprintf (asm_out_file, "\t.loc 0 %d 0\n", line);
+ #endif
/* Indicate that line number info exists. */
++line_info_table_in_use;
*************** dwarf2out_line (filename, line)
*** 11067,11073 ****
/* Add the new entry at the end of the line_info_table. */
line_info
= &separate_line_info_table[separate_line_info_table_in_use++];
! line_info->dw_file_num = lookup_filename (filename);
line_info->dw_line_num = line;
line_info->function = current_funcdef_number;
}
--- 11100,11106 ----
/* Add the new entry at the end of the line_info_table. */
line_info
= &separate_line_info_table[separate_line_info_table_in_use++];
! line_info->dw_file_num = lookup_filename (&line_file_table, filename);
line_info->dw_line_num = line;
line_info->function = current_funcdef_number;
}
*************** dwarf2out_line (filename, line)
*** 11094,11100 ****
/* Add the new entry at the end of the line_info_table. */
line_info = &line_info_table[line_info_table_in_use++];
! line_info->dw_file_num = lookup_filename (filename);
line_info->dw_line_num = line;
}
}
--- 11127,11133 ----
/* Add the new entry at the end of the line_info_table. */
line_info = &line_info_table[line_info_table_in_use++];
! line_info->dw_file_num = lookup_filename (&line_file_table, filename);
line_info->dw_line_num = line;
}
}
*************** dwarf2out_init (asm_out_file, main_input
*** 11166,11177 ****
/* Remember the name of the primary input file. */
primary_filename = main_input_filename;
! /* Allocate the initial hunk of the file_table. */
! file_table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *));
! file_table_allocated = FILE_TABLE_INCREMENT;
!
! /* Skip the first entry - file numbers begin at 1. */
! file_table_in_use = 1;
/* Allocate the initial hunk of the decl_die_table. */
decl_die_table
--- 11199,11206 ----
/* Remember the name of the primary input file. */
primary_filename = main_input_filename;
! init_file_table (&decl_file_table);
! init_file_table (&line_file_table);
/* Allocate the initial hunk of the decl_die_table. */
decl_die_table