Make symfile_add_flags and objfile->flags strongly typed

This makes these flag types be "enum flag" types.  The benefit is
making use of C++'s stronger typing -- mixing the flags types by
mistake errors at compile time.

This caught one old bug in symbol_file_add_main_1 already, fixed by
this patch as well:

  @@ -1318,7 +1326,7 @@ symbol_file_add_main_1 (const char *args, int from_tty, int flags)
	what is frameless.  */
     reinit_frame_cache ();

  -  if ((flags & SYMFILE_NO_READ) == 0)
  +  if ((add_flags & SYMFILE_NO_READ) == 0)
       set_initial_language ();
   }

Above, "flags" are objfile flags, not symfile_add_flags.  So that was
actually checking for "flag & OBJF_PSYMTABS_READ", which has the same
value as SYMFILE_NO_READ...

I moved the flags definitions to separate files to break circular
dependencies.

Built with --enable-targets=all and tested on x86-64 Fedora 23.

gdb/ChangeLog:
2016-10-26  Pedro Alves  <palves@redhat.com>

	* coffread.c (coff_symfile_read): Use symfile_add_flags.
	* dbxread.c (dbx_symfile_read): Ditto.
	* elfread.c (elf_symfile_read): Ditto.
	* inferior.h: Include symfile-add-flags.h.
	(struct inferior) <symfile_flags>: Now symfile_add_flags.
	* machoread.c (macho_add_oso_symfile, macho_symfile_read_all_oso)
	(macho_symfile_read, mipscoff_symfile_read): Use
	symfile_add_flags.
	* objfile-flags.h: New file.
	* objfiles.c (allocate_objfile): Use objfile_flags.
	* objfiles.h: Include objfile-flags.h.
	(struct objfile) <flags>: Now an objfile_flags.
	(OBJF_REORDERED, OBJF_SHARED, OBJF_READNOW, OBJF_USERLOADED)
	(OBJF_PSYMTABS_READ, OBJF_MAINLINE, OBJF_NOT_FILENAME): Delete.
	Converted to an enum-flags in objfile-flags.h.
	(allocate_objfile): Use objfile_flags.
	* python/py-objfile.c (objfpy_add_separate_debug_file): Remove
	unnecessary local.
	* solib.c (solib_read_symbols, solib_add)
	(reload_shared_libraries_1): Use symfile_add_flags.
	* solib.h: Include "symfile-add-flags.h".
	(solib_read_symbols): Use symfile_add_flags.
	* symfile-add-flags.h: New file.
	* symfile-debug.c (debug_sym_read): Use symfile_add_flags.
	* symfile-mem.c (symbol_file_add_from_memory): Use
	symfile_add_flags.
	* symfile.c (read_symbols, syms_from_objfile_1)
	(syms_from_objfile, finish_new_objfile): Use symfile_add_flags.
	(symbol_file_add_with_addrs): Use symfile_add_flags and
	objfile_flags.
	(symbol_file_add_separate): Use symfile_add_flags.
	(symbol_file_add_from_bfd, symbol_file_add): Use symfile_add_flags
	and objfile_flags.
	(symbol_file_add_main_1): : Use objfile_flags.  Fix add_flags vs
	flags confusion.
	(symbol_file_command): Use objfile_flags.
	(add_symbol_file_command): Use symfile_add_flags and
	objfile_flags.
	(clear_symtab_users): Use symfile_add_flags.
	* symfile.h: Include "symfile-add-flags.h" and "objfile-flags.h".
	(struct sym_fns) <sym_read>: Use symfile_add_flags.
	(clear_symtab_users): Use symfile_add_flags.
	(enum symfile_add_flags): Delete, moved to symfile-add-flags.h and
	converted to enum-flags.
	(symbol_file_add, symbol_file_add_from_bfd)
	(symbol_file_add_separate): Use symfile_add_flags.
	* xcoffread.c (xcoff_initial_scan): Use symfile_add_flags.
This commit is contained in:
Pedro Alves 2016-10-26 16:47:10 +01:00
parent 85ad3aaf40
commit b15cc25cbe
19 changed files with 257 additions and 129 deletions

View File

