[2/2] gdb: make inherit_abstract_dies use vector iterators

Message ID 20221021132104.1772565-2-simon.marchi@polymtl.ca
State Committed
Commit 129d1afcc50c0aa3cf69fb3c5d4d8c825bec1061
Headers
Series [1/2] gdb: check for empty offsets vector in inherit_abstract_dies |

Commit Message

Simon Marchi Oct. 21, 2022, 1:21 p.m. UTC
  Small cleanup to use std::vector iterators rather than raw pointers.

Change-Id: I8d50dbb3f2d8dad7ff94066a578d523f1f31b590
---
 gdb/dwarf2/read.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
  

Comments

Tom Tromey Oct. 21, 2022, 6:04 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Small cleanup to use std::vector iterators rather than raw pointers.

Looks good.

I think my previous note about hoisting the loop might be wrong after
all.

Simon> -      if (offsetp >= offsets_end
Simon> -	  || *offsetp > origin_child_die->sect_off)
Simon> +      if (offsets_it == offsets.end ()

... like I guess this could trigger.

This code is extremely hard to read IMO.

Tom
  
Simon Marchi Oct. 21, 2022, 6:26 p.m. UTC | #2
On 2022-10-21 14:04, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Small cleanup to use std::vector iterators rather than raw pointers.
> 
> Looks good.
> 
> I think my previous note about hoisting the loop might be wrong after
> all.
> 
> Simon> -      if (offsetp >= offsets_end
> Simon> -	  || *offsetp > origin_child_die->sect_off)
> Simon> +      if (offsets_it == offsets.end ()
> 
> ... like I guess this could trigger.

That's what I thought.  I will push the series, leaving this part as is
just to stay on the safe side.

Thanks,

Simon
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bf52354c4260..c233b3743140 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -11952,29 +11952,28 @@  inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
   if (!offsets.empty ())
     {
       std::sort (offsets.begin (), offsets.end ());
-      sect_offset *offsets_end = offsets.data () + offsets.size ();
-      for (sect_offset *offsetp = offsets.data () + 1;
-	   offsetp < offsets_end;
-	   offsetp++)
-	if (offsetp[-1] == *offsetp)
+
+      for (auto offsets_it = offsets.begin () + 1;
+	   offsets_it < offsets.end ();
+	   ++offsets_it)
+	if (*(offsets_it - 1) == *offsets_it)
 	  complaint (_("Multiple children of DIE %s refer "
 		       "to DIE %s as their abstract origin"),
 		     sect_offset_str (die->sect_off),
-		     sect_offset_str (*offsetp));
+		     sect_offset_str (*offsets_it));
     }
 
-  sect_offset *offsetp = offsets.data ();
-  sect_offset *offsets_end = offsets.data () + offsets.size ();
+  auto offsets_it = offsets.begin ();
   die_info *origin_child_die = origin_die->child;
   while (origin_child_die != nullptr && origin_child_die->tag != 0)
     {
       /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children?  */
-      while (offsetp < offsets_end
-	     && *offsetp < origin_child_die->sect_off)
-	offsetp++;
+      while (offsets_it < offsets.end ()
+	     && *offsets_it < origin_child_die->sect_off)
+	++offsets_it;
 
-      if (offsetp >= offsets_end
-	  || *offsetp > origin_child_die->sect_off)
+      if (offsets_it == offsets.end ()
+	  || *offsets_it > origin_child_die->sect_off)
 	{
 	  /* Found that ORIGIN_CHILD_DIE is really not referenced.
 	     Check whether we're already processing ORIGIN_CHILD_DIE.