diff --git a/libdw/dwarf_getabbrev.c b/libdw/dwarf_getabbrev.c index 5b02333f34677e22c05dd899ae2295e33a1e04f2..d9a6c0228251dc079f8dd7bce8d6c3bfd3861443 100644 --- a/libdw/dwarf_getabbrev.c +++ b/libdw/dwarf_getabbrev.c @@ -1,5 +1,6 @@ /* Get abbreviation at given offset. Copyright (C) 2003, 2004, 2005, 2006, 2014, 2017 Red Hat, Inc. + Copyright (C) 2025 Mark J. Wielaard This file is part of elfutils. Written by Ulrich Drepper , 2003. @@ -38,7 +39,7 @@ Dwarf_Abbrev * internal_function __libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, Dwarf_Off offset, - size_t *lengthp, Dwarf_Abbrev *result) + size_t *lengthp) { /* Don't fail if there is not .debug_abbrev section. */ if (dbg->sectiondata[IDX_debug_abbrev] == NULL) @@ -85,12 +86,7 @@ __libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, Dwarf_Off offset, Dwarf_Abbrev *abb = NULL; if (cu == NULL || (abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code)) == NULL) - { - if (result == NULL) - abb = libdw_typed_alloc (dbg, Dwarf_Abbrev); - else - abb = result; - } + abb = libdw_typed_alloc (dbg, Dwarf_Abbrev); else { foundit = true; @@ -183,5 +179,5 @@ dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset, size_t *lengthp) return NULL; } - return __libdw_getabbrev (dbg, cu, abbrev_offset + offset, lengthp, NULL); + return __libdw_getabbrev (dbg, cu, abbrev_offset + offset, lengthp); } diff --git a/libdw/dwarf_offabbrev.c b/libdw/dwarf_offabbrev.c index 27cdad64d4488f9506068d8e2efba07e56fef80c..41df69bf7749299d791fcc6ca149cbf1a1af4527 100644 --- a/libdw/dwarf_offabbrev.c +++ b/libdw/dwarf_offabbrev.c @@ -41,11 +41,15 @@ dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp, if (dbg == NULL) return -1; - Dwarf_Abbrev *abbrev = __libdw_getabbrev (dbg, NULL, offset, lengthp, - abbrevp); + Dwarf_Abbrev *abbrev = __libdw_getabbrev (dbg, NULL, offset, lengthp); if (abbrev == NULL) return -1; - return abbrev == DWARF_END_ABBREV ? 1 : 0; + if (abbrev == DWARF_END_ABBREV) + return 1; + + *abbrevp = *abbrev; + + return 0; } diff --git a/libdw/dwarf_tag.c b/libdw/dwarf_tag.c index d784970caddfbc2956995d94f7d693c1178475ca..218382a173386dbb5739c13228ac7f2a922b3a48 100644 --- a/libdw/dwarf_tag.c +++ b/libdw/dwarf_tag.c @@ -53,8 +53,7 @@ __libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code) /* Find the next entry. It gets automatically added to the hash table. */ - abb = __libdw_getabbrev (cu->dbg, cu, cu->last_abbrev_offset, &length, - NULL); + abb = __libdw_getabbrev (cu->dbg, cu, cu->last_abbrev_offset, &length); if (abb == NULL || abb == DWARF_END_ABBREV) { /* Make sure we do not try to search for it again. */ diff --git a/libdw/libdw.h b/libdw/libdw.h index 64d1689a309869ce4a12874b2d9cab8b42ce1d81..829cc211a07b007cd8067ec1fc98f910c74e679e 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -587,7 +587,9 @@ extern int dwarf_srclang (Dwarf_Die *die); extern Dwarf_Abbrev *dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset, size_t *lengthp); -/* Get abbreviation at given offset in .debug_abbrev section. */ +/* Get abbreviation at given offset in .debug_abbrev section. On + success return zero and fills in ABBREVP. When there is no (more) + abbrev at offset returns one. On error returns a negative value. */ extern int dwarf_offabbrev (Dwarf *dbg, Dwarf_Off offset, size_t *lengthp, Dwarf_Abbrev *abbrevp) __nonnull_attribute__ (4); diff --git a/libdw/libdwP.h b/libdw/libdwP.h index aef42267e7f9526ca7c369a0f135ceeb0703d89d..7a1f448f4d6395fad24610cbeefccd8e67783782 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -691,8 +691,7 @@ extern Dwarf_Abbrev *__libdw_findabbrev (struct Dwarf_CU *cu, /* Get abbreviation at given offset. */ extern Dwarf_Abbrev *__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, - Dwarf_Off offset, size_t *lengthp, - Dwarf_Abbrev *result) + Dwarf_Off offset, size_t *lengthp) __nonnull_attribute__ (1) internal_function; /* Get abbreviation of given DIE, and optionally set *READP to the DIE memory