Constify get_exec_file
authorTom Tromey <tromey@adacore.com>
Fri, 13 Dec 2019 22:09:37 +0000 (15:09 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 16 Dec 2019 21:08:11 +0000 (14:08 -0700)
I noticed that get_exec_file could return a "const char *".  This
patch implements this change.

I couldn't build all the code -- but I did build Linux native and a
mingw cross.

Consequently, the NTO code has a hack, where it casts away const.  I
think this can be removed, but that required more work there, and
since I couldn't compile it, I felt it best not to try.

Let me know what you think.

gdb/ChangeLog
2019-12-16  Tom Tromey  <tromey@adacore.com>

* windows-nat.c (windows_nat_target::attach): Update.
* remote.c (extended_remote_target::attach): Update.
* procfs.c (procfs_target::attach): Update.
* nto-procfs.c (nto_procfs_target::attach): Update.
(nto_procfs_target::create_inferior): Update.
* inf-ptrace.c (inf_ptrace_target::attach): Update.
* gnu-nat.c (gnu_nat_target::attach): Update.
(gnu_nat_target::detach): Update.
* darwin-nat.c (darwin_nat_target::attach): Update.
* corefile.c (get_exec_file): Constify result.  Remove extraneous
return.
* bsd-kvm.c (bsd_kvm_target_open): Update.
* gdbsupport/common-inferior.h (get_exec_file): Constify result.

gdb/gdbserver/ChangeLog
2019-12-16  Tom Tromey  <tromey@adacore.com>

* server.c (get_exec_file): Constify result.

Change-Id: I29c60f7313a7def0dcb290ff0c2a4c1dea4f981f

13 files changed:
gdb/ChangeLog
gdb/bsd-kvm.c
gdb/corefile.c
gdb/darwin-nat.c
gdb/gdbserver/ChangeLog
gdb/gdbserver/server.c
gdb/gdbsupport/common-inferior.h
gdb/gnu-nat.c
gdb/inf-ptrace.c
gdb/nto-procfs.c
gdb/procfs.c
gdb/remote.c
gdb/windows-nat.c

index 2ecc2aae4704e88d85b2ddc12f93c861234df8a9..d2660cc711260cdc537252c4244498a886c9a713 100644 (file)
@@ -1,3 +1,19 @@
+2019-12-16  Tom Tromey  <tromey@adacore.com>
+
+       * windows-nat.c (windows_nat_target::attach): Update.
+       * remote.c (extended_remote_target::attach): Update.
+       * procfs.c (procfs_target::attach): Update.
+       * nto-procfs.c (nto_procfs_target::attach): Update.
+       (nto_procfs_target::create_inferior): Update.
+       * inf-ptrace.c (inf_ptrace_target::attach): Update.
+       * gnu-nat.c (gnu_nat_target::attach): Update.
+       (gnu_nat_target::detach): Update.
+       * darwin-nat.c (darwin_nat_target::attach): Update.
+       * corefile.c (get_exec_file): Constify result.  Remove extraneous
+       return.
+       * bsd-kvm.c (bsd_kvm_target_open): Update.
+       * gdbsupport/common-inferior.h (get_exec_file): Constify result.
+
 2019-12-16  Christian Biesinger  <cbiesinger@google.com>
 
        * gdbsupport/common-defs.h: Remove workaround for a gnulib bug
index 895686ef628a72b2d1599308da018ea991617634..74c044f6c734f2f2256ff650a633155c3942257c 100644 (file)
@@ -106,7 +106,7 @@ static void
 bsd_kvm_target_open (const char *arg, int from_tty)
 {
   char errbuf[_POSIX2_LINE_MAX];
-  char *execfile = NULL;
+  const char *execfile = NULL;
   kvm_t *temp_kd;
   char *filename = NULL;
 
index f22c1540cb16b4bd441ee983013f7c6efc14c861..c4735ada00ae0c2fcbcedd979a2ae1723e7ddfd6 100644 (file)
@@ -141,7 +141,7 @@ validate_files (void)
 
 /* See gdbsupport/common-inferior.h.  */
 
-char *
+const char *
 get_exec_file (int err)
 {
   if (exec_filename)
@@ -151,7 +151,6 @@ get_exec_file (int err)
 
   error (_("No executable file specified.\n\
 Use the \"file\" or \"exec-file\" command."));
-  return NULL;
 }
 \f
 
index ecc7fc07f69a8a4ccc80cfa1a7db01c2b2a26e36..c3905d1a30eb4a87edbb02f2c1dd2986387134ff 100644 (file)
@@ -2045,7 +2045,7 @@ darwin_nat_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      char *exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
index 36dece61723c10cccc8d6ce6c31eaa28cf8f17d6..ecc3db53ebba20cb78c6722f71ee6389314eb56c 100644 (file)
@@ -1,3 +1,7 @@
+2019-12-16  Tom Tromey  <tromey@adacore.com>
+
+       * server.c (get_exec_file): Constify result.
+
 2019-12-10  Christian Biesinger  <cbiesinger@google.com>
 
        * Makefile.in: Add safe-strerror.c to gdbreplay and IPA, and change
index c5f7176cff83755ea98072ce2013695b43b64223..a425fbaa013702b727e2d7c94d630a1e957adaf2 100644 (file)
@@ -265,7 +265,7 @@ get_exec_wrapper ()
 
 /* See gdbsupport/common-inferior.h.  */
 
-char *
+const char *
 get_exec_file (int err)
 {
   if (err && program_path.get () == NULL)
index 77d4ad93d3569197b621fa9533039947cc10b8c7..0ee554e7ad08a954f0a4e7db3e4ff433837cb15e 100644 (file)
@@ -28,7 +28,7 @@ extern const char *get_exec_wrapper ();
 /* Return the name of the executable file as a string.
    ERR nonzero means get error if there is none specified;
    otherwise return 0 in that case.  */
-extern char *get_exec_file (int err);
+extern const char *get_exec_file (int err);
 
 /* Return the inferior's current working directory.  If nothing has
    been set, then return NULL.  */
index 93a50becceb66d33cd52fcde4690e94367f8fbd6..cf42af43673a5b39825e558f9a687caf9dce114b 100644 (file)
@@ -2195,7 +2195,6 @@ void
 gnu_nat_target::attach (const char *args, int from_tty)
 {
   int pid;
-  char *exec_file;
   struct inf *inf = cur_inf ();
   struct inferior *inferior;
 
@@ -2206,7 +2205,7 @@ gnu_nat_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      exec_file = (char *) get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered ("Attaching to program `%s', pid %d\n",
@@ -2260,7 +2259,7 @@ gnu_nat_target::detach (inferior *inf, int from_tty)
 
   if (from_tty)
     {
-      char *exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered ("Detaching from program `%s' pid %d\n",
index 4a8e7323736cdab22ee328119a0b2ffa0b0600e9..fd18146efe156e0b117b59de626b64db86d30c70 100644 (file)
@@ -186,7 +186,6 @@ inf_ptrace_target::mourn_inferior ()
 void
 inf_ptrace_target::attach (const char *args, int from_tty)
 {
-  char *exec_file;
   pid_t pid;
   struct inferior *inf;
 
@@ -210,7 +209,7 @@ inf_ptrace_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
index dcb0494e9c96b916345a5a49afd9b11a2ef7be5f..42b23484511d4a185fd75804ac373b5414a10918 100644 (file)
@@ -693,7 +693,6 @@ nto_procfs_target::pid_to_exec_file (const int pid)
 void
 nto_procfs_target::attach (const char *args, int from_tty)
 {
-  char *exec_file;
   int pid;
   struct inferior *inf;
 
@@ -704,7 +703,7 @@ nto_procfs_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      exec_file = (char *) get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
@@ -1215,7 +1214,7 @@ nto_procfs_target::create_inferior (const char *exec_file,
 
   argv = xmalloc ((allargs.size () / (unsigned) 2 + 2) *
                  sizeof (*argv));
-  argv[0] = get_exec_file (1);
+  argv[0] = const_cast<char *> (get_exec_file (1));
   if (!argv[0])
     {
       if (exec_file)
index 57d4b8f0bfbbdeb3ee3f8593f8e83114011f8a70..ccc5e26064bf3620947219d32e166381e2c15667 100644 (file)
@@ -1870,7 +1870,6 @@ procfs_debug_inferior (procinfo *pi)
 void
 procfs_target::attach (const char *args, int from_tty)
 {
-  char *exec_file;
   int   pid;
 
   pid = parse_pid_to_attach (args);
@@ -1880,7 +1879,7 @@ procfs_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_filtered (_("Attaching to program `%s', %s\n"),
index e7a8bb61860407d46cf5fd59b833e290c3c6ad4a..3c544502a85a5db4c6ea52fc2aa56f6c8fa8477e 100644 (file)
@@ -5792,7 +5792,7 @@ extended_remote_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      char *exec_file = get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
index d77828291c5ec87ae3cc29216981ccf52612b872..10d5c95d091d02a1e50406b186c5e48864911528 100644 (file)
@@ -1990,7 +1990,7 @@ windows_nat_target::attach (const char *args, int from_tty)
 
   if (from_tty)
     {
-      char *exec_file = (char *) get_exec_file (0);
+      const char *exec_file = get_exec_file (0);
 
       if (exec_file)
        printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
This page took 0.041274 seconds and 4 git commands to generate.