From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 22D263857368; Fri, 13 May 2022 14:37:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22D263857368 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] Constify target_pid_to_exec_file X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: f1025b233f6dad43981f5ad35c81481f8d3658bf X-Git-Newrev: 0e90c441629bcf1f53ba484f7d855ed8eb68f138 Message-Id: <20220513143708.22D263857368@sourceware.org> Date: Fri, 13 May 2022 14:37:08 +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: Fri, 13 May 2022 14:37:08 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D0e90c441629b= cf1f53ba484f7d855ed8eb68f138 commit 0e90c441629bcf1f53ba484f7d855ed8eb68f138 Author: Tom Tromey Date: Tue Apr 26 14:08:03 2022 -0600 Constify target_pid_to_exec_file =20 This changes target_pid_to_exec_file and target_ops::pid_to_exec_file to return a "const char *". I couldn't build many of these targets, but did examine the code by hand -- also, as this only affects the return type, it's normally pretty safe. This brings gdb and gdbserver a bit closer, and allows for the removal of a const_cast as well. Diff: --- gdb/darwin-nat.c | 2 +- gdb/darwin-nat.h | 2 +- gdb/exec.c | 2 +- gdb/fbsd-nat.c | 2 +- gdb/fbsd-nat.h | 2 +- gdb/inf-child.c | 2 +- gdb/inf-child.h | 2 +- gdb/linux-nat.c | 2 +- gdb/linux-nat.h | 2 +- gdb/nat/linux-procfs.c | 2 +- gdb/nat/linux-procfs.h | 2 +- gdb/netbsd-nat.c | 4 ++-- gdb/netbsd-nat.h | 2 +- gdb/nto-procfs.c | 4 ++-- gdb/procfs.c | 4 ++-- gdb/remote.c | 4 ++-- gdb/target-delegates.c | 14 +++++++------- gdb/target.c | 2 +- gdb/target.h | 4 ++-- gdb/windows-nat.c | 4 ++-- 20 files changed, 32 insertions(+), 32 deletions(-) diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 17723656930..eca97c9bde9 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -2373,7 +2373,7 @@ set_enable_mach_exceptions (const char *args, int fro= m_tty, } } =20 -char * +const char * darwin_nat_target::pid_to_exec_file (int pid) { static char path[PATH_MAX]; diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h index 733ac7cc058..e3dcd963706 100644 --- a/gdb/darwin-nat.h +++ b/gdb/darwin-nat.h @@ -100,7 +100,7 @@ class darwin_nat_target : public inf_child_target =20 std::string pid_to_str (ptid_t) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 enum target_xfer_status xfer_partial (enum target_object object, const char *annex, diff --git a/gdb/exec.c b/gdb/exec.c index 38540c0840b..40c89d53ba9 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -314,7 +314,7 @@ validate_exec_file (int from_tty) void exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty) { - char *exec_file_target; + const char *exec_file_target; symfile_add_flags add_flags =3D 0; =20 /* Do nothing if we already have an executable filename. */ diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index a501d9212c0..281b034b115 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -57,7 +57,7 @@ /* Return the name of a file that can be opened to get the symbols for the child process identified by PID. */ =20 -char * +const char * fbsd_nat_target::pid_to_exec_file (int pid) { static char buf[PATH_MAX]; diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index ba359c62314..3a13bc8711f 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -44,7 +44,7 @@ class fbsd_nat_target : public inf_ptrace_target { public: - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 int find_memory_regions (find_memory_region_ftype func, void *data) over= ride; =20 diff --git a/gdb/inf-child.c b/gdb/inf-child.c index cc00867787a..56ebd2a5549 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -220,7 +220,7 @@ inf_child_target::can_attach () return true; } =20 -char * +const char * inf_child_target::pid_to_exec_file (int pid) { /* This target doesn't support translation of a process ID to the diff --git a/gdb/inf-child.h b/gdb/inf-child.h index a017032a32f..ae5ace46f30 100644 --- a/gdb/inf-child.h +++ b/gdb/inf-child.h @@ -71,7 +71,7 @@ public: =20 void post_attach (int) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 int fileio_open (struct inferior *inf, const char *filename, int flags, int mode, int warn_if_slow, diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 740cc0ddfc0..3b5400896bc 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -3764,7 +3764,7 @@ linux_nat_target::thread_name (struct thread_info *th= r) /* Accepts an integer PID; Returns a string representing a file that can be opened to get the symbols for the child process. */ =20 -char * +const char * linux_nat_target::pid_to_exec_file (int pid) { return linux_proc_pid_to_exec_file (pid); diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 12a90eccb28..11043c4b9f6 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -123,7 +123,7 @@ public: int set_syscall_catchpoint (int pid, bool needed, int any_count, gdb::array_view syscall_counts) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 void post_attach (int) override; =20 diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c index 2618c99d9f4..99e645786c2 100644 --- a/gdb/nat/linux-procfs.c +++ b/gdb/nat/linux-procfs.c @@ -341,7 +341,7 @@ linux_proc_task_list_dir_exists (pid_t pid) =20 /* See linux-procfs.h. */ =20 -char * +const char * linux_proc_pid_to_exec_file (int pid) { static char buf[PATH_MAX]; diff --git a/gdb/nat/linux-procfs.h b/gdb/nat/linux-procfs.h index fa1280a8967..fcc8280adf1 100644 --- a/gdb/nat/linux-procfs.h +++ b/gdb/nat/linux-procfs.h @@ -78,7 +78,7 @@ extern int linux_proc_task_list_dir_exists (pid_t pid); to create the process PID. The returned value persists until this function is next called. */ =20 -extern char *linux_proc_pid_to_exec_file (int pid); +extern const char *linux_proc_pid_to_exec_file (int pid); =20 /* Display possible problems on this system. Display them only once per GDB execution. */ diff --git a/gdb/netbsd-nat.c b/gdb/netbsd-nat.c index f2eeb3ff61e..2ccd0e014c2 100644 --- a/gdb/netbsd-nat.c +++ b/gdb/netbsd-nat.c @@ -34,10 +34,10 @@ /* Return the name of a file that can be opened to get the symbols for the child process identified by PID. */ =20 -char * +const char * nbsd_nat_target::pid_to_exec_file (int pid) { - return const_cast (netbsd_nat::pid_to_exec_file (pid)); + return netbsd_nat::pid_to_exec_file (pid); } =20 /* Return the current directory for the process identified by PID. */ diff --git a/gdb/netbsd-nat.h b/gdb/netbsd-nat.h index ef190c4e471..ff468452b2c 100644 --- a/gdb/netbsd-nat.h +++ b/gdb/netbsd-nat.h @@ -28,7 +28,7 @@ struct thread_info; =20 struct nbsd_nat_target : public inf_ptrace_target { - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 bool thread_alive (ptid_t ptid) override; const char *thread_name (struct thread_info *thr) override; diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 61374c9fad4..ef9e0f05261 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -121,7 +121,7 @@ struct nto_procfs_target : public inf_child_target =20 const char *extra_thread_info (struct thread_info *) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; }; =20 /* For "target native". */ @@ -664,7 +664,7 @@ nto_procfs_target::files_info () =20 /* Target to_pid_to_exec_file implementation. */ =20 -char * +const char * nto_procfs_target::pid_to_exec_file (const int pid) { int proc_fd; diff --git a/gdb/procfs.c b/gdb/procfs.c index f6ca1345a21..d290505d8c3 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -127,7 +127,7 @@ public: =20 std::string pid_to_str (ptid_t) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 thread_control_capabilities get_thread_control_capabilities () override { return tc_schedlock; } @@ -2927,7 +2927,7 @@ procfs_target::pid_to_str (ptid_t ptid) /* Accepts an integer PID; Returns a string representing a file that can be opened to get the symbols for the child process. */ =20 -char * +const char * procfs_target::pid_to_exec_file (int pid) { static char buf[PATH_MAX]; diff --git a/gdb/remote.c b/gdb/remote.c index b8df3326849..f41e6ce82c2 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -508,7 +508,7 @@ public: =20 void rcmd (const char *command, struct ui_file *output) override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 void log_command (const char *cmd) override { @@ -14353,7 +14353,7 @@ remote_target::load (const char *name, int from_tty) can be opened on the remote side to get the symbols for the child process. Returns NULL if the operation is not supported. */ =20 -char * +const char * remote_target::pid_to_exec_file (int pid) { static gdb::optional filename; diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 4e653e8f429..8a9986454dd 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -94,7 +94,7 @@ struct dummy_target : public target_ops void interrupt () override; void pass_ctrlc () override; void rcmd (const char *arg0, struct ui_file *arg1) override; - char *pid_to_exec_file (int arg0) override; + const char *pid_to_exec_file (int arg0) override; void log_command (const char *arg0) override; const target_section_table *get_section_table () override; thread_control_capabilities get_thread_control_capabilities () override; @@ -268,7 +268,7 @@ struct debug_target : public target_ops void interrupt () override; void pass_ctrlc () override; void rcmd (const char *arg0, struct ui_file *arg1) override; - char *pid_to_exec_file (int arg0) override; + const char *pid_to_exec_file (int arg0) override; void log_command (const char *arg0) override; const target_section_table *get_section_table () override; thread_control_capabilities get_thread_control_capabilities () override; @@ -1983,28 +1983,28 @@ debug_target::rcmd (const char *arg0, struct ui_fil= e *arg1) gdb_puts (")\n", gdb_stdlog); } =20 -char * +const char * target_ops::pid_to_exec_file (int arg0) { return this->beneath ()->pid_to_exec_file (arg0); } =20 -char * +const char * dummy_target::pid_to_exec_file (int arg0) { return NULL; } =20 -char * +const char * debug_target::pid_to_exec_file (int arg0) { - char * result; + const char * result; gdb_printf (gdb_stdlog, "-> %s->pid_to_exec_file (...)\n", this->beneath= ()->shortname ()); result =3D this->beneath ()->pid_to_exec_file (arg0); gdb_printf (gdb_stdlog, "<- %s->pid_to_exec_file (", this->beneath ()->s= hortname ()); target_debug_print_int (arg0); gdb_puts (") =3D ", gdb_stdlog); - target_debug_print_char_p (result); + target_debug_print_const_char_p (result); gdb_puts ("\n", gdb_stdlog); return result; } diff --git a/gdb/target.c b/gdb/target.c index 1063f8086bc..18e53aa5d27 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -423,7 +423,7 @@ target_extra_thread_info (thread_info *tp) =20 /* See target.h. */ =20 -char * +const char * target_pid_to_exec_file (int pid) { return current_inferior ()->top_target ()->pid_to_exec_file (pid); diff --git a/gdb/target.h b/gdb/target.h index f77dbf05113..18559feef89 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -688,7 +688,7 @@ struct target_ops TARGET_DEFAULT_FUNC (default_target_pass_ctrlc); virtual void rcmd (const char *command, struct ui_file *output) TARGET_DEFAULT_FUNC (default_rcmd); - virtual char *pid_to_exec_file (int pid) + virtual const char *pid_to_exec_file (int pid) TARGET_DEFAULT_RETURN (NULL); virtual void log_command (const char *) TARGET_DEFAULT_IGNORE (); @@ -1951,7 +1951,7 @@ extern gdb::byte_vector target_thread_info_to_thread_= handle the client if the string will not be immediately used, or if it must persist. */ =20 -extern char *target_pid_to_exec_file (int pid); +extern const char *target_pid_to_exec_file (int pid); =20 /* See the to_thread_architecture description in struct target_ops. */ =20 diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 1068558cd21..cd43409a02f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -276,7 +276,7 @@ struct windows_nat_target final : public x86_nat_target= =20 void interrupt () override; =20 - char *pid_to_exec_file (int pid) override; + const char *pid_to_exec_file (int pid) override; =20 ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override; =20 @@ -2005,7 +2005,7 @@ windows_get_exec_module_filename (char *exe_name_ret,= size_t exe_name_max_len) =20 /* The pid_to_exec_file target_ops method for this platform. */ =20 -char * +const char * windows_nat_target::pid_to_exec_file (int pid) { static char path[__PMAX];