diff options
author | Petr Machata <pmachata@redhat.com> | 2012-04-30 20:53:22 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2012-04-30 20:53:22 +0200 |
commit | 5b3e26acd50d74e8b7c007f8b5dfb1a825ef9aff (patch) | |
tree | 772060b93ec39b2fefdb03d908d1abf6d4252f81 | |
parent | 3a01cd7a2fcf200cedd0770e137a28764f679c3c (diff) | |
download | ltrace-5b3e26acd50d74e8b7c007f8b5dfb1a825ef9aff.tar.gz |
Add elf_get_section_named
Document elf_get_section_* in ChangeLog
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | ltrace-elf.c | 27 | ||||
-rw-r--r-- | ltrace-elf.h | 2 |
3 files changed, 34 insertions, 0 deletions
@@ -1,3 +1,8 @@ +2012-04-30 Petr Machata <pmachata@redhat.com> + + * ltrace-elf.h (elf_get_section_named): New function. + (elf_get_section_covering, elf_get_section_type): Likewise. + 2012-04-26 Petr Machata <pmachata@redhat.com> * common.h (arch_breakpoint_init, arch_breakpoint_destroy) diff --git a/ltrace-elf.c b/ltrace-elf.c index 3f0c636..19f1c64 100644 --- a/ltrace-elf.c +++ b/ltrace-elf.c @@ -143,6 +143,33 @@ elf_get_section_type(struct ltelf *lte, GElf_Word type, &type_p, &type); } +struct section_named_data { + struct ltelf *lte; + const char *name; +}; + +static int +name_p(Elf_Scn *scn, GElf_Shdr *shdr, void *d) +{ + struct section_named_data *data = d; + const char *name = elf_strptr(data->lte->elf, + data->lte->ehdr.e_shstrndx, + shdr->sh_name); + return strcmp(name, data->name) == 0; +} + +int +elf_get_section_named(struct ltelf *lte, const char *name, + Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr) +{ + struct section_named_data data = { + .lte = lte, + .name = name, + }; + return elf_get_section_if(lte, tgt_sec, tgt_shdr, + &name_p, &data); +} + static int need_data(Elf_Data *data, GElf_Xword offset, GElf_Xword size) { diff --git a/ltrace-elf.h b/ltrace-elf.h index 54a5386..64d1cb8 100644 --- a/ltrace-elf.h +++ b/ltrace-elf.h @@ -63,6 +63,8 @@ int elf_get_section_covering(struct ltelf *lte, GElf_Addr addr, Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr); int elf_get_section_type(struct ltelf *lte, GElf_Word type, Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr); +int elf_get_section_named(struct ltelf *lte, const char *name, + Elf_Scn **tgt_sec, GElf_Shdr *tgt_shdr); /* Read, respectively, 2, 4, or 8 bytes from Elf data at given OFFSET, * and store it in *RETP. Returns 0 on success or a negative value if |