From: Tristan Gingold <gingold@adacore.com>
To: gdb-patches ml <gdb-patches@sourceware.org>
Subject: [RFA]: add sym_relocate method to sym_fns
Date: Thu, 28 Jan 2010 09:40:00 -0000 [thread overview]
Message-ID: <89835999-77F3-4D3A-BF16-F790560A336B@adacore.com> (raw)
Hi,
I need to add a new method to sym_fns to relocate sections. So instead of always calling
bfd_simple_get_relocated_section_content, symfile_relocate_debug_section will call this method to do
a file specific action.
This is required because Mach-O adds object files, which cannot be relocated using only offsets (eg: common
symbols).
This first patch just adds this method but uses the default implementation, so this is a no-op.
The interface is also slightly modified: the first argument is the objfile instead of its bfd.
Tested on gnu/linux x86.
Tristan.
2010-01-14 Tristan Gingold <gingold@adacore.com>
* symfile.h (struct sym_fns): Add sym_relocate field.
(default_symfile_relocate): New prototype.
(symfile_relocate_debug_section): First argument is now an objfile.
* symfile.c (default_symfile_relocate): Rename from
symfile_relocate_debug_section, first argument is now an objfile.
(symfile_relocate_debug_section): New function.
* coffread.c (coff_sym_fns): Set sym_relocate field.
* somread.c (som_sym_fns): Ditto.
* mipsread.c (ecoff_sym_fns): Ditto.
* machoread.c (macho_sym_fns): Ditto.
* elfread.c (elf_sym_fns): Ditto.
* dwarf2read.c (dwarf2_read_section): Ditto.
* xcoffread.c (xcoff_sym_fns): Ditto.
* dbxread.c (aout_sym_fns): Ditto.
(dbx_psymtab_to_symtab): Adjust call to symfile_relocate_debug_section.
(elfstab_build_psymtabs): Ditto.
---
gdb/coffread.c | 1 +
gdb/dbxread.c | 5 +++--
gdb/dwarf2read.c | 2 +-
gdb/elfread.c | 1 +
gdb/machoread.c | 3 +++
gdb/mipsread.c | 1 +
gdb/somread.c | 1 +
gdb/symfile.c | 16 +++++++++++++++-
gdb/symfile.h | 17 +++++++++++++++--
gdb/xcoffread.c | 1 +
10 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 8e5dca9..ba413ad 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -2128,6 +2128,7 @@ static struct sym_fns coff_sym_fns =
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 6ef6767..c9a5754 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2473,7 +2473,7 @@ Shouldn't happen.\n",
if (DBX_STAB_SECTION (pst->objfile))
{
stabs_data
- = symfile_relocate_debug_section (pst->objfile->obfd,
+ = symfile_relocate_debug_section (pst->objfile,
DBX_STAB_SECTION (pst->objfile),
NULL);
if (stabs_data)
@@ -3460,7 +3460,7 @@ elfstab_build_psymtabs (struct objfile *objfile, asection *stabsect,
symbuf_read = 0;
symbuf_left = bfd_section_size (objfile->obfd, stabsect);
- stabs_data = symfile_relocate_debug_section (objfile->obfd, stabsect, NULL);
+ stabs_data = symfile_relocate_debug_section (objfile, stabsect, NULL);
if (stabs_data)
back_to = make_cleanup (free_current_contents, (void *) &stabs_data);
@@ -3571,6 +3571,7 @@ static struct sym_fns aout_sym_fns =
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2f671ca..cd4114c 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1412,7 +1412,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
We never compress sections in .o files, so we only need to
try this when the section is not compressed. */
- retbuf = symfile_relocate_debug_section (abfd, sectp, buf);
+ retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
if (retbuf != NULL)
{
info->buffer = retbuf;
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 78e9163..9a2a1e3 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1057,6 +1057,7 @@ static struct sym_fns elf_sym_fns =
elf_symfile_segments, /* sym_segments: Get segment information from
a file. */
NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 02b61d3..be9e2a5 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -759,6 +759,9 @@ static struct sym_fns macho_sym_fns = {
macho_symfile_offsets, /* sym_offsets: xlate external to internal form */
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
+ NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
+
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index 4ef817e..093313e 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -399,6 +399,7 @@ static struct sym_fns ecoff_sym_fns =
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/somread.c b/gdb/somread.c
index c7beaba..3d93c5e 100644
--- a/gdb/somread.c
+++ b/gdb/somread.c
@@ -437,6 +437,7 @@ static struct sym_fns som_sym_fns =
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
NULL, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
diff --git a/gdb/symfile.c b/gdb/symfile.c
index bc52406..d82f02b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3642,8 +3642,11 @@ symfile_dummy_outputs (bfd *abfd, asection *sectp, void *dummy)
debug section. */
bfd_byte *
-symfile_relocate_debug_section (bfd *abfd, asection *sectp, bfd_byte *buf)
+default_symfile_relocate (struct objfile *objfile, asection *sectp,
+ bfd_byte *buf)
{
+ bfd *abfd = objfile->obfd;
+
/* We're only interested in sections with relocation
information. */
if ((sectp->flags & SEC_RELOC) == 0)
@@ -3656,6 +3659,17 @@ symfile_relocate_debug_section (bfd *abfd, asection *sectp, bfd_byte *buf)
return bfd_simple_get_relocated_section_contents (abfd, sectp, buf, NULL);
}
+/* Default implementation for sym_relocate. */
+
+bfd_byte *
+symfile_relocate_debug_section (struct objfile *objfile,
+ asection *sectp, bfd_byte *buf)
+{
+ gdb_assert (objfile->sf->sym_relocate);
+
+ return (*objfile->sf->sym_relocate)(objfile, sectp, buf);
+}
+
struct symfile_segment_data *
get_symfile_segment_data (bfd *abfd)
{
diff --git a/gdb/symfile.h b/gdb/symfile.h
index efa069e..302c29f 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -163,8 +163,15 @@ struct sym_fns
/* This function should read the linetable from the objfile when
the line table cannot be read while processing the debugging
information. */
+
void (*sym_read_linetable) (void);
+ /* Relocate the contents of a debug section SECTP. The
+ contents are stored in BUF if it is non-NULL, or returned in a
+ malloc'd buffer otherwise. */
+
+ bfd_byte *(*sym_relocate) (struct objfile *, asection *sectp, bfd_byte *buf);
+
/* Finds the next struct sym_fns. They are allocated and
initialized in whatever module implements the functions pointed
to; an initializer calls add_symtab_fns to add them to the global
@@ -195,6 +202,12 @@ extern void default_symfile_offsets (struct objfile *objfile,
extern struct symfile_segment_data *default_symfile_segments (bfd *abfd);
+/* The default version of sym_fns.sym_relocate for readers that don't
+ do anything special. */
+
+extern bfd_byte *default_symfile_relocate (struct objfile *objfile,
+ asection *sectp, bfd_byte *buf);
+
extern void extend_psymbol_list (struct psymbol_allocation_list *,
struct objfile *);
@@ -374,8 +387,8 @@ extern void symbol_file_clear (int from_tty);
/* Default overlay update function. */
extern void simple_overlay_update (struct obj_section *);
-extern bfd_byte *symfile_relocate_debug_section (bfd *abfd, asection *sectp,
- bfd_byte * buf);
+extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *,
+ bfd_byte *);
extern int symfile_map_offsets_to_segments (bfd *,
struct symfile_segment_data *,
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 25cc2d9..acd7b50 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -3035,6 +3035,7 @@ static struct sym_fns xcoff_sym_fns =
default_symfile_segments, /* sym_segments: Get segment information from
a file. */
aix_process_linenos, /* sym_read_linetable */
+ default_symfile_relocate, /* sym_relocate: Relocate a debug section. */
NULL /* next: pointer to next struct sym_fns */
};
--
1.6.2
next reply other threads:[~2010-01-28 9:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-28 9:40 Tristan Gingold [this message]
2010-01-29 19:04 ` Tom Tromey
2010-02-03 14:21 ` Tristan Gingold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=89835999-77F3-4D3A-BF16-F790560A336B@adacore.com \
--to=gingold@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).