[v2] gdb: sim: handle target sysroot prefix

Message ID 1435073379-30787-1-git-send-email-vapier@gentoo.org
State Committed
Headers

Commit Message

Mike Frysinger June 23, 2015, 3:29 p.m. UTC
  The default gdb sysroot now sets itself to "target:".  This works for
most remote targets, but when using the simulator, this causes problems
as the sim will attempt to search for that path.

Update the remote-sim logic to skip this leading prefix when it is found
so that the sysroot isn't passed in as an invalid value.

2015-06-21  Mike Frysinger  <vapier@gentoo.org>

	* remote-sim.c: Include gdb_bfd.h.
	(gdbsim_open): Declare new local sysroot pointing to gdb_sysroot.
	Skip TARGET_SYSROOT_PREFIX in gdb_sysroot when it is active.
---
v2
	- use is_target_filename

 gdb/remote-sim.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
  

Comments

Gary Benson June 24, 2015, 10:31 a.m. UTC | #1
Mike Frysinger wrote:
> The default gdb sysroot now sets itself to "target:".  This works
> for most remote targets, but when using the simulator, this causes
> problems as the sim will attempt to search for that path.
> 
> Update the remote-sim logic to skip this leading prefix when it is
> found so that the sysroot isn't passed in as an invalid value.
> 
> 2015-06-21  Mike Frysinger  <vapier@gentoo.org>
> 
> 	* remote-sim.c: Include gdb_bfd.h.
> 	(gdbsim_open): Declare new local sysroot pointing to gdb_sysroot.
> 	Skip TARGET_SYSROOT_PREFIX in gdb_sysroot when it is active.

Looks good to me :)

Cheers,
Gary
  
Pedro Alves June 24, 2015, 1:46 p.m. UTC | #2
On 06/23/2015 04:29 PM, Mike Frysinger wrote:

>  gdb/remote-sim.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
> index fd2fd58..0c43379 100644
> --- a/gdb/remote-sim.c
> +++ b/gdb/remote-sim.c
> @@ -21,6 +21,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>  
>  #include "defs.h"
> +#include "gdb_bfd.h"
>  #include "inferior.h"
>  #include "infrun.h"
>  #include "value.h"
> @@ -669,6 +670,7 @@ gdbsim_open (const char *args, int from_tty)
>    int len;
>    char *arg_buf;
>    struct sim_inferior_data *sim_data;
> +  const char *sysroot = gdb_sysroot;
>    SIM_DESC gdbsim_desc;
>  
>    if (remote_debug)
> @@ -688,7 +690,7 @@ gdbsim_open (const char *args, int from_tty)
>    len = (7 + 1			/* gdbsim */
>  	 + strlen (" -E little")
>  	 + strlen (" --architecture=xxxxxxxxxx")
> -	 + strlen (" --sysroot=") + strlen (gdb_sysroot) +
> +	 + strlen (" --sysroot=") + strlen (sysroot) +
>  	 + (args ? strlen (args) : 0)
>  	 + 50) /* slack */ ;
>    arg_buf = (char *) alloca (len);
> @@ -715,7 +717,9 @@ gdbsim_open (const char *args, int from_tty)
>      }
>    /* Pass along gdb's concept of the sysroot.  */
>    strcat (arg_buf, " --sysroot=");
> -  strcat (arg_buf, gdb_sysroot);
> +  if (is_target_filename (sysroot))
> +    sysroot += strlen (TARGET_SYSROOT_PREFIX);

Please do this skipping above the "len = " computation.  As is
we'll just oversize arg_bug, but there's no good reason
for the discrepancy.

OK with that change.

(it would be easy to get rid of all that using reconcat.)

Thanks you; thanks Gary.
  

Patch

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index fd2fd58..0c43379 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -21,6 +21,7 @@ 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "gdb_bfd.h"
 #include "inferior.h"
 #include "infrun.h"
 #include "value.h"
@@ -669,6 +670,7 @@  gdbsim_open (const char *args, int from_tty)
   int len;
   char *arg_buf;
   struct sim_inferior_data *sim_data;
+  const char *sysroot = gdb_sysroot;
   SIM_DESC gdbsim_desc;
 
   if (remote_debug)
@@ -688,7 +690,7 @@  gdbsim_open (const char *args, int from_tty)
   len = (7 + 1			/* gdbsim */
 	 + strlen (" -E little")
 	 + strlen (" --architecture=xxxxxxxxxx")
-	 + strlen (" --sysroot=") + strlen (gdb_sysroot) +
+	 + strlen (" --sysroot=") + strlen (sysroot) +
 	 + (args ? strlen (args) : 0)
 	 + 50) /* slack */ ;
   arg_buf = (char *) alloca (len);
@@ -715,7 +717,9 @@  gdbsim_open (const char *args, int from_tty)
     }
   /* Pass along gdb's concept of the sysroot.  */
   strcat (arg_buf, " --sysroot=");
-  strcat (arg_buf, gdb_sysroot);
+  if (is_target_filename (sysroot))
+    sysroot += strlen (TARGET_SYSROOT_PREFIX);
+  strcat (arg_buf, sysroot);
   /* finally, any explicit args */
   if (args)
     {