This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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] Delete program spaces directly when removing inferiors


On 09/29/2014 09:33 PM, Simon Marchi wrote:

> -void
> -delete_inferior (int pid)
> -{
> -  struct inferior *inf = find_inferior_pid (pid);
> -
> -  delete_inferior_1 (inf, 0);
> -
> -  if (print_inferior_events)
> -    printf_unfiltered (_("[Inferior %d exited]\n"), pid);
> -}
> +  /* If this program space is rendered useless, remove it. */
> +  if (program_space_empty_p (inf->pspace))
> +      delete_program_space (inf->pspace);

I think there's something odd with indentation here.

> -  struct program_space *ss, **ss_link;
> -  struct program_space *current = current_program_space;
> +  gdb_assert(pspace != NULL);
> +  gdb_assert(pspace != current_program_space);
>  
> -  ss = program_spaces;
> -  ss_link = &program_spaces;
> -  while (ss)
> +  if (pspace == program_spaces)
> +    program_spaces = pspace->next;
> +  else
>      {
> -      if (ss == current || !pspace_empty_p (ss))
> +      struct program_space *i = program_spaces;
> +
> +      for (i = program_spaces; i != NULL; i = i->next)
>  	{
> -	  ss_link = &ss->next;
> -	  ss = *ss_link;
> -	  continue;
> +	  if (i->next == pspace)
> +	    {
> +	      i->next = i->next->next;
> +	      break;
> +	    }
>  	}
> -
> -      *ss_link = ss->next;
> -      release_program_space (ss);
> -      ss = *ss_link;
>      }

I don't find this conversion from while to if+else+for an
improvement.  You can instead write:

  ss = program_spaces;
  ss_link = &program_spaces;
  while (ss != NULL)
    {
      if (ss == pspace)
        {
         *ss_link = ss->next;
          break;
        }

      ss_link = &ss->next;
      ss = *ss_link;
    }
  release_program_space (pspace);

We use this _link pattern in several places.

OK with that change.

Thanks,
Pedro Alves


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