From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id DBE943857017; Wed, 22 Jun 2022 19:50:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DBE943857017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use std::string for interpreter_p X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: ee04bfc01e51faae3fb64f6582f0e207d3ad898d X-Git-Newrev: b2a696a8810f2ec36765c9bdcb56e62737376caf Message-Id: <20220622195056.DBE943857017@sourceware.org> Date: Wed, 22 Jun 2022 19:50:56 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2022 19:50:57 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Db2a696a8810f= 2ec36765c9bdcb56e62737376caf commit b2a696a8810f2ec36765c9bdcb56e62737376caf Author: Tom Tromey Date: Fri Jun 17 10:01:45 2022 -0600 Use std::string for interpreter_p =20 The global interpreter_p is a manually-managed 'char *'. This patch changes it to be a std::string instead, and removes some erroneous comments. Diff: --- gdb/interps.c | 11 ++--------- gdb/main.c | 24 +++++++++--------------- gdb/main.h | 2 +- gdb/tui/tui-interp.c | 9 +++------ 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index 0c440e78685..3a9c590b8c8 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -168,15 +168,8 @@ interp_set (struct interp *interp, bool top_level) if (top_level) ui_interp->top_level_interpreter =3D interp; =20 - /* We use interpreter_p for the "set interpreter" variable, so we need - to make sure we have a malloc'ed copy for the set command to free. */ - if (interpreter_p !=3D NULL - && strcmp (interp->name (), interpreter_p) !=3D 0) - { - xfree (interpreter_p); - - interpreter_p =3D xstrdup (interp->name ()); - } + if (interpreter_p !=3D interp->name ()) + interpreter_p =3D interp->name (); =20 /* Run the init proc. */ if (!interp->inited) diff --git a/gdb/main.c b/gdb/main.c index ec2b7b01752..8c97987956b 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -56,10 +56,8 @@ #include "observable.h" #include "serial.h" =20 -/* The selected interpreter. This will be used as a set command - variable, so it should always be malloc'ed - since - do_setshow_command will free it. */ -char *interpreter_p; +/* The selected interpreter. */ +std::string interpreter_p; =20 /* System root path, used to find libraries etc. */ std::string gdb_sysroot; @@ -729,7 +727,7 @@ captured_main_1 (struct captured_main_args *context) this captured main, or one specified by the user at start up, or the console. Initialize the interpreter to the one requested by=20 the application. */ - interpreter_p =3D xstrdup (context->interpreter_p); + interpreter_p =3D context->interpreter_p; =20 /* Parse arguments and options. */ { @@ -866,8 +864,7 @@ captured_main_1 (struct captured_main_args *context) case OPT_TUI: /* --tui is equivalent to -i=3Dtui. */ #ifdef TUI - xfree (interpreter_p); - interpreter_p =3D xstrdup (INTERP_TUI); + interpreter_p =3D INTERP_TUI; #else error (_("%s: TUI mode is not supported"), gdb_program_name); #endif @@ -877,14 +874,12 @@ captured_main_1 (struct captured_main_args *context) actually useful, and if it is, what it should do. */ #ifdef GDBTK /* --windows is equivalent to -i=3Dinsight. */ - xfree (interpreter_p); - interpreter_p =3D xstrdup (INTERP_INSIGHT); + interpreter_p =3D INTERP_INSIGHT; #endif break; case OPT_NOWINDOWS: /* -nw is equivalent to -i=3Dconsole. */ - xfree (interpreter_p); - interpreter_p =3D xstrdup (INTERP_CONSOLE); + interpreter_p =3D INTERP_CONSOLE; break; case 'f': annotation_level =3D 1; @@ -950,8 +945,7 @@ captured_main_1 (struct captured_main_args *context) } #endif /* GDBTK */ case 'i': - xfree (interpreter_p); - interpreter_p =3D xstrdup (optarg); + interpreter_p =3D optarg; break; case 'd': dirarg.push_back (optarg); @@ -1133,7 +1127,7 @@ captured_main_1 (struct captured_main_args *context) GDB retain the old MI1 interpreter startup behavior. Output the copyright message before the interpreter is installed. That way it isn't encapsulated in MI output. */ - if (!quiet && strcmp (interpreter_p, INTERP_MI1) =3D=3D 0) + if (!quiet && interpreter_p =3D=3D INTERP_MI1) { /* Print all the junk at the top, with trailing "..." if we are about to read a symbol file (possibly slowly). */ @@ -1147,7 +1141,7 @@ captured_main_1 (struct captured_main_args *context) =20 /* Install the default UI. All the interpreters should have had a look at things by now. Initialize the default interpreter. */ - set_top_level_interpreter (interpreter_p); + set_top_level_interpreter (interpreter_p.c_str ()); =20 /* FIXME: cagney/2003-02-03: The big hack (part 2 of 2) that lets GDB retain the old MI1 interpreter startup behavior. Output the diff --git a/gdb/main.h b/gdb/main.h index 60b3569438e..7cdd93f3420 100644 --- a/gdb/main.h +++ b/gdb/main.h @@ -36,7 +36,7 @@ extern int batch_silent; extern int batch_flag; =20 /* * The name of the interpreter if specified on the command line. */ -extern char *interpreter_p; +extern std::string interpreter_p; =20 /* From mingw-hdep.c, used by main.c. */ =20 diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c index e867441afb0..b4faede8ce6 100644 --- a/gdb/tui/tui-interp.c +++ b/gdb/tui/tui-interp.c @@ -343,14 +343,11 @@ _initialize_tui_interp () { interp_factory_register (INTERP_TUI, tui_interp_factory); =20 - if (interpreter_p && strcmp (interpreter_p, INTERP_TUI) =3D=3D 0) + if (interpreter_p =3D=3D INTERP_TUI) tui_start_enabled =3D true; =20 - if (interpreter_p && strcmp (interpreter_p, INTERP_CONSOLE) =3D=3D 0) - { - xfree (interpreter_p); - interpreter_p =3D xstrdup (INTERP_TUI); - } + if (interpreter_p =3D=3D INTERP_CONSOLE) + interpreter_p =3D INTERP_TUI; =20 /* If changing this, remember to update cli-interp.c as well. */ gdb::observers::normal_stop.attach (tui_on_normal_stop, "tui-interp");