gdb: fix remote-sim.c build

Message ID 20211004012538.1125209-1-simon.marchi@efficios.com
State New
Headers show
Series
  • gdb: fix remote-sim.c build
Related show

Commit Message

Lancelot SIX via Gdb-patches Oct. 4, 2021, 1:25 a.m.
Commit e0700ba44c56 ("gdb: make string-like set show commands use
std::string variable") broke the build:

      CXX    remote-sim.o
    /home/smarchi/src/binutils-gdb/gdb/remote-sim.c: In function ‘void gdbsim_target_open(const char*, int)’:
    /home/smarchi/src/binutils-gdb/gdb/remote-sim.c:686:27: error: cannot convert ‘const string’ {aka ‘const std::__cxx11::basic_string<char>’} to ‘const char*’
      686 |   if (is_target_filename (sysroot))
          |                           ^~~~~~~
          |                           |
          |                           const string {aka const std::__cxx11::basic_string<char>}
    In file included from /home/smarchi/src/binutils-gdb/gdb/remote-sim.c:24:
    /home/smarchi/src/binutils-gdb/gdb/gdb_bfd.h:39:37: note:   initializing argument 1 of ‘int is_target_filename(const char*)’
       39 | int is_target_filename (const char *name);
          |                         ~~~~~~~~~~~~^~~~

Fix that by making the code look like it was before that commit
but with a .c_str() added (instead of trying to use an std::string
reference).

Change-Id: I7ae5d39e1fcb06ff9a3d3717f403d8be95dc122b
---
 gdb/remote-sim.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

-- 
2.33.0

Comments

Lancelot SIX via Gdb-patches Oct. 4, 2021, 7:42 p.m. | #1
>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:


Simon> Commit e0700ba44c56 ("gdb: make string-like set show commands use
Simon> std::string variable") broke the build:
[...]

I found this before reading the list, so I ended up already pushing a
nearly identical patch to fix the build.

Tom

Patch

diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c
index 5bfce2a9a31..84a223411cb 100644
--- a/gdb/remote-sim.c
+++ b/gdb/remote-sim.c
@@ -680,9 +680,10 @@  gdbsim_target_open (const char *args, int from_tty)
   int len;
   char *arg_buf;
   struct sim_inferior_data *sim_data;
+  const char *sysroot;
   SIM_DESC gdbsim_desc;
 
-  const std::string &sysroot = gdb_sysroot;
+  sysroot = gdb_sysroot.c_str ();
   if (is_target_filename (sysroot))
     sysroot += strlen (TARGET_SYSROOT_PREFIX);
 
@@ -703,7 +704,7 @@  gdbsim_target_open (const char *args, int from_tty)
   len = (7 + 1			/* gdbsim */
 	 + strlen (" -E little")
 	 + strlen (" --architecture=xxxxxxxxxx")
-	 + strlen (" --sysroot=") + sysroot.length () +
+	 + strlen (" --sysroot=") + strlen (sysroot) +
 	 + (args ? strlen (args) : 0)
 	 + 50) /* slack */ ;
   arg_buf = (char *) alloca (len);
@@ -730,7 +731,7 @@  gdbsim_target_open (const char *args, int from_tty)
     }
   /* Pass along gdb's concept of the sysroot.  */
   strcat (arg_buf, " --sysroot=");
-  strcat (arg_buf, sysroot.c_str ());
+  strcat (arg_buf, sysroot);
   /* finally, any explicit args */
   if (args)
     {