From: jbj Date: Tue, 4 Mar 2003 21:57:14 +0000 (+0000) Subject: Initial revision X-Git-Tag: rpm-4.4-release~686 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c207ce7fd07e3d149bf6ac179d937a6f96ea9d24;p=platform%2Fupstream%2Frpm.git Initial revision CVS patchset: 6646 CVS date: 2003/03/04 21:57:14 --- diff --git a/elfutils/libdw/dwarf_get_pubnames.c b/elfutils/libdw/dwarf_get_pubnames.c new file mode 100644 index 0000000..022e06d --- /dev/null +++ b/elfutils/libdw/dwarf_get_pubnames.c @@ -0,0 +1,205 @@ +/* Get public symbol information. + Copyright (C) 2002 Red Hat, Inc. + Written by Ulrich Drepper , 2002. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + 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. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include + +#include + + +static int +get_offsets (Dwarf *dbg) +{ + size_t allocated = 0; + size_t cnt = 0; + struct pubnames_s *mem = NULL; + const size_t entsize = sizeof (struct pubnames_s); + unsigned char *const startp = dbg->sectiondata[IDX_debug_pubnames]->d_buf; + unsigned char *readp = startp; + unsigned char *endp = readp + dbg->sectiondata[IDX_debug_pubnames]->d_size; + + while (readp + 14 < endp) + { + /* If necessary, allocate more entries. */ + if (cnt >= allocated) + { + allocated = MAX (10, 2 * allocated); + struct pubnames_s *newmem + = (struct pubnames_s *) realloc (mem, allocated * entsize); + if (newmem == NULL) + { + __libdwarf_seterrno (DWARF_E_NOMEM); + err_return: + free (mem); + return -1; + } + + mem = newmem; + } + + /* Read the set header. */ + int len_bytes = 4; + Dwarf_Off len = read_4ubyte_unaligned_inc (dbg, readp); + if (len == 0xffffffff) + { + len = read_8ubyte_unaligned_inc (dbg, readp); + len_bytes = 8; + } + + /* Now we know the offset of the first offset/name pair. */ + mem[cnt].set_start = readp + 2 + 2 * len_bytes - startp; + mem[cnt].address_len = len_bytes; + if (mem[cnt].set_start >= dbg->sectiondata[IDX_debug_pubnames]->d_size) + /* Something wrong, the first entry is beyond the end of + the section. */ + break; + + /* Read the version. It better be two for now. */ + uint16_t version = read_2ubyte_unaligned (dbg, readp); + if (version != 2) + { + __libdwarf_seterrno (DWARF_E_INVALID_VERSION); + goto err_return; + } + + /* Get the CU offset. */ + if (len_bytes == 4) + mem[cnt].cu_offset = read_4ubyte_unaligned (dbg, readp + 2); + else + mem[cnt].cu_offset = read_8ubyte_unaligned (dbg, readp + 2); + + /* Determine the size of the CU header. */ + assert (dbg->sectiondata[IDX_debug_info] != NULL); + assert (dbg->sectiondata[IDX_debug_info]->d_buf != NULL); + assert (mem[cnt].cu_offset + 3 + < dbg->sectiondata[IDX_debug_info]->d_size); + unsigned char *infop + = ((unsigned char *) dbg->sectiondata[IDX_debug_info]->d_buf + + mem[cnt].cu_offset); + if (read_4ubyte_unaligned_noncvt (infop) == 0xffffffff) + mem[cnt].cu_header_size = 23; + else + mem[cnt].cu_header_size = 11; + + ++cnt; + + /* Advance to the next set. */ + readp += len; + } + + if (mem == NULL) + { + __libdwarf_seterrno (DWARF_E_NO_ENTRY); + return -1; + } + + dbg->pubnames_sets = (struct pubnames_s *) realloc (mem, cnt * entsize); + dbg->pubnames_nsets = cnt; + + return 0; +} + + +size_t +dwarf_get_pubnames (dbg, callback, arg, offset) + Dwarf *dbg; + int (*callback) (Dwarf *, Dwarf_Global *, void *); + void *arg; + size_t offset; +{ + /* Make sure it is a valid offset. */ + if (unlikely (dbg->sectiondata[IDX_debug_pubnames] == NULL + || offset >= dbg->sectiondata[IDX_debug_pubnames]->d_size)) + /* No (more) entry. */ + return 0; + + /* If necessary read the set information. */ + if (dbg->pubnames_nsets == 0 && get_offsets (dbg) != 0) + return (size_t) -1; + + /* Find the place where to start. */ + size_t cnt; + if (offset == 0) + { + cnt = 0; + offset = dbg->pubnames_sets[0].set_start; + } + else + { + for (cnt = 0; cnt + 1 < dbg->pubnames_nsets; ++cnt) + if (offset >= dbg->pubnames_sets[cnt].set_start) + { + assert (offset < dbg->pubnames_sets[cnt + 1].set_start); + break; + } + assert (cnt + 1 < dbg->pubnames_nsets); + } + + unsigned char *startp + = (unsigned char *) dbg->sectiondata[IDX_debug_pubnames]->d_buf; + unsigned char *readp = startp + offset; + while (1) + { + Dwarf_Global gl; + + gl.cu_offset = (dbg->pubnames_sets[cnt].cu_offset + + dbg->pubnames_sets[cnt].cu_header_size); + + while (1) + { + /* READP points to the next offset/name pair. */ + if (dbg->pubnames_sets[cnt].address_len == 4) + gl.die_offset = read_4ubyte_unaligned_inc (dbg, readp); + else + gl.die_offset = read_8ubyte_unaligned_inc (dbg, readp); + + /* If the offset is zero we reached the end of the set. */ + if (gl.die_offset == 0) + break; + + /* Add the CU offset. */ + gl.die_offset += dbg->pubnames_sets[cnt].cu_offset; + + gl.name = (char *) readp; + readp = (unsigned char *) rawmemchr (gl.name, '\0') + 1; + + /* We found name and DIE offset. Report it. */ + if (callback (dbg, &gl, arg) != DWARF_CB_OK) + { + /* The user wants us to stop. Return the offset of the + next entry. */ + return readp - startp; + } + } + + if (++cnt == dbg->pubnames_nsets) + /* This was the last set. */ + break; + + startp = (unsigned char *) dbg->sectiondata[IDX_debug_pubnames]->d_buf; + readp = startp + dbg->pubnames_sets[cnt].set_start; + } + + /* We are done. No more entries. */ + return 0; +} diff --git a/elfutils/libebl/ebldebugscnp.c b/elfutils/libebl/ebldebugscnp.c new file mode 100644 index 0000000..59310b5 --- /dev/null +++ b/elfutils/libebl/ebldebugscnp.c @@ -0,0 +1,29 @@ +/* Check section name for being that of a debug informatino section. + Copyright (C) 2002 Red Hat, Inc. + Written by Ulrich Drepper , 2002. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + + +bool +ebl_debugscn_p (ebl, name) + Ebl *ebl; + const char *name; +{ + return ebl->debugscn_p (name); +} diff --git a/elfutils/libebl/libebl_sparc.h b/elfutils/libebl/libebl_sparc.h new file mode 100644 index 0000000..c06228e --- /dev/null +++ b/elfutils/libebl/libebl_sparc.h @@ -0,0 +1,37 @@ +/* Interface for libebl_sparc module. + Copyright (C) 2002 Red Hat, Inc. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#ifndef _LIBEBL_SPARC_H +#define _LIBEBL_SPARC_H 1 + +#include + + +/* Constructor. */ +extern int sparc_init (Elf *elf, GElf_Half machine, Ebl *eh, size_t ehlen); + +/* Destructor. */ +extern void sparc_destr (Ebl *bh); + + +/* Function to get relocation type name. */ +extern const char *sparc_reloc_type_name (int type, char *buf, size_t len); + +/* Check relocation type. */ +extern bool sparc_reloc_type_check (int type); + +/* Code note handling. */ +extern bool sparc_core_note (const char *name, uint32_t type, uint32_t descsz, + const char *desc); + +#endif /* libebl_sparc.h */ diff --git a/elfutils/libebl/libebl_sparc.map b/elfutils/libebl/libebl_sparc.map new file mode 100644 index 0000000..7ca6038 --- /dev/null +++ b/elfutils/libebl/libebl_sparc.map @@ -0,0 +1,11 @@ +ELFUTILS_1.0 { + global: + sparc_backend_name; + sparc_destr; + sparc_init; + sparc_reloc_type_check; + sparc_reloc_type_name; + + local: + *; +}; diff --git a/elfutils/libebl/sparc_destr.c b/elfutils/libebl/sparc_destr.c new file mode 100644 index 0000000..ced2291 --- /dev/null +++ b/elfutils/libebl/sparc_destr.c @@ -0,0 +1,26 @@ +/* Destructor for SPARC specific backend library. + Copyright (C) 2002 Red Hat, Inc. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + + +void +sparc_destr (bh) + Ebl *bh; +{ + /* Nothing to do so far. */ +} diff --git a/elfutils/libebl/sparc_init.c b/elfutils/libebl/sparc_init.c new file mode 100644 index 0000000..2bb1f79 --- /dev/null +++ b/elfutils/libebl/sparc_init.c @@ -0,0 +1,45 @@ +/* Initialization of SPARC specific backend library. + Copyright (C) 2002 Red Hat, Inc. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + + +int +sparc_init (elf, machine, eh, ehlen) + Elf *elf; + GElf_Half machine; + Ebl *eh; + size_t ehlen; +{ + /* Check whether the Elf_BH object has a sufficent size. */ + if (ehlen < sizeof (Ebl)) + return 1; + + /* We handle it. */ + if (machine == EM_SPARCV9) + eh->name = "SPARC v9"; + else if (machine == EM_SPARC32PLUS) + eh->name = "SPARC v8+"; + else + eh->name = "SPARC"; + eh->reloc_type_name = sparc_reloc_type_name; + eh->reloc_type_check = sparc_reloc_type_check; + //eh->core_note = sparc_core_note; + eh->destr = sparc_destr; + + return 0; +} diff --git a/elfutils/libebl/sparc_symbol.c b/elfutils/libebl/sparc_symbol.c new file mode 100644 index 0000000..eed31d1 --- /dev/null +++ b/elfutils/libebl/sparc_symbol.c @@ -0,0 +1,141 @@ +/* SPARC specific symbolic name handling. + Copyright (C) 2002, 2003 Red Hat, Inc. + Written by Jakub Jelinek , 2002. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include + + +/* Return of the backend. */ +const char * +sparc_backend_name (void) +{ + return "sparc"; +} + + +/* Relocation mapping table. */ +static const char *reloc_map_table[] = + { + [R_SPARC_NONE] = "R_SPARC_NONE", + [R_SPARC_8] = "R_SPARC_8", + [R_SPARC_16] = "R_SPARC_16", + [R_SPARC_32] = "R_SPARC_32", + [R_SPARC_DISP8] = "R_SPARC_DISP8", + [R_SPARC_DISP16] = "R_SPARC_DISP16", + [R_SPARC_DISP32] = "R_SPARC_DISP32", + [R_SPARC_WDISP30] = "R_SPARC_WDISP30", + [R_SPARC_WDISP22] = "R_SPARC_WDISP22", + [R_SPARC_HI22] = "R_SPARC_HI22", + [R_SPARC_22] = "R_SPARC_22", + [R_SPARC_13] = "R_SPARC_13", + [R_SPARC_LO10] = "R_SPARC_LO10", + [R_SPARC_GOT10] = "R_SPARC_GOT10", + [R_SPARC_GOT13] = "R_SPARC_GOT13", + [R_SPARC_GOT22] = "R_SPARC_GOT22", + [R_SPARC_PC10] = "R_SPARC_PC10", + [R_SPARC_PC22] = "R_SPARC_PC22", + [R_SPARC_WPLT30] = "R_SPARC_WPLT30", + [R_SPARC_COPY] = "R_SPARC_COPY", + [R_SPARC_GLOB_DAT] = "R_SPARC_GLOB_DAT", + [R_SPARC_JMP_SLOT] = "R_SPARC_JMP_SLOT", + [R_SPARC_RELATIVE] = "R_SPARC_RELATIVE", + [R_SPARC_UA32] = "R_SPARC_UA32", + [R_SPARC_PLT32] = "R_SPARC_PLT32", + [R_SPARC_HIPLT22] = "R_SPARC_HIPLT22", + [R_SPARC_LOPLT10] = "R_SPARC_LOPLT10", + [R_SPARC_PCPLT32] = "R_SPARC_PCPLT32", + [R_SPARC_PCPLT22] = "R_SPARC_PCPLT22", + [R_SPARC_PCPLT10] = "R_SPARC_PCPLT10", + [R_SPARC_10] = "R_SPARC_10", + [R_SPARC_11] = "R_SPARC_11", + [R_SPARC_64] = "R_SPARC_64", + [R_SPARC_OLO10] = "R_SPARC_OLO10", + [R_SPARC_HH22] = "R_SPARC_HH22", + [R_SPARC_HM10] = "R_SPARC_HM10", + [R_SPARC_LM22] = "R_SPARC_LM22", + [R_SPARC_PC_HH22] = "R_SPARC_PC_HH22", + [R_SPARC_PC_HM10] = "R_SPARC_PC_HM10", + [R_SPARC_PC_LM22] = "R_SPARC_PC_LM22", + [R_SPARC_WDISP16] = "R_SPARC_WDISP16", + [R_SPARC_WDISP19] = "R_SPARC_WDISP19", + [R_SPARC_7] = "R_SPARC_7", + [R_SPARC_5] = "R_SPARC_5", + [R_SPARC_6] = "R_SPARC_6", + [R_SPARC_DISP64] = "R_SPARC_DISP64", + [R_SPARC_PLT64] = "R_SPARC_PLT64", + [R_SPARC_HIX22] = "R_SPARC_HIX22", + [R_SPARC_LOX10] = "R_SPARC_LOX10", + [R_SPARC_H44] = "R_SPARC_H44", + [R_SPARC_M44] = "R_SPARC_M44", + [R_SPARC_L44] = "R_SPARC_L44", + [R_SPARC_REGISTER] = "R_SPARC_REGISTER", + [R_SPARC_UA64] = "R_SPARC_UA64", + [R_SPARC_UA16] = "R_SPARC_UA16", + [R_SPARC_TLS_GD_HI22] = "R_SPARC_TLS_GD_HI22", + [R_SPARC_TLS_GD_LO10] = "R_SPARC_TLS_GD_LO10", + [R_SPARC_TLS_GD_ADD] = "R_SPARC_TLS_GD_ADD", + [R_SPARC_TLS_GD_CALL] = "R_SPARC_TLS_GD_CALL", + [R_SPARC_TLS_LDM_HI22] = "R_SPARC_TLS_LDM_HI22", + [R_SPARC_TLS_LDM_LO10] = "R_SPARC_TLS_LDM_LO10", + [R_SPARC_TLS_LDM_ADD] = "R_SPARC_TLS_LDM_ADD", + [R_SPARC_TLS_LDM_CALL] = "R_SPARC_TLS_LDM_CALL", + [R_SPARC_TLS_LDO_HIX22] = "R_SPARC_TLS_LDO_HIX22", + [R_SPARC_TLS_LDO_LOX10] = "R_SPARC_TLS_LDO_LOX10", + [R_SPARC_TLS_LDO_ADD] = "R_SPARC_TLS_LDO_ADD", + [R_SPARC_TLS_IE_HI22] = "R_SPARC_TLS_IE_HI22", + [R_SPARC_TLS_IE_LO10] = "R_SPARC_TLS_IE_LO10", + [R_SPARC_TLS_IE_LD] = "R_SPARC_TLS_IE_LD", + [R_SPARC_TLS_IE_LDX] = "R_SPARC_TLS_IE_LDX", + [R_SPARC_TLS_IE_ADD] = "R_SPARC_TLS_IE_ADD", + [R_SPARC_TLS_LE_HIX22] = "R_SPARC_TLS_LE_HIX22", + [R_SPARC_TLS_LE_LOX10] = "R_SPARC_TLS_LE_LOX10", + [R_SPARC_TLS_DTPMOD32] = "R_SPARC_TLS_DTPMOD32", + [R_SPARC_TLS_DTPMOD64] = "R_SPARC_TLS_DTPMOD64", + [R_SPARC_TLS_DTPOFF32] = "R_SPARC_TLS_DTPOFF32", + [R_SPARC_TLS_DTPOFF64] = "R_SPARC_TLS_DTPOFF64", + [R_SPARC_TLS_TPOFF32] = "R_SPARC_TLS_TPOFF32", + [R_SPARC_TLS_TPOFF64] = "R_SPARC_TLS_TPOFF64" + }; + + +/* Determine relocation type string for sparc. */ +const char * +sparc_reloc_type_name (int type, char *buf, size_t len) +{ + /* High 24 bits of r_type are used for second addend in R_SPARC_OLO10. */ + if ((type & 0xff) == R_SPARC_OLO10) + return reloc_map_table[type & 0xff]; + + if (type < 0 || type >= R_SPARC_NUM) + return NULL; + + return reloc_map_table[type]; +} + + +/* Check for correct relocation type. */ +bool +sparc_reloc_type_check (int type) +{ + if ((type & 0xff) == R_SPARC_OLO10) + return true; + return (type >= R_SPARC_NONE && type < R_SPARC_NUM + && reloc_map_table[type] != NULL) ? true : false; +} diff --git a/elfutils/tests/ecp.c b/elfutils/tests/ecp.c new file mode 100644 index 0000000..15bc71c --- /dev/null +++ b/elfutils/tests/ecp.c @@ -0,0 +1,88 @@ +/* Copyright (C) 2002 Red Hat, Inc. + Written by Ulrich Drepper , 2002. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#include +#include +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + if (argc < 3) + error (EXIT_FAILURE, 0, "usage: %s FROMNAME TONAME", argv[0]); + + elf_version (EV_CURRENT); + + int infd = open (argv[1], O_RDONLY); + if (infd == -1) + error (EXIT_FAILURE, errno, "cannot open input file '%s'", argv[1]); + + Elf *inelf = elf_begin (infd, ELF_C_READ, NULL); + if (inelf == NULL) + error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s", + argv[1], elf_errmsg (-1)); + + int outfd = creat (argv[2], 0666); + if (outfd == -1) + error (EXIT_FAILURE, errno, "cannot open output file '%s'", argv[2]); + + Elf *outelf = elf_begin (outfd, ELF_C_WRITE, NULL); + if (outelf == NULL) + error (EXIT_FAILURE, 0, "problems opening '%s' as ELF file: %s", + argv[2], elf_errmsg (-1)); + + gelf_newehdr (outelf, gelf_getclass (inelf)); + + GElf_Ehdr ehdr_mem; + GElf_Ehdr *ehdr; + gelf_update_ehdr (outelf, (ehdr = gelf_getehdr (inelf, &ehdr_mem))); + + if (ehdr->e_phnum > 0) + { + int cnt; + + if (gelf_newphdr (outelf, ehdr->e_phnum) == 0) + error (EXIT_FAILURE, 0, "cannot create program header: %s", + elf_errmsg (-1)); + + for (cnt = 0; cnt < ehdr->e_phnum; ++cnt) + { + GElf_Phdr phdr_mem; + + gelf_update_phdr (outelf, cnt, gelf_getphdr (inelf, cnt, &phdr_mem)); + } + } + + Elf_Scn *scn = NULL; + while ((scn = elf_nextscn (inelf, scn)) != NULL) + { + Elf_Scn *newscn = elf_newscn (outelf); + + GElf_Shdr shdr_mem; + gelf_update_shdr (newscn, gelf_getshdr (scn, &shdr_mem)); + + *elf_newdata (newscn) = *elf_getdata (scn, NULL); + } + + elf_flagelf (outelf, ELF_C_SET, ELF_F_LAYOUT); + + if (elf_update (outelf, ELF_C_WRITE) == -1) + error (EXIT_FAILURE, 0, "elf_update failed: %s", elf_errmsg (-1)); + + close (outfd); + + return 0; +} diff --git a/elfutils/tests/get-pubnames2.c b/elfutils/tests/get-pubnames2.c new file mode 100644 index 0000000..9aa6451 --- /dev/null +++ b/elfutils/tests/get-pubnames2.c @@ -0,0 +1,94 @@ +/* Copyright (C) 2002 Red Hat, Inc. + Written by Ulrich Drepper , 2002. + + This program is Open Source software; you can redistribute it and/or + modify it under the terms of the Open Software License version 1.0 as + published by the Open Source Initiative. + + You should have received a copy of the Open Software License along + with this program; if not, you may obtain a copy of the Open Software + License version 1.0 from http://www.opensource.org/licenses/osl.php or + by writing the Open Source Initiative c/o Lawrence Rosen, Esq., + 3001 King Ranch Road, Ukiah, CA 95482. */ + +#include +#include +#include +#include +#include + + +static int globcnt; + +static int +callback (Dwarf *dbg, Dwarf_Global *gl, void *arg) +{ + printf (" [%2d] \"%s\", die: %llu, cu: %llu\n", + globcnt++, gl->name, (unsigned long long int) gl->die_offset, + (unsigned long long int) gl->cu_offset); + +#if 0 + Dwarf_Die cu_die; + const char *cuname; + if (dwarf_offdie (dbg, gl->cu_offset, &cu_die) == NULL + || (cuname = dwarf_diename (&cu_die)) == NULL) + { + puts ("failed to get CU die"); + result = 1; + } + else + { + printf ("CU name: \"%s\"\n", cuname); + dwarf_dealloc (dbg, cuname, DW_DLA_STRING); + } + + const char *diename; + if (dwarf_offdie (dbg, gl->die_offset, &die) == NULL + || (diename = dwarf_diename (&die)) == NULL) + { + puts ("failed to get object die"); + result = 1; + } + else + { + printf ("object name: \"%s\"\n", diename); + dwarf_dealloc (dbg, diename, DW_DLA_STRING); + } +#endif + return DWARF_CB_OK; +} + + +int +main (int argc, char *argv[]) +{ + int result = 0; + int cnt; + + for (cnt = 1; cnt < argc; ++cnt) + { + int fd = open (argv[cnt], O_RDONLY); + Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ); + if (dbg == NULL) + { + printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1)); + result = 1; + close (fd); + continue; + } + + globcnt = 0; + + if (dwarf_get_pubnames (dbg, callback, NULL, 0) != 0) + { + printf ("dwarf_get_pubnames didn't return zero: %s\n", + dwarf_errmsg (-1)); + result = 1; + } + + dwarf_end (dbg); + close (fd); + } + + return result; +} diff --git a/elfutils/tests/run-ecp-test.sh b/elfutils/tests/run-ecp-test.sh new file mode 100755 index 0000000..ee2e0c9 --- /dev/null +++ b/elfutils/tests/run-ecp-test.sh @@ -0,0 +1,22 @@ +#! /bin/sh +# Copyright (C) 2002 Red Hat, Inc. +# Written by Jakub Jelinek , 2002. +# +# This program is Open Source software; you can redistribute it and/or +# modify it under the terms of the Open Software License version 1.0 as +# published by the Open Source Initiative. +# +# You should have received a copy of the Open Software License along +# with this program; if not, you may obtain a copy of the Open Software +# License version 1.0 from http://www.opensource.org/licenses/osl.php or +# by writing the Open Source Initiative c/o Lawrence Rosen, Esq., +# 3001 King Ranch Road, Ukiah, CA 95482. +set -e + +./ecp $srcdir/testfile10 testfile10.tmp + +cmp $srcdir/testfile10 testfile10.tmp + +rm -f testfile10.tmp + +exit 0 diff --git a/elfutils/tests/run-ecp-test2.sh b/elfutils/tests/run-ecp-test2.sh new file mode 100755 index 0000000..e023593 --- /dev/null +++ b/elfutils/tests/run-ecp-test2.sh @@ -0,0 +1,20 @@ +#! /bin/sh +# Copyright (C) 2002 Red Hat, Inc. +# Written by Jakub Jelinek , 2002. +# +# This program is Open Source software; you can redistribute it and/or +# modify it under the terms of the Open Software License version 1.0 as +# published by the Open Source Initiative. +# +# You should have received a copy of the Open Software License along +# with this program; if not, you may obtain a copy of the Open Software +# License version 1.0 from http://www.opensource.org/licenses/osl.php or +# by writing the Open Source Initiative c/o Lawrence Rosen, Esq., +# 3001 King Ranch Road, Ukiah, CA 95482. +set -e + +./ecp $srcdir/testfile2 testfile2.tmp + +rm -f testfile2.tmp + +exit 0 diff --git a/elfutils/tests/run-get-pubnames2.sh b/elfutils/tests/run-get-pubnames2.sh new file mode 100755 index 0000000..fafee07 --- /dev/null +++ b/elfutils/tests/run-get-pubnames2.sh @@ -0,0 +1,57 @@ +#! /bin/sh +# Copyright (C) 1999, 2000, 2002 Red Hat, Inc. +# Written by Ulrich Drepper , 1999. +# +# This program is Open Source software; you can redistribute it and/or +# modify it under the terms of the Open Software License version 1.0 as +# published by the Open Source Initiative. +# +# You should have received a copy of the Open Software License along +# with this program; if not, you may obtain a copy of the Open Software +# License version 1.0 from http://www.opensource.org/licenses/osl.php or +# by writing the Open Source Initiative c/o Lawrence Rosen, Esq., +# 3001 King Ranch Road, Ukiah, CA 95482. +set -e + +./get-pubnames2 $srcdir/testfile $srcdir/testfile2 > get-pubnames2.out + +#diff -u get-pubnames2.out - <<"EOF" +# [ 0] "main", die: 104, cu: 11 +#CU name: "m.c" +#object name: "main" +# [ 1] "a", die: 174, cu: 11 +#CU name: "m.c" +#object name: "a" +# [ 2] "bar", die: 295, cu: 202 +#CU name: "b.c" +#object name: "bar" +# [ 3] "foo", die: 5721, cu: 5628 +#CU name: "f.c" +#object name: "foo" +# [ 0] "bar", die: 72, cu: 11 +#CU name: "b.c" +#object name: "bar" +# [ 1] "foo", die: 2490, cu: 2429 +#CU name: "f.c" +#object name: "foo" +# [ 2] "main", die: 2593, cu: 2532 +#CU name: "m.c" +#object name: "main" +# [ 3] "a", die: 2663, cu: 2532 +#CU name: "m.c" +#object name: "a" +#EOF +diff -u get-pubnames2.out - <<"EOF" + [ 0] "main", die: 104, cu: 11 + [ 1] "a", die: 174, cu: 11 + [ 2] "bar", die: 295, cu: 202 + [ 3] "foo", die: 5721, cu: 5628 + [ 0] "bar", die: 72, cu: 11 + [ 1] "foo", die: 2490, cu: 2429 + [ 2] "main", die: 2593, cu: 2532 + [ 3] "a", die: 2663, cu: 2532 +EOF + +rm -f get-pubnames2.out + +exit 0 diff --git a/elfutils/tests/testfile b/elfutils/tests/testfile new file mode 100644 index 0000000..736c137 Binary files /dev/null and b/elfutils/tests/testfile differ diff --git a/elfutils/tests/testfile10 b/elfutils/tests/testfile10 new file mode 100644 index 0000000..dcf230b Binary files /dev/null and b/elfutils/tests/testfile10 differ diff --git a/elfutils/tests/testfile2 b/elfutils/tests/testfile2 new file mode 100644 index 0000000..d3ce6b3 Binary files /dev/null and b/elfutils/tests/testfile2 differ diff --git a/elfutils/tests/testfile3 b/elfutils/tests/testfile3 new file mode 100644 index 0000000..9fa1eac Binary files /dev/null and b/elfutils/tests/testfile3 differ diff --git a/elfutils/tests/testfile4 b/elfutils/tests/testfile4 new file mode 100644 index 0000000..2415b0d Binary files /dev/null and b/elfutils/tests/testfile4 differ diff --git a/elfutils/tests/testfile5 b/elfutils/tests/testfile5 new file mode 100644 index 0000000..45e4cb1 Binary files /dev/null and b/elfutils/tests/testfile5 differ diff --git a/elfutils/tests/testfile6.bz2 b/elfutils/tests/testfile6.bz2 new file mode 100644 index 0000000..fd376b2 Binary files /dev/null and b/elfutils/tests/testfile6.bz2 differ diff --git a/elfutils/tests/testfile7.bz2 b/elfutils/tests/testfile7.bz2 new file mode 100644 index 0000000..87cc2cd Binary files /dev/null and b/elfutils/tests/testfile7.bz2 differ diff --git a/elfutils/tests/testfile8.bz2 b/elfutils/tests/testfile8.bz2 new file mode 100644 index 0000000..1ff4994 Binary files /dev/null and b/elfutils/tests/testfile8.bz2 differ diff --git a/elfutils/tests/testfile9.bz2 b/elfutils/tests/testfile9.bz2 new file mode 100644 index 0000000..26c5473 Binary files /dev/null and b/elfutils/tests/testfile9.bz2 differ