@ -1,3 +1,53 @@
2016-10-26 Pedro Alves <palves@redhat.com>
* coffread.c (coff_symfile_read): Use symfile_add_flags.
* dbxread.c (dbx_symfile_read): Ditto.
* elfread.c (elf_symfile_read): Ditto.
* inferior.h: Include symfile-add-flags.h.
(struct inferior) <symfile_flags>: Now symfile_add_flags.
* machoread.c (macho_add_oso_symfile, macho_symfile_read_all_oso)
(macho_symfile_read, mipscoff_symfile_read): Use
symfile_add_flags.
* objfile-flags.h: New file.
* objfiles.c (allocate_objfile): Use objfile_flags.
* objfiles.h: Include objfile-flags.h.
(struct objfile) <flags>: Now an objfile_flags.
(OBJF_REORDERED, OBJF_SHARED, OBJF_READNOW, OBJF_USERLOADED)
(OBJF_PSYMTABS_READ, OBJF_MAINLINE, OBJF_NOT_FILENAME): Delete.
Converted to an enum-flags in objfile-flags.h.
(allocate_objfile): Use objfile_flags.
* python/py-objfile.c (objfpy_add_separate_debug_file): Remove
unnecessary local.
* solib.c (solib_read_symbols, solib_add)
(reload_shared_libraries_1): Use symfile_add_flags.
* solib.h: Include "symfile-add-flags.h".
(solib_read_symbols): Use symfile_add_flags.
* symfile-add-flags.h: New file.
* symfile-debug.c (debug_sym_read): Use symfile_add_flags.
* symfile-mem.c (symbol_file_add_from_memory): Use
symfile_add_flags.
* symfile.c (read_symbols, syms_from_objfile_1)
(syms_from_objfile, finish_new_objfile): Use symfile_add_flags.
(symbol_file_add_with_addrs): Use symfile_add_flags and
objfile_flags.
(symbol_file_add_separate): Use symfile_add_flags.
(symbol_file_add_from_bfd, symbol_file_add): Use symfile_add_flags
and objfile_flags.
(symbol_file_add_main_1): : Use objfile_flags. Fix add_flags vs
flags confusion.
(symbol_file_command): Use objfile_flags.
(add_symbol_file_command): Use symfile_add_flags and
objfile_flags.
(clear_symtab_users): Use symfile_add_flags.
* symfile.h: Include "symfile-add-flags.h" and "objfile-flags.h".
(struct sym_fns) <sym_read>: Use symfile_add_flags.
(clear_symtab_users): Use symfile_add_flags.
(enum symfile_add_flags): Delete, moved to symfile-add-flags.h and
converted to enum-flags.
(symbol_file_add, symbol_file_add_from_bfd)
(symbol_file_add_separate): Use symfile_add_flags.
* xcoffread.c (xcoff_initial_scan): Use symfile_add_flags.
2016-10-26 Pedro Alves <palves@redhat.com> 2016-10-26 Pedro Alves <palves@redhat.com>
* inferior.h (ALL_NON_EXITED_INFERIORS): New macro. * inferior.h (ALL_NON_EXITED_INFERIORS): New macro.

View File

@ -559,7 +559,7 @@ static bfd *symfile_bfd;
/* Read a symbol file, after initialization by coff_symfile_init. */ /* Read a symbol file, after initialization by coff_symfile_init. */
static void static void
coff_symfile_read (struct objfile *objfile, int symfile_flags) coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
struct coff_symfile_info *info; struct coff_symfile_info *info;
bfd *abfd = objfile->obfd; bfd *abfd = objfile->obfd;

View File

