From 609fd03384f8c43977732aac6385c3f7b7298579 Mon Sep 17 00:00:00 2001 From: Fred Fish Date: Sat, 28 Jun 1997 06:10:06 +0000 Subject: * buildsym.h (struct subfile): Add debugformat member. (record_debugformat): Declare global function. * buildsym.c (start_subfile): Initialize debugformat member to NULL. (record_debugformat): New function to record the format. (end_symtab): Copy format into symtab debugformat member. (end_symtab): Free subfile debugformat member. * symmisc.c (free_symtab): Free debugformat when freeing symtab. * symfile.c (allocate_symtab): Initialize the new debugformat member for new symtabs. * symtab.h (struct symtab): Add debugformat member. * source.c (source_info): Print the debug format. * os9kread.c (os9k_process_one_symbol): Call record_debugformat with "OS9". * hpread.c (hpread_expand_symtab): Call record_debugformat with "HP". (hpread_process_one_debug_symbol): Ditto. * dbxread.c (process_one_symbol): Call record_debugformat with "stabs". * coffread.c (coff_start_symtab): Call record_debugformat with "COFF". * xcoffread.c (read_xcoff_symtab): Call record_debugformat with "XCOFF". * dwarfread.c (read_file_scope): Call record_debugformat with "DWARF 1". * dwarf2read.c (read_file_scope): Call record_debugformat with "DWARF 2". * dstread.c (dst_end_symtab): Set debugformat to be "Apollo DST". * mdebugread.c (new_symtab): Set debugformat to be "ECOFF". --- gdb/ChangeLog | 35 +++++++++++++++++++++++++++++++++++ gdb/buildsym.c | 24 ++++++++++++++++++++++++ gdb/buildsym.h | 4 ++++ gdb/dbxread.c | 30 +++++++++++++++++++++++++----- gdb/dstread.c | 2 ++ gdb/dwarf2read.c | 1 + gdb/dwarfread.c | 1 + gdb/hpread.c | 6 +++++- gdb/mdebugread.c | 3 ++- gdb/os9kread.c | 1 + gdb/source.c | 51 ++++++++++++++++++++++++++++++++++----------------- gdb/symtab.h | 7 +++++++ gdb/xcoffread.c | 4 ++++ 13 files changed, 145 insertions(+), 24 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index de31698..c4cac29 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,38 @@ +Fri Jun 27 23:03:53 1997 Fred Fish + + * buildsym.h (struct subfile): Add debugformat member. + (record_debugformat): Declare global function. + * buildsym.c (start_subfile): Initialize debugformat member + to NULL. + (record_debugformat): New function to record the format. + (end_symtab): Copy format into symtab debugformat member. + (end_symtab): Free subfile debugformat member. + * symmisc.c (free_symtab): Free debugformat when freeing + symtab. + * symfile.c (allocate_symtab): Initialize the new debugformat + member for new symtabs. + * symtab.h (struct symtab): Add debugformat member. + * source.c (source_info): Print the debug format. + + * os9kread.c (os9k_process_one_symbol): Call record_debugformat + with "OS9". + * hpread.c (hpread_expand_symtab): Call record_debugformat + with "HP". + (hpread_process_one_debug_symbol): Ditto. + * dbxread.c (process_one_symbol): Call record_debugformat + with "stabs". + * coffread.c (coff_start_symtab): Call record_debugformat + with "COFF". + * xcoffread.c (read_xcoff_symtab): Call record_debugformat + with "XCOFF". + * dwarfread.c (read_file_scope): Call record_debugformat + with "DWARF 1". + * dwarf2read.c (read_file_scope): Call record_debugformat + with "DWARF 2". + * dstread.c (dst_end_symtab): Set debugformat to be + "Apollo DST". + * mdebugread.c (new_symtab): Set debugformat to be "ECOFF". + Fri Jun 27 21:05:45 1997 Michael Snyder (msnyder@cleaver.cygnus.com) * mips-tdep.c (mips_push_arguments): handle alignment of diff --git a/gdb/buildsym.c b/gdb/buildsym.c index b9c70b7..6c94407 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -566,6 +566,10 @@ start_subfile (name, dirname) subfile->language = subfile->next->language; } + /* Initialize the debug format string to NULL. We may supply it + later via a call to record_debugformat. */ + subfile->debugformat = NULL; + /* cfront output is a C program, so in most ways it looks like a C program. But to demangle we need to set the language to C++. We can distinguish cfront code by the fact that it has #line @@ -968,6 +972,14 @@ end_symtab (end_addr, objfile, section) language it is from things we found in the symbols. */ symtab->language = subfile->language; + /* Save the debug format string (if any) in the symtab */ + if (subfile -> debugformat != NULL) + { + symtab->debugformat = obsavestring (subfile->debugformat, + strlen (subfile->debugformat), + &objfile -> symbol_obstack); + } + /* All symtabs for the main file and the subfiles share a blockvector, so we need to clear primary for everything but the main file. */ @@ -986,6 +998,10 @@ end_symtab (end_addr, objfile, section) { free ((PTR) subfile->line_vector); } + if (subfile->debugformat != NULL) + { + free ((PTR) subfile->debugformat); + } nextsub = subfile->next; free ((PTR)subfile); @@ -1066,6 +1082,14 @@ hashname (name) } +void +record_debugformat (format) + char *format; +{ + current_subfile -> debugformat = savestring (format, strlen (format)); +} + + /* Initialize anything that needs initializing when starting to read a fresh piece of a symbol file, e.g. reading in the stuff corresponding to a psymtab. */ diff --git a/gdb/buildsym.h b/gdb/buildsym.h index b50f9d8..5f572b2 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -60,6 +60,7 @@ struct subfile struct linetable *line_vector; int line_vector_length; enum language language; + char *debugformat; }; EXTERN struct subfile *subfiles; @@ -264,6 +265,9 @@ extern void record_pending_block PARAMS ((struct objfile *, struct block *, struct pending_block *)); +extern void +record_debugformat PARAMS ((char *)); + #undef EXTERN #endif /* defined (BUILDSYM_H) */ diff --git a/gdb/dbxread.c b/gdb/dbxread.c index ecd638e..41323ce 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -415,29 +415,35 @@ record_minimal_symbol (name, address, type, objfile) { enum minimal_symbol_type ms_type; int section; + asection *bfd_section; switch (type) { case N_TEXT | N_EXT: ms_type = mst_text; section = SECT_OFF_TEXT; + bfd_section = DBX_TEXT_SECTION (objfile); break; case N_DATA | N_EXT: ms_type = mst_data; section = SECT_OFF_DATA; + bfd_section = DBX_DATA_SECTION (objfile); break; case N_BSS | N_EXT: ms_type = mst_bss; section = SECT_OFF_BSS; + bfd_section = DBX_BSS_SECTION (objfile); break; case N_ABS | N_EXT: ms_type = mst_abs; section = -1; + bfd_section = NULL; break; #ifdef N_SETV case N_SETV | N_EXT: ms_type = mst_data; section = SECT_OFF_DATA; + bfd_section = DBX_DATA_SECTION (objfile); break; case N_SETV: /* I don't think this type actually exists; since a N_SETV is the result @@ -445,6 +451,7 @@ record_minimal_symbol (name, address, type, objfile) file local. */ ms_type = mst_file_data; section = SECT_OFF_DATA; + bfd_section = DBX_DATA_SECTION (objfile); break; #endif case N_TEXT: @@ -453,6 +460,7 @@ record_minimal_symbol (name, address, type, objfile) case N_FN_SEQ: ms_type = mst_file_text; section = SECT_OFF_TEXT; + bfd_section = DBX_TEXT_SECTION (objfile); break; case N_DATA: ms_type = mst_file_data; @@ -473,14 +481,17 @@ record_minimal_symbol (name, address, type, objfile) ms_type = mst_data; } section = SECT_OFF_DATA; + bfd_section = DBX_DATA_SECTION (objfile); break; case N_BSS: ms_type = mst_file_bss; section = SECT_OFF_BSS; + bfd_section = DBX_BSS_SECTION (objfile); break; default: ms_type = mst_unknown; section = -1; + bfd_section = NULL; break; } @@ -489,7 +500,7 @@ record_minimal_symbol (name, address, type, objfile) lowest_text_address = address; prim_record_minimal_symbol_and_info - (name, address, ms_type, NULL, section, objfile); + (name, address, ms_type, NULL, section, bfd_section, objfile); } /* Scan and build partial symbols for a symbol file. @@ -613,6 +624,11 @@ dbx_symfile_init (objfile) /* Allocate struct to keep track of the symfile */ objfile->sym_stab_info = (PTR) xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info)); + memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info)); + + DBX_TEXT_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".text"); + DBX_DATA_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".data"); + DBX_BSS_SECTION (objfile) = bfd_get_section_by_name (sym_bfd, ".bss"); /* FIXME POKING INSIDE BFD DATA STRUCTURES */ #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd)) @@ -727,6 +743,7 @@ dbx_symfile_finish (objfile) while (--i >= 0) { free (hfiles [i].name); + free (hfiles [i].vector); } free ((PTR) hfiles); } @@ -939,6 +956,8 @@ add_bincl_to_list (pst, name, instance) bincl_list = (struct header_file_location *) xmrealloc (pst->objfile->md, (char *)bincl_list, bincls_allocated * sizeof (struct header_file_location)); + if (bincl_list == NULL) + fatal ("virtual memory exhausted in add_bincl_to_list ();"); next_bincl = bincl_list + offset; } next_bincl->pst = pst; @@ -1850,7 +1869,7 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile) /* Make a block for the local symbols within. */ finish_block (new->name, &local_symbols, new->old_blocks, - function_start_offset, function_start_offset + valu, + new->start_addr, new->start_addr + valu, objfile); break; } @@ -2017,6 +2036,7 @@ process_one_symbol (type, desc, valu, name, section_offsets, objfile) start_stabs (); start_symtab (name, NULL, valu); + record_debugformat ("stabs"); break; case N_SOL: @@ -2366,7 +2386,7 @@ coffstab_build_psymtabs (objfile, section_offsets, mainline, /* There is already a dbx_symfile_info allocated by our caller. It might even contain some info from the coff symtab to help us. */ - info = (struct dbx_symfile_info *) objfile->sym_stab_info; + info = objfile->sym_stab_info; DBX_TEXT_ADDR (objfile) = textaddr; DBX_TEXT_SIZE (objfile) = textsize; @@ -2467,7 +2487,7 @@ elfstab_build_psymtabs (objfile, section_offsets, mainline, /* There is already a dbx_symfile_info allocated by our caller. It might even contain some info from the ELF symtab to help us. */ - info = (struct dbx_symfile_info *) objfile->sym_stab_info; + info = objfile->sym_stab_info; text_sect = bfd_get_section_by_name (sym_bfd, ".text"); if (!text_sect) @@ -2555,7 +2575,7 @@ stabsect_build_psymtabs (objfile, section_offsets, mainline, stab_name, stab_name, stabstr_name); objfile->sym_stab_info = (PTR) xmalloc (sizeof (struct dbx_symfile_info)); - memset (DBX_SYMFILE_INFO (objfile), 0, sizeof (struct dbx_symfile_info)); + memset (objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info)); text_sect = bfd_get_section_by_name (sym_bfd, text_name); if (!text_sect) diff --git a/gdb/dstread.c b/gdb/dstread.c index faa375d..f0d2a98 100644 --- a/gdb/dstread.c +++ b/gdb/dstread.c @@ -177,6 +177,8 @@ dst_end_symtab (objfile) symtab->free_ptr = 0; symtab->filename = last_source_file; symtab->dirname = NULL; + symtab->debugformat = obsavestring ("Apollo DST", 10, + &objfile -> symbol_obstack); lv = line_vector; lv->nitems = line_vector_index; symtab->linetable = (struct linetable *) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index ab35ce5..6434246 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1482,6 +1482,7 @@ read_file_scope (die, objfile) memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); start_symtab (name, comp_dir, lowpc); + record_debugformat ("DWARF 2"); /* Decode line number information if present. */ attr = dwarf_attr (die, DW_AT_stmt_list); diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c index 09b7f10..cec763a 100644 --- a/gdb/dwarfread.c +++ b/gdb/dwarfread.c @@ -1975,6 +1975,7 @@ read_file_scope (dip, thisdie, enddie, objfile) memset (utypes, 0, numutypes * sizeof (struct type *)); memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); start_symtab (dip -> at_name, dip -> at_comp_dir, dip -> at_low_pc); + record_debugformat ("DWARF 1"); decode_line_numbers (lnbase); process_dies (thisdie + dip -> die_length, enddie, objfile); diff --git a/gdb/hpread.c b/gdb/hpread.c index 9aa1fb1..68bb40f 100644 --- a/gdb/hpread.c +++ b/gdb/hpread.c @@ -1095,7 +1095,10 @@ hpread_expand_symtab (objfile, sym_offset, sym_size, text_offset, text_size, dn_bufp = hpread_get_lntt (sym_index, objfile); if (!((dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_SRCFILE) || (dn_bufp->dblock.kind == (unsigned char) DNTT_TYPE_MODULE))) - start_symtab ("globals", NULL, 0); + { + start_symtab ("globals", NULL, 0); + record_debugformat ("HP"); + } max_symnum = sym_size / sizeof (struct dntt_type_block); @@ -1825,6 +1828,7 @@ hpread_process_one_debug_symbol (dn_bufp, name, section_offsets, objfile, if (!last_source_file) { start_symtab (name, NULL, valu); + record_debugformat ("HP"); SL_INDEX (objfile) = dn_bufp->dsfile.address; } else diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index dda7c8c..6adba9b 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -4009,7 +4009,8 @@ new_symtab (name, maxsyms, maxlines, objfile) BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK); s->free_code = free_linetable; - + s->debugformat = obsavestring ("ECOFF", 5, + &objfile -> symbol_obstack); return (s); } diff --git a/gdb/os9kread.c b/gdb/os9kread.c index 5b9489b..4370653 100644 --- a/gdb/os9kread.c +++ b/gdb/os9kread.c @@ -1570,6 +1570,7 @@ os9k_process_one_symbol (type, desc, valu, name, section_offsets, objfile) start_stabs (); os9k_stabs = 1; start_symtab (n, dirn, valu); + record_debugformat ("OS9"); } else { push_subfile(); start_subfile (n, dirn!=NULL ? dirn : current_subfile->dirname); diff --git a/gdb/source.c b/gdb/source.c index e2ceb91..b86df91 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -16,7 +16,7 @@ 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 the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "defs.h" #include "symtab.h" @@ -25,17 +25,17 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "command.h" #include "gdbcmd.h" #include "frame.h" +#include "value.h" #include #include "gdb_string.h" -#include #include "gdb_stat.h" #include #ifdef HAVE_UNISTD_H #include #endif #include "gdbcore.h" -#include "regex.h" +#include "gnu-regex.h" #include "symfile.h" #include "objfiles.h" #include "annotate.h" @@ -306,9 +306,12 @@ mod_path (dirname, which_path) } } +#ifndef WIN32 + /* On win32 h:\ is different to h: */ if (SLASH_P (p[-1])) /* Sigh. "foo/" => "foo" */ --p; +#endif *p = '\0'; while (p[-1] == '.') @@ -341,7 +344,7 @@ mod_path (dirname, which_path) if (name[0] == '~') name = tilde_expand (name); - else if (!SLASH_P (name[0]) && name[0] != '$') + else if (!ROOTED_P (name) && name[0] != '$') name = concat (current_directory, SLASH_STRING, name, NULL); else name = savestring (name, p - name); @@ -446,7 +449,8 @@ source_info (ignore, from_tty) printf_filtered ("Contains %d line%s.\n", s->nlines, s->nlines == 1 ? "" : "s"); - printf_filtered("Source language is %s.\n", language_str (s->language)); + printf_filtered ("Source language is %s.\n", language_str (s->language)); + printf_filtered ("Compiled with %s debugging format.\n", s->debugformat); } @@ -489,6 +493,10 @@ openp (path, try_cwd_first, string, mode, prot, filename_opened) if (!path) path = "."; +#ifdef WIN32 + mode |= O_BINARY; +#endif + if (try_cwd_first || SLASH_P (string[0])) { int i; @@ -497,8 +505,8 @@ openp (path, try_cwd_first, string, mode, prot, filename_opened) if (fd >= 0) goto done; for (i = 0; string[i]; i++) - if (SLASH_P(string[0])) - goto done; + if (SLASH_P (string[i])) + goto done; } /* ./foo => foo */ @@ -517,7 +525,7 @@ openp (path, try_cwd_first, string, mode, prot, filename_opened) len = strlen (p); if (len == 4 && p[0] == '$' && p[1] == 'c' - && p[2] == 'w' && p[3] == 'd') { + && p[2] == 'w' && p[3] == 'd') { /* Name is $cwd -- insert current directory name instead. */ int newlen; @@ -537,7 +545,7 @@ openp (path, try_cwd_first, string, mode, prot, filename_opened) /* Remove trailing slashes */ while (len > 0 && SLASH_P (filename[len-1])) - filename[--len] = 0; + filename[--len] = 0; strcat (filename+len, SLASH_STRING); strcat (filename, string); @@ -707,7 +715,7 @@ find_source_lines (s, desc) int nlines = 0; int lines_allocated = 1000; int *line_charpos; - long exec_mtime; + long mtime; int size; line_charpos = (int *) xmmalloc (s -> objfile -> md, @@ -715,10 +723,16 @@ find_source_lines (s, desc) if (fstat (desc, &st) < 0) perror_with_name (s->filename); - if (exec_bfd) + if (s && s->objfile && s->objfile->obfd) { - exec_mtime = bfd_get_mtime(exec_bfd); - if (exec_mtime && exec_mtime < st.st_mtime) + mtime = bfd_get_mtime(s->objfile->obfd); + if (mtime && mtime < st.st_mtime) + printf_filtered ("Source file is more recent than executable.\n"); + } + else if (exec_bfd) + { + mtime = bfd_get_mtime(exec_bfd); + if (mtime && mtime < st.st_mtime) printf_filtered ("Source file is more recent than executable.\n"); } @@ -728,7 +742,7 @@ find_source_lines (s, desc) /* Have to read it byte by byte to find out where the chars live */ - line_charpos[0] = tell(desc); + line_charpos[0] = lseek (desc, 0, SEEK_CUR); nlines = 1; while (myread(desc, &c, 1)>0) { @@ -741,7 +755,7 @@ find_source_lines (s, desc) (int *) xmrealloc (s -> objfile -> md, (char *) line_charpos, sizeof (int) * lines_allocated); } - line_charpos[nlines++] = tell(desc); + line_charpos[nlines++] = lseek (desc, 0, SEEK_CUR); } } } @@ -758,7 +772,9 @@ find_source_lines (s, desc) data = (char *) xmalloc (size); old_cleanups = make_cleanup (free, data); - if (myread (desc, data, size) < 0) + /* Reassign `size' to result of read for systems where \r\n -> \n. */ + size = myread (desc, data, size); + if (size < 0) perror_with_name (s->filename); end = data + size; p = data; @@ -1164,11 +1180,12 @@ line_info (arg, from_tty) CORE_ADDR start_pc, end_pc; int i; + INIT_SAL (&sal); /* initialize to zeroes */ + if (arg == 0) { sal.symtab = current_source_symtab; sal.line = last_line_listed; - sal.pc = 0; sals.nelts = 1; sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); diff --git a/gdb/symtab.h b/gdb/symtab.h index f54cc5b..83c2377 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -807,6 +807,13 @@ struct symtab enum language language; + /* String that identifies the format of the debugging information, such + as "stabs", "dwarf 1", "dwarf 2", "coff", etc. This is mostly useful + for automated testing of gdb but may also be information that is + useful to the user. */ + + char *debugformat; + /* String of version information. May be zero. */ char *version; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 49814c3..5ec0638 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -997,6 +997,7 @@ read_xcoff_symtab (pst) start_stabs (); start_symtab (filestring, (char *)NULL, file_start_addr); + record_debugformat ("XCOFF"); symnum = ((struct symloc *)pst->read_symtab_private)->first_symnum; max_symnum = symnum + ((struct symloc *)pst->read_symtab_private)->numsyms; @@ -1090,6 +1091,7 @@ read_xcoff_symtab (pst) start_stabs (); start_symtab ("_globals_", (char *)NULL, (CORE_ADDR)0); + record_debugformat ("XCOFF"); cur_src_end_addr = first_object_file_end; /* done with all files, everything from here on is globals */ } @@ -1154,6 +1156,7 @@ read_xcoff_symtab (pst) /* Give all csects for this source file the same name. */ start_symtab (filestring, NULL, (CORE_ADDR)0); + record_debugformat ("XCOFF"); } /* If this is the very first csect seen, @@ -1282,6 +1285,7 @@ read_xcoff_symtab (pst) start_stabs (); start_symtab (filestring, (char *)NULL, (CORE_ADDR)0); + record_debugformat ("XCOFF"); last_csect_name = 0; /* reset file start and end addresses. A compilation unit with no text -- cgit v1.1