This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: provide pass-through value in bfd_elf_bfd_from_remote_memory



The only effect of this patch at the moment is to make
bfd_elf_bfd_from_remote_memory a bit clumsier to use by the only code
that uses it.  That function is only expected to be used from GDB,
which actually does have a function called "target_read_memory", whose
type is exactly that expected by the old interface.  It does, in fact,
rely on global variables to decide what to read.

But I do think it's a better interface, and that eventually GDB's
target_read_memory function will change.  So I think it's a good idea
to get the interface right early.

Yes, but while you're there can the can you please also expunge that ehdr_vma parameter so that this uses a normal read() function that takes an offset.


However, I think this really should be done right the first time (a proper way of supplying the read functions to a generic bfd).

Andrew

PS: Please anything but baton, context for instance.

bfd/ChangeLog:
2003-05-21  Jim Blandy  <jimb@redhat.com>

	* bfd-in.h (bfd_elf_bfd_from_remote_memory): Add 'BATON' argument,
	passed through to TARGET_READ_MEMORY.
	* elf-bfd.h (struct elf_backend_data): Adjust type of
	elf_backend_bfd_from_remote_memory.
	(_bfd_elf32_bfd_from_remote_memory,
	_bfd_elf64_bfd_from_remote_memory): Adjust prototypes.
	* elf.c (bfd_elf_bfd_from_remote_memory): Pass new 'BATON'
	argument through to the backend function.
	* elfcode.h (NAME(_bfd_elf,bfd_from_remote_memory)): Pass new
	'BATON' argument through to TARGET_READ_MEMORY.
	* bfd-in2.h: Regenerated.

Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.61
diff -c -r1.61 bfd-in.h
*** bfd/bfd-in.h 21 May 2003 00:57:20 -0000 1.61
--- bfd/bfd-in.h 21 May 2003 13:55:17 -0000
***************
*** 701,714 ****
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from the
! remote memory at target address VMA into the local buffer at MYADDR; it
! should return zero on success or an `errno' code on failure. TEMPL must
! be a BFD for an ELF target with the word size and byte order found in
! the remote memory. */
extern bfd *bfd_elf_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
! int (*target_read_memory) (bfd_vma vma, char *myaddr, int len)));
/* Return the arch_size field of an elf bfd, or -1 if not elf. */
extern int bfd_get_arch_size
--- 701,716 ----
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from
! the remote memory at target address VMA into the local buffer at
! MYADDR; it should return zero on success or an `errno' code on
! failure. BFD passes BATON through to TARGET_READ_MEMORY unchanged.
! TEMPL must be a BFD for an ELF target with the word size and byte
! order found in the remote memory. */
extern bfd *bfd_elf_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, void *baton,
! int (*target_read_memory) (void *baton,
! bfd_vma vma, char *myaddr, int len)));
/* Return the arch_size field of an elf bfd, or -1 if not elf. */
extern int bfd_get_arch_size
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.217
diff -c -r1.217 bfd-in2.h
*** bfd/bfd-in2.h 21 May 2003 00:57:20 -0000 1.217
--- bfd/bfd-in2.h 21 May 2003 13:55:19 -0000
***************
*** 708,721 ****
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from the
! remote memory at target address VMA into the local buffer at MYADDR; it
! should return zero on success or an `errno' code on failure. TEMPL must
! be a BFD for an ELF target with the word size and byte order found in
! the remote memory. */
extern bfd *bfd_elf_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
! int (*target_read_memory) (bfd_vma vma, char *myaddr, int len)));
/* Return the arch_size field of an elf bfd, or -1 if not elf. */
extern int bfd_get_arch_size
--- 708,723 ----
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from
! the remote memory at target address VMA into the local buffer at
! MYADDR; it should return zero on success or an `errno' code on
! failure. BFD passes BATON through to TARGET_READ_MEMORY unchanged.
! TEMPL must be a BFD for an ELF target with the word size and byte
! order found in the remote memory. */
extern bfd *bfd_elf_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, void *baton,
! int (*target_read_memory) (void *baton,
! bfd_vma vma, char *myaddr, int len)));
/* Return the arch_size field of an elf bfd, or -1 if not elf. */
extern int bfd_get_arch_size
Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.97
diff -c -r1.97 elf-bfd.h
*** bfd/elf-bfd.h 21 May 2003 00:56:05 -0000 1.97
--- bfd/elf-bfd.h 21 May 2003 13:55:21 -0000
***************
*** 878,885 ****
/* This function implements `bfd_elf_bfd_from_remote_memory';
see elf.c, elfcode.h. */
bfd *(*elf_backend_bfd_from_remote_memory)
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
! int (*target_read_memory) (bfd_vma vma, char *myaddr, int len)));
/* Alternate EM_xxxx machine codes for this backend. */
int elf_machine_alt1;
--- 878,886 ----
/* This function implements `bfd_elf_bfd_from_remote_memory';
see elf.c, elfcode.h. */
bfd *(*elf_backend_bfd_from_remote_memory)
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, void *baton,
! int (*target_read_memory) (void *baton,
! bfd_vma vma, char *myaddr, int len)));
/* Alternate EM_xxxx machine codes for this backend. */
int elf_machine_alt1;
***************
*** 1757,1767 ****
PARAMS ((bfd *, char *, int *, long, int, const PTR));
extern bfd *_bfd_elf32_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
! int (*target_read_memory) (bfd_vma, char *, int)));
extern bfd *_bfd_elf64_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep,
! int (*target_read_memory) (bfd_vma, char *, int)));
/* SH ELF specific routine. */
--- 1758,1768 ----
PARAMS ((bfd *, char *, int *, long, int, const PTR));
extern bfd *_bfd_elf32_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, void *baton,
! int (*target_read_memory) (void *, bfd_vma, char *, int)));
extern bfd *_bfd_elf64_bfd_from_remote_memory
! PARAMS ((bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, void *baton,
! int (*target_read_memory) (void *, bfd_vma, char *, int)));
/* SH ELF specific routine. */
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.187
diff -c -r1.187 elf.c
*** bfd/elf.c 21 May 2003 09:23:07 -0000 1.187
--- bfd/elf.c 21 May 2003 13:55:24 -0000
***************
*** 7557,7575 ****
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from the
! remote memory at target address VMA into the local buffer at MYADDR; it
! should return zero on success or an `errno' code on failure. TEMPL must
! be a BFD for an ELF target with the word size and byte order found in
! the remote memory. */
bfd *
! bfd_elf_bfd_from_remote_memory (templ, ehdr_vma, loadbasep, target_read_memory)
bfd *templ;
bfd_vma ehdr_vma;
bfd_vma *loadbasep;
! int (*target_read_memory) PARAMS ((bfd_vma vma, char *myaddr, int len));
{
return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory)
! (templ, ehdr_vma, loadbasep, target_read_memory);
}
--- 7557,7579 ----
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from
! the remote memory at target address VMA into the local buffer at
! MYADDR; it should return zero on success or an `errno' code on
! failure. BFD passes BATON through to TARGET_READ_MEMORY unchanged.
! TEMPL must be a BFD for an ELF target with the word size and byte
! order found in the remote memory. */
bfd *
! bfd_elf_bfd_from_remote_memory (templ, ehdr_vma, loadbasep,
! baton, target_read_memory)
bfd *templ;
bfd_vma ehdr_vma;
bfd_vma *loadbasep;
! void *baton;
! int (*target_read_memory) PARAMS ((void *, ! bfd_vma vma, char *myaddr, int len));
{
return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory)
! (templ, ehdr_vma, loadbasep, baton, target_read_memory);
}
Index: bfd/elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.42
diff -c -r1.42 elfcode.h
*** bfd/elfcode.h 21 May 2003 00:56:05 -0000 1.42
--- bfd/elfcode.h 21 May 2003 13:55:25 -0000
***************
*** 1575,1593 ****
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from the
! remote memory at target address VMA into the local buffer at MYADDR; it
! should return zero on success or an `errno' code on failure. TEMPL must
! be a BFD for a target with the word size and byte order found in the
! remote memory. */
bfd *
! NAME(_bfd_elf,bfd_from_remote_memory) (templ, ehdr_vma, loadbasep,
target_read_memory)
bfd *templ;
bfd_vma ehdr_vma;
bfd_vma *loadbasep;
! int (*target_read_memory) PARAMS ((bfd_vma vma, char *myaddr, int len));
{
Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
--- 1575,1596 ----
between the VMAs from which the segments were read, and the VMAs the
file headers (and hence BFD's idea of each section's VMA) put them at.
! The function TARGET_READ_MEMORY is called to copy LEN bytes from
! the remote memory at target address VMA into the local buffer at
! MYADDR; it should return zero on success or an `errno' code on
! failure. BFD passes BATON through to TARGET_READ_MEMORY unchanged.
! TEMPL must be a BFD for an ELF target with the word size and byte
! order found in the remote memory. */
bfd *
! NAME(_bfd_elf,bfd_from_remote_memory) (templ, ehdr_vma, loadbasep, baton,
target_read_memory)
bfd *templ;
bfd_vma ehdr_vma;
bfd_vma *loadbasep;
! void *baton;
! int (*target_read_memory) PARAMS ((void *baton, ! bfd_vma vma, char *myaddr, int len));
{
Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */
***************
*** 1602,1608 ****
bfd_vma loadbase;
/* Read in the ELF header in external format. */
! err = target_read_memory (ehdr_vma, (char *) &x_ehdr, sizeof x_ehdr);
if (err)
{
bfd_set_error (bfd_error_system_call);
--- 1605,1611 ----
bfd_vma loadbase;
/* Read in the ELF header in external format. */
! err = target_read_memory (baton, ehdr_vma, (char *) &x_ehdr, sizeof x_ehdr);
if (err)
{
bfd_set_error (bfd_error_system_call);
***************
*** 1663,1669 ****
bfd_set_error (bfd_error_no_memory);
return NULL;
}
! err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (char *) x_phdrs,
i_ehdr.e_phnum * sizeof x_phdrs[0]);
if (err)
{
--- 1666,1672 ----
bfd_set_error (bfd_error_no_memory);
return NULL;
}
! err = target_read_memory (baton, ehdr_vma + i_ehdr.e_phoff, (char *) x_phdrs,
i_ehdr.e_phnum * sizeof x_phdrs[0]);
if (err)
{
***************
*** 1734,1741 ****
+ i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
if (end > (bfd_vma) contents_size)
end = contents_size;
! err = target_read_memory ((loadbase + i_phdrs[i].p_vaddr)
! & -i_phdrs[i].p_align,
contents + start, end - start);
if (err)
{
--- 1737,1745 ----
+ i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
if (end > (bfd_vma) contents_size)
end = contents_size;
! err = target_read_memory (baton,
! ((loadbase + i_phdrs[i].p_vaddr)
! & -i_phdrs[i].p_align),
contents + start, end - start);
if (err)
{





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]