Re: [PATCH] Always fetch Ada "main" name from the executable

Andrew Burgess <[email protected]>
Newsgroups gmane.comp.gdb.patches
Message-ID <[email protected]>
Tom Tromey <[email protected]> writes:

>>>>>> "Andrew" == Andrew Burgess <[email protected]> writes:
>
> Andrew>     gdb/ada: avoid rereading stale main name data in edge case
>     
> Andrew> diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
> Andrew> index 906c5cd3465..174e04af04c 100644
> Andrew> --- a/gdb/ada-lang.c
> Andrew> +++ b/gdb/ada-lang.c
> Andrew> @@ -806,8 +806,7 @@ ada_main_name ()
> Andrew>  					      sections)
> Andrew>  	   == TARGET_XFER_OK)
> Andrew>  	  && xferred > 0
> Andrew> -	  && (strnlen ((char *) main_program_name, sizeof (main_program_name))
> Andrew> -	      < sizeof (main_program_name)))
> Andrew> +	  && (strnlen ((char *) main_program_name, xferred) < xferred))
> Andrew>  	return (char *) main_program_name;
> Andrew>      }
>
> Looks good to me.
>
> I suppose xferred < sizeof (main_program_name) and so the first strnlen

I did think about this, but the section_table_xfer_memory_partial call
is capped at 'sizeof (main_program_name)' so this check would really be
an assert.

But as the section_table_xfer_memory_partial call is part of this same
`if` condition we'd have to split the code like:

  if (section_table_xfer_memory_partial (....) == TARGET_XFER_OK)
    {
      gdb_assert (xferred < sizeof (main_program_name));

      if (xferred > 0
          && strnlen ((char *) main_program_name, xferred) < xferred)
        return (char *) main_program_name;
    }

And the extra complexity didn't seem worth it.

> is probably now redundant.  However this doesn't really matter, the main
> name is not examined very often.
>
> Approved-By: Tom Tromey <[email protected]>

I've pushed the patch now.

Thanks,
Andrew
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.