Use exec_file_find to prepend gdb_sysroot in follow_exec

Message ID 1429277318-26646-1-git-send-email-gbenson@redhat.com
State Committed
Headers

Commit Message

Gary Benson April 17, 2015, 1:28 p.m. UTC
  Hi all,

This commit updates follow_exec to use exec_file_find to prefix
the new executable's filename with gdb_sysroot rather than doing
it longhand.

Built and regtested on RHEL6.6 x86_64.

Ok to commit?

Cheers,
Gary


gdb/ChangeLog:

	* infrun.c (solist.h): New include.
	(follow_exec): Use exec_file_find to prefix execd_pathname
	with gdb_sysroot.
---
 gdb/ChangeLog |    6 ++++++
 gdb/infrun.c  |   18 +++++++++++-------
 2 files changed, 17 insertions(+), 7 deletions(-)
  

Comments

Gary Benson April 27, 2015, 10:38 a.m. UTC | #1
Ping:
https://sourceware.org/ml/gdb-patches/2015-04/msg00674.html

Gary Benson wrote:
> Hi all,
> 
> This commit updates follow_exec to use exec_file_find to prefix
> the new executable's filename with gdb_sysroot rather than doing
> it longhand.
> 
> Built and regtested on RHEL6.6 x86_64.
> 
> Ok to commit?
> 
> Cheers,
> Gary
> 
> 
> gdb/ChangeLog:
> 
> 	* infrun.c (solist.h): New include.
> 	(follow_exec): Use exec_file_find to prefix execd_pathname
> 	with gdb_sysroot.
> ---
>  gdb/ChangeLog |    6 ++++++
>  gdb/infrun.c  |   18 +++++++++++-------
>  2 files changed, 17 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 7870f70..f09e2da 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -60,6 +60,7 @@
>  #include "target-descriptions.h"
>  #include "target-dcache.h"
>  #include "terminal.h"
> +#include "solist.h"
>  
>  /* Prototypes for local functions */
>  
> @@ -1133,15 +1134,18 @@ follow_exec (ptid_t ptid, char *execd_pathname)
>  
>    breakpoint_init_inferior (inf_execd);
>  
> -  if (gdb_sysroot && *gdb_sysroot)
> +  if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
>      {
> -      char *name = alloca (strlen (gdb_sysroot)
> -			    + strlen (execd_pathname)
> -			    + 1);
> +      int fd = -1;
> +      char *name;
>  
> -      strcpy (name, gdb_sysroot);
> -      strcat (name, execd_pathname);
> -      execd_pathname = name;
> +      name = exec_file_find (execd_pathname, &fd);
> +      if (fd >= 0)
> +	close (fd);
> +
> +      execd_pathname = alloca (strlen (name) + 1);
> +      strcpy (execd_pathname, name);
> +      xfree (name);
>      }
>  
>    /* Reset the shared library package.  This ensures that we get a
> -- 
> 1.7.1
>
  
Pedro Alves April 27, 2015, 3:59 p.m. UTC | #2
On 04/17/2015 02:28 PM, Gary Benson wrote:
> Hi all,
> 
> This commit updates follow_exec to use exec_file_find to prefix
> the new executable's filename with gdb_sysroot rather than doing
> it longhand.
> 
> Built and regtested on RHEL6.6 x86_64.
> 
> Ok to commit?

OK.

> -  if (gdb_sysroot && *gdb_sysroot)
> +  if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
>      {
> -      char *name = alloca (strlen (gdb_sysroot)
> -			    + strlen (execd_pathname)
> -			    + 1);
> +      int fd = -1;
> +      char *name;
>  
> -      strcpy (name, gdb_sysroot);
> -      strcat (name, execd_pathname);
> -      execd_pathname = name;
> +      name = exec_file_find (execd_pathname, &fd);
> +      if (fd >= 0)
> +	close (fd);

We now have at least two places that need to remember to call
close.  IWBN if we hid that close in a exec_file_find variant, so
that callers didn't have to recall to do it.  Maybe
rename exec_file_find to (e.g.) exec_file_find_fd and reuse
the exec_file_find name, even.

Thanks,
Pedro Alves
  
Gary Benson April 28, 2015, 11:29 a.m. UTC | #3
Pedro Alves wrote:
> On 04/17/2015 02:28 PM, Gary Benson wrote:
> > This commit updates follow_exec to use exec_file_find to prefix
> > the new executable's filename with gdb_sysroot rather than doing
> > it longhand.
> > 
> > Built and regtested on RHEL6.6 x86_64.
> > 
> > Ok to commit?
> 
> OK.

Thanks, I pushed it.

> > -  if (gdb_sysroot && *gdb_sysroot)
> > +  if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
> >      {
> > -      char *name = alloca (strlen (gdb_sysroot)
> > -			    + strlen (execd_pathname)
> > -			    + 1);
> > +      int fd = -1;
> > +      char *name;
> >  
> > -      strcpy (name, gdb_sysroot);
> > -      strcat (name, execd_pathname);
> > -      execd_pathname = name;
> > +      name = exec_file_find (execd_pathname, &fd);
> > +      if (fd >= 0)
> > +	close (fd);
> 
> We now have at least two places that need to remember to call close.
> IWBN if we hid that close in a exec_file_find variant, so that
> callers didn't have to recall to do it.  Maybe rename exec_file_find
> to (e.g.) exec_file_find_fd and reuse the exec_file_find name, even.

Good shout.  How about I fix solib_find_1 to accept fd == NULL, and
put the closing logic in there?  That would work for solib_find too
then (I'm not sure if there are any "solib_find; close" places in
GDB but I'll look.)

Cheers,
Gary
  
Pedro Alves April 28, 2015, 11:31 a.m. UTC | #4
On 04/28/2015 12:29 PM, Gary Benson wrote:
> Pedro Alves wrote:

>> We now have at least two places that need to remember to call close.
>> IWBN if we hid that close in a exec_file_find variant, so that
>> callers didn't have to recall to do it.  Maybe rename exec_file_find
>> to (e.g.) exec_file_find_fd and reuse the exec_file_find name, even.
> 
> Good shout.  How about I fix solib_find_1 to accept fd == NULL, and
> put the closing logic in there?  That

Sounds good.

> would work for solib_find too then (I'm not sure if there are
> any "solib_find; close" places in GDB but I'll look.)

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 7870f70..f09e2da 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -60,6 +60,7 @@ 
 #include "target-descriptions.h"
 #include "target-dcache.h"
 #include "terminal.h"
+#include "solist.h"
 
 /* Prototypes for local functions */
 
@@ -1133,15 +1134,18 @@  follow_exec (ptid_t ptid, char *execd_pathname)
 
   breakpoint_init_inferior (inf_execd);
 
-  if (gdb_sysroot && *gdb_sysroot)
+  if (gdb_sysroot != NULL && *gdb_sysroot != '\0')
     {
-      char *name = alloca (strlen (gdb_sysroot)
-			    + strlen (execd_pathname)
-			    + 1);
+      int fd = -1;
+      char *name;
 
-      strcpy (name, gdb_sysroot);
-      strcat (name, execd_pathname);
-      execd_pathname = name;
+      name = exec_file_find (execd_pathname, &fd);
+      if (fd >= 0)
+	close (fd);
+
+      execd_pathname = alloca (strlen (name) + 1);
+      strcpy (execd_pathname, name);
+      xfree (name);
     }
 
   /* Reset the shared library package.  This ensures that we get a