mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-18 16:53:50 +08:00
Make read_program_headers_from_bfd return a gdb::byte_vector
This patch makes read_program_headers_from_bfd return a gdb::byte_vector instead of a plain pointer. gdb/ChangeLog: * solib-svr4.c (read_program_headers_from_bfd): Return gdb::optional<gdb::byte_vector>. (svr4_exec_displacement): Adjust.
This commit is contained in:

committed by
Simon Marchi

parent
17658d46e4
commit
d1012b8e33
@ -1,3 +1,9 @@
|
|||||||
|
2018-08-22 Simon Marchi <simon.marchi@polymtl.ca>
|
||||||
|
|
||||||
|
* solib-svr4.c (read_program_headers_from_bfd): Return
|
||||||
|
gdb::optional<gdb::byte_vector>.
|
||||||
|
(svr4_exec_displacement): Adjust.
|
||||||
|
|
||||||
2018-08-22 Simon Marchi <simon.marchi@polymtl.ca>
|
2018-08-22 Simon Marchi <simon.marchi@polymtl.ca>
|
||||||
|
|
||||||
* solib-svr4.c (read_program_header): Return
|
* solib-svr4.c (read_program_header): Return
|
||||||
|
@ -2471,28 +2471,20 @@ enable_break (struct svr4_info *info, int from_tty)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the ELF program headers from ABFD. Return the contents and
|
/* Read the ELF program headers from ABFD. */
|
||||||
set *PHDRS_SIZE to the size of the program headers. */
|
|
||||||
|
|
||||||
static gdb_byte *
|
static gdb::optional<gdb::byte_vector>
|
||||||
read_program_headers_from_bfd (bfd *abfd, int *phdrs_size)
|
read_program_headers_from_bfd (bfd *abfd)
|
||||||
{
|
{
|
||||||
Elf_Internal_Ehdr *ehdr;
|
Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd);
|
||||||
gdb_byte *buf;
|
int phdrs_size = ehdr->e_phnum * ehdr->e_phentsize;
|
||||||
|
if (phdrs_size == 0)
|
||||||
|
return {};
|
||||||
|
|
||||||
ehdr = elf_elfheader (abfd);
|
gdb::byte_vector buf (phdrs_size);
|
||||||
|
|
||||||
*phdrs_size = ehdr->e_phnum * ehdr->e_phentsize;
|
|
||||||
if (*phdrs_size == 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
buf = (gdb_byte *) xmalloc (*phdrs_size);
|
|
||||||
if (bfd_seek (abfd, ehdr->e_phoff, SEEK_SET) != 0
|
if (bfd_seek (abfd, ehdr->e_phoff, SEEK_SET) != 0
|
||||||
|| bfd_bread (buf, *phdrs_size, abfd) != *phdrs_size)
|
|| bfd_bread (buf.data (), phdrs_size, abfd) != phdrs_size)
|
||||||
{
|
return {};
|
||||||
xfree (buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@ -2586,16 +2578,15 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
|
|
||||||
if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
|
if (bfd_get_flavour (exec_bfd) == bfd_target_elf_flavour)
|
||||||
{
|
{
|
||||||
/* Be optimistic and clear OK only if GDB was able to verify the headers
|
/* Be optimistic and return 0 only if GDB was able to verify the headers
|
||||||
really do not match. */
|
really do not match. */
|
||||||
int phdrs2_size, ok = 1;
|
|
||||||
gdb_byte *buf2;
|
|
||||||
int arch_size;
|
int arch_size;
|
||||||
|
|
||||||
gdb::optional<gdb::byte_vector> phdrs_target
|
gdb::optional<gdb::byte_vector> phdrs_target
|
||||||
= read_program_header (-1, &arch_size, NULL);
|
= read_program_header (-1, &arch_size, NULL);
|
||||||
buf2 = read_program_headers_from_bfd (exec_bfd, &phdrs2_size);
|
gdb::optional<gdb::byte_vector> phdrs_binary
|
||||||
if (phdrs_target && buf2 != NULL)
|
= read_program_headers_from_bfd (exec_bfd);
|
||||||
|
if (phdrs_target && phdrs_binary)
|
||||||
{
|
{
|
||||||
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
|
||||||
|
|
||||||
@ -2612,9 +2603,9 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
relocate BUF and BUF2 just by the EXEC_BFD vs. target memory
|
relocate BUF and BUF2 just by the EXEC_BFD vs. target memory
|
||||||
content offset for the verification purpose. */
|
content offset for the verification purpose. */
|
||||||
|
|
||||||
if (phdrs_target->size () != phdrs2_size
|
if (phdrs_target->size () != phdrs_binary->size ()
|
||||||
|| bfd_get_arch_size (exec_bfd) != arch_size)
|
|| bfd_get_arch_size (exec_bfd) != arch_size)
|
||||||
ok = 0;
|
return 0;
|
||||||
else if (arch_size == 32
|
else if (arch_size == 32
|
||||||
&& phdrs_target->size () >= sizeof (Elf32_External_Phdr)
|
&& phdrs_target->size () >= sizeof (Elf32_External_Phdr)
|
||||||
&& phdrs_target->size () % sizeof (Elf32_External_Phdr) == 0)
|
&& phdrs_target->size () % sizeof (Elf32_External_Phdr) == 0)
|
||||||
@ -2672,7 +2663,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
phdrp = &((Elf32_External_Phdr *) phdrs_target->data ())[i];
|
phdrp = &((Elf32_External_Phdr *) phdrs_target->data ())[i];
|
||||||
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
|
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
|
||||||
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
|
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
|
||||||
phdr2p = &((Elf32_External_Phdr *) buf2)[i];
|
phdr2p = &((Elf32_External_Phdr *) phdrs_binary->data ())[i];
|
||||||
|
|
||||||
/* PT_GNU_STACK is an exception by being never relocated by
|
/* PT_GNU_STACK is an exception by being never relocated by
|
||||||
prelink as its addresses are always zero. */
|
prelink as its addresses are always zero. */
|
||||||
@ -2747,8 +2738,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = 0;
|
return 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (arch_size == 64
|
else if (arch_size == 64
|
||||||
@ -2807,7 +2797,7 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
phdrp = &((Elf64_External_Phdr *) phdrs_target->data ())[i];
|
phdrp = &((Elf64_External_Phdr *) phdrs_target->data ())[i];
|
||||||
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
|
buf_vaddr_p = (gdb_byte *) &phdrp->p_vaddr;
|
||||||
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
|
buf_paddr_p = (gdb_byte *) &phdrp->p_paddr;
|
||||||
phdr2p = &((Elf64_External_Phdr *) buf2)[i];
|
phdr2p = &((Elf64_External_Phdr *) phdrs_binary->data ())[i];
|
||||||
|
|
||||||
/* PT_GNU_STACK is an exception by being never relocated by
|
/* PT_GNU_STACK is an exception by being never relocated by
|
||||||
prelink as its addresses are always zero. */
|
prelink as its addresses are always zero. */
|
||||||
@ -2882,19 +2872,13 @@ svr4_exec_displacement (CORE_ADDR *displacementp)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = 0;
|
return 0;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ok = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
xfree (buf2);
|
|
||||||
|
|
||||||
if (!ok)
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (info_verbose)
|
if (info_verbose)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user