@ -283,7 +283,7 @@ static void dbx_symfile_init (struct objfile *);
static void dbx_new_init (struct objfile *); static void dbx_new_init (struct objfile *);
static void dbx_symfile_read (struct objfile *, int); static void dbx_symfile_read (struct objfile *, symfile_add_flags);
static void dbx_symfile_finish (struct objfile *); static void dbx_symfile_finish (struct objfile *);
@ -520,7 +520,7 @@ record_minimal_symbol (minimal_symbol_reader &reader,
hung off the objfile structure. */ hung off the objfile structure. */
static void static void
dbx_symfile_read (struct objfile *objfile, int symfile_flags) dbx_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
bfd *sym_bfd; bfd *sym_bfd;
int val; int val;

View File

@ -1181,7 +1181,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
capability even for files compiled without -g. */ capability even for files compiled without -g. */
static void static void
elf_symfile_read (struct objfile *objfile, int symfile_flags) elf_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
bfd *abfd = objfile->obfd; bfd *abfd = objfile->obfd;
struct elfinfo ei; struct elfinfo ei;

View File

@ -43,6 +43,8 @@ struct target_desc_info;
#include "progspace.h" #include "progspace.h"
#include "registry.h" #include "registry.h"
#include "symfile-add-flags.h"
struct infcall_suspend_state; struct infcall_suspend_state;
struct infcall_control_state; struct infcall_control_state;
@ -388,9 +390,8 @@ struct inferior
LONGEST exit_code; LONGEST exit_code;
/* Default flags to pass to the symbol reading functions. These are /* Default flags to pass to the symbol reading functions. These are
used whenever a new objfile is created. The valid values come used whenever a new objfile is created. */
from enum symfile_add_flags. */ symfile_add_flags symfile_flags;
int symfile_flags;
/* Info about an inferior's target description (if it's fetched; the /* Info about an inferior's target description (if it's fetched; the
user supplied description's filename, if any; etc.). */ user supplied description's filename, if any; etc.). */

View File

@ -430,7 +430,8 @@ macho_resolve_oso_sym_with_minsym (struct objfile *main_objfile, asymbol *sym)
static void static void
macho_add_oso_symfile (oso_el *oso, bfd *abfd, const char *name, macho_add_oso_symfile (oso_el *oso, bfd *abfd, const char *name,
struct objfile *main_objfile, int symfile_flags) struct objfile *main_objfile,
symfile_add_flags symfile_flags)
{ {
int storage; int storage;
int i; int i;
@ -632,7 +633,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd, const char *name,
static void static void
macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr, macho_symfile_read_all_oso (VEC (oso_el) **oso_vector_ptr,
struct objfile *main_objfile, struct objfile *main_objfile,
int symfile_flags) symfile_add_flags symfile_flags)
{ {
int ix; int ix;
VEC (oso_el) *vec = *oso_vector_ptr; VEC (oso_el) *vec = *oso_vector_ptr;
@ -826,7 +827,7 @@ macho_check_dsym (struct objfile *objfile, char **filenamep)
} }
static void static void
macho_symfile_read (struct objfile *objfile, int symfile_flags) macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
bfd *abfd = objfile->obfd; bfd *abfd = objfile->obfd;
long storage_needed; long storage_needed;

View File

@ -67,7 +67,7 @@ mipscoff_symfile_init (struct objfile *objfile)
/* Read a symbol file from a file. */ /* Read a symbol file from a file. */
static void static void
mipscoff_symfile_read (struct objfile *objfile, int symfile_flags) mipscoff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
bfd *abfd = objfile->obfd; bfd *abfd = objfile->obfd;

71
gdb/objfile-flags.h Normal file
View File

@ -0,0 +1,71 @@
/* Definition of objfile flags.
Copyright (C) 1992-2016 Free Software Foundation, Inc.
This file is part of GDB.
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 3 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, see <http://www.gnu.org/licenses/>. */
#if !defined (OBJFILE_FLAGS_H)
#define OBJFILE_FLAGS_H
#include "common/enum-flags.h"
/* Defines for the objfile flags field. Defined in a separate file to
break circular header dependencies. */
enum objfile_flag
{
/* When an object file has its functions reordered (currently
Irix-5.2 shared libraries exhibit this behaviour), we will need
an expensive algorithm to locate a partial symtab or symtab via
an address. To avoid this penalty for normal object files, we
use this flag, whose setting is determined upon symbol table
read in. */
OBJF_REORDERED = 1 << 0, /* Functions are reordered */
/* Distinguish between an objfile for a shared library and a
"vanilla" objfile. This may come from a target's
implementation of the solib interface, from add-symbol-file, or
any other mechanism that loads dynamic objects. */
OBJF_SHARED = 1 << 1, /* From a shared library */
/* User requested that this objfile be read in it's entirety. */
OBJF_READNOW = 1 << 2, /* Immediate full read */
/* This objfile was created because the user explicitly caused it
(e.g., used the add-symbol-file command). This bit offers a
way for run_command to remove old objfile entries which are no
longer valid (i.e., are associated with an old inferior), but
to preserve ones that the user explicitly loaded via the
add-symbol-file command. */
OBJF_USERLOADED = 1 << 3, /* User loaded */
/* Set if we have tried to read partial symtabs for this objfile.
This is used to allow lazy reading of partial symtabs. */
OBJF_PSYMTABS_READ = 1 << 4,
/* Set if this is the main symbol file (as opposed to symbol file
for dynamically loaded code). */
OBJF_MAINLINE = 1 << 5,
/* ORIGINAL_NAME and OBFD->FILENAME correspond to text description
unrelated to filesystem names. It can be for example
"<image in memory>". */
OBJF_NOT_FILENAME = 1 << 6,
};
DEF_ENUM_FLAGS_TYPE (enum objfile_flag, objfile_flags);
#endif /* !defined (OBJFILE_FLAGS_H) */

View File

@ -366,7 +366,7 @@ build_objfile_section_table (struct objfile *objfile)
simply copied through to the new objfile flags member. */ simply copied through to the new objfile flags member. */
struct objfile * struct objfile *
allocate_objfile (bfd *abfd, const char *name, int flags) allocate_objfile (bfd *abfd, const char *name, objfile_flags flags)
{ {
struct objfile *objfile; struct objfile *objfile;
char *expanded_name; char *expanded_name;

View File

@ -22,6 +22,7 @@
#include "hashtab.h" #include "hashtab.h"
#include "gdb_obstack.h" /* For obstack internals. */ #include "gdb_obstack.h" /* For obstack internals. */
#include "objfile-flags.h"
#include "symfile.h" /* For struct psymbol_allocation_list. */ #include "symfile.h" /* For struct psymbol_allocation_list. */
#include "progspace.h" #include "progspace.h"
#include "registry.h" #include "registry.h"
@ -288,10 +289,9 @@ struct objfile
CORE_ADDR addr_low; CORE_ADDR addr_low;
/* Some flag bits for this objfile. /* Some flag bits for this objfile. */
The values are defined by OBJF_*. */
unsigned short flags; objfile_flags flags;
/* The program space associated with this objfile. */ /* The program space associated with this objfile. */
@ -444,54 +444,10 @@ struct objfile
htab_t static_links; htab_t static_links;
}; };
/* Defines for the objfile flag word. */
/* When an object file has its functions reordered (currently Irix-5.2
shared libraries exhibit this behaviour), we will need an expensive
algorithm to locate a partial symtab or symtab via an address.
To avoid this penalty for normal object files, we use this flag,
whose setting is determined upon symbol table read in. */
#define OBJF_REORDERED (1 << 0) /* Functions are reordered */
/* Distinguish between an objfile for a shared library and a "vanilla"
objfile. This may come from a target's implementation of the solib
interface, from add-symbol-file, or any other mechanism that loads
dynamic objects. */
#define OBJF_SHARED (1 << 1) /* From a shared library */
/* User requested that this objfile be read in it's entirety. */
#define OBJF_READNOW (1 << 2) /* Immediate full read */
/* This objfile was created because the user explicitly caused it
(e.g., used the add-symbol-file command). This bit offers a way
for run_command to remove old objfile entries which are no longer
valid (i.e., are associated with an old inferior), but to preserve
ones that the user explicitly loaded via the add-symbol-file
command. */
#define OBJF_USERLOADED (1 << 3) /* User loaded */
/* Set if we have tried to read partial symtabs for this objfile.
This is used to allow lazy reading of partial symtabs. */
#define OBJF_PSYMTABS_READ (1 << 4)
/* Set if this is the main symbol file
(as opposed to symbol file for dynamically loaded code). */
#define OBJF_MAINLINE (1 << 5)
/* ORIGINAL_NAME and OBFD->FILENAME correspond to text description unrelated to
filesystem names. It can be for example "<image in memory>". */
#define OBJF_NOT_FILENAME (1 << 6)
/* Declarations for functions defined in objfiles.c */ /* Declarations for functions defined in objfiles.c */
extern struct objfile *allocate_objfile (bfd *, const char *name, int); extern struct objfile *allocate_objfile (bfd *, const char *name,
objfile_flags);
extern struct gdbarch *get_objfile_arch (const struct objfile *); extern struct gdbarch *get_objfile_arch (const struct objfile *);

View File

@ -437,7 +437,6 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
static char *keywords[] = { "file_name", NULL }; static char *keywords[] = { "file_name", NULL };
objfile_object *obj = (objfile_object *) self; objfile_object *obj = (objfile_object *) self;
const char *file_name; const char *file_name;
int symfile_flags = 0;
OBJFPY_REQUIRE_VALID (obj); OBJFPY_REQUIRE_VALID (obj);
@ -448,7 +447,7 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
{ {
bfd *abfd = symfile_bfd_open (file_name); bfd *abfd = symfile_bfd_open (file_name);
symbol_file_add_separate (abfd, file_name, symfile_flags, obj->objfile); symbol_file_add_separate (abfd, file_name, 0, obj->objfile);
} }
CATCH (except, RETURN_MASK_ALL) CATCH (except, RETURN_MASK_ALL)
{ {

View File

@ -669,7 +669,7 @@ master_so_list (void)
loaded. */ loaded. */
int int
solib_read_symbols (struct so_list *so, int flags) solib_read_symbols (struct so_list *so, symfile_add_flags flags)
{ {
if (so->symbols_loaded) if (so->symbols_loaded)
{ {
@ -999,8 +999,10 @@ solib_add (const char *pattern, int from_tty,
{ {
int any_matches = 0; int any_matches = 0;
int loaded_any_symbols = 0; int loaded_any_symbols = 0;
const int flags = symfile_add_flags add_flags = SYMFILE_DEFER_BP_RESET;
SYMFILE_DEFER_BP_RESET | (from_tty ? SYMFILE_VERBOSE : 0);
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
for (gdb = so_list_head; gdb; gdb = gdb->next) for (gdb = so_list_head; gdb; gdb = gdb->next)
if (! pattern || re_exec (gdb->so_name)) if (! pattern || re_exec (gdb->so_name))
@ -1024,7 +1026,7 @@ solib_add (const char *pattern, int from_tty,
printf_unfiltered (_("Symbols already loaded for %s\n"), printf_unfiltered (_("Symbols already loaded for %s\n"),
gdb->so_name); gdb->so_name);
} }
else if (solib_read_symbols (gdb, flags)) else if (solib_read_symbols (gdb, add_flags))
loaded_any_symbols = 1; loaded_any_symbols = 1;
} }
} }
@ -1357,8 +1359,10 @@ reload_shared_libraries_1 (int from_tty)
char *filename, *found_pathname = NULL; char *filename, *found_pathname = NULL;
bfd *abfd; bfd *abfd;
int was_loaded = so->symbols_loaded; int was_loaded = so->symbols_loaded;
const int flags = symfile_add_flags add_flags = SYMFILE_DEFER_BP_RESET;
SYMFILE_DEFER_BP_RESET | (from_tty ? SYMFILE_VERBOSE : 0);
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
filename = tilde_expand (so->so_original_name); filename = tilde_expand (so->so_original_name);
make_cleanup (xfree, filename); make_cleanup (xfree, filename);
@ -1407,7 +1411,7 @@ reload_shared_libraries_1 (int from_tty)
if (!got_error if (!got_error
&& (auto_solib_add || was_loaded || libpthread_solib_p (so))) && (auto_solib_add || was_loaded || libpthread_solib_p (so)))
solib_read_symbols (so, flags); solib_read_symbols (so, add_flags);
} }
} }

View File

@ -26,6 +26,8 @@ struct target_ops;
struct target_so_ops; struct target_so_ops;
struct program_space; struct program_space;
#include "symfile-add-flags.h"
/* Called when we free all symtabs, to free the shared library information /* Called when we free all symtabs, to free the shared library information
as well. */ as well. */
@ -34,7 +36,7 @@ extern void clear_solib (void);
/* Called to add symbols from a shared library to gdb's symbol table. */ /* Called to add symbols from a shared library to gdb's symbol table. */
extern void solib_add (const char *, int, struct target_ops *, int); extern void solib_add (const char *, int, struct target_ops *, int);
extern int solib_read_symbols (struct so_list *, int); extern int solib_read_symbols (struct so_list *, symfile_add_flags);
/* Function to be called when the inferior starts up, to discover the /* Function to be called when the inferior starts up, to discover the
names of shared libraries that are dynamically linked, the base names of shared libraries that are dynamically linked, the base

48
gdb/symfile-add-flags.h Normal file
View File

@ -0,0 +1,48 @@
/* Definition of symfile add flags.
Copyright (C) 1990-2016 Free Software Foundation, Inc.
This file is part of GDB.
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 3 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, see <http://www.gnu.org/licenses/>. */
#if !defined (SYMFILE_ADD_FLAGS_H)
#define SYMFILE_ADD_FLAGS_H
#include "common/enum-flags.h"
/* This enum encodes bit-flags passed as ADD_FLAGS parameter to
symbol_file_add, etc. Defined in a separate file to break circular
header dependencies. */
enum symfile_add_flag
{
/* Be chatty about what you are doing. */
SYMFILE_VERBOSE = 1 << 1,
/* This is the main symbol file (as opposed to symbol file for
dynamically loaded code). */
SYMFILE_MAINLINE = 1 << 2,
/* Do not call breakpoint_re_set when adding this symbol file. */
SYMFILE_DEFER_BP_RESET = 1 << 3,
/* Do not immediately read symbols for this file. By default,
symbols are read when the objfile is created. */
SYMFILE_NO_READ = 1 << 4
};
DEF_ENUM_FLAGS_TYPE (enum symfile_add_flag, symfile_add_flags);
#endif /* !defined(SYMFILE_ADD_FLAGS_H) */

View File

@ -442,14 +442,14 @@ debug_sym_init (struct objfile *objfile)
} }
static void static void
debug_sym_read (struct objfile *objfile, int symfile_flags) debug_sym_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
const struct debug_sym_fns_data *debug_data const struct debug_sym_fns_data *debug_data
= ((const struct debug_sym_fns_data *) = ((const struct debug_sym_fns_data *)
objfile_data (objfile, symfile_debug_objfile_data_key)); objfile_data (objfile, symfile_debug_objfile_data_key));
fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n", fprintf_filtered (gdb_stdlog, "sf->sym_read (%s, 0x%x)\n",
objfile_debug_name (objfile), symfile_flags); objfile_debug_name (objfile), (unsigned) symfile_flags);
debug_data->real_sf->sym_read (objfile, symfile_flags); debug_data->real_sf->sym_read (objfile, symfile_flags);
} }

View File

@ -91,6 +91,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
struct section_addr_info *sai; struct section_addr_info *sai;
unsigned int i; unsigned int i;
struct cleanup *cleanup; struct cleanup *cleanup;
symfile_add_flags add_flags = 0;
if (bfd_get_flavour (templ) != bfd_target_elf_flavour) if (bfd_get_flavour (templ) != bfd_target_elf_flavour)
error (_("add-symbol-file-from-memory not supported for this target")); error (_("add-symbol-file-from-memory not supported for this target"));
@ -126,9 +127,11 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
} }
sai->num_sections = i; sai->num_sections = i;
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd), objf = symbol_file_add_from_bfd (nbfd, bfd_get_filename (nbfd),
from_tty ? SYMFILE_VERBOSE : 0, add_flags, sai, OBJF_SHARED, NULL);
sai, OBJF_SHARED, NULL);
add_target_sections_of_objfile (objf); add_target_sections_of_objfile (objf);

View File

@ -85,7 +85,8 @@ int readnow_symbol_files; /* Read full symbols immediately. */
static void load_command (char *, int); static void load_command (char *, int);
static void symbol_file_add_main_1 (const char *args, int from_tty, int flags); static void symbol_file_add_main_1 (const char *args, int from_tty,
objfile_flags flags);
static void add_symbol_file_command (char *, int); static void add_symbol_file_command (char *, int);
@ -865,7 +866,7 @@ default_symfile_segments (bfd *abfd)
possibly force the partial symbols to be read. */ possibly force the partial symbols to be read. */
static void static void
read_symbols (struct objfile *objfile, int add_flags) read_symbols (struct objfile *objfile, symfile_add_flags add_flags)
{ {
(*objfile->sf->sym_read) (objfile, add_flags); (*objfile->sf->sym_read) (objfile, add_flags);
objfile->per_bfd->minsyms_read = 1; objfile->per_bfd->minsyms_read = 1;
@ -994,7 +995,7 @@ init_entry_point_info (struct objfile *objfile)
static void static void
syms_from_objfile_1 (struct objfile *objfile, syms_from_objfile_1 (struct objfile *objfile,
struct section_addr_info *addrs, struct section_addr_info *addrs,
int add_flags) symfile_add_flags add_flags)
{ {
struct section_addr_info *local_addr = NULL; struct section_addr_info *local_addr = NULL;
struct cleanup *old_chain; struct cleanup *old_chain;
@ -1085,7 +1086,7 @@ syms_from_objfile_1 (struct objfile *objfile,
static void static void
syms_from_objfile (struct objfile *objfile, syms_from_objfile (struct objfile *objfile,
struct section_addr_info *addrs, struct section_addr_info *addrs,
int add_flags) symfile_add_flags add_flags)
{ {
syms_from_objfile_1 (objfile, addrs, add_flags); syms_from_objfile_1 (objfile, addrs, add_flags);
init_entry_point_info (objfile); init_entry_point_info (objfile);
@ -1096,7 +1097,7 @@ syms_from_objfile (struct objfile *objfile,
objfile. ADD_FLAGS is a bitmask of enum symfile_add_flags. */ objfile. ADD_FLAGS is a bitmask of enum symfile_add_flags. */
static void static void
finish_new_objfile (struct objfile *objfile, int add_flags) finish_new_objfile (struct objfile *objfile, symfile_add_flags add_flags)
{ {
/* If this is the main symbol file we have to clean up all users of the /* If this is the main symbol file we have to clean up all users of the
old main symbol file. Otherwise it is sufficient to fixup all the old main symbol file. Otherwise it is sufficient to fixup all the
@ -1138,9 +1139,10 @@ finish_new_objfile (struct objfile *objfile, int add_flags)
Upon failure, jumps back to command level (never returns). */ Upon failure, jumps back to command level (never returns). */
static struct objfile * static struct objfile *
symbol_file_add_with_addrs (bfd *abfd, const char *name, int add_flags, symbol_file_add_with_addrs (bfd *abfd, const char *name,
symfile_add_flags add_flags,
struct section_addr_info *addrs, struct section_addr_info *addrs,
int flags, struct objfile *parent) objfile_flags flags, struct objfile *parent)
{ {
struct objfile *objfile; struct objfile *objfile;
const int from_tty = add_flags & SYMFILE_VERBOSE; const int from_tty = add_flags & SYMFILE_VERBOSE;
@ -1164,8 +1166,9 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name, int add_flags,
&& !query (_("Load new symbol table from \"%s\"? "), name)) && !query (_("Load new symbol table from \"%s\"? "), name))
error (_("Not confirmed.")); error (_("Not confirmed."));
objfile = allocate_objfile (abfd, name, if (mainline)
flags | (mainline ? OBJF_MAINLINE : 0)); flags |= OBJF_MAINLINE;
objfile = allocate_objfile (abfd, name, flags);
if (parent) if (parent)
add_separate_debug_objfile (objfile, parent); add_separate_debug_objfile (objfile, parent);
@ -1242,7 +1245,8 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name, int add_flags,
see allocate_objfile's definition. */ see allocate_objfile's definition. */
void void
symbol_file_add_separate (bfd *bfd, const char *name, int symfile_flags, symbol_file_add_separate (bfd *bfd, const char *name,
symfile_add_flags symfile_flags,
struct objfile *objfile) struct objfile *objfile)
{ {
struct section_addr_info *sap; struct section_addr_info *sap;
@ -1268,9 +1272,10 @@ symbol_file_add_separate (bfd *bfd, const char *name, int symfile_flags,
See symbol_file_add_with_addrs's comments for details. */ See symbol_file_add_with_addrs's comments for details. */
struct objfile * struct objfile *
symbol_file_add_from_bfd (bfd *abfd, const char *name, int add_flags, symbol_file_add_from_bfd (bfd *abfd, const char *name,
symfile_add_flags add_flags,
struct section_addr_info *addrs, struct section_addr_info *addrs,
int flags, struct objfile *parent) objfile_flags flags, struct objfile *parent)
{ {
return symbol_file_add_with_addrs (abfd, name, add_flags, addrs, flags, return symbol_file_add_with_addrs (abfd, name, add_flags, addrs, flags,
parent); parent);
@ -1280,8 +1285,8 @@ symbol_file_add_from_bfd (bfd *abfd, const char *name, int add_flags,
loaded file. See symbol_file_add_with_addrs's comments for details. */ loaded file. See symbol_file_add_with_addrs's comments for details. */
struct objfile * struct objfile *
symbol_file_add (const char *name, int add_flags, symbol_file_add (const char *name, symfile_add_flags add_flags,
struct section_addr_info *addrs, int flags) struct section_addr_info *addrs, objfile_flags flags)
{ {
bfd *bfd = symfile_bfd_open (name); bfd *bfd = symfile_bfd_open (name);
struct cleanup *cleanup = make_cleanup_bfd_unref (bfd); struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
@ -1307,10 +1312,13 @@ symbol_file_add_main (const char *args, int from_tty)
} }
static void static void
symbol_file_add_main_1 (const char *args, int from_tty, int flags) symbol_file_add_main_1 (const char *args, int from_tty, objfile_flags flags)
{ {
const int add_flags = (current_inferior ()->symfile_flags symfile_add_flags add_flags = (current_inferior ()->symfile_flags
| SYMFILE_MAINLINE | (from_tty ? SYMFILE_VERBOSE : 0)); | SYMFILE_MAINLINE);
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
symbol_file_add (args, add_flags, NULL, flags); symbol_file_add (args, add_flags, NULL, flags);
@ -1318,7 +1326,7 @@ symbol_file_add_main_1 (const char *args, int from_tty, int flags)
what is frameless. */ what is frameless. */
reinit_frame_cache (); reinit_frame_cache ();
if ((flags & SYMFILE_NO_READ) == 0) if ((add_flags & SYMFILE_NO_READ) == 0)
set_initial_language (); set_initial_language ();
} }
@ -1646,7 +1654,7 @@ symbol_file_command (char *args, int from_tty)
else else
{ {
char **argv = gdb_buildargv (args); char **argv = gdb_buildargv (args);
int flags = OBJF_USERLOADED; objfile_flags flags = OBJF_USERLOADED;
struct cleanup *cleanups; struct cleanup *cleanups;
char *name = NULL; char *name = NULL;
@ -2222,7 +2230,6 @@ add_symbol_file_command (char *args, int from_tty)
{ {
struct gdbarch *gdbarch = get_current_arch (); struct gdbarch *gdbarch = get_current_arch ();
char *filename = NULL; char *filename = NULL;
int flags = OBJF_USERLOADED | OBJF_SHARED;
char *arg; char *arg;
int section_index = 0; int section_index = 0;
int argcnt = 0; int argcnt = 0;
@ -2232,6 +2239,11 @@ add_symbol_file_command (char *args, int from_tty)
int expecting_sec_addr = 0; int expecting_sec_addr = 0;
char **argv; char **argv;
struct objfile *objf; struct objfile *objf;
objfile_flags flags = OBJF_USERLOADED | OBJF_SHARED;
symfile_add_flags add_flags = 0;
if (from_tty)
add_flags |= SYMFILE_VERBOSE;
struct sect_opt struct sect_opt
{ {
@ -2357,8 +2369,7 @@ add_symbol_file_command (char *args, int from_tty)
if (from_tty && (!query ("%s", ""))) if (from_tty && (!query ("%s", "")))
error (_("Not confirmed.")); error (_("Not confirmed."));
objf = symbol_file_add (filename, from_tty ? SYMFILE_VERBOSE : 0, objf = symbol_file_add (filename, add_flags, section_addrs, flags);
section_addrs, flags);
add_target_sections_of_objfile (objf); add_target_sections_of_objfile (objf);
@ -2937,11 +2948,11 @@ add_compunit_symtab_to_objfile (struct compunit_symtab *cu)
} }
/* Reset all data structures in gdb which may contain references to symbol /* Reset all data structures in gdb which may contain references to
table data. ADD_FLAGS is a bitmask of enum symfile_add_flags. */ symbol table data. */
void void
clear_symtab_users (int add_flags) clear_symtab_users (symfile_add_flags add_flags)
{ {
/* Someday, we should do better than this, by only blowing away /* Someday, we should do better than this, by only blowing away
the things that really need to be blown. */ the things that really need to be blown. */

View File

@ -23,6 +23,8 @@
/* This file requires that you first include "bfd.h". */ /* This file requires that you first include "bfd.h". */
#include "symtab.h" #include "symtab.h"
#include "probe.h" #include "probe.h"
#include "symfile-add-flags.h"
#include "objfile-flags.h"
/* Opaque declarations. */ /* Opaque declarations. */
struct target_section; struct target_section;
@ -347,7 +349,7 @@ struct sym_fns
file we are reading. SYMFILE_FLAGS are the flags passed to file we are reading. SYMFILE_FLAGS are the flags passed to
symbol_file_add & co. */ symbol_file_add & co. */
void (*sym_read) (struct objfile *, int); void (*sym_read) (struct objfile *, symfile_add_flags);
/* Read the partial symbols for an objfile. This may be NULL, in which case /* Read the partial symbols for an objfile. This may be NULL, in which case
gdb has to check other ways if this objfile has any symbols. This may gdb has to check other ways if this objfile has any symbols. This may
@ -436,7 +438,7 @@ extern void add_compunit_symtab_to_objfile (struct compunit_symtab *cu);
extern void add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *); extern void add_symtab_fns (enum bfd_flavour flavour, const struct sym_fns *);
extern void clear_symtab_users (int add_flags); extern void clear_symtab_users (symfile_add_flags add_flags);
extern enum language deduce_language_from_filename (const char *); extern enum language deduce_language_from_filename (const char *);
@ -445,34 +447,14 @@ extern enum language deduce_language_from_filename (const char *);
function. */ function. */
extern void add_filename_language (const char *ext, enum language lang); extern void add_filename_language (const char *ext, enum language lang);
/* This enum encodes bit-flags passed as ADD_FLAGS parameter to extern struct objfile *symbol_file_add (const char *, symfile_add_flags,
symbol_file_add, etc. */ struct section_addr_info *, objfile_flags);
enum symfile_add_flags extern struct objfile *symbol_file_add_from_bfd (bfd *, const char *, symfile_add_flags,
{
/* Be chatty about what you are doing. */
SYMFILE_VERBOSE = 1 << 1,
/* This is the main symbol file (as opposed to symbol file for dynamically
loaded code). */
SYMFILE_MAINLINE = 1 << 2,
/* Do not call breakpoint_re_set when adding this symbol file. */
SYMFILE_DEFER_BP_RESET = 1 << 3,
/* Do not immediately read symbols for this file. By default,
symbols are read when the objfile is created. */
SYMFILE_NO_READ = 1 << 4
};
extern struct objfile *symbol_file_add (const char *, int,
struct section_addr_info *, int);
extern struct objfile *symbol_file_add_from_bfd (bfd *, const char *, int,
struct section_addr_info *, struct section_addr_info *,
int, struct objfile *parent); objfile_flags, struct objfile *parent);
extern void symbol_file_add_separate (bfd *, const char *, int, extern void symbol_file_add_separate (bfd *, const char *, symfile_add_flags,
struct objfile *); struct objfile *);
extern char *find_separate_debug_file_by_debuglink (struct objfile *); extern char *find_separate_debug_file_by_debuglink (struct objfile *);

View File

@ -195,7 +195,7 @@ eb_complaint (int arg1)
_("Mismatched .eb symbol ignored starting at symnum %d"), arg1); _("Mismatched .eb symbol ignored starting at symnum %d"), arg1);
} }
static void xcoff_initial_scan (struct objfile *, int); static void xcoff_initial_scan (struct objfile *, symfile_add_flags);
static void scan_xcoff_symtab (minimal_symbol_reader &, static void scan_xcoff_symtab (minimal_symbol_reader &,
struct objfile *); struct objfile *);
@ -2925,7 +2925,7 @@ xcoff_get_toc_offset (struct objfile *objfile)
loaded). */ loaded). */
static void static void
xcoff_initial_scan (struct objfile *objfile, int symfile_flags) xcoff_initial_scan (struct objfile *objfile, symfile_add_flags symfile_flags)
{ {
bfd *abfd; bfd *abfd;
int val; int val;