[PATCH 4/4] gdb: change regcache list to be a map

Pedro Alves pedro@palves.net
Wed Aug 5 18:02:29 GMT 2020


On 7/30/20 6:03 PM, Simon Marchi wrote:
> On 2020-07-30 12:58 p.m., Simon Marchi wrote:
>> It's down to:
>>
>>        for (auto it = regcaches.begin (); it != regcaches.end ();)
>> 	 {
>> 	   if (it->second->target () == target)
>> 	     it = regcaches.erase (it);
>> 	   else
>> 	     it++;
>> 	 }
> Ah, I see that you've provided me a patch for that too (I thought you only
> did the multi-level map thing).

Note that it's idiomatic to write ++it instead of it++, to avoid
creating a temporary.  It's possible that compilers nowadays optimize
it away, but it still looks odd to not write ++it to me.


  Your code is:
> 
>         for (auto it = regcaches.begin (); it != regcaches.end ();)
>           {
>             if (it->second->target () == target)
>               {
>                 delete it->second;
>                 it = regcaches.erase (it);
>               }
>           }
> 
> I think you are missing an it++ in the else?  Otherwise, when the target doesn't
> match, we'll get into an infinite loop I presume.

Yes, I was.  I didn't notice because I jumped straight to the multi-map
patch on top, which deletes that code, IIRC.

Thanks,
Pedro Alves


More information about the Gdb-patches mailing list