This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 1/4] Make gdb_dirbuf local to functions
- From: Sergio Durigan Junior <sergiodj at redhat dot com>
- To: GDB Patches <gdb-patches at sourceware dot org>
- Cc: Pedro Alves <palves at redhat dot com>, Sergio Durigan Junior <sergiodj at redhat dot com>
- Date: Tue, 12 Sep 2017 00:23:22 -0400
- Subject: [PATCH 1/4] Make gdb_dirbuf local to functions
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=sergiodj at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06EB68553F
- References: <20170912042325.14927-1-sergiodj@redhat.com>
This is not a requirement for the feature, but I think it's a good
cleanup and is related anyway. Currently we have "current_directory"
and "gdb_dirbuf" globals, which means that we basically have two
possible places to consult when we want to know GDB's current working
directory.
This is not ideal and can lead to confusion, so my proposal is to
"internalize" the "gdb_dirbuf" variable, because it is really just
that: a buffer to be used when calling "getcwd". With this, only
"current_directory" should be used to determine the cwd.
gdb/ChangeLog:
yyyy-mm-dd Sergio Durigan Junior <sergiodj@redhat.com>
* cli/cli-cmds.c (quit_command): Declare "gdb_dirbuf".
(cd_command): Free "current_directory" before assigning to it.
* main.c (captured_main_1): Likewise. Call "xstrdup" when
storing it on "current_directory".
* mi/mi-cmd-env.c (mi_cmd_env_pwd): Declare "gdb_dirbuf".
* top.c (gdb_dirbuf): Remove global declaration.
* top.h (gdb_dirbuf): Likewise.
---
gdb/cli/cli-cmds.c | 7 ++++++-
gdb/main.c | 4 +++-
gdb/mi/mi-cmd-env.c | 1 +
gdb/top.c | 3 ---
gdb/top.h | 1 -
5 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 883844ee70..64e893c784 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -380,6 +380,8 @@ quit_command (char *args, int from_tty)
static void
pwd_command (char *args, int from_tty)
{
+ char gdb_dirbuf[BUFSIZ];
+
if (args)
error (_("The \"pwd\" command does not take an argument: %s"), args);
if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
@@ -434,7 +436,10 @@ cd_command (char *dir, int from_tty)
dir_holder.reset (savestring (dir, len));
if (IS_ABSOLUTE_PATH (dir_holder.get ()))
- current_directory = dir_holder.release ();
+ {
+ xfree (current_directory);
+ current_directory = dir_holder.release ();
+ }
else
{
if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]))
diff --git a/gdb/main.c b/gdb/main.c
index a0646edad6..9837729966 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -549,10 +549,12 @@ captured_main_1 (struct captured_main_args *context)
(xstrprintf ("%s: warning: ", gdb_program_name));
warning_pre_print = tmp_warn_preprint.get ();
+ char gdb_dirbuf[BUFSIZ];
+
if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
perror_warning_with_name (_("error finding working directory"));
- current_directory = gdb_dirbuf;
+ current_directory = xstrdup (gdb_dirbuf);
/* Set the sysroot path. */
gdb_sysroot = relocate_gdb_directory (TARGET_SYSTEM_ROOT,
diff --git a/gdb/mi/mi-cmd-env.c b/gdb/mi/mi-cmd-env.c
index 977b6e274d..55d08ee5f2 100644
--- a/gdb/mi/mi-cmd-env.c
+++ b/gdb/mi/mi-cmd-env.c
@@ -62,6 +62,7 @@ void
mi_cmd_env_pwd (const char *command, char **argv, int argc)
{
struct ui_out *uiout = current_uiout;
+ char gdb_dirbuf[BUFSIZ];
if (argc > 0)
error (_("-environment-pwd: No arguments allowed"));
diff --git a/gdb/top.c b/gdb/top.c
index 742c1e7a07..0f36dce760 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -133,9 +133,6 @@ show_confirm (struct ui_file *file, int from_tty,
char *current_directory;
-/* The directory name is actually stored here (usually). */
-char gdb_dirbuf[1024];
-
/* The last command line executed on the console. Used for command
repetitions. */
char *saved_command_line;
diff --git a/gdb/top.h b/gdb/top.h
index 45798897f6..6b66083995 100644
--- a/gdb/top.h
+++ b/gdb/top.h
@@ -219,7 +219,6 @@ extern void ui_unregister_input_event_handler (struct ui *ui);
/* From top.c. */
extern char *saved_command_line;
extern int confirm;
-extern char gdb_dirbuf[1024];
extern int inhibit_gdbinit;
extern const char gdbinit[];
--
2.13.3