From: Mark Wielaard Date: Fri, 15 Aug 2014 14:03:21 +0000 (+0200) Subject: libdw: Add new function dwarf_cu_die. X-Git-Tag: elfutils-0.160~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f18f233615cdae0a3633506238348a1dee9d3ea0;p=thirdparty%2Felfutils.git libdw: Add new function dwarf_cu_die. Given a Dwarf_Die or Dwarf_Attribute it is often convenient to get at the CU DIE and the CU header information. There is dwarf_diecu but that doesn't provide all information from the header and it doesn't work for attributes. Add a new dwarf_cu_die function that provides all information given a Dwarf_CU, which both Dwarf_Die and Dwarf_Attribute reference. Signed-off-by: Mark Wielaard --- diff --git a/ChangeLog b/ChangeLog index dd92265ea..d79d269bd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-08-15 Mark Wielaard + + * NEWS: Add dwarf_cu_die. + 2014-08-15 Mark Wielaard * NEWS: Add dwarf_cu_getdwarf. diff --git a/NEWS b/NEWS index 3e4e8cc06..6ee49673c 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ Version 0.160 -libdw: New function dwarf_cu_getdwarf. +libdw: New functions dwarf_cu_getdwarf, dwarf_cu_die. unstrip: New option -F, --force to combining files even if some ELF headers don't seem to match. diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 8dfd11e8f..5f9b09719 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,10 @@ +2014-08-15 Mark Wielaard + + * dwarf_cu_die.c: New file. + * Makefile.am (libdw_a_SOURCES): Add dwarf_cu_die.c. + * libdw.h (dwarf_cu_die): New function declaration. + * libdw.map (ELFUTILS_0.160): Add dwarf_cu_die. + 2014-08-15 Mark Wielaard * dwarf_cu_getdwarf.c: New file. diff --git a/libdw/Makefile.am b/libdw/Makefile.am index e39ab9a65..2e42a3764 100644 --- a/libdw/Makefile.am +++ b/libdw/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to create Makefile.in ## -## Copyright (C) 2002-2010, 2012 Red Hat, Inc. +## Copyright (C) 2002-2010, 2012, 2014 Red Hat, Inc. ## This file is part of elfutils. ## ## This file is free software; you can redistribute it and/or modify @@ -86,7 +86,8 @@ libdw_a_SOURCES = dwarf_begin.c dwarf_begin_elf.c dwarf_end.c dwarf_getelf.c \ dwarf_getcfi.c dwarf_getcfi_elf.c dwarf_cfi_end.c \ dwarf_aggregate_size.c dwarf_getlocation_implicit_pointer.c \ dwarf_getlocation_die.c dwarf_getlocation_attr.c \ - dwarf_getalt.c dwarf_setalt.c dwarf_cu_getdwarf.c + dwarf_getalt.c dwarf_setalt.c dwarf_cu_getdwarf.c \ + dwarf_cu_die.c if MAINTAINER_MODE BUILT_SOURCES = $(srcdir)/known-dwarf.h diff --git a/libdw/dwarf_cu_die.c b/libdw/dwarf_cu_die.c new file mode 100644 index 000000000..48f4176fe --- /dev/null +++ b/libdw/dwarf_cu_die.c @@ -0,0 +1,68 @@ +/* Internal definitions for libdwarf. + Copyright (C) 2014 Red Hat, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils 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 copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include "libdwP.h" + + +Dwarf_Die * +dwarf_cu_die (cu, result, versionp, abbrev_offsetp, address_sizep, + offset_sizep, type_signaturep, type_offsetp) + Dwarf_CU *cu; + Dwarf_Die *result; + Dwarf_Half *versionp; + Dwarf_Off *abbrev_offsetp; + uint8_t *address_sizep; + uint8_t *offset_sizep; + uint64_t *type_signaturep; + Dwarf_Off *type_offsetp; +{ + if (cu == NULL) + return NULL; + + *result = CUDIE (cu); + + if (versionp != NULL) + *versionp = cu->version; + if (abbrev_offsetp != NULL) + *abbrev_offsetp = cu->orig_abbrev_offset; + if (address_sizep != NULL) + *address_sizep = cu->address_size; + if (offset_sizep != NULL) + *offset_sizep = cu->offset_size; + if (type_signaturep != NULL) + *type_signaturep = cu->type_sig8; + if (type_offsetp != NULL) + *type_offsetp = cu->type_offset; + + return result; +} diff --git a/libdw/libdw.h b/libdw/libdw.h index 61d3b3866..196d54ae0 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -364,6 +364,23 @@ extern Dwarf_Die *dwarf_diecu (Dwarf_Die *die, Dwarf_Die *result, uint8_t *address_sizep, uint8_t *offset_sizep) __nonnull_attribute__ (2); +/* Return the CU DIE and the header info associated with a Dwarf_Die + or Dwarf_Attribute. A Dwarf_Die or a Dwarf_Attribute is associated + with a particular Dwarf_CU handle. This function returns the CU or + type unit DIE and header information for that Dwarf_CU. The + returned DIE is either a compile_unit, partial_unit or type_unit. + If it is a type_unit, then the type signature and type offset are + also provided, otherwise type_offset will be set to zero. See also + dwarf_diecu and dwarf_next_unit. */ +extern Dwarf_Die *dwarf_cu_die (Dwarf_CU *cu, Dwarf_Die *result, + Dwarf_Half *versionp, + Dwarf_Off *abbrev_offsetp, + uint8_t *address_sizep, + uint8_t *offset_sizep, + uint64_t *type_signaturep, + Dwarf_Off *type_offsetp) + __nonnull_attribute__ (2); + /* Return CU DIE containing given address. */ extern Dwarf_Die *dwarf_addrdie (Dwarf *dbg, Dwarf_Addr addr, Dwarf_Die *result) __nonnull_attribute__ (3); diff --git a/libdw/libdw.map b/libdw/libdw.map index 27e2273e4..55bc5371a 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -305,4 +305,5 @@ ELFUTILS_0.159 { ELFUTILS_0.160 { global: dwarf_cu_getdwarf; + dwarf_cu_die; } ELFUTILS_0.159; \ No newline at end of file