This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix bug using dwarf_next_unit to iterate over .debug_types


On Wed, 2012-03-21 at 08:54 -0600, Tom Tromey wrote:
> 	* libdw_findcu.c (findcu_cb): Move earlier.
> 	(__libdw_intern_next_unit): Add new CU to search tree here...
> 	(__libdw_findcu): ... not here.
> 
> 	* typeiter.c: New file.
> 	* run-typeiter.sh: New file.
> 	* testfile59.bz2: New file.
> 	* Makefile.am (noinst_PROGRAMS): Add typeiter.
> 	(TESTS): Add run-typeiter.sh.
> 	(EXTRA_DIST): Add run-typeiter.sh, testfile59.bz2.
> 	(typeiter_LDADD): New variable.

Thanks for adding the testcase. I tested that it fails before and
succeeds after the fix. Also the systemtap testcase works with this.
Since roland already OKed the code I pushed it for you with one small
change. I added the actual source that was used to create the test
binary to the testcase as comment in case anybody wants to recreate it
in the future.

Cheers,

Mark

# struct s1
# {
#   char c;
#   short s;
#   int i;
#   long l;
#   float f;
#   double d;
# };
# 
# s1 S1;
# 
# int func (s1 *p)
# {
#   return p->i;
# }
# 
# int main()
# {
#   return func (&S1);
# }
#
# g++ -gdwarf-4 -g -fdebug-types-section


