aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorFred Fish <fnf@specifix.com>1992-03-27 01:04:14 +0000
committerFred Fish <fnf@specifix.com>1992-03-27 01:04:14 +0000
commit3624c875921a343ff6e5a96fb004296dd4d1d253 (patch)
tree2f5ae3448a7690849d9e251e90bdb087865cc3d2 /gdb
parent17904eeb4dae7d47bd83398c33ccae3be5ed6dee (diff)
downloadgdb-3624c875921a343ff6e5a96fb004296dd4d1d253.zip
gdb-3624c875921a343ff6e5a96fb004296dd4d1d253.tar.gz
gdb-3624c875921a343ff6e5a96fb004296dd4d1d253.tar.bz2
Mostly changes to dbxread.c to preserve stringtab's on a per-objfile
basis, for use in expanding psymtabs to full symtabs. See ChangeLog for other details.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog45
-rw-r--r--gdb/coffread.c41
-rw-r--r--gdb/dbxread.c249
-rw-r--r--gdb/objfiles.c9
-rw-r--r--gdb/utils.c248
5 files changed, 331 insertions, 261 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bdc69e8..2da155d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,48 @@
+Thu Mar 26 17:01:18 1992 Fred Fish (fnf@cygnus.com)
+
+ * coffread.c (coff_symfile_init): Update comment.
+ * dbxread.c (DBX_SYMFILE_INFO, DBX_TEXT_SECT, DBX_SYMCOUNT,
+ DBX_STRINGTAB, DBX_STRINGTAB_SIZE, DBX_SYMTAB_OFFSET): Define
+ macros to access the dbx specific objfile information.
+ * dbxread.c (symfile_string_table, symfile_string_table_size):
+ Remove these local variables.
+ * dbxread.c (read_ofile_symtab, psymtab_to_symtab_1,
+ read_dbx_symtab): Remove the stringtab and stringtab_size params
+ from the function prototypes, the function definition, and the
+ function calls. These are now available via DBX_STRINGTAB and
+ DBX_STRINGTAB_SIZE using the objfile pointer.
+ * dbxread.c (dbx_symfile_read): Relocate addr before using as
+ an arg to read_dbx_symtab.
+ * dbxread.c (dbx_symfile_read): Remove code that free'd the
+ stringtab and the dbx specific per-objfile private info.
+ * dbxread.c (init_psymbol_list): Remove symbol count from passed
+ args in prototype, function definition, and function calls. It is
+ now available via the DBX_SYMCOUNT macro using the objfile
+ pointer.
+ * dbxread.c (dbx_symfile_read, dbx_symfile_init): Remove the
+ local instance of struct dbx_symfile_info and replace with DBX_*
+ macros.
+ * dbxread.c (dbx_symfile_read): Remove init's of now deleted
+ symfile_string_table and symfile_string_table_size.
+ * dbxread.c (dbx_symfile_finish): Remove now obsolete free of
+ symfile_string_table.
+ * dbxread.c (init_psymbol_list): Use DBX_SYMCOUNT.
+ * dbxread.c (dbx_psymtab_to_symtab): Remove local stringtab and
+ stringtab size variables. Remove all code that used to reread
+ the stringtab.
+ * objfiles.c (allocate_objfile): Move calls to init_malloc()
+ to prior to any calls to mmalloc for the objfile specific heap.
+ * utils.c (init_malloc): Document the requirement that for each
+ heap for which corruption checking is desired, that init_mmalloc
+ must be called prior to any mmalloc calls on the heap.
+
+Thu Mar 26 13:20:06 1992 Per Bothner (bothner@cygnus.com)
+
+ * rs6000-pinsn.c: Make dis-assembly output more like
+ other targets: Don't print instruction in hex before
+ the assembly; use print_address to print out jump
+ destinations.
+
Wed Mar 25 16:52:35 1992 Per Bothner (bothner@cygnus.com)
* c-exp.y, gdbtypes.h: Add builtin_type_signed_char.
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 2804508..f61d806 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -24,6 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "breakpoint.h"
#include "bfd.h"
#include "symfile.h"
+#include "objfiles.h"
#include "buildsym.h"
#include <obstack.h>
@@ -162,9 +163,6 @@ struct type *in_function_type;
struct pending_block *pending_blocks;
-extern CORE_ADDR startup_file_start; /* From blockframe.c */
-extern CORE_ADDR startup_file_end; /* From blockframe.c */
-
/* Complaints about various problems in the file being read */
struct complaint ef_complaint =
@@ -547,11 +545,11 @@ complete_symtab (name, start_addr, size)
cur_src_start_addr = start_addr;
cur_src_end_addr = start_addr + size;
- if (entry_point < cur_src_end_addr
- && entry_point >= cur_src_start_addr)
+ if (current_objfile -> ei.entry_point >= cur_src_start_addr &&
+ current_objfile -> ei.entry_point < cur_src_end_addr)
{
- startup_file_start = cur_src_start_addr;
- startup_file_end = cur_src_end_addr;
+ current_objfile -> ei.entry_file_lowpc = cur_src_start_addr;
+ current_objfile -> ei.entry_file_highpc = cur_src_end_addr;
}
}
@@ -639,7 +637,7 @@ record_minimal_symbol (name, address)
/* coff_symfile_init ()
is the coff-specific initialization routine for reading symbols.
- It is passed a struct sym_fns which contains, among other things,
+ It is passed a struct objfile which contains, among other things,
the BFD for the file whose symbols are being read, and a slot for
a pointer to "private data" which we fill with cookies and other
treats for coff_symfile_read ().
@@ -668,28 +666,13 @@ coff_symfile_init (objfile)
objfile -> sym_private = xmmalloc (objfile -> md,
sizeof (struct coff_symfile_info));
- /* Save startup file's range of PC addresses to help blockframe.c
- decide where the bottom of the stack is. */
- if (bfd_get_file_flags (abfd) & EXEC_P)
- {
- /* Executable file -- record its entry point so we'll recognize
- the startup file because it contains the entry point. */
- entry_point = bfd_get_start_address (abfd);
- }
+ init_entry_point_info (objfile);
+
+ /* Save the section number for the text section */
+ if (section = bfd_get_section_by_name(abfd,".text"))
+ text_bfd_scnum = section->index;
else
- {
- /* Examination of non-executable.o files. Short-circuit this stuff. */
- /* ~0 will not be in any file, we hope. */
- entry_point = ~0;
- /* set the startup file to be an empty range. */
- startup_file_start = 0;
- startup_file_end = 0;
- }
- /* Save the section number for the text section */
- if (section = bfd_get_section_by_name(abfd,".text"))
- text_bfd_scnum = section->index;
- else
- text_bfd_scnum = -1;
+ text_bfd_scnum = -1;
}
/* This function is called for every section; it finds the outer limits
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 1650c8a..999e0f7 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -55,6 +55,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "gdbcore.h" /* for bfd stuff */
#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
#include "symfile.h"
+#include "objfiles.h"
#include "buildsym.h"
#include "aout/aout64.h"
@@ -62,7 +63,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Information is passed among various dbxread routines for accessing
symbol files. A pointer to this structure is kept in the sym_private
- field of the objfile struct passed in by symfile.h. */
+ field of the objfile struct. */
struct dbx_symfile_info {
asection *text_sect; /* Text section accessor */
@@ -72,6 +73,12 @@ struct dbx_symfile_info {
off_t symtab_offset; /* Offset in file to symbol table */
};
+#define DBX_SYMFILE_INFO(o) ((struct dbx_symfile_info *)((o)->sym_private))
+#define DBX_TEXT_SECT(o) (DBX_SYMFILE_INFO(o)->text_sect)
+#define DBX_SYMCOUNT(o) (DBX_SYMFILE_INFO(o)->symcount)
+#define DBX_STRINGTAB(o) (DBX_SYMFILE_INFO(o)->stringtab)
+#define DBX_STRINGTAB_SIZE(o) (DBX_SYMFILE_INFO(o)->stringtab_size)
+#define DBX_SYMTAB_OFFSET(o) (DBX_SYMFILE_INFO(o)->symtab_offset)
/* Each partial symbol table entry contains a pointer to private data for the
read_symtab() function to use when expanding a partial symbol table entry
@@ -129,13 +136,6 @@ static bfd *symfile_bfd;
static struct objfile *our_objfile;
-/* String table for the main symbol file. It is kept in memory
- permanently, to speed up symbol reading. Other files' symbol tables
- are read in on demand. FIXME, this should be cleaner. */
-
-static char *symfile_string_table;
-static int symfile_string_table_size;
-
/* The size of each symbol in the symbol file (in external form).
This is set by dbx_symfile_read when building psymtabs, and by
dbx_psymtab_to_symtab when building symtabs. */
@@ -191,18 +191,16 @@ static struct pending *
copy_pending PARAMS ((struct pending *, int, struct pending *));
static struct symtab *
-read_ofile_symtab PARAMS ((struct objfile *, char *, unsigned int, int, int,
- CORE_ADDR, int, int));
+read_ofile_symtab PARAMS ((struct objfile *, int, int, CORE_ADDR, int, int));
static void
dbx_psymtab_to_symtab PARAMS ((struct partial_symtab *));
static void
-psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *, int, int));
+psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, int));
static void
-read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, char *, long, int,
- CORE_ADDR, int));
+read_dbx_symtab PARAMS ((CORE_ADDR, struct objfile *, CORE_ADDR, int));
static void
free_bincl_list PARAMS ((struct objfile *));
@@ -217,7 +215,7 @@ static void
init_bincl_list PARAMS ((int, struct objfile *));
static void
-init_psymbol_list PARAMS ((int, struct objfile *));
+init_psymbol_list PARAMS ((struct objfile *));
static char *
dbx_next_symbol_text PARAMS ((void));
@@ -417,8 +415,8 @@ record_minimal_symbol (name, address, type, objfile)
/* Scan and build partial symbols for a symbol file.
We have been initialized by a call to dbx_symfile_init, which
- put all the relevant info into a "struct dbx_symfile_info"
- hung off the struct sym_fns SF.
+ put all the relevant info into a "struct dbx_symfile_info",
+ hung off the objfile structure.
ADDR is the address relative to which the symbols in it are (e.g.
the base address of the text segment).
@@ -431,26 +429,17 @@ dbx_symfile_read (objfile, addr, mainline)
CORE_ADDR addr;
int mainline; /* FIXME comments above */
{
- struct dbx_symfile_info *info;
bfd *sym_bfd;
int val;
sym_bfd = objfile->obfd;
- info = (struct dbx_symfile_info *) (objfile -> sym_private);
- val = bfd_seek (objfile->obfd, info->symtab_offset, L_SET);
+ val = bfd_seek (objfile->obfd, DBX_SYMTAB_OFFSET (objfile), L_SET);
if (val < 0)
perror_with_name (objfile->name);
- /* If mainline, set global string table pointers, and reinitialize global
- partial symbol list. */
- if (mainline) {
- symfile_string_table = info->stringtab;
- symfile_string_table_size = info->stringtab_size;
- }
-
/* If we are reinitializing, or if we have never loaded syms yet, init */
if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0)
- init_psymbol_list (info->symcount, objfile);
+ init_psymbol_list (objfile);
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
symbol_size = obj_symbol_entry_size (sym_bfd);
@@ -464,25 +453,16 @@ dbx_symfile_read (objfile, addr, mainline)
/* Now that the symbol table data of the executable file are all in core,
process them and define symbols accordingly. */
- read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
- objfile, info->stringtab, info->stringtab_size,
- info->symcount,
- bfd_section_vma (sym_bfd, info->text_sect),
- bfd_section_size (sym_bfd, info->text_sect));
+ addr -= bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)); /*offset*/
+ read_dbx_symtab (addr, objfile,
+ bfd_section_vma (sym_bfd, DBX_TEXT_SECT (objfile)),
+ bfd_section_size (sym_bfd, DBX_TEXT_SECT (objfile)));
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
install_minimal_symbols (objfile);
- /* Free up any memory we allocated for ourselves. */
-
- if (!mainline) {
- mfree (objfile->md, info->stringtab); /* Stringtab is only saved for mainline */
- }
- mfree (objfile->md, info);
- /* Zap pointer to our (now gone) info struct */
- objfile -> sym_private = NULL;
if (!have_partial_symbols ()) {
wrap_here ("");
printf_filtered ("(no debugging symbols found)...");
@@ -523,56 +503,64 @@ dbx_symfile_init (objfile)
int val;
bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
- struct dbx_symfile_info *info;
unsigned char size_temp[4];
/* Allocate struct to keep track of the symfile */
- objfile-> sym_private = xmmalloc (objfile -> md, sizeof (*info));
- info = (struct dbx_symfile_info *) objfile -> sym_private;
+ DBX_SYMFILE_INFO (objfile) = (struct dbx_symfile_info *)
+ xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
#define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
- info->text_sect = bfd_get_section_by_name (sym_bfd, ".text");
- if (!info->text_sect)
+ DBX_TEXT_SECT (objfile) = bfd_get_section_by_name (sym_bfd, ".text");
+ if (!DBX_TEXT_SECT (objfile))
abort();
- info->symcount = bfd_get_symcount (sym_bfd);
+ DBX_SYMCOUNT (objfile) = bfd_get_symcount (sym_bfd);
+
+ /* Read the string table and stash it away in the psymbol_obstack. It is
+ only needed as long as we need to expand psymbols into full symbols,
+ so when we blow away the psymbol the string table goes away as well.
+ Note that gdb used to use the results of attempting to malloc the
+ string table, based on the size it read, as a form of sanity check
+ for botched byte swapping, on the theory that a byte swapped string
+ table size would be so totally bogus that the malloc would fail. Now
+ that we put in on the psymbol_obstack, we can't do this since gdb gets
+ a fatal error (out of virtual memory) if the size is bogus. We can
+ however at least check to see if the size is zero or some negative
+ value. */
- /* Read the string table size and check it for bogosity. */
val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
if (val < 0)
- perror_with_name (name);
+ perror_with_name (name);
val = bfd_read (size_temp, sizeof (long), 1, sym_bfd);
if (val < 0)
- perror_with_name (name);
- info->stringtab_size = bfd_h_get_32 (sym_bfd, size_temp);
-
- if (info->stringtab_size >= 0)
- {
- /* Yes, this should be malloc, not xmalloc. We check its result. */
- info->stringtab = (char *) mmalloc (objfile->md, info->stringtab_size);
- /* Caller is responsible for freeing the string table. No cleanup. */
- }
- else
- info->stringtab = NULL;
- if (info->stringtab == NULL && info->stringtab_size != 0)
- error ("ridiculous string table size: %d bytes", info->stringtab_size);
+ perror_with_name (name);
+
+ DBX_STRINGTAB_SIZE (objfile) = bfd_h_get_32 (sym_bfd, size_temp);
+ if (DBX_STRINGTAB_SIZE (objfile) <= 0)
+ error ("ridiculous string table size (%d bytes).",
+ DBX_STRINGTAB_SIZE (objfile));
+
+ DBX_STRINGTAB (objfile) =
+ (char *) obstack_alloc (&objfile -> psymbol_obstack,
+ DBX_STRINGTAB_SIZE (objfile));
/* Now read in the string table in one big gulp. */
val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
if (val < 0)
perror_with_name (name);
- val = bfd_read (info->stringtab, info->stringtab_size, 1, sym_bfd);
- if (val != info->stringtab_size)
+ val = bfd_read (DBX_STRINGTAB (objfile), DBX_STRINGTAB_SIZE (objfile), 1,
+ sym_bfd);
+ if (val != DBX_STRINGTAB_SIZE (objfile))
perror_with_name (name);
/* Record the position of the symbol table for later use. */
- info->symtab_offset = SYMBOL_TABLE_OFFSET;
+ DBX_SYMTAB_OFFSET (objfile) = SYMBOL_TABLE_OFFSET;
}
/* Perform any local cleanups required when we are done with a particular
@@ -584,15 +572,9 @@ static void
dbx_symfile_finish (objfile)
struct objfile *objfile;
{
- if (objfile -> sym_private != NULL)
- {
- mfree (objfile -> md, objfile -> sym_private);
- }
- if (symfile_string_table)
+ if (DBX_SYMFILE_INFO (objfile) != NULL)
{
- free (symfile_string_table);
- symfile_string_table = 0;
- symfile_string_table_size = 0;
+ mfree (objfile -> md, DBX_SYMFILE_INFO (objfile));
}
free_header_files ();
}
@@ -662,8 +644,7 @@ dbx_next_symbol_text ()
created by read_dbx_symtab and subsidiaries. */
static void
-init_psymbol_list (total_symbols, objfile)
- int total_symbols;
+init_psymbol_list (objfile)
struct objfile *objfile;
{
/* Free any previously allocated psymbol lists. */
@@ -675,8 +656,8 @@ init_psymbol_list (total_symbols, objfile)
/* Current best guess is that there are approximately a twentieth
of the total symbols (in a debugging file) are global or static
oriented symbols */
- objfile -> global_psymbols.size = total_symbols / 10;
- objfile -> static_psymbols.size = total_symbols / 10;
+ objfile -> global_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
+ objfile -> static_psymbols.size = DBX_SYMCOUNT (objfile) / 10;
objfile -> global_psymbols.next = objfile -> global_psymbols.list = (struct partial_symbol *)
xmmalloc (objfile -> md, objfile -> global_psymbols.size * sizeof (struct partial_symbol));
objfile -> static_psymbols.next = objfile -> static_psymbols.list = (struct partial_symbol *)
@@ -749,20 +730,14 @@ free_bincl_list (objfile)
/* Given pointers to an a.out symbol table in core containing dbx
style data, setup partial_symtab's describing each source file for
- which debugging information is available. NLISTLEN is the number
- of symbols in the symbol table. All symbol names are given as
- offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
- STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
+ which debugging information is available.
+ SYMFILE_NAME is the name of the file we are reading from
and ADDR is its relocated address (if incremental) or 0 (if not). */
static void
-read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
- text_addr, text_size)
+read_dbx_symtab (addr, objfile, text_addr, text_size)
CORE_ADDR addr;
struct objfile *objfile;
- register char *stringtab;
- register long stringtab_size;
- register int nlistlen;
CORE_ADDR text_addr;
int text_size;
{
@@ -789,7 +764,7 @@ read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
struct partial_symtab **dependency_list;
int dependencies_used, dependencies_allocated;
- stringtab_global = stringtab;
+ stringtab_global = DBX_STRINGTAB (objfile);
pst = (struct partial_symtab *) 0;
@@ -823,7 +798,7 @@ read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
symbuf_end = symbuf_idx = 0;
next_symbol_text_func = dbx_next_symbol_text;
- for (symnum = 0; symnum < nlistlen; symnum++)
+ for (symnum = 0; symnum < DBX_SYMCOUNT (objfile); symnum++)
{
/* Get the symbol for this run and pull out some info */
QUIT; /* allow this to be interruptable */
@@ -854,11 +829,11 @@ read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
give a fake name, and print a single error message per symbol file read,
rather than abort the symbol reading or flood the user with messages. */
#define SET_NAMESTRING()\
- if (((unsigned)bufp->n_strx) >= stringtab_size) { \
+ if (((unsigned)bufp->n_strx) >= DBX_STRINGTAB_SIZE (objfile)) { \
complain (&string_table_offset_complaint, (char *) symnum); \
namestring = "foo"; \
} else \
- namestring = bufp->n_strx + stringtab
+ namestring = bufp->n_strx + DBX_STRINGTAB (objfile)
#define CUR_SYMBOL_TYPE bufp->n_type
#define CUR_SYMBOL_VALUE bufp->n_value
@@ -872,12 +847,12 @@ read_dbx_symtab (addr, objfile, stringtab, stringtab_size, nlistlen,
}
/* If there's stuff to be cleaned up, clean it up. */
- if (nlistlen > 0 /* We have some syms */
- && entry_point < bufp->n_value
- && entry_point >= last_o_file_start)
+ if (DBX_SYMCOUNT (objfile) > 0 /* We have some syms */
+ && objfile -> ei.entry_point < bufp->n_value
+ && objfile -> ei.entry_point >= last_o_file_start)
{
- startup_file_start = last_o_file_start;
- startup_file_end = bufp->n_value;
+ objfile -> ei.entry_file_lowpc = last_o_file_start;
+ objfile -> ei.entry_file_highpc = bufp->n_value;
}
if (pst)
@@ -1034,10 +1009,8 @@ end_psymtab (pst, include_list, num_includes, capping_symbol_offset,
}
static void
-psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
+psymtab_to_symtab_1 (pst, sym_offset)
struct partial_symtab *pst;
- char *stringtab;
- int stringtab_size;
int sym_offset;
{
struct cleanup *old_chain;
@@ -1068,8 +1041,7 @@ psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
wrap_here (""); /* Flush output */
fflush (stdout);
}
- psymtab_to_symtab_1 (pst->dependencies[i],
- stringtab, stringtab_size, sym_offset);
+ psymtab_to_symtab_1 (pst->dependencies[i], sym_offset);
}
if (LDSYMLEN(pst)) /* Otherwise it's a dummy */
@@ -1081,10 +1053,9 @@ psymtab_to_symtab_1 (pst, stringtab, stringtab_size, sym_offset)
/* Read in this files symbols */
bfd_seek (pst->objfile->obfd, sym_offset, L_SET);
pst->symtab =
- read_ofile_symtab (pst->objfile, stringtab, stringtab_size,
- LDSYMOFF(pst),
- LDSYMLEN(pst), pst->textlow,
- pst->texthigh - pst->textlow, pst->addr);
+ read_ofile_symtab (pst->objfile, LDSYMOFF(pst), LDSYMLEN(pst),
+ pst->textlow, pst->texthigh - pst->textlow,
+ pst->addr);
sort_symtab_syms (pst->symtab);
do_cleanups (old_chain);
@@ -1101,8 +1072,7 @@ static void
dbx_psymtab_to_symtab (pst)
struct partial_symtab *pst;
{
- char *stringtab;
- int stsize, val;
+ int val;
bfd *sym_bfd;
long st_temp;
@@ -1128,58 +1098,6 @@ dbx_psymtab_to_symtab (pst)
sym_bfd = pst->objfile->obfd;
- /* We keep the string table for the main symfile resident in memory, but
- not the string table for any other symbol files. */
- if (symfile_objfile != pst->objfile)
- {
- /* Read in the string table */
-
- /* FIXME, this uses internal BFD variables. See above in
- dbx_symbol_file_open where the macro is defined! */
- bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
-
- val = bfd_read (&st_temp, sizeof st_temp, 1, sym_bfd);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- stsize = bfd_h_get_32 (sym_bfd, (unsigned char *)&st_temp);
-#if 0
- /* BFD doesn't provide a way to know the total file size, sigh */
- struct stat statbuf;
- if (fstat (desc, &statbuf) < 0)
- perror_with_name (pst->objfile->name);
-
- if (stsize >= 0 && stsize < statbuf.st_size)
-#else
- if (stsize >= 0)
-#endif
- {
-#ifdef BROKEN_LARGE_ALLOCA
- stringtab = (char *) xmalloc (stsize);
- make_cleanup (free, stringtab);
-#else
- stringtab = (char *) alloca (stsize);
-#endif
- }
- else
- stringtab = NULL;
- if (stringtab == NULL && stsize != 0)
- error ("ridiculous string table size: %d bytes", stsize);
-
- /* FIXME, this uses internal BFD variables. See above in
- dbx_symbol_file_open where the macro is defined! */
- val = bfd_seek (sym_bfd, STRING_TABLE_OFFSET, L_SET);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- val = bfd_read (stringtab, stsize, 1, sym_bfd);
- if (val < 0)
- perror_with_name (pst->objfile->name);
- }
- else
- {
- stringtab = symfile_string_table;
- stsize = symfile_string_table_size;
- }
-
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
symbol_size = obj_symbol_entry_size (sym_bfd);
@@ -1187,8 +1105,7 @@ dbx_psymtab_to_symtab (pst)
/* FIXME, this uses internal BFD variables. See above in
dbx_symbol_file_open where the macro is defined! */
- psymtab_to_symtab_1 (pst, stringtab, stsize,
- SYMBOL_TABLE_OFFSET);
+ psymtab_to_symtab_1 (pst, SYMBOL_TABLE_OFFSET);
/* Match with global symbols. This only needs to be done once,
after all of the symtabs and dependencies have been read in. */
@@ -1205,22 +1122,18 @@ dbx_psymtab_to_symtab (pst)
*
* DESC is the file descriptor for the file, positioned at the
* beginning of the symtab
- * STRINGTAB is a pointer to the files string
- * table, already read in
* SYM_OFFSET is the offset within the file of
- * the beginning of the symbols we want to read, NUM_SUMBOLS is the
- * number of symbols to read
+ * the beginning of the symbols we want to read
+ * SYM_SIZE is the size of the symbol info to read in.
* TEXT_OFFSET is the beginning of the text segment we are reading symbols for
* TEXT_SIZE is the size of the text segment read in.
* OFFSET is a relocation offset which gets added to each symbol
*/
static struct symtab *
-read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
- sym_size, text_offset, text_size, offset)
+read_ofile_symtab (objfile, sym_offset, sym_size, text_offset, text_size,
+ offset)
struct objfile *objfile;
- register char *stringtab;
- unsigned int stringtab_size;
int sym_offset;
int sym_size;
CORE_ADDR text_offset;
@@ -1236,7 +1149,7 @@ read_ofile_symtab (objfile, stringtab, stringtab_size, sym_offset,
current_objfile = objfile;
subfile_stack = 0;
- stringtab_global = stringtab;
+ stringtab_global = DBX_STRINGTAB (objfile);
last_source_file = 0;
abfd = objfile->obfd;
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 35121a9..66bfd56 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -88,6 +88,8 @@ allocate_objfile (abfd, mapped)
}
else if ((objfile = (struct objfile *) mmalloc_getkey (md, 0)) != NULL)
{
+ /* Update memory corruption handler function addresses. */
+ init_malloc (md);
objfile -> md = md;
/* Update pointers to functions to *our* copies */
obstack_chunkfun (&objfile -> psymbol_obstack, xmmalloc);
@@ -96,11 +98,12 @@ allocate_objfile (abfd, mapped)
obstack_freefun (&objfile -> symbol_obstack, mfree);
obstack_chunkfun (&objfile -> type_obstack, xmmalloc);
obstack_freefun (&objfile -> type_obstack, mfree);
- /* Update memory corruption handler function addresses */
- init_malloc (objfile -> md);
}
else
{
+ /* Set up to detect internal memory corruption. MUST be done before
+ the first malloc. See comments in init_malloc() and mmcheck(). */
+ init_malloc (md);
objfile = (struct objfile *) xmmalloc (md, sizeof (struct objfile));
(void) memset (objfile, 0, sizeof (struct objfile));
objfile -> md = md;
@@ -115,8 +118,6 @@ allocate_objfile (abfd, mapped)
obstack_full_begin (&objfile -> type_obstack, 0, 0,
xmmalloc, mfree, objfile -> md,
OBSTACK_MMALLOC_LIKE);
- /* Set up to detect internal memory corruption */
- init_malloc (objfile -> md);
}
}
diff --git a/gdb/utils.c b/gdb/utils.c
index cc1573d..24fd9ea 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -35,8 +35,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Prototypes for local functions */
#if !defined (NO_MALLOC_CHECK)
+
static void
malloc_botch PARAMS ((void));
+
#endif /* NO_MALLOC_CHECK */
static void
@@ -91,7 +93,7 @@ int sevenbit_strings = 0;
/* String to be printed before error messages, if any. */
char *error_pre_print;
-char *warning_pre_print;
+char *warning_pre_print = "\nwarning: ";
/* Add a new cleanup to the cleanup_chain,
and return the previous chain pointer
@@ -274,7 +276,7 @@ fatal (va_alist)
va_start (args);
string = va_arg (args, char *);
- fprintf (stderr, "gdb: ");
+ fprintf (stderr, "\ngdb: ");
vfprintf (stderr, string, args);
fprintf (stderr, "\n");
va_end (args);
@@ -296,7 +298,7 @@ fatal_dump_core (va_alist)
string = va_arg (args, char *);
/* "internal error" is always correct, since GDB should never dump
core, no matter what the input. */
- fprintf (stderr, "gdb internal error: ");
+ fprintf (stderr, "\ngdb internal error: ");
vfprintf (stderr, string, args);
fprintf (stderr, "\n");
va_end (args);
@@ -307,62 +309,6 @@ fatal_dump_core (va_alist)
exit (1);
}
-
-/* Memory management stuff (malloc friends). */
-
-#if defined (NO_MALLOC_CHECK)
-void
-init_malloc ()
-{}
-#else /* Have mcheck(). */
-static void
-malloc_botch ()
-{
- fatal_dump_core ("Memory corruption");
-}
-
-void
-init_malloc ()
-{
- extern PTR (*__morecore) PARAMS ((long));
-
- mcheck (malloc_botch);
- mtrace ();
-}
-#endif /* Have mcheck(). */
-
-/* Like malloc but get error if no storage available. */
-
-PTR
-xmalloc (size)
- long size;
-{
- register char *val;
-
- /* Protect against gdb wanting to allocate zero bytes. */
- if (size == 0)
- return NULL;
-
- val = (char *) malloc (size);
- if (!val)
- fatal ("virtual memory exhausted.", 0);
- return val;
-}
-
-/* Like realloc but get error if no storage available. */
-
-PTR
-xrealloc (ptr, size)
- char *ptr;
- long size;
-{
- register char *val =
- ptr ? (char *) realloc (ptr, size) : (char*) malloc (size);
- if (!val)
- fatal ("virtual memory exhausted.", 0);
- return val;
-}
-
/* Print the system error message for errno, and also mention STRING
as the file name for which the error was encountered.
Then return to command level. */
@@ -456,6 +402,168 @@ request_quit (signo)
if (immediate_quit)
quit ();
}
+
+
+/* Memory management stuff (malloc friends). */
+
+#if defined (NO_MMALLOC)
+
+PTR
+mmalloc (md, size)
+ PTR md;
+ long size;
+{
+ return (malloc (size));
+}
+
+PTR
+mrealloc (md, ptr, size)
+ PTR md;
+ PTR ptr;
+ long size;
+{
+ return (realloc (ptr, size));
+}
+
+void
+mfree (md, ptr)
+ PTR md;
+ PTR ptr;
+{
+ free (ptr);
+}
+
+#endif /* NO_MMALLOC */
+
+#if defined (NO_MMALLOC) || defined (NO_MMALLOC_CHECK)
+
+void
+init_malloc (md)
+ PTR md;
+{
+}
+
+#else /* have mmalloc and want corruption checking */
+
+static void
+malloc_botch ()
+{
+ fatal_dump_core ("Memory corruption");
+}
+
+/* Attempt to install hooks in mmalloc/mrealloc/mfree for the heap specified
+ by MD, to detect memory corruption. Note that MD may be NULL to specify
+ the default heap that grows via sbrk.
+
+ Note that for freshly created regions, we must call mmcheck prior to any
+ mallocs in the region. Otherwise, any region which was allocated prior to
+ installing the checking hooks, which is later reallocated or freed, will
+ fail the checks! The mmcheck function only allows initial hooks to be
+ installed before the first mmalloc. However, anytime after we have called
+ mmcheck the first time to install the checking hooks, we can call it again
+ to update the function pointer to the memory corruption handler.
+
+ Returns zero on failure, non-zero on success. */
+
+void
+init_malloc (md)
+ PTR md;
+{
+ if (!mmcheck (md, malloc_botch))
+ {
+ warning ("internal error: failed to install memory consistency checks");
+ }
+
+ (void) mmtrace ();
+}
+
+#endif /* Have mmalloc and want corruption checking */
+
+/* Called when a memory allocation fails, with the number of bytes of
+ memory requested in SIZE. */
+
+NORETURN void
+nomem (size)
+ long size;
+{
+ if (size > 0)
+ {
+ fatal ("virtual memory exhausted: can't allocate %ld bytes.", size);
+ }
+ else
+ {
+ fatal ("virtual memory exhausted.");
+ }
+}
+
+/* Like mmalloc but get error if no storage available, and protect against
+ the caller wanting to allocate zero bytes. Whether to return NULL for
+ a zero byte request, or translate the request into a request for one
+ byte of zero'd storage, is a religious issue. */
+
+PTR
+xmmalloc (md, size)
+ PTR md;
+ long size;
+{
+ register PTR val;
+
+ if (size == 0)
+ {
+ val = NULL;
+ }
+ else if ((val = mmalloc (md, size)) == NULL)
+ {
+ nomem (size);
+ }
+ return (val);
+}
+
+/* Like mrealloc but get error if no storage available. */
+
+PTR
+xmrealloc (md, ptr, size)
+ PTR md;
+ PTR ptr;
+ long size;
+{
+ register PTR val;
+
+ if (ptr != NULL)
+ {
+ val = mrealloc (md, ptr, size);
+ }
+ else
+ {
+ val = mmalloc (md, size);
+ }
+ if (val == NULL)
+ {
+ nomem (size);
+ }
+ return (val);
+}
+
+/* Like malloc but get error if no storage available, and protect against
+ the caller wanting to allocate zero bytes. */
+
+PTR
+xmalloc (size)
+ long size;
+{
+ return (xmmalloc ((void *) NULL, size));
+}
+
+/* Like mrealloc but get error if no storage available. */
+
+PTR
+xrealloc (ptr, size)
+ PTR ptr;
+ long size;
+{
+ return (xmrealloc ((void *) NULL, ptr, size));
+}
+
/* My replacement for the read system call.
Used like `read' but keeps going if `read' returns too soon. */
@@ -497,6 +605,18 @@ savestring (ptr, size)
return p;
}
+char *
+msavestring (md, ptr, size)
+ void *md;
+ const char *ptr;
+ int size;
+{
+ register char *p = (char *) xmmalloc (md, size + 1);
+ bcopy (ptr, p, size);
+ p[size] = 0;
+ return p;
+}
+
/* The "const" is so it compiles under DGUX (which prototypes strsave
in <string.h>. FIXME: This should be named "xstrsave", shouldn't it?
Doesn't real strsave return NULL if out of memory? */
@@ -507,6 +627,14 @@ strsave (ptr)
return savestring (ptr, strlen (ptr));
}
+char *
+mstrsave (md, ptr)
+ void *md;
+ const char *ptr;
+{
+ return (msavestring (md, ptr, strlen (ptr)));
+}
+
void
print_spaces (n, file)
register int n;
@@ -1101,7 +1229,7 @@ n_spaces (n)
{
if (spaces)
free (spaces);
- spaces = (char *) malloc (n+1);
+ spaces = (char *) xmalloc (n+1);
for (t = spaces+n; t != spaces;)
*--t = ' ';
spaces[n] = '\0';