aboutsummaryrefslogtreecommitdiff
path: root/gdb/remote.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2019-02-28 09:09:55 -0700
committerTom Tromey <tromey@adacore.com>2019-03-13 13:50:13 -0600
commita068643d69ce0f25d5f7cbdaa1d0a3211d72c081 (patch)
tree4b0da08750a1d8fb4db7889fd2f42ea49580cbae /gdb/remote.c
parentb4be1b0648608a2578bbed39841c8ee411773edd (diff)
downloadgdb-a068643d69ce0f25d5f7cbdaa1d0a3211d72c081.zip
gdb-a068643d69ce0f25d5f7cbdaa1d0a3211d72c081.tar.gz
gdb-a068643d69ce0f25d5f7cbdaa1d0a3211d72c081.tar.bz2
Change pid_to_str to return std::string
Currently the target pid_to_str method returns a const char *, so many implementations have a static buffer that they update. This patch changes these methods to return a std::string instead. I think this is cleaner and avoids possible gotchas when calling pid_to_str on different ptids in a single statement. (Though no such calls exist currently.) This also updates various helper functions, and the gdbarch pid_to_str methods. I also made a best effort to fix all the callers, but I can't build some of the *-nat.c files. Tested by the buildbot. gdb/ChangeLog 2019-03-13 Tom Tromey <tromey@adacore.com> * i386-gnu-nat.c (i386_gnu_nat_target::fetch_registers) (i386_gnu_nat_target::store_registers): Update. * target-debug.h (target_debug_print_std_string): New macro. * x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update. * windows-tdep.c (display_one_tib): Update. * tui/tui-stack.c (tui_make_status_line): Update. * top.c (print_inferior_quit_action): Update. * thread.c (thr_try_catch_cmd): Update. (add_thread_with_info): Update. (thread_target_id_str): Update. (thr_try_catch_cmd): Update. (thread_command): Update. (thread_find_command): Update. * record-btrace.c (record_btrace_target::info_record) (record_btrace_resume_thread, record_btrace_target::resume) (record_btrace_cancel_resume, record_btrace_step_thread) (record_btrace_target::wait, record_btrace_target::wait) (record_btrace_target::wait, record_btrace_target::stop): Update. * progspace.c (print_program_space): Update. * process-stratum-target.c (process_stratum_target::thread_address_space): Update. * linux-fork.c (linux_fork_mourn_inferior) (detach_checkpoint_command, info_checkpoints_command) (linux_fork_context): Update. (linux_fork_detach): Update. (class scoped_switch_fork_info): Update. (delete_checkpoint_command): Update. * infrun.c (follow_fork_inferior): Update. (follow_fork_inferior): Update. (proceed_after_vfork_done): Update. (handle_vfork_child_exec_or_exit): Update. (follow_exec): Update. (displaced_step_prepare_throw): Update. (displaced_step_restore): Update. (start_step_over): Update. (resume_1): Update. (clear_proceed_status_thread): Update. (proceed): Update. (print_target_wait_results): Update. (do_target_wait): Update. (context_switch): Update. (stop_all_threads): Update. (restart_threads): Update. (finish_step_over): Update. (handle_signal_stop): Update. (switch_back_to_stepped_thread): Update. (keep_going_pass_signal): Update. (print_exited_reason): Update. (normal_stop): Update. * inferior.c (inferior_pid_to_str): Change return type. (print_selected_inferior): Update. (add_inferior): Update. (detach_inferior): Update. * dummy-frame.c (fprint_dummy_frames): Update. * dcache.c (dcache_info_1): Update. * btrace.c (btrace_enable, btrace_disable, btrace_teardown) (btrace_fetch, btrace_clear): Update. * linux-tdep.c (linux_core_pid_to_str): Change return type. * i386-cygwin-tdep.c (i386_windows_core_pid_to_str): Change return type. * fbsd-tdep.c (fbsd_core_pid_to_str): Change return type. * sol2-tdep.h (sol2_core_pid_to_str): Change return type. * sol2-tdep.c (sol2_core_pid_to_str): Change return type. * gdbarch.c, gdbarch.h: Rebuild. * gdbarch.sh (core_pid_to_str): Change return type. * windows-nat.c (struct windows_nat_target) <pid_to_str>: Change return type. (windows_nat_target::pid_to_str): Change return type. (windows_delete_thread): Update. (windows_nat_target::attach): Update. (windows_nat_target::files_info): Update. * target-delegates.c: Rebuild. * sol-thread.c (class sol_thread_target) <pid_to_str>: Change return type. (sol_thread_target::pid_to_str): Change return type. * remote.c (class remote_target) <pid_to_str>: Change return type. (remote_target::pid_to_str): Change return type. (extended_remote_target::attach, remote_target::remote_stop_ns) (remote_target::remote_notif_remove_queued_reply) (remote_target::push_stop_reply, remote_target::disable_btrace): Update. (extended_remote_target::attach): Update. * remote-sim.c (struct gdbsim_target) <pid_to_str>: Change return type. (gdbsim_target::pid_to_str): Change return type. * ravenscar-thread.c (struct ravenscar_thread_target) <pid_to_str>: Change return type. (ravenscar_thread_target::pid_to_str): Change return type. * procfs.c (class procfs_target) <pid_to_str>: Change return type. (procfs_target::pid_to_str): Change return type. (procfs_target::attach): Update. (procfs_target::detach): Update. (procfs_target::fetch_registers): Update. (procfs_target::store_registers): Update. (procfs_target::wait): Update. (procfs_target::files_info): Update. * obsd-nat.c (obsd_nat_target::pid_to_str): Change return type. * nto-procfs.c (struct nto_procfs_target) <pid_to_str>: Change return type. (nto_procfs_target::pid_to_str): Change return type. (nto_procfs_target::files_info, nto_procfs_target::attach): Update. * linux-thread-db.c (class thread_db_target) <pid_to_str>: Change return type. * linux-nat.c (linux_nat_target::pid_to_str): Change return type. (exit_lwp): Update. (attach_proc_task_lwp_callback, get_detach_signal) (detach_one_lwp, resume_lwp, linux_nat_target::resume) (linux_nat_target::resume, wait_lwp, stop_callback) (maybe_clear_ignore_sigint, stop_wait_callback, status_callback) (save_stop_reason, select_event_lwp, linux_nat_filter_event) (linux_nat_wait_1, resume_stopped_resumed_lwps) (linux_nat_target::wait, linux_nat_stop_lwp): Update. * inf-ptrace.c (inf_ptrace_target::pid_to_str): Change return type. (inf_ptrace_target::attach): Update. (inf_ptrace_target::files_info): Update. * go32-nat.c (struct go32_nat_target) <pid_to_str>: Change return type. (go32_nat_target::pid_to_str): Change return type. * gnu-nat.c (gnu_nat_target::pid_to_str): Change return type. (gnu_nat_target::wait): Update. (gnu_nat_target::wait): Update. (gnu_nat_target::resume): Update. * fbsd-nat.c (fbsd_nat_target::pid_to_str): Change return type. (fbsd_nat_target::wait): Update. * darwin-nat.c (darwin_nat_target::pid_to_str): Change return type. (darwin_nat_target::attach): Update. * corelow.c (class core_target) <pid_to_str>: Change return type. (core_target::pid_to_str): Change return type. * target.c (normal_pid_to_str): Change return type. (default_pid_to_str): Likewise. (target_pid_to_str): Change return type. (target_translate_tls_address): Update. (target_announce_detach): Update. * bsd-uthread.c (struct bsd_uthread_target) <pid_to_str>: Change return type. (bsd_uthread_target::pid_to_str): Change return type. * bsd-kvm.c (class bsd_kvm_target) <pid_to_str>: Change return type. (bsd_kvm_target::pid_to_str): Change return type. * aix-thread.c (class aix_thread_target) <pid_to_str>: Change return type. (aix_thread_target::pid_to_str): Change return type. * target.h (struct target_ops) <pid_to_str>: Change return type. (target_pid_to_str, normal_pid_to_str): Likewise. * obsd-nat.h (class obsd_nat_target) <pid_to_str>: Change return type. * linux-nat.h (class linux_nat_target) <pid_to_str>: Change return type. * inf-ptrace.h (struct inf_ptrace_target) <pid_to_str>: Change return type. * gnu-nat.h (struct gnu_nat_target) <pid_to_str>: Change return type. * fbsd-nat.h (class fbsd_nat_target) <pid_to_str>: Change return type. * darwin-nat.h (class darwin_nat_target) <pid_to_str>: Change return type.
Diffstat (limited to 'gdb/remote.c')
-rw-r--r--gdb/remote.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/gdb/remote.c b/gdb/remote.c
index d113f99..657a4a2 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -475,7 +475,7 @@ public:
void update_thread_list () override;
- const char *pid_to_str (ptid_t) override;
+ std::string pid_to_str (ptid_t) override;
const char *extra_thread_info (struct thread_info *) override;
@@ -5814,10 +5814,10 @@ extended_remote_target::attach (const char *args, int from_tty)
if (exec_file)
printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
- target_pid_to_str (ptid_t (pid)));
+ target_pid_to_str (ptid_t (pid)).c_str ());
else
printf_unfiltered (_("Attaching to %s\n"),
- target_pid_to_str (ptid_t (pid)));
+ target_pid_to_str (ptid_t (pid)).c_str ());
}
xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid);
@@ -5836,14 +5836,14 @@ extended_remote_target::attach (const char *args, int from_tty)
}
else if (strcmp (rs->buf.data (), "OK") != 0)
error (_("Attaching to %s failed with: %s"),
- target_pid_to_str (ptid_t (pid)),
+ target_pid_to_str (ptid_t (pid)).c_str (),
rs->buf.data ());
break;
case PACKET_UNKNOWN:
error (_("This target does not support attaching to a process"));
default:
error (_("Attaching to %s failed"),
- target_pid_to_str (ptid_t (pid)));
+ target_pid_to_str (ptid_t (pid)).c_str ());
}
set_current_inferior (remote_add_inferior (0, pid, 1, 0));
@@ -6638,7 +6638,7 @@ remote_target::remote_stop_ns (ptid_t ptid)
putpkt (rs->buf);
getpkt (&rs->buf, 0);
if (strcmp (rs->buf.data (), "OK") != 0)
- error (_("Stopping %s failed: %s"), target_pid_to_str (ptid),
+ error (_("Stopping %s failed: %s"), target_pid_to_str (ptid).c_str (),
rs->buf.data ());
}
@@ -7096,7 +7096,7 @@ remote_target::remote_notif_remove_queued_reply (ptid_t ptid)
if (notif_debug)
fprintf_unfiltered (gdb_stdlog,
"notif: discard queued event: 'Stop' in %s\n",
- target_pid_to_str (ptid));
+ target_pid_to_str (ptid).c_str ());
return result;
}
@@ -7134,7 +7134,7 @@ remote_target::push_stop_reply (struct stop_reply *new_event)
if (notif_debug)
fprintf_unfiltered (gdb_stdlog,
"notif: push 'Stop' %s to queue %d\n",
- target_pid_to_str (new_event->ptid),
+ target_pid_to_str (new_event->ptid).c_str (),
int (rs->stop_reply_queue.size ()));
mark_async_event_handler (rs->remote_async_inferior_event_token);
@@ -11397,13 +11397,11 @@ init_remote_threadtests (void)
#endif /* 0 */
-/* Convert a thread ID to a string. Returns the string in a static
- buffer. */
+/* Convert a thread ID to a string. */
-const char *
+std::string
remote_target::pid_to_str (ptid_t ptid)
{
- static char buf[64];
struct remote_state *rs = get_remote_state ();
if (ptid == null_ptid)
@@ -11422,27 +11420,22 @@ remote_target::pid_to_str (ptid_t ptid)
attached to a process, and reporting yes to qAttached, hence
no smart special casing here. */
if (!remote_multi_process_p (rs))
- {
- xsnprintf (buf, sizeof buf, "Remote target");
- return buf;
- }
+ return "Remote target";
return normal_pid_to_str (ptid);
}
else
{
if (magic_null_ptid == ptid)
- xsnprintf (buf, sizeof buf, "Thread <main>");
+ return "Thread <main>";
else if (remote_multi_process_p (rs))
if (ptid.lwp () == 0)
return normal_pid_to_str (ptid);
else
- xsnprintf (buf, sizeof buf, "Thread %d.%ld",
- ptid.pid (), ptid.lwp ());
+ return string_printf ("Thread %d.%ld",
+ ptid.pid (), ptid.lwp ());
else
- xsnprintf (buf, sizeof buf, "Thread %ld",
- ptid.lwp ());
- return buf;
+ return string_printf ("Thread %ld", ptid.lwp ());
}
}
@@ -13786,10 +13779,10 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf)
{
if (rs->buf[0] == 'E' && rs->buf[1] == '.')
error (_("Could not enable branch tracing for %s: %s"),
- target_pid_to_str (ptid), &rs->buf[2]);
+ target_pid_to_str (ptid).c_str (), &rs->buf[2]);
else
error (_("Could not enable branch tracing for %s."),
- target_pid_to_str (ptid));
+ target_pid_to_str (ptid).c_str ());
}
tinfo = XCNEW (struct btrace_target_info);
@@ -13834,10 +13827,10 @@ remote_target::disable_btrace (struct btrace_target_info *tinfo)
{
if (rs->buf[0] == 'E' && rs->buf[1] == '.')
error (_("Could not disable branch tracing for %s: %s"),
- target_pid_to_str (tinfo->ptid), &rs->buf[2]);
+ target_pid_to_str (tinfo->ptid).c_str (), &rs->buf[2]);
else
error (_("Could not disable branch tracing for %s."),
- target_pid_to_str (tinfo->ptid));
+ target_pid_to_str (tinfo->ptid).c_str ());
}
xfree (tinfo);