aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorJim Blandy <jimb@codesourcery.com>2004-05-02 10:14:02 +0000
committerJim Blandy <jimb@codesourcery.com>2004-05-02 10:14:02 +0000
commiteb4556d736ee14965782a320db1496fb070e54c3 (patch)
tree3fcf21764625660cd2d0cc44d1f9a5ab42129959 /gdb
parentad7b9a3686f628880fa3d7aa900f1211ae27e90e (diff)
downloadgdb-eb4556d736ee14965782a320db1496fb070e54c3.zip
gdb-eb4556d736ee14965782a320db1496fb070e54c3.tar.gz
gdb-eb4556d736ee14965782a320db1496fb070e54c3.tar.bz2
Move the symbol-file-from-memory functions into their own file.
* symfile-mem.c, symfile-mem.h: New files. * symfile.c (symbol_file_add_from_bfd): New function. (symbol_file_add): Call symbol_file_add_from_bfd. (symbol_file_add_from_memory, add_symbol_file_from_memory_command): Moved to symfile-mem.c. (_initialize_symfile): Move definition of add-symbol-file-from-memory command to symfile-mem.c. * symfile.h (symbol_file_add_from_bfd): New declaration. * config/i386/linux.mt (TDEPFILES): Add symfile-mem.o. * config/powerpc/linux.mt (TDEPFILES): Same. * Makefile.in (SFILES): Add symfile-mem.c. (symfile_mem_h): New variable. (HFILES_NO_SRCDIR): Add symfile-mem.h. (symfile-mem.o): New rule.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog18
-rw-r--r--gdb/Makefile.in10
-rw-r--r--gdb/config/i386/linux.mt2
-rw-r--r--gdb/symfile-mem.c151
-rw-r--r--gdb/symfile-mem.h33
-rw-r--r--gdb/symfile.c115
-rw-r--r--gdb/symfile.h4
7 files changed, 233 insertions, 100 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index bc5fa13..64317a7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,21 @@
+2004-05-02 Jim Blandy <jimb@redhat.com>
+
+ Move the symbol-file-from-memory functions into their own file.
+ * symfile-mem.c, symfile-mem.h: New files.
+ * symfile.c (symbol_file_add_from_bfd): New function.
+ (symbol_file_add): Call symbol_file_add_from_bfd.
+ (symbol_file_add_from_memory, add_symbol_file_from_memory_command):
+ Moved to symfile-mem.c.
+ (_initialize_symfile): Move definition of
+ add-symbol-file-from-memory command to symfile-mem.c.
+ * symfile.h (symbol_file_add_from_bfd): New declaration.
+ * config/i386/linux.mt (TDEPFILES): Add symfile-mem.o.
+ * config/powerpc/linux.mt (TDEPFILES): Same.
+ * Makefile.in (SFILES): Add symfile-mem.c.
+ (symfile_mem_h): New variable.
+ (HFILES_NO_SRCDIR): Add symfile-mem.h.
+ (symfile-mem.o): New rule.
+
2004-05-01 Andrew Cagney <cagney@redhat.com>
* breakpoint.c (insert_bp_location): Use get_frame_id, and
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index fc8d990..221d1c0 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -538,7 +538,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
scm-exp.c scm-lang.c scm-valprint.c \
sentinel-frame.c \
serial.c ser-unix.c source.c \
- stabsread.c stack.c std-regs.c symfile.c symmisc.c symtab.c \
+ stabsread.c stack.c std-regs.c symfile.c symfile-mem.c symmisc.c \
+ symtab.c \
target.c thread.c top.c tracepoint.c \
trad-frame.c \
tramp-frame.c \
@@ -754,6 +755,7 @@ srec_h = srec.h
stabsread_h = stabsread.h
stack_h = stack.h
symfile_h = symfile.h
+symfile_mem_h = symfile-mem.h
symtab_h = symtab.h
target_h = target.h $(bfd_h) $(symtab_h) $(dcache_h) $(memattr_h)
terminal_h = terminal.h
@@ -827,7 +829,8 @@ HFILES_NO_SRCDIR = bcache.h buildsym.h call-cmds.h coff-solib.h defs.h \
environ.h $(gdbcmd_h) gdb.h gdbcore.h \
gdb-stabs.h $(inferior_h) language.h minimon.h monitor.h \
objfiles.h parser-defs.h serial.h solib.h \
- symfile.h stabsread.h target.h terminal.h typeprint.h xcoffsolib.h \
+ symfile.h symfile-mem.h stabsread.h target.h terminal.h typeprint.h \
+ xcoffsolib.h \
macrotab.h macroexp.h macroscope.h \
c-lang.h f-lang.h \
jv-lang.h \
@@ -2435,6 +2438,9 @@ symfile.o: symfile.c $(defs_h) $(bfdlink_h) $(symtab_h) $(gdbtypes_h) \
$(gdb_stabs_h) $(gdb_obstack_h) $(completer_h) $(bcache_h) \
$(hashtab_h) $(readline_h) $(gdb_assert_h) $(block_h) \
$(gdb_string_h) $(gdb_stat_h)
+symfile-mem.o: symfile-mem.c $(defs_h) $(symtab_h) $(gdbcore_h) \
+ $(objfiles_h) $(gdbcmd_h) $(target_h) $(value_h) $(symfile_h) \
+ $(symfile_mem_h)
symmisc.o: symmisc.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(bfd_h) \
$(symfile_h) $(objfiles_h) $(breakpoint_h) $(command_h) \
$(gdb_obstack_h) $(language_h) $(bcache_h) $(block_h) $(gdb_regex_h) \
diff --git a/gdb/config/i386/linux.mt b/gdb/config/i386/linux.mt
index 36115de..522453f 100644
--- a/gdb/config/i386/linux.mt
+++ b/gdb/config/i386/linux.mt
@@ -1,4 +1,4 @@
# Target: Intel 386 running GNU/Linux
TDEPFILES= i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
- solib.o solib-svr4.o
+ solib.o solib-svr4.o symfile-mem.o
TM_FILE= tm-linux.h
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
new file mode 100644
index 0000000..d914ac7
--- /dev/null
+++ b/gdb/symfile-mem.c
@@ -0,0 +1,151 @@
+/* Reading symbol files from memory.
+
+ Copyright 1986, 1987, 1989, 1991, 1994, 1995, 1996, 1998, 2000,
+ 2001, 2002, 2003, 2004 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* This file defines functions (and commands to exercise those
+ functions) for reading debugging information from object files
+ whose images are mapped directly into the inferior's memory. For
+ example, the Linux kernel maps a "syscall DSO" into each process's
+ address space; this DSO provides kernel-specific code for some
+ system calls.
+
+ At the moment, BFD only has functions for parsing object files from
+ memory for the ELF format, even though the general idea isn't
+ ELF-specific. This means that BFD only provides the functions GDB
+ needs when configured for ELF-based targets. So these functions
+ may only be compiled on ELF-based targets.
+
+ GDB has no idea whether it has been configured for an ELF-based
+ target or not: it just tries to handle whatever files it is given.
+ But this means there are no preprocessor symbols on which we could
+ make these functions' compilation conditional.
+
+ So, for the time being, we put these functions alone in this file,
+ and have .mt files reference them as appropriate. In the future, I
+ hope BFD will provide a format-independent bfd_from_remote_memory
+ entry point. */
+
+
+#include "defs.h"
+#include "symtab.h"
+#include "gdbcore.h"
+#include "objfiles.h"
+#include "gdbcmd.h"
+#include "target.h"
+#include "value.h"
+#include "symfile.h"
+#include "symfile-mem.h"
+
+
+/* Read inferior memory at ADDR to find the header of a loaded object file
+ and read its in-core symbols out of inferior memory. TEMPL is a bfd
+ representing the target's format. */
+struct objfile *
+symbol_file_add_from_memory (bfd *templ, CORE_ADDR addr, int from_tty)
+{
+ struct objfile *objf;
+ bfd *nbfd;
+ asection *sec;
+ bfd_vma loadbase;
+ struct section_addr_info *sai;
+ unsigned int i;
+
+ if (bfd_get_flavour (templ) != bfd_target_elf_flavour)
+ error ("add-symbol-file-from-memory not supported for this target");
+
+ nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase,
+ target_read_memory);
+ if (nbfd == NULL)
+ {
+ error ("Failed to read a valid object file image from memory.");
+ return NULL;
+ }
+
+ nbfd->filename = xstrdup ("shared object read from target memory");
+
+ if (!bfd_check_format (nbfd, bfd_object))
+ {
+ /* FIXME: should be checking for errors from bfd_close (for one thing,
+ on error it does not free all the storage associated with the
+ bfd). */
+ bfd_close (nbfd);
+ error ("Got object file from memory but can't read symbols: %s.",
+ bfd_errmsg (bfd_get_error ()));
+ return NULL;
+ }
+
+ sai = alloc_section_addr_info (bfd_count_sections (nbfd));
+ make_cleanup (xfree, sai);
+ i = 0;
+ for (sec = nbfd->sections; sec != NULL; sec = sec->next)
+ if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
+ {
+ sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase;
+ sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec);
+ sai->other[i].sectindex = sec->index;
+ ++i;
+ }
+
+ objf = symbol_file_add_from_bfd (nbfd, from_tty,
+ sai, 0, OBJF_SHARED);
+
+ /* This might change our ideas about frames already looked at. */
+ reinit_frame_cache ();
+
+ return objf;
+}
+
+
+static void
+add_symbol_file_from_memory_command (char *args, int from_tty)
+{
+ CORE_ADDR addr;
+ bfd *templ;
+
+ if (args == NULL)
+ error ("add-symbol-file-from-memory requires an expression argument");
+
+ addr = parse_and_eval_address (args);
+
+ /* We need some representative bfd to know the target we are looking at. */
+ if (symfile_objfile != NULL)
+ templ = symfile_objfile->obfd;
+ else
+ templ = exec_bfd;
+ if (templ == NULL)
+ error ("\
+Must use symbol-file or exec-file before add-symbol-file-from-memory.");
+
+ symbol_file_add_from_memory (templ, addr, from_tty);
+}
+
+
+void
+_initialize_symfile_mem ()
+{
+ add_cmd ("add-symbol-file-from-memory", class_files,
+ add_symbol_file_from_memory_command,
+ "\
+Load the symbols out of memory from a dynamically loaded object file.\n\
+Give an expression for the address of the file's shared object file header.",
+ &cmdlist);
+
+}
diff --git a/gdb/symfile-mem.h b/gdb/symfile-mem.h
new file mode 100644
index 0000000..b89d589
--- /dev/null
+++ b/gdb/symfile-mem.h
@@ -0,0 +1,33 @@
+/* Declarations for reading symbol files from memory into GDB.
+
+ Copyright 2004 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#if !defined (SYMFILE_MEM_H)
+#define SYMFILE_MEM_H
+
+/* You must #include "bfd.h" and "defs.h" before #including this file. */
+
+/* Forward declarations. */
+struct objfile;
+
+struct objfile *(symbol_file_add_from_memory
+ (bfd *templ, CORE_ADDR addr, int from_tty));
+
+#endif /* SYMFILE_MEM_H */
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 7c83011..b688cae 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -910,6 +910,22 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd, int from_tty,
}
+/* Process the symbol file ABFD, as either the main file or as a
+ dynamically loaded file.
+
+ See symbol_file_add_with_addrs_or_offsets's comments for
+ details. */
+struct objfile *
+symbol_file_add_from_bfd (bfd *abfd, int from_tty,
+ struct section_addr_info *addrs,
+ int mainline, int flags)
+{
+ return symbol_file_add_with_addrs_or_offsets (abfd,
+ from_tty, addrs, 0, 0,
+ mainline, flags);
+}
+
+
/* Process a symbol file, as either the main file or as a dynamically
loaded file. See symbol_file_add_with_addrs_or_offsets's comments
for details. */
@@ -917,9 +933,8 @@ struct objfile *
symbol_file_add (char *name, int from_tty, struct section_addr_info *addrs,
int mainline, int flags)
{
- return symbol_file_add_with_addrs_or_offsets (symfile_bfd_open (name),
- from_tty, addrs, 0, 0,
- mainline, flags);
+ return symbol_file_add_from_bfd (symfile_bfd_open (name), from_tty,
+ addrs, mainline, flags);
}
@@ -1769,93 +1784,6 @@ add_shared_symbol_files_command (char *args, int from_tty)
#endif
}
-#if 0
-/* Read inferior memory at ADDR to find the header of a loaded object file
- and read its in-core symbols out of inferior memory. TEMPL is a bfd
- representing the target's format. */
-struct objfile *
-symbol_file_add_from_memory (bfd *templ, CORE_ADDR addr, int from_tty)
-{
- struct objfile *objf;
- bfd *nbfd;
- asection *sec;
- bfd_vma loadbase;
- struct section_addr_info *sai;
- unsigned int i;
-
- if (bfd_get_flavour (templ) != bfd_target_elf_flavour)
- error ("add-symbol-file-from-memory not supported for this target");
-
- nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase,
- target_read_memory);
- if (nbfd == NULL)
- {
- error ("Failed to read a valid object file image from memory.");
- return NULL;
- }
-
- nbfd->filename = xstrdup ("shared object read from target memory");
-
- if (!bfd_check_format (nbfd, bfd_object))
- {
- /* FIXME: should be checking for errors from bfd_close (for one thing,
- on error it does not free all the storage associated with the
- bfd). */
- bfd_close (nbfd);
- error ("Got object file from memory but can't read symbols: %s.",
- bfd_errmsg (bfd_get_error ()));
- return NULL;
- }
-
- sai = alloc_section_addr_info (bfd_count_sections (nbfd));
- make_cleanup (xfree, sai);
- i = 0;
- for (sec = nbfd->sections; sec != NULL; sec = sec->next)
- if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
- {
- sai->other[i].addr = bfd_get_section_vma (nbfd, sec) + loadbase;
- sai->other[i].name = (char *) bfd_get_section_name (nbfd, sec);
- sai->other[i].sectindex = sec->index;
- ++i;
- }
-
- objf = symbol_file_add_with_addrs_or_offsets (nbfd, from_tty,
- sai, NULL, 0, 0, OBJF_SHARED);
-
- /* This might change our ideas about frames already looked at. */
- reinit_frame_cache ();
-
- return objf;
-}
-#endif
-
-static void
-add_symbol_file_from_memory_command (char *args, int from_tty)
-{
-#if 0
- CORE_ADDR addr;
- bfd *templ;
-
- if (args == NULL)
- error ("add-symbol-file-from-memory requires an expression argument");
-
- addr = parse_and_eval_address (args);
-
- /* We need some representative bfd to know the target we are looking at. */
- if (symfile_objfile != NULL)
- templ = symfile_objfile->obfd;
- else
- templ = exec_bfd;
- if (templ == NULL)
- error ("\
-Must use symbol-file or exec-file before add-symbol-file-from-memory.");
-
- symbol_file_add_from_memory (templ, addr, from_tty);
-#else
- error ("add-symbol-file-from-memory not implemented");
-#endif
-}
-
/* Re-read symbols if a symbol-file has changed. */
void
reread_symbols (void)
@@ -3615,13 +3543,6 @@ with the text. SECT is a section name to be loaded at SECT_ADDR.",
&cmdlist);
set_cmd_completer (c, filename_completer);
- c = add_cmd ("add-symbol-file-from-memory", class_files,
- add_symbol_file_from_memory_command,
- "\
-Load the symbols out of memory from a dynamically loaded object file.\n\
-Give an expression for the address of the file's shared object file header.",
- &cmdlist);
-
c = add_cmd ("add-shared-symbol-files", class_files,
add_shared_symbol_files_command,
"Load the symbols from shared objects in the dynamic linker's link map.",
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 61809ba..4c08596 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -189,6 +189,10 @@ extern void new_symfile_objfile (struct objfile *, int, int);
extern struct objfile *symbol_file_add (char *, int,
struct section_addr_info *, int, int);
+extern struct objfile *symbol_file_add_from_bfd (bfd *, int,
+ struct section_addr_info *,
+ int, int);
+
/* Create a new section_addr_info, with room for NUM_SECTIONS. */
extern struct section_addr_info *alloc_section_addr_info (size_t