> If you call dwarf_next_unit to iterate over .debug_types, then call
> dwarf_offdie_types, you can see a failure if some earlier call
> happened to call __libdw_intern_next_unit via dwarf_formref_die.
> 
> What happens is that __libdw_intern_next_unit updates the Dwarf's
> next_tu_offset, but does not add the TU to the TU search tree.  So,
> the call to dwarf_offdie_types does not find the TU in the tree, and
> will not search any more, causing a failure.
> 
> This fix changes __libdw_intern_next_unit to add the TU to the search
> tree, rather than relying on __libdw_findcu to do it.
> ---
>  libdw/ChangeLog       |    6 +++
>  libdw/libdw_findcu.c  |   68 ++++++++++++++++-----------------
>  tests/ChangeLog       |   10 +++++
>  tests/Makefile.am     |    8 ++-
>  tests/run-typeiter.sh |   34 +++++++++++++++++
>  tests/testfile59.bz2  |  Bin 0 -> 3097 bytes
>  tests/typeiter.c      |   98 +++++++++++++++++++++++++++++++++++++++++++++++++
>  7 files changed, 186 insertions(+), 38 deletions(-)
>  create mode 100755 tests/run-typeiter.sh
>  create mode 100755 tests/testfile59.bz2
>  create mode 100644 tests/typeiter.c
> 
> diff --git a/libdw/ChangeLog b/libdw/ChangeLog
> index 98b67f4..f96c0d1 100644
> --- a/libdw/ChangeLog
> +++ b/libdw/ChangeLog
> @@ -1,3 +1,9 @@
> +2012-03-19  Tom Tromey  <tromey@redhat.com>
> +
> +	* libdw_findcu.c (findcu_cb): Move earlier.
> +	(__libdw_intern_next_unit): Add new CU to search tree here...
> +	(__libdw_findcu): ... not here.
> +
>  2012-01-31  Mark Wielaard  <mjw@redhat.com>
>  
>  	* dwarf_formudata.c (dwarf_formudata): Handle DW_FORM_sec_offset.
> diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c
> index 8e5f9e9..83c96ba 100644
> --- a/libdw/libdw_findcu.c
> +++ b/libdw/libdw_findcu.c
> @@ -56,6 +56,31 @@
>  #include <search.h>
>  #include "libdwP.h"
>  
> +static int
> +findcu_cb (const void *arg1, const void *arg2)
> +{
> +  struct Dwarf_CU *cu1 = (struct Dwarf_CU *) arg1;
> +  struct Dwarf_CU *cu2 = (struct Dwarf_CU *) arg2;
> +
> +  /* Find out which of the two arguments is the search value.  It has
> +     end offset 0.  */
> +  if (cu1->end == 0)
> +    {
> +      if (cu1->start < cu2->start)
> +	return -1;
> +      if (cu1->start >= cu2->end)
> +	return 1;
> +    }
> +  else
> +    {
> +      if (cu2->start < cu1->start)
> +	return 1;
> +      if (cu2->start >= cu1->end)
> +	return -1;
> +    }
> +
> +  return 0;
> +}
>  
>  struct Dwarf_CU *
>  internal_function
> @@ -65,6 +90,7 @@ __libdw_intern_next_unit (dbg, debug_types)
>  {
>    Dwarf_Off *const offsetp
>      = debug_types ? &dbg->next_tu_offset : &dbg->next_cu_offset;
> +  void **tree = debug_types ? &dbg->tu_tree : &dbg->cu_tree;
>  
>    Dwarf_Off oldoff = *offsetp;
>    uint16_t version;
> @@ -105,34 +131,16 @@ __libdw_intern_next_unit (dbg, debug_types)
>    newp->lines = NULL;
>    newp->locs = NULL;
>  
> -  return newp;
> -}
> -
> -
> -static int
> -findcu_cb (const void *arg1, const void *arg2)
> -{
> -  struct Dwarf_CU *cu1 = (struct Dwarf_CU *) arg1;
> -  struct Dwarf_CU *cu2 = (struct Dwarf_CU *) arg2;
> -
> -  /* Find out which of the two arguments is the search value.  It has
> -     end offset 0.  */
> -  if (cu1->end == 0)
> +  /* Add the new entry to the search tree.  */
> +  if (tsearch (newp, tree, findcu_cb) == NULL)
>      {
> -      if (cu1->start < cu2->start)
> -	return -1;
> -      if (cu1->start >= cu2->end)
> -	return 1;
> -    }
> -  else
> -    {
> -      if (cu2->start < cu1->start)
> -	return 1;
> -      if (cu2->start >= cu1->end)
> -	return -1;
> +      /* Something went wrong.  Undo the operation.  */
> +      *offsetp = oldoff;
> +      __libdw_seterrno (DWARF_E_NOMEM);
> +      return NULL;
>      }
>  
> -  return 0;
> +  return newp;
>  }
>  
>  struct Dwarf_CU *
> @@ -160,20 +168,10 @@ __libdw_findcu (dbg, start, debug_types)
>    /* No.  Then read more CUs.  */
>    while (1)
>      {
> -      Dwarf_Off oldoff = *next_offset;
>        struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, debug_types);
>        if (newp == NULL)
>  	return NULL;
>  
> -      /* Add the new entry to the search tree.  */
> -      if (tsearch (newp, tree, findcu_cb) == NULL)
> -	{
> -	  /* Something went wrong.  Undo the operation.  */
> -	  *next_offset = oldoff;
> -	  __libdw_seterrno (DWARF_E_NOMEM);
> -	  return NULL;
> -	}
> -
>        /* Is this the one we are looking for?  */
>        if (start < *next_offset)
>  	// XXX Match exact offset.
> diff --git a/tests/ChangeLog b/tests/ChangeLog
> index a782591..8d2b83f 100644
> --- a/tests/ChangeLog
> +++ b/tests/ChangeLog
> @@ -1,3 +1,13 @@
> +2012-03-21  Tom Tromey  <tromey@redhat.com>
> +
> +	* typeiter.c: New file.
> +	* run-typeiter.sh: New file.
> +	* testfile59.bz2: New file.
> +	* Makefile.am (noinst_PROGRAMS): Add typeiter.
> +	(TESTS): Add run-typeiter.sh.
> +	(EXTRA_DIST): Add run-typeiter.sh, testfile59.bz2.
> +	(typeiter_LDADD): New variable.
> +
>  2012-02-21  Kurt Roeckx  <kurt@roeckx.be>
>  
>  	* run-alldts.sh: testrun ./alldts.
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 3074c89..f2c211b 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -58,7 +58,7 @@ noinst_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
>  		  dwfl-addr-sect dwfl-bug-report early-offscn \
>  		  dwfl-bug-getmodules dwarf-getmacros addrcfi \
>  		  test-flag-nobits dwarf-getstring rerequest_tag \
> -		  alldts md5-sha1-test
> +		  alldts md5-sha1-test typeiter
>  asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
>  	    asm-tst6 asm-tst7 asm-tst8 asm-tst9
>  
> @@ -86,7 +86,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \
>  	run-disasm-x86.sh run-disasm-x86-64.sh \
>  	run-early-offscn.sh run-dwarf-getmacros.sh \
>  	run-test-flag-nobits.sh run-prelink-addr-test.sh \
> -	run-dwarf-getstring.sh run-rerequest_tag.sh
> +	run-dwarf-getstring.sh run-rerequest_tag.sh run-typeiter.sh
>  # run-show-ciefde.sh
>  
>  if !STANDALONE
> @@ -161,7 +161,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \
>  	     testfile55-32.bz2 testfile55-32.debug.bz2 \
>  	     testfile55-32.prelink.bz2 testfile55-64.bz2 \
>  	     testfile55-64.debug.bz2 testfile55-64.prelink.bz2 \
> -	     testfile56.bz2 testfile57.bz2 testfile58.bz2
> +	     testfile56.bz2 testfile57.bz2 testfile58.bz2 \
> +	     run-typeiter.sh testfile59.bz2
>  
>  installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \
>  			      bindir=$(DESTDIR)$(bindir) \
> @@ -258,6 +259,7 @@ test_flag_nobits_LDADD = $(libelf) $(libmudflap)
>  rerequest_tag_LDADD = $(libdw) $(libmudflap)
>  alldts_LDADD = $(libebl) $(libelf) $(libmudflap)
>  md5_sha1_test_LDADD = $(libeu)
> +typeiter_LDADD = $(libdw) $(libelf) $(libmudflap)
>  
>  if GCOV
>  check: check-am coverage
> diff --git a/tests/run-typeiter.sh b/tests/run-typeiter.sh
> new file mode 100755
> index 0000000..34a4eb3
> --- /dev/null
> +++ b/tests/run-typeiter.sh
> @@ -0,0 +1,34 @@
> +#! /bin/sh
> +# Copyright (C) 2012 Red Hat, Inc.
> +# This file is part of Red Hat elfutils.
> +#
> +# Red Hat elfutils is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by the
> +# Free Software Foundation; version 2 of the License.
> +#
> +# Red Hat 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 a copy of the GNU General Public License along
> +# with Red Hat elfutils; if not, write to the Free Software Foundation,
> +# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
> +#
> +# Red Hat elfutils is an included package of the Open Invention Network.
> +# An included package of the Open Invention Network is a package for which
> +# Open Invention Network licensees cross-license their patents.  No patent
> +# license is granted, either expressly or impliedly, by designation as an
> +# included package.  Should you wish to participate in the Open Invention
> +# Network licensing program, please visit www.openinventionnetwork.com
> +# <http://www.openinventionnetwork.com>.
> +
> +. $srcdir/test-subr.sh
> +
> +testfiles testfile59
> +
> +testrun_compare ./typeiter testfile59 <<\EOF
> +ok
> +EOF
> +
> +exit 0
> diff --git a/tests/testfile59.bz2 b/tests/testfile59.bz2
> new file mode 100755
> index 0000000000000000000000000000000000000000..bcee648cfcfd204b8c793937bb87393c67b1b754
> GIT binary patch
> literal 3097
> zcmV+!4CeDfT4*^jL0KkKSsZy2^#BUCfB*mg|Ns8~|NsC0|9}7g-~RtE_59LpYk2SR
> ze9nJ=|J&dSPQv?|KsdB}n<rA{g{>=fzyaI3ox(a)EcCPs;&giKSyJyRy0r<7)%sp@*4
> zsi(a)kXlgb-YO*W^g<vmYR(r9f(a)M9?yNfYW-R<c7+5O$M7p(?)>Ny-?FZ>NL=38V9NB
> zXnKH(a)Ab^@=CIFhArcG1wOpHvMRK)c^QKD^3fM^G)p`bDYOb~5A01X?}JwO0(a)fChjD
> zfM{qmXbq?}Gy-J_Jx^0d>X{m300x1e&;T?6rhotd0ie(T4FCWDGynhq0000FP$WeY
> zL`-U)Oo`$rsix91Nuc!%O*B0~XlQAtsiuHv4Lu+l0Av~&0002UXwU#O01W^Epa=i}
> z0LTCh0BN9TG&BG-&=~*#216qR0MHo#(9kr~Kr{nD05Sl`$N*I`Kmnit05oJY0002c
> z8U{cb0000027ojMngBF1XwWnRKmcd}2Gz`cu7+fpTs&vd{ify!y|ffp0f(__fWlg;
> z`2|#`Gwxtw6#Ql_Ye6pckjBzu$3z#_%OhI*SA1X1D#~uOOW!FK&8qaZtFZ=}(LB^Q
> z29}2fcNeWwYBtL}mnDvdb-|izQ^+l{L)Uqoi2kS=jw`;&etO`-y>8rQGMAfpK9wA}
> zvR6ImR<g{o;lBoHb}g~MmlVCN>wEXObY;5;HNI2eziQ-aDw)yMfT*i&SW!h4P<l55
> zlh$*7{(g5aUVfJ^Q-g0>{z&BeiaN?EW<8TsI$_0U4TG%z<rN?=0LsmAr+R1aq+z?f
> zDYQJjBt4{~uY?#Cf)D{g00<w*AUB?2Ebo5*KThUbR+fOEe6J(a)MeOQdx@i`OnA3=UX
> z5{Q?i4k<v0Ee*Y4x#z`$P<NCy-RtS-6hH-02#}JZYN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GPyd)C{XeEJ(t++9j>2cj+E#@4r^6Gw;(i*VGR(%
> n`)`V!EM~SKh&7WPtOO%hvcIomXNSF6|Ha&qP81{u9z^{>xIenj
> 
> literal 0
> HcmV?d00001
> 
> diff --git a/tests/typeiter.c b/tests/typeiter.c
> new file mode 100644
> index 0000000..184b00b
> --- /dev/null
> +++ b/tests/typeiter.c
> @@ -0,0 +1,98 @@
> +/* Copyright (C) 2012 Red Hat, Inc.
> +   This file is part of Red Hat elfutils.
> +
> +   Red Hat elfutils is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by the
> +   Free Software Foundation; version 2 of the License.
> +
> +   Red Hat 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 a copy of the GNU General Public License along
> +   with Red Hat elfutils; if not, write to the Free Software Foundation,
> +   Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
> +
> +   Red Hat elfutils is an included package of the Open Invention Network.
> +   An included package of the Open Invention Network is a package for which
> +   Open Invention Network licensees cross-license their patents.  No patent
> +   license is granted, either expressly or impliedly, by designation as an
> +   included package.  Should you wish to participate in the Open Invention
> +   Network licensing program, please visit www.openinventionnetwork.com
> +   <http://www.openinventionnetwork.com>.  */
> +
> +#ifdef HAVE_CONFIG_H
> +# include <config.h>
> +#endif
> +
> +#include <fcntl.h>
> +#include ELFUTILS_HEADER(dw)
> +#include <stdio.h>
> +#include <unistd.h>
> +#include <dwarf.h>
> +
> +int
> +main (int argc, char *argv[])
> +{
> +  for (int i = 1; i < argc; ++i)
> +    {
> +      int fd = open (argv[i], O_RDONLY);
> +
> +      Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
> +      if (dbg != NULL)
> +	{
> +	  Dwarf_Off off = 0;
> +	  size_t cuhl;
> +	  Dwarf_Off noff;
> +
> +	  while (dwarf_nextcu (dbg, off, &noff, &cuhl, NULL, NULL, NULL) == 0)
> +	    {
> +	      Dwarf_Die die_mem;
> +	      Dwarf_Die *die = dwarf_offdie (dbg, off + cuhl, &die_mem);
> +
> +	      Dwarf_Die iter_mem;
> +	      Dwarf_Die *iter = &iter_mem;
> +	      dwarf_child (die, &iter_mem);
> +
> +	      while (1)
> +		{
> +		  if (dwarf_tag (iter) == DW_TAG_variable)
> +		    {
> +		      Dwarf_Attribute attr_mem;
> +		      Dwarf_Die form_mem;
> +		      dwarf_formref_die (dwarf_attr (iter, DW_AT_type,
> +						     &attr_mem),
> +					 &form_mem);
> +		    }
> +
> +		  if (dwarf_siblingof (iter, &iter_mem) != 0)
> +		    break;
> +		}
> +
> +	      off = noff;
> +	    }
> +
> +	  off = 0;
> +	  uint64_t type_sig;
> +
> +	  while (dwarf_next_unit (dbg, off, &noff, &cuhl, NULL, NULL, NULL,
> +				  NULL, &type_sig, NULL) == 0)
> +	    {
> +	      Dwarf_Die die_mem;
> +	      Dwarf_Die *die = dwarf_offdie_types (dbg, off + cuhl, &die_mem);
> +
> +	      if (die == NULL)
> +		printf ("fail\n");
> +	      else
> +		printf ("ok\n");
> +
> +	      off = noff;
> +	    }
> +
> +	  dwarf_end (dbg);
> +	}
> +
> +      close (fd);
> +    }
> +}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]