gdb: sim: handle target sysroot prefix
Commit Message
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 set.
---
gdb/remote-sim.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Comments
Hi Mike,
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 set.
> ---
> gdb/remote-sim.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
> index fd2fd58..b4f25bf 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)
> @@ -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 (startswith (sysroot, TARGET_SYSROOT_PREFIX))
> + sysroot += strlen (TARGET_SYSROOT_PREFIX);
> + strcat (arg_buf, sysroot);
> /* finally, any explicit args */
> if (args)
> {
Please use "is_target_filename (sysroot)" rather than startswith.
Please also update the "strlen (gdb_sysroot)" in this function.
Please note that gdb_sysroot can be NULL.
Otherwise looks good to me :)
Cheers,
Gary
On 22 Jun 2015 10:50, Gary Benson wrote:
> Mike Frysinger wrote:
> > @@ -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 (startswith (sysroot, TARGET_SYSROOT_PREFIX))
> > + sysroot += strlen (TARGET_SYSROOT_PREFIX);
> > + strcat (arg_buf, sysroot);
> > /* finally, any explicit args */
> > if (args)
> > {
>
> Please use "is_target_filename (sysroot)" rather than startswith.
OK
> Please also update the "strlen (gdb_sysroot)" in this function.
OK
> Please note that gdb_sysroot can be NULL.
how so ? main.c:captured_main specifically handles that:
/* Set the sysroot path. */
gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
TARGET_SYSTEM_ROOT_RELOCATABLE);
if (gdb_sysroot == NULL || *gdb_sysroot == '\0')
{
xfree (gdb_sysroot);
gdb_sysroot = xstrdup (TARGET_SYSROOT_PREFIX);
}
-mike
Mike Frysinger wrote:
> On 22 Jun 2015 10:50, Gary Benson wrote:
> > Please note that gdb_sysroot can be NULL.
>
> how so ? main.c:captured_main specifically handles that:
>
> /* Set the sysroot path. */
> gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
> TARGET_SYSTEM_ROOT_RELOCATABLE);
>
> if (gdb_sysroot == NULL || *gdb_sysroot == '\0')
> {
> xfree (gdb_sysroot);
> gdb_sysroot = xstrdup (TARGET_SYSROOT_PREFIX);
> }
Good point. I may go and clear out all the gdb_sysroot == NULL
checks.
Cheers,
Gary
@@ -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)
@@ -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 (startswith (sysroot, TARGET_SYSROOT_PREFIX))
+ sysroot += strlen (TARGET_SYSROOT_PREFIX);
+ strcat (arg_buf, sysroot);
/* finally, any explicit args */
if (args)
{