Signed-off-by: Petr Machata <[email protected]> --- libdw/ChangeLog | 9 +++++++++ libdw/dwarf_error.c | 3 ++- libdw/dwarf_getsrcfiles.c | 9 +++++---- libdw/dwarf_getsrclines.c | 11 ++++++----- libdw/libdwP.h | 7 +++++++ 5 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 3ca85cb..4fb4763 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,12 @@ +2015-04-01 Petr Machata <[email protected]> + + * libdwP.h (DWARF_E_NOT_CUDIE): New enumerator. + (is_cudie): New function. + * dwarf_error.c (errmsgs): Add message for DWARF_E_NOT_CUDIE. + * dwarf_getsrcfiles.c (dwarf_getsrcfiles): Call is_cudie instead + of white-listing valid tags. + * dwarf_getsrclines.c (dwarf_getsrclines.c): Likewise. + 2015-03-18 Petr Machata <[email protected]> * Makefile.am (pkginclude_HEADERS): Add known-dwarf.h. diff --git a/libdw/dwarf_error.c b/libdw/dwarf_error.c index 08b691a..aa97a68 100644 --- a/libdw/dwarf_error.c +++ b/libdw/dwarf_error.c @@ -1,5 +1,5 @@ /* Retrieve ELF descriptor used for DWARF access. - Copyright (C) 2002, 2003, 2004, 2005, 2009, 2014 Red Hat, Inc. + Copyright (C) 2002, 2003, 2004, 2005, 2009, 2014, 2015 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2002. @@ -93,6 +93,7 @@ static const char *errmsgs[] = [DWARF_E_INVALID_CFI] = N_("invalid CFI section"), [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"), [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"), + [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"), }; #define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0])) diff --git a/libdw/dwarf_getsrcfiles.c b/libdw/dwarf_getsrcfiles.c index 4bfc34b..30bf8f5 100644 --- a/libdw/dwarf_getsrcfiles.c +++ b/libdw/dwarf_getsrcfiles.c @@ -39,10 +39,11 @@ int dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles) { - if (unlikely (cudie == NULL - || (INTUSE(dwarf_tag) (cudie) != DW_TAG_compile_unit - && INTUSE(dwarf_tag) (cudie) != DW_TAG_partial_unit))) - return -1; + if (cudie == NULL || ! is_cudie (cudie)) + { + __libdw_seterrno (DWARF_E_NOT_CUDIE); + return -1; + } int res = -1; diff --git a/libdw/dwarf_getsrclines.c b/libdw/dwarf_getsrclines.c index 053b30f..1b31721 100644 --- a/libdw/dwarf_getsrclines.c +++ b/libdw/dwarf_getsrclines.c @@ -1,5 +1,5 @@ /* Return line number information of CU. - Copyright (C) 2004-2010, 2013, 2014 Red Hat, Inc. + Copyright (C) 2004-2010, 2013, 2014, 2015 Red Hat, Inc. This file is part of elfutils. Written by Ulrich Drepper <[email protected]>, 2004. @@ -838,10 +838,11 @@ __libdw_getcompdir (Dwarf_Die *cudie) int dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines) { - if (unlikely (cudie == NULL - || (INTUSE(dwarf_tag) (cudie) != DW_TAG_compile_unit - && INTUSE(dwarf_tag) (cudie) != DW_TAG_partial_unit))) - return -1; + if (cudie == NULL || ! is_cudie (cudie)) + { + __libdw_seterrno (DWARF_E_NOT_CUDIE); + return -1; + } /* Get the information if it is not already known. */ struct Dwarf_CU *const cu = cudie->cu; diff --git a/libdw/libdwP.h b/libdw/libdwP.h index e38e0c9..fc77960 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -128,6 +128,7 @@ enum DWARF_E_INVALID_CFI, DWARF_E_NO_ALT_DEBUGLINK, DWARF_E_INVALID_OPCODE, + DWARF_E_NOT_CUDIE, }; @@ -725,6 +726,12 @@ cu_sec_idx (struct Dwarf_CU *cu) return cu->type_offset == 0 ? IDX_debug_info : IDX_debug_types; } +static inline bool +is_cudie (Dwarf_Die *cudie) +{ + return CUDIE (cudie->cu).addr == cudie->addr; +} + /* Read up begin/end pair and increment read pointer. - If it's normal range record, set up *BEGINP and *ENDP and return 0. - If it's base address selection record, set up *BASEP and return 1. -- 2.1.0
