From patchwork Thu Feb 28 17:36:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31688 Received: (qmail 8917 invoked by alias); 28 Feb 2019 17:36:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8887 invoked by uid 89); 28 Feb 2019 17:36:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, TIME_LIMIT_EXCEEDED autolearn=unavailable version=3.3.2 spammy=UD:aix-thread.c, aix-thread.c, aixthreadc, tp X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 28 Feb 2019 17:36:15 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 50FF1560EE; Thu, 28 Feb 2019 12:36:13 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id jxKXZOsAMSwx; Thu, 28 Feb 2019 12:36:13 -0500 (EST) Received: from murgatroyd.Home (75-166-85-218.hlrn.qwest.net [75.166.85.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 955BE560ED; Thu, 28 Feb 2019 12:36:12 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Change pid_to_str to return std::string Date: Thu, 28 Feb 2019 10:36:10 -0700 Message-Id: <20190228173610.3777-1-tromey@adacore.com> MIME-Version: 1.0 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-02-28 Tom Tromey * 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) : 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) : Change return type. (sol_thread_target::pid_to_str): Change return type. * remote.c (class remote_target) : 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) : Change return type. (gdbsim_target::pid_to_str): Change return type. * ravenscar-thread.c (struct ravenscar_thread_target) : Change return type. (ravenscar_thread_target::pid_to_str): Change return type. * procfs.c (class procfs_target) : 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) : 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) : 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) : 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) : 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) : Change return type. (bsd_uthread_target::pid_to_str): Change return type. * bsd-kvm.c (class bsd_kvm_target) : Change return type. (bsd_kvm_target::pid_to_str): Change return type. * aix-thread.c (class aix_thread_target) : Change return type. (aix_thread_target::pid_to_str): Change return type. * target.h (struct target_ops) : Change return type. (target_pid_to_str, normal_pid_to_str): Likewise. * obsd-nat.h (class obsd_nat_target) : Change return type. * linux-nat.h (class linux_nat_target) : Change return type. * inf-ptrace.h (struct inf_ptrace_target) : Change return type. * gnu-nat.h (struct gnu_nat_target) : Change return type. * fbsd-nat.h (class fbsd_nat_target) : Change return type. * darwin-nat.h (class darwin_nat_target) : Change return type. --- gdb/ChangeLog | 163 +++++++++++++++++++++++++++++++++++ gdb/aix-thread.c | 13 +-- gdb/bsd-kvm.c | 8 +- gdb/bsd-uthread.c | 13 +-- gdb/btrace.c | 10 +-- gdb/corelow.c | 8 +- gdb/darwin-nat.c | 14 ++- gdb/darwin-nat.h | 2 +- gdb/dcache.c | 2 +- gdb/dummy-frame.c | 2 +- gdb/fbsd-nat.c | 13 ++- gdb/fbsd-nat.h | 2 +- gdb/fbsd-tdep.c | 9 +- gdb/gdbarch.c | 2 +- gdb/gdbarch.h | 4 +- gdb/gdbarch.sh | 2 +- gdb/gnu-nat.c | 25 +++--- gdb/gnu-nat.h | 2 +- gdb/go32-nat.c | 4 +- gdb/i386-cygwin-tdep.c | 9 +- gdb/i386-gnu-nat.c | 4 +- gdb/inf-ptrace.c | 8 +- gdb/inf-ptrace.h | 2 +- gdb/inferior.c | 8 +- gdb/infrun.c | 123 +++++++++++++------------- gdb/linux-fork.c | 25 +++--- gdb/linux-nat.c | 109 ++++++++++++----------- gdb/linux-nat.h | 2 +- gdb/linux-tdep.c | 9 +- gdb/linux-thread-db.c | 11 +-- gdb/nto-procfs.c | 17 ++-- gdb/obsd-nat.c | 9 +- gdb/obsd-nat.h | 2 +- gdb/process-stratum-target.c | 2 +- gdb/procfs.c | 31 +++---- gdb/progspace.c | 4 +- gdb/ravenscar-thread.c | 9 +- gdb/record-btrace.c | 20 +++-- gdb/remote-sim.c | 7 +- gdb/remote.c | 45 ++++------ gdb/sol-thread.c | 24 +++--- gdb/sol2-tdep.c | 11 +-- gdb/sol2-tdep.h | 2 +- gdb/target-debug.h | 2 + gdb/target-delegates.c | 14 +-- gdb/target.c | 25 +++--- gdb/target.h | 6 +- gdb/thread.c | 27 +++--- gdb/top.c | 4 +- gdb/tui/tui-stack.c | 6 +- gdb/windows-nat.c | 23 ++--- gdb/windows-tdep.c | 8 +- gdb/x86-linux-nat.c | 2 +- 53 files changed, 500 insertions(+), 408 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 655c085734c..ffa3352d039 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -140,7 +140,7 @@ public: bool thread_alive (ptid_t ptid) 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; @@ -1746,20 +1746,13 @@ aix_thread_target::thread_alive (ptid_t ptid) /* Return a printable representation of composite PID for use in "info threads" output. */ -const char * +std::string aix_thread_target::pid_to_str (ptid_t ptid) { - static char *ret = NULL; - if (!PD_TID (ptid)) return beneath ()->pid_to_str (ptid); - /* Free previous return value; a new one will be allocated by - xstrprintf(). */ - xfree (ret); - - ret = xstrprintf (_("Thread %ld"), ptid.tid ()); - return ret; + return string_printf (_("Thread %ld"), ptid.tid ()); } /* Return a printable representation of extra information about diff --git a/gdb/bsd-kvm.c b/gdb/bsd-kvm.c index 46f222558f3..21f978728da 100644 --- a/gdb/bsd-kvm.c +++ b/gdb/bsd-kvm.c @@ -92,7 +92,7 @@ public: void files_info () override; bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; bool has_memory () override { return true; } bool has_stack () override { return true; } @@ -368,12 +368,10 @@ bsd_kvm_target::thread_alive (ptid_t ptid) return true; } -const char * +std::string bsd_kvm_target::pid_to_str (ptid_t ptid) { - static char buf[64]; - xsnprintf (buf, sizeof buf, ""); - return buf; + return ""; } /* Add the libkvm interface to the list of all possible targets and diff --git a/gdb/bsd-uthread.c b/gdb/bsd-uthread.c index 3b3a420f2a4..af048f7a18f 100644 --- a/gdb/bsd-uthread.c +++ b/gdb/bsd-uthread.c @@ -62,7 +62,7 @@ struct bsd_uthread_target final : public target_ops const char *extra_thread_info (struct thread_info *) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; }; static bsd_uthread_target bsd_uthread_ops; @@ -530,17 +530,12 @@ bsd_uthread_target::extra_thread_info (thread_info *info) return NULL; } -const char * +std::string bsd_uthread_target::pid_to_str (ptid_t ptid) { if (ptid.tid () != 0) - { - static char buf[64]; - - xsnprintf (buf, sizeof buf, "process %d, thread 0x%lx", - ptid.pid (), ptid.tid ()); - return buf; - } + return string_printf ("process %d, thread 0x%lx", + ptid.pid (), ptid.tid ()); return normal_pid_to_str (ptid); } diff --git a/gdb/btrace.c b/gdb/btrace.c index 000db4260e2..12af46814a9 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1608,7 +1608,7 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf) #endif /* !defined (HAVE_LIBIPT) */ DEBUG ("enable thread %s (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); tp->btrace.target = target_enable_btrace (tp->ptid, conf); @@ -1663,7 +1663,7 @@ btrace_disable (struct thread_info *tp) return; DEBUG ("disable thread %s (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); target_disable_btrace (btp->target); btp->target = NULL; @@ -1682,7 +1682,7 @@ btrace_teardown (struct thread_info *tp) return; DEBUG ("teardown thread %s (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); target_teardown_btrace (btp->target); btp->target = NULL; @@ -1905,7 +1905,7 @@ btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu) int errcode; DEBUG ("fetch thread %s (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); btinfo = &tp->btrace; tinfo = btinfo->target; @@ -1981,7 +1981,7 @@ btrace_clear (struct thread_info *tp) struct btrace_thread_info *btinfo; DEBUG ("clear thread %s (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); /* Make sure btrace frames that may hold a pointer into the branch trace data are destroyed. */ diff --git a/gdb/corelow.c b/gdb/corelow.c index 6a29d6a2328..7fb42970de4 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -83,7 +83,7 @@ public: bool thread_alive (ptid_t ptid) override; const struct target_desc *read_description () override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; const char *thread_name (struct thread_info *) override; @@ -985,10 +985,9 @@ core_target::read_description () return this->beneath ()->read_description (); } -const char * +std::string core_target::pid_to_str (ptid_t ptid) { - static char buf[64]; struct inferior *inf; int pid; @@ -1013,8 +1012,7 @@ core_target::pid_to_str (ptid_t ptid) return normal_pid_to_str (ptid); /* No luck. We simply don't have a valid PID to print. */ - xsnprintf (buf, sizeof buf, "
"); - return buf; + return "
"; } const char * diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 8c34aa8a3f2..97bbbe9298f 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -2052,10 +2052,10 @@ darwin_nat_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 ()); gdb_flush (gdb_stdout); } @@ -2128,18 +2128,14 @@ darwin_nat_target::detach (inferior *inf, int from_tty) mourn_inferior (); } -const char * +std::string darwin_nat_target::pid_to_str (ptid_t ptid) { - static char buf[80]; long tid = ptid.tid (); if (tid != 0) - { - snprintf (buf, sizeof (buf), _("Thread 0x%lx of process %u"), - tid, ptid.pid ()); - return buf; - } + return string_printf (_("Thread 0x%lx of process %u"), + tid, ptid.pid ()); return normal_pid_to_str (ptid); } diff --git a/gdb/darwin-nat.h b/gdb/darwin-nat.h index f33e25316f5..9091efd88f1 100644 --- a/gdb/darwin-nat.h +++ b/gdb/darwin-nat.h @@ -45,7 +45,7 @@ class darwin_nat_target : public inf_child_target bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; char *pid_to_exec_file (int pid) override; diff --git a/gdb/dcache.c b/gdb/dcache.c index 82cb34b08ad..5a2e8f8000b 100644 --- a/gdb/dcache.c +++ b/gdb/dcache.c @@ -615,7 +615,7 @@ dcache_info_1 (DCACHE *dcache, const char *exp) } printf_filtered (_("Contains data for %s\n"), - target_pid_to_str (dcache->ptid)); + target_pid_to_str (dcache->ptid).c_str ()); refcount = 0; diff --git a/gdb/dummy-frame.c b/gdb/dummy-frame.c index a36cdff459e..aebdd233d74 100644 --- a/gdb/dummy-frame.c +++ b/gdb/dummy-frame.c @@ -409,7 +409,7 @@ fprint_dummy_frames (struct ui_file *file) fprintf_unfiltered (file, " id="); fprint_frame_id (file, s->id.id); fprintf_unfiltered (file, ", ptid=%s", - target_pid_to_str (s->id.thread->ptid)); + target_pid_to_str (s->id.thread->ptid).c_str ()); fprintf_unfiltered (file, "\n"); } } diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c index 184d63939f4..d4f4c8cf359 100644 --- a/gdb/fbsd-nat.c +++ b/gdb/fbsd-nat.c @@ -897,10 +897,9 @@ fbsd_nat_target::thread_alive (ptid_t ptid) return true; } -/* Convert PTID to a string. Returns the string in a static - buffer. */ +/* Convert PTID to a string. */ -const char * +std::string fbsd_nat_target::pid_to_str (ptid_t ptid) { lwpid_t lwp; @@ -908,11 +907,9 @@ fbsd_nat_target::pid_to_str (ptid_t ptid) lwp = ptid.lwp (); if (lwp != 0) { - static char buf[64]; int pid = ptid.pid (); - xsnprintf (buf, sizeof buf, "LWP %d of process %d", lwp, pid); - return buf; + return string_printf ("LWP %d of process %d", lwp, pid); } return normal_pid_to_str (ptid); @@ -1350,8 +1347,8 @@ fbsd_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, "FLWP: deleting thread for LWP %u\n", pl.pl_lwpid); if (print_thread_events) - printf_unfiltered (_("[%s exited]\n"), target_pid_to_str - (wptid)); + printf_unfiltered (_("[%s exited]\n"), + target_pid_to_str (wptid).c_str ()); delete_thread (thr); } if (ptrace (PT_CONTINUE, pid, (caddr_t) 1, 0) == -1) diff --git a/gdb/fbsd-nat.h b/gdb/fbsd-nat.h index 45861d0257a..b0c9eb16c77 100644 --- a/gdb/fbsd-nat.h +++ b/gdb/fbsd-nat.h @@ -51,7 +51,7 @@ public: #ifdef PT_LWPINFO bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_TDNAME const char *thread_name (struct thread_info *) override; diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index d971d3a6533..9279189ae2c 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -446,16 +446,11 @@ get_fbsd_gdbarch_data (struct gdbarch *gdbarch) /* This is how we want PTIDs from core files to be printed. */ -static const char * +static std::string fbsd_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { - static char buf[80]; - if (ptid.lwp () != 0) - { - xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ()); - return buf; - } + return string_printf ("LWP %ld", ptid.lwp ()); return normal_pid_to_str (ptid); } diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 434ee3bfcf0..fd00efdb84c 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -3734,7 +3734,7 @@ gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch) return gdbarch->core_pid_to_str != NULL; } -const char * +std::string gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { gdb_assert (gdbarch != NULL); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 75618376abb..b56832cb01e 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -947,8 +947,8 @@ extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, extern int gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch); -typedef const char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid); -extern const char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); +typedef std::string (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid); +extern std::string gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_pid_to_str_ftype *core_pid_to_str); /* How the core target extracts the name of a thread from a core file. */ diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index 48fcebd19a0..fb9d0215d84 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -759,7 +759,7 @@ M;ULONGEST;core_xfer_shared_libraries;gdb_byte *readbuf, ULONGEST offset, ULONGE M;ULONGEST;core_xfer_shared_libraries_aix;gdb_byte *readbuf, ULONGEST offset, ULONGEST len;readbuf, offset, len # How the core target converts a PTID from a core file to a string. -M;const char *;core_pid_to_str;ptid_t ptid;ptid +M;std::string;core_pid_to_str;ptid_t ptid;ptid # How the core target extracts the name of a thread from a core file. M;const char *;core_thread_name;struct thread_info *thr;thr diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 53f23068a40..11beb5f16a5 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -1493,7 +1493,7 @@ gnu_nat_target::wait (ptid_t ptid, struct target_waitstatus *status, waiting_inf = inf; - inf_debug (inf, "waiting for: %s", target_pid_to_str (ptid)); + inf_debug (inf, "waiting for: %s", target_pid_to_str (ptid).c_str ()); rewait: if (proc_wait_pid != inf->pid && !inf->no_wait) @@ -1648,7 +1648,7 @@ rewait: } inf_debug (inf, "returning ptid = %s, status = %s (%d)", - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), status->kind == TARGET_WAITKIND_EXITED ? "EXITED" : status->kind == TARGET_WAITKIND_STOPPED ? "STOPPED" : status->kind == TARGET_WAITKIND_SIGNALLED ? "SIGNALLED" @@ -2012,7 +2012,7 @@ gnu_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) struct inf *inf = gnu_current_inf; inf_debug (inf, "ptid = %s, step = %d, sig = %d", - target_pid_to_str (ptid), step, sig); + target_pid_to_str (ptid).c_str (), step, sig); inf_validate_procinfo (inf); @@ -2058,8 +2058,9 @@ gnu_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) if (!thread) error (_("Can't run single thread id %s: no such thread!"), - target_pid_to_str (ptid)); - inf_debug (inf, "running one thread: %s", target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); + inf_debug (inf, "running one thread: %s", + target_pid_to_str (ptid).c_str ()); inf_set_threads_resume_sc (inf, thread, 0); } @@ -2068,9 +2069,10 @@ gnu_nat_target::resume (ptid_t ptid, int step, enum gdb_signal sig) step_thread = inf_tid_to_thread (inf, ptid.lwp ()); if (!step_thread) warning (_("Can't step thread id %s: no such thread."), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); else - inf_debug (inf, "stepping thread: %s", target_pid_to_str (ptid)); + inf_debug (inf, "stepping thread: %s", + target_pid_to_str (ptid).c_str ()); } if (step_thread != inf->step_thread) inf_set_step_thread (inf, step_thread); @@ -2717,7 +2719,7 @@ proc_string (struct proc *proc) return tid_str; } -const char * +std::string gnu_nat_target::pid_to_str (ptid_t ptid) { struct inf *inf = gnu_current_inf; @@ -2727,12 +2729,7 @@ gnu_nat_target::pid_to_str (ptid_t ptid) if (thread) return proc_string (thread); else - { - static char tid_str[80]; - - xsnprintf (tid_str, sizeof (tid_str), "bogus thread id %d", tid); - return tid_str; - } + return string_printf ("bogus thread id %d", tid); } diff --git a/gdb/gnu-nat.h b/gdb/gnu-nat.h index 4bd4176ead8..a22df89fe2d 100644 --- a/gdb/gnu-nat.h +++ b/gdb/gnu-nat.h @@ -146,7 +146,7 @@ struct gnu_nat_target : public inf_child_target char **, int) override; void mourn_inferior () override; bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; void stop (ptid_t) override; }; diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 27e236918f0..ea0872363d3 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -377,7 +377,7 @@ struct go32_nat_target final : public x86_nat_target bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; }; static go32_nat_target the_go32_nat_target; @@ -992,7 +992,7 @@ go32_nat_target::thread_alive (ptid_t ptid) return ptid != null_ptid; } -const char * +std::string go32_nat_target::pid_to_str (ptid_t ptid) { return normal_pid_to_str (ptid); diff --git a/gdb/i386-cygwin-tdep.c b/gdb/i386-cygwin-tdep.c index e6a9f828929..1acd37975ee 100644 --- a/gdb/i386-cygwin-tdep.c +++ b/gdb/i386-cygwin-tdep.c @@ -178,16 +178,11 @@ windows_core_xfer_shared_libraries (struct gdbarch *gdbarch, /* This is how we want PTIDs from core files to be printed. */ -static const char * +static std::string i386_windows_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { - static char buf[80]; - if (ptid.lwp () != 0) - { - snprintf (buf, sizeof (buf), "Thread 0x%lx", ptid.lwp ()); - return buf; - } + return string_printf ("Thread 0x%lx", ptid.lwp ()); return normal_pid_to_str (ptid); } diff --git a/gdb/i386-gnu-nat.c b/gdb/i386-gnu-nat.c index 75ae641f8e0..087445bc626 100644 --- a/gdb/i386-gnu-nat.c +++ b/gdb/i386-gnu-nat.c @@ -117,7 +117,7 @@ i386_gnu_nat_target::fetch_registers (struct regcache *regcache, int regno) thread = inf_tid_to_thread (gnu_current_inf, ptid.lwp ()); if (!thread) error (_("Can't fetch registers from thread %s: No such thread"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); if (regno < I386_NUM_GREGS || regno == -1) { @@ -208,7 +208,7 @@ i386_gnu_nat_target::store_registers (struct regcache *regcache, int regno) thread = inf_tid_to_thread (gnu_current_inf, ptid.lwp ()); if (!thread) error (_("Couldn't store registers into thread %s: No such thread"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); if (regno < I386_NUM_GREGS || regno == -1) { diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 0956094c6a4..0378926eb53 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -213,10 +213,10 @@ inf_ptrace_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 ()); gdb_flush (gdb_stdout); } @@ -626,10 +626,10 @@ inf_ptrace_target::files_info () printf_filtered (_("\tUsing the running image of %s %s.\n"), inf->attach_flag ? "attached" : "child", - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); } -const char * +std::string inf_ptrace_target::pid_to_str (ptid_t ptid) { return normal_pid_to_str (ptid); diff --git a/gdb/inf-ptrace.h b/gdb/inf-ptrace.h index 2165578083d..98b5d2e09e6 100644 --- a/gdb/inf-ptrace.h +++ b/gdb/inf-ptrace.h @@ -59,7 +59,7 @@ struct inf_ptrace_target : public inf_child_target bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; enum target_xfer_status xfer_partial (enum target_object object, const char *annex, diff --git a/gdb/inferior.c b/gdb/inferior.c index b13d8f3bff5..f367e74e661 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -126,7 +126,7 @@ add_inferior (int pid) if (pid != 0) printf_unfiltered (_("[New inferior %d (%s)]\n"), inf->num, - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); else printf_unfiltered (_("[New inferior %d]\n"), inf->num); } @@ -243,7 +243,7 @@ detach_inferior (inferior *inf) if (print_inferior_events) printf_unfiltered (_("[Inferior %d (%s) detached]\n"), inf->num, - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); } void @@ -407,7 +407,7 @@ number_of_inferiors (void) /* Converts an inferior process id to a string. Like target_pid_to_str, but special cases the null process. */ -static const char * +static std::string inferior_pid_to_str (int pid) { if (pid != 0) @@ -428,7 +428,7 @@ print_selected_inferior (struct ui_out *uiout) filename = _(""); uiout->message (_("[Switching to inferior %d [%s] (%s)]\n"), - inf->num, inferior_pid_to_str (inf->pid), filename); + inf->num, inferior_pid_to_str (inf->pid).c_str (), filename); } /* Prints the list of inferiors and their details on UIOUT. This is a diff --git a/gdb/infrun.c b/gdb/infrun.c index b32635fc422..a05a9343235 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -470,7 +470,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ fprintf_filtered (gdb_stdlog, _("[Detaching after %s from child %s]\n"), has_vforked ? "vfork" : "fork", - target_pid_to_str (process_ptid)); + target_pid_to_str (process_ptid).c_str ()); } } else @@ -606,7 +606,7 @@ holding the child stopped. Try \"set detach-on-fork\" or \ fprintf_filtered (gdb_stdlog, _("[Detaching after fork from " "parent %s]\n"), - target_pid_to_str (process_ptid)); + target_pid_to_str (process_ptid).c_str ()); } target_detach (parent_inf, 0); @@ -875,7 +875,7 @@ proceed_after_vfork_done (struct thread_info *thread, if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: resuming vfork parent thread %s\n", - target_pid_to_str (thread->ptid)); + target_pid_to_str (thread->ptid).c_str ()); switch_to_thread (thread); clear_proceed_status (0); @@ -962,7 +962,7 @@ handle_vfork_child_exec_or_exit (int exec) if (print_inferior_events) { - const char *pidstr + std::string pidstr = target_pid_to_str (ptid_t (inf->vfork_parent->pid)); target_terminal::ours_for_output (); @@ -971,13 +971,13 @@ handle_vfork_child_exec_or_exit (int exec) { fprintf_filtered (gdb_stdlog, _("[Detaching vfork parent %s " - "after child exec]\n"), pidstr); + "after child exec]\n"), pidstr.c_str ()); } else { fprintf_filtered (gdb_stdlog, _("[Detaching vfork parent %s " - "after child exit]\n"), pidstr); + "after child exit]\n"), pidstr.c_str ()); } } @@ -1153,7 +1153,7 @@ follow_exec (ptid_t ptid, char *exec_file_target) /* What is this a.out's name? */ process_ptid = ptid_t (pid); printf_unfiltered (_("%s is executing new program: %s\n"), - target_pid_to_str (process_ptid), + target_pid_to_str (process_ptid).c_str (), exec_file_target); /* We've followed the inferior through an exec. Therefore, the @@ -1674,7 +1674,7 @@ displaced_step_prepare_throw (thread_info *tp) if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: deferring step of %s\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); thread_step_over_chain_enqueue (tp); return 0; @@ -1684,7 +1684,7 @@ displaced_step_prepare_throw (thread_info *tp) if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: stepping %s now\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); } displaced_step_clear (displaced); @@ -1836,7 +1836,7 @@ displaced_step_restore (struct displaced_step_inferior_state *displaced, displaced->step_saved_copy.data (), len); if (debug_displaced) fprintf_unfiltered (gdb_stdlog, "displaced: restored %s %s\n", - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), paddress (displaced->step_gdbarch, displaced->step_copy)); } @@ -1995,7 +1995,7 @@ start_step_over (void) internal_error (__FILE__, __LINE__, "[%s] has inconsistent state: " "trap_expected=%d, resumed=%d, executing=%d\n", - target_pid_to_str (tp->ptid), + target_pid_to_str (tp->ptid).c_str (), tp->control.trap_expected, tp->resumed, tp->executing); @@ -2004,7 +2004,7 @@ start_step_over (void) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: resuming [%s] for step-over\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); /* keep_going_pass_signal skips the step-over if the breakpoint is no longer inserted. In all-stop, we want to keep looking @@ -2263,7 +2263,8 @@ resume_1 (enum gdb_signal sig) fprintf_unfiltered (gdb_stdlog, "infrun: resume: thread %s has pending wait " "status %s (currently_stepping=%d).\n", - target_pid_to_str (tp->ptid), statstr.c_str (), + target_pid_to_str (tp->ptid).c_str (), + statstr.c_str (), currently_stepping (tp)); } @@ -2275,7 +2276,8 @@ resume_1 (enum gdb_signal sig) if (sig != GDB_SIGNAL_0) { warning (_("Couldn't deliver signal %s to %s."), - gdb_signal_to_name (sig), target_pid_to_str (tp->ptid)); + gdb_signal_to_name (sig), + target_pid_to_str (tp->ptid).c_str ()); } tp->suspend.stop_signal = GDB_SIGNAL_0; @@ -2319,7 +2321,7 @@ resume_1 (enum gdb_signal sig) "trap_expected=%d, current thread [%s] at %s\n", step, gdb_signal_to_symbol_string (sig), tp->control.trap_expected, - target_pid_to_str (inferior_ptid), + target_pid_to_str (inferior_ptid).c_str (), paddress (gdbarch, pc)); /* Normally, by the time we reach `resume', the breakpoints are either @@ -2568,7 +2570,7 @@ resume_1 (enum gdb_signal sig) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: resume: [%s] stepped breakpoint\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); tp->stepped_breakpoint = 1; @@ -2673,7 +2675,7 @@ clear_proceed_status_thread (struct thread_info *tp) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: clear_proceed_status_thread (%s)\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); /* If we're starting a new sequence, then the previous finished single-step is no longer relevant. */ @@ -2686,7 +2688,7 @@ clear_proceed_status_thread (struct thread_info *tp) "infrun: clear_proceed_status: pending " "event of %s was a finished step. " "Discarding.\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); tp->suspend.waitstatus_pending_p = 0; tp->suspend.stop_reason = TARGET_STOPPED_BY_NO_REASON; @@ -2700,7 +2702,8 @@ clear_proceed_status_thread (struct thread_info *tp) "infrun: clear_proceed_status_thread: thread %s " "has pending wait status %s " "(currently_stepping=%d).\n", - target_pid_to_str (tp->ptid), statstr.c_str (), + target_pid_to_str (tp->ptid).c_str (), + statstr.c_str (), currently_stepping (tp)); } } @@ -2970,7 +2973,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: need to step-over [%s] first\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); thread_step_over_chain_enqueue (tp); } @@ -3015,7 +3018,7 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: proceed: [%s] resumed\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); gdb_assert (tp->executing || tp->suspend.waitstatus_pending_p); continue; } @@ -3025,14 +3028,14 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: proceed: [%s] needs step-over\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); continue; } if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: proceed: resuming %s\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); reset_ecs (ecs, tp); switch_to_thread (tp); @@ -3266,13 +3269,13 @@ print_target_wait_results (ptid_t waiton_ptid, ptid_t result_ptid, waiton_ptid.lwp (), waiton_ptid.tid ()); if (waiton_ptid.pid () != -1) - stb.printf (" [%s]", target_pid_to_str (waiton_ptid)); + stb.printf (" [%s]", target_pid_to_str (waiton_ptid).c_str ()); stb.printf (", status) =\n"); stb.printf ("infrun: %d.%ld.%ld [%s],\n", result_ptid.pid (), result_ptid.lwp (), result_ptid.tid (), - target_pid_to_str (result_ptid)); + target_pid_to_str (result_ptid).c_str ()); stb.printf ("infrun: %s\n", status_string.c_str ()); /* This uses %s in part to handle %'s in the text, but also to avoid @@ -3342,7 +3345,7 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: Waiting for specific thread %s.\n", - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); /* We have a specific thread to check. */ tp = find_thread_ptid (ptid); @@ -3367,7 +3370,7 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: PC of %s changed. was=%s, now=%s\n", - target_pid_to_str (tp->ptid), + target_pid_to_str (tp->ptid).c_str (), paddress (gdbarch, tp->suspend.stop_pc), paddress (gdbarch, pc)); discard = 1; @@ -3377,7 +3380,7 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: previous breakpoint of %s, at %s gone\n", - target_pid_to_str (tp->ptid), + target_pid_to_str (tp->ptid).c_str (), paddress (gdbarch, pc)); discard = 1; @@ -3388,7 +3391,7 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: pending event of %s cancelled.\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); tp->suspend.waitstatus.kind = TARGET_WAITKIND_SPURIOUS; tp->suspend.stop_reason = TARGET_STOPPED_BY_NO_REASON; @@ -3405,7 +3408,7 @@ do_target_wait (ptid_t ptid, struct target_waitstatus *status, int options) fprintf_unfiltered (gdb_stdlog, "infrun: Using pending wait status %s for %s.\n", statstr.c_str (), - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); } /* Now that we've selected our final event LWP, un-adjust its PC @@ -3880,9 +3883,9 @@ context_switch (execution_control_state *ecs) && ecs->event_thread != inferior_thread ()) { fprintf_unfiltered (gdb_stdlog, "infrun: Switching context from %s ", - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); fprintf_unfiltered (gdb_stdlog, "to %s\n", - target_pid_to_str (ecs->ptid)); + target_pid_to_str (ecs->ptid).c_str ()); } switch_to_thread (ecs->event_thread); @@ -4322,7 +4325,7 @@ stop_all_threads (void) fprintf_unfiltered (gdb_stdlog, "infrun: %s executing, " "need stop\n", - target_pid_to_str (t->ptid)); + target_pid_to_str (t->ptid).c_str ()); target_stop (t->ptid); t->stop_requested = 1; } @@ -4332,7 +4335,7 @@ stop_all_threads (void) fprintf_unfiltered (gdb_stdlog, "infrun: %s executing, " "already stopping\n", - target_pid_to_str (t->ptid)); + target_pid_to_str (t->ptid).c_str ()); } if (t->stop_requested) @@ -4343,7 +4346,7 @@ stop_all_threads (void) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: %s not executing\n", - target_pid_to_str (t->ptid)); + target_pid_to_str (t->ptid).c_str ()); /* The thread may be not executing, but still be resumed with a pending status to process. */ @@ -4377,7 +4380,7 @@ stop_all_threads (void) fprintf_unfiltered (gdb_stdlog, "infrun: %s exited while " "stopping threads\n", - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); } } else @@ -4417,7 +4420,7 @@ stop_all_threads (void) "infrun: displaced-step of %s " "canceled: adding back to the " "step-over queue\n", - target_pid_to_str (t->ptid)); + target_pid_to_str (t->ptid).c_str ()); } t->control.trap_expected = 0; thread_step_over_chain_enqueue (t); @@ -4464,7 +4467,7 @@ stop_all_threads (void) "(currently_stepping=%d)\n", paddress (target_gdbarch (), t->suspend.stop_pc), - target_pid_to_str (t->ptid), + target_pid_to_str (t->ptid).c_str (), currently_stepping (t)); } } @@ -5230,7 +5233,7 @@ restart_threads (struct thread_info *event_thread) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: " "[%s] is event thread\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); continue; } @@ -5240,7 +5243,7 @@ restart_threads (struct thread_info *event_thread) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: " "[%s] not meant to be running\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); continue; } @@ -5249,7 +5252,7 @@ restart_threads (struct thread_info *event_thread) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: [%s] resumed\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); gdb_assert (tp->executing || tp->suspend.waitstatus_pending_p); continue; } @@ -5260,7 +5263,7 @@ restart_threads (struct thread_info *event_thread) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: " "[%s] needs step-over\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); gdb_assert (!tp->resumed); continue; } @@ -5272,7 +5275,7 @@ restart_threads (struct thread_info *event_thread) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: " "[%s] has pending status\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); tp->resumed = 1; continue; } @@ -5287,7 +5290,7 @@ restart_threads (struct thread_info *event_thread) internal_error (__FILE__, __LINE__, "thread [%s] needs a step-over, but not in " "step-over queue\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); } if (currently_stepping (tp)) @@ -5295,7 +5298,7 @@ restart_threads (struct thread_info *event_thread) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: [%s] was stepping\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); keep_going_stepped_thread (tp); } else @@ -5306,7 +5309,7 @@ restart_threads (struct thread_info *event_thread) if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: restart threads: [%s] continuing\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); reset_ecs (ecs, tp); switch_to_thread (tp); keep_going_pass_signal (ecs); @@ -5427,7 +5430,7 @@ finish_step_over (struct execution_control_state *ecs) "(currently_stepping=%d)\n", paddress (target_gdbarch (), tp->suspend.stop_pc), - target_pid_to_str (tp->ptid), + target_pid_to_str (tp->ptid).c_str (), currently_stepping (tp)); } @@ -5590,7 +5593,7 @@ handle_signal_stop (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: [%s] hit another thread's " "single-step breakpoint\n", - target_pid_to_str (ecs->ptid)); + target_pid_to_str (ecs->ptid).c_str ()); } ecs->hit_singlestep_breakpoint = 1; } @@ -5602,7 +5605,7 @@ handle_signal_stop (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: [%s] hit its " "single-step breakpoint\n", - target_pid_to_str (ecs->ptid)); + target_pid_to_str (ecs->ptid).c_str ()); } } } @@ -6852,7 +6855,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs) { fprintf_unfiltered (gdb_stdlog, "infrun: need to finish step-over of [%s]\n", - target_pid_to_str (ecs->event_thread->ptid)); + target_pid_to_str (ecs->event_thread->ptid).c_str ()); } keep_going (ecs); return 1; @@ -6867,7 +6870,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: need to step [%s] over single-step " "breakpoint\n", - target_pid_to_str (ecs->ptid)); + target_pid_to_str (ecs->ptid).c_str ()); } keep_going (ecs); return 1; @@ -6882,7 +6885,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs) { fprintf_unfiltered (gdb_stdlog, "infrun: thread [%s] still needs step-over\n", - target_pid_to_str (ecs->event_thread->ptid)); + target_pid_to_str (ecs->event_thread->ptid).c_str ()); } keep_going (ecs); return 1; @@ -6933,7 +6936,7 @@ switch_back_to_stepped_thread (struct execution_control_state *ecs) internal_error (__FILE__, __LINE__, "[%s] has inconsistent state: " "trap_expected=%d\n", - target_pid_to_str (tp->ptid), + target_pid_to_str (tp->ptid).c_str (), tp->control.trap_expected); } @@ -7503,7 +7506,7 @@ keep_going_pass_signal (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: %s has trap_expected set, " "resuming to collect trap\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); /* We haven't yet gotten our trap, and either: intercepted a non-signal event (e.g., a fork); or took a signal which we @@ -7525,7 +7528,7 @@ keep_going_pass_signal (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: step-over already in progress: " "step-over for %s deferred\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); thread_step_over_chain_enqueue (tp); } else @@ -7534,7 +7537,7 @@ keep_going_pass_signal (struct execution_control_state *ecs) fprintf_unfiltered (gdb_stdlog, "infrun: step-over in progress: " "resume of %s deferred\n", - target_pid_to_str (tp->ptid)); + target_pid_to_str (tp->ptid).c_str ()); } } else @@ -7702,7 +7705,7 @@ void print_exited_reason (struct ui_out *uiout, int exitstatus) { struct inferior *inf = current_inferior (); - const char *pidstr = target_pid_to_str (ptid_t (inf->pid)); + std::string pidstr = target_pid_to_str (ptid_t (inf->pid)); annotate_exited (exitstatus); if (exitstatus) @@ -7712,7 +7715,7 @@ print_exited_reason (struct ui_out *uiout, int exitstatus) uiout->text ("[Inferior "); uiout->text (plongest (inf->num)); uiout->text (" ("); - uiout->text (pidstr); + uiout->text (pidstr.c_str ()); uiout->text (") exited with code "); uiout->field_fmt ("exit-code", "0%o", (unsigned int) exitstatus); uiout->text ("]\n"); @@ -7725,7 +7728,7 @@ print_exited_reason (struct ui_out *uiout, int exitstatus) uiout->text ("[Inferior "); uiout->text (plongest (inf->num)); uiout->text (" ("); - uiout->text (pidstr); + uiout->text (pidstr.c_str ()); uiout->text (") exited normally]\n"); } } @@ -8056,7 +8059,7 @@ normal_stop (void) { target_terminal::ours_for_output (); printf_filtered (_("[Switching to %s]\n"), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); annotate_thread_changed (); } previous_inferior_ptid = inferior_ptid; diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index b1b390c5c6e..f80fb986209 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -398,7 +398,7 @@ linux_fork_mourn_inferior (void) last = find_last_fork (); fork_load_infrun_state (last); printf_filtered (_("[Switching to %s]\n"), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); /* If there's only one fork, switch back to non-fork mode. */ if (fork_list->next == NULL) @@ -417,7 +417,8 @@ linux_fork_detach (int from_tty) fork. */ if (ptrace (PTRACE_DETACH, inferior_ptid.pid (), 0, 0)) - error (_("Unable to detach %s"), target_pid_to_str (inferior_ptid)); + error (_("Unable to detach %s"), + target_pid_to_str (inferior_ptid).c_str ()); delete_fork (inferior_ptid); @@ -430,7 +431,7 @@ linux_fork_detach (int from_tty) if (from_tty) printf_filtered (_("[Switching to %s]\n"), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); /* If there's only one fork, switch back to non-fork mode. */ if (fork_list->next == NULL) @@ -481,7 +482,7 @@ public: CATCH (ex, RETURN_MASK_ALL) { warning (_("Couldn't restore checkpoint state in %s: %s"), - target_pid_to_str (m_oldfp->ptid), ex.message); + target_pid_to_str (m_oldfp->ptid).c_str (), ex.message); } END_CATCH } @@ -550,14 +551,14 @@ delete_checkpoint_command (const char *args, int from_tty) Please switch to another checkpoint before deleting the current one")); if (ptrace (PTRACE_KILL, ptid.pid (), 0, 0)) - error (_("Unable to kill pid %s"), target_pid_to_str (ptid)); + error (_("Unable to kill pid %s"), target_pid_to_str (ptid).c_str ()); fi = find_fork_ptid (ptid); gdb_assert (fi); pptid = fi->parent_ptid; if (from_tty) - printf_filtered (_("Killed %s\n"), target_pid_to_str (ptid)); + printf_filtered (_("Killed %s\n"), target_pid_to_str (ptid).c_str ()); delete_fork (ptid); @@ -570,7 +571,8 @@ Please switch to another checkpoint before deleting the current one")); || (parent != NULL && parent->state == THREAD_STOPPED)) { if (inferior_call_waitpid (pptid, ptid.pid ())) - warning (_("Unable to wait pid %s"), target_pid_to_str (ptid)); + warning (_("Unable to wait pid %s"), + target_pid_to_str (ptid).c_str ()); } } @@ -591,10 +593,10 @@ detach_checkpoint_command (const char *args, int from_tty) Please switch to another checkpoint before detaching the current one")); if (ptrace (PTRACE_DETACH, ptid.pid (), 0, 0)) - error (_("Unable to detach %s"), target_pid_to_str (ptid)); + error (_("Unable to detach %s"), target_pid_to_str (ptid).c_str ()); if (from_tty) - printf_filtered (_("Detached %s\n"), target_pid_to_str (ptid)); + printf_filtered (_("Detached %s\n"), target_pid_to_str (ptid).c_str ()); delete_fork (ptid); } @@ -626,7 +628,8 @@ info_checkpoints_command (const char *arg, int from_tty) printf_filtered (" "); pc = fp->pc; - printf_filtered ("%d %s", fp->num, target_pid_to_str (fp->ptid)); + printf_filtered ("%d %s", fp->num, + target_pid_to_str (fp->ptid).c_str ()); if (fp->num == 0) printf_filtered (_(" (main process)")); printf_filtered (_(" at ")); @@ -781,7 +784,7 @@ linux_fork_context (struct fork_info *newfp, int from_tty) insert_breakpoints (); printf_filtered (_("Switching to %s\n"), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1); } diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 063afe26666..171d67674ab 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1015,7 +1015,8 @@ exit_lwp (struct lwp_info *lp) if (th) { if (print_thread_events) - printf_unfiltered (_("[%s exited]\n"), target_pid_to_str (lp->ptid)); + printf_unfiltered (_("[%s exited]\n"), + target_pid_to_str (lp->ptid).c_str ()); delete_thread (th); } @@ -1151,7 +1152,7 @@ attach_proc_task_lwp_callback (ptid_t ptid) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "PTRACE_ATTACH %s, 0, 0 (OK)\n", - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); lp = add_lwp (ptid); @@ -1337,7 +1338,7 @@ get_detach_signal (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "GPT: lwp %s has no pending signal\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else if (!signal_pass_state (signo)) { @@ -1345,7 +1346,7 @@ get_detach_signal (struct lwp_info *lp) fprintf_unfiltered (gdb_stdlog, "GPT: lwp %s had signal %s, " "but it is in no pass state\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), gdb_signal_to_string (signo)); } else @@ -1353,7 +1354,7 @@ get_detach_signal (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "GPT: lwp %s has pending signal %s\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), gdb_signal_to_string (signo)); return gdb_signal_to_host (signo); @@ -1377,7 +1378,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p) if (debug_linux_nat && lp->status) fprintf_unfiltered (gdb_stdlog, "DC: Pending %s for %s on detach.\n", strsignal (WSTOPSIG (lp->status)), - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* If there is a pending SIGSTOP, get rid of it. */ if (lp->signalled) @@ -1385,7 +1386,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "DC: Sending SIGCONT to %s\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); kill_lwp (lwpid, SIGCONT); lp->signalled = 0; @@ -1440,7 +1441,8 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p) } else { - error (_("Can't detach %s: %s"), target_pid_to_str (lp->ptid), + error (_("Can't detach %s: %s"), + target_pid_to_str (lp->ptid).c_str (), safe_strerror (save_errno)); } } @@ -1448,7 +1450,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p) { fprintf_unfiltered (gdb_stdlog, "PTRACE_DETACH (%s, %s, 0) (OK)\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), strsignal (signo)); } @@ -1610,14 +1612,14 @@ resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RC: Not resuming %s (vfork parent)\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else if (!lwp_status_pending_p (lp)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RC: Resuming sibling %s, %s, %s\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), (signo != GDB_SIGNAL_0 ? strsignal (gdb_signal_to_host (signo)) : "0"), @@ -1630,7 +1632,7 @@ resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (has pending)\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } } else @@ -1638,7 +1640,7 @@ resume_lwp (struct lwp_info *lp, int step, enum gdb_signal signo) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RC: Not resuming sibling %s (not stopped)\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } } @@ -1695,10 +1697,10 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo) fprintf_unfiltered (gdb_stdlog, "LLR: Preparing to %s %s, %s, inferior_ptid %s\n", step ? "step" : "resume", - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), (signo != GDB_SIGNAL_0 ? strsignal (gdb_signal_to_host (signo)) : "0"), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); /* A specific PTID means `step only this process id'. */ resume_many = (minus_one_ptid == ptid @@ -1772,7 +1774,7 @@ linux_nat_target::resume (ptid_t ptid, int step, enum gdb_signal signo) fprintf_unfiltered (gdb_stdlog, "LLR: %s %s, %s (resume event thread)\n", step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), (signo != GDB_SIGNAL_0 ? strsignal (gdb_signal_to_host (signo)) : "0")); @@ -2173,7 +2175,7 @@ wait_lwp (struct lwp_info *lp) thread_dead = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: %s vanished.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } if (pid != 0) break; @@ -2199,7 +2201,7 @@ wait_lwp (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: Thread group leader %s vanished.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); break; } @@ -2222,7 +2224,7 @@ wait_lwp (struct lwp_info *lp) { fprintf_unfiltered (gdb_stdlog, "WL: waitpid %s received %s\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), status_to_str (status)); } @@ -2247,7 +2249,7 @@ wait_lwp (struct lwp_info *lp) thread_dead = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "WL: %s exited.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } } @@ -2315,7 +2317,7 @@ stop_callback (struct lwp_info *lp, void *data) { fprintf_unfiltered (gdb_stdlog, "SC: kill %s ****\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } errno = 0; ret = kill_lwp (lp->ptid.lwp (), SIGSTOP); @@ -2413,7 +2415,7 @@ maybe_clear_ignore_sigint (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "MCIS: Clearing bogus flag for %s\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); lp->ignore_sigint = 0; } } @@ -2513,7 +2515,7 @@ stop_wait_callback (struct lwp_info *lp, void *data) fprintf_unfiltered (gdb_stdlog, "PTRACE_CONT %s, 0, 0 (%s) " "(discarding SIGINT)\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), errno ? safe_strerror (errno) : "OK"); return stop_wait_callback (lp, NULL); @@ -2529,7 +2531,7 @@ stop_wait_callback (struct lwp_info *lp, void *data) fprintf_unfiltered (gdb_stdlog, "SWC: Pending event %s in %s\n", status_to_str ((int) status), - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* Save the sigtrap event. */ lp->status = status; @@ -2543,7 +2545,7 @@ stop_wait_callback (struct lwp_info *lp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "SWC: Expected SIGSTOP caught for %s.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); lp->signalled = 0; @@ -2590,7 +2592,7 @@ status_callback (struct lwp_info *lp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "SC: PC of %s changed. was=%s, now=%s\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), paddress (target_gdbarch (), lp->stop_pc), paddress (target_gdbarch (), pc)); discard = 1; @@ -2602,7 +2604,7 @@ status_callback (struct lwp_info *lp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "SC: previous breakpoint of %s, at %s gone\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), paddress (target_gdbarch (), lp->stop_pc)); discard = 1; @@ -2614,7 +2616,7 @@ status_callback (struct lwp_info *lp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "SC: pending event of %s cancelled.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); lp->status = 0; linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0); @@ -2744,7 +2746,7 @@ save_stop_reason (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "CSBB: %s stopped by trace\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* We may have single stepped an instruction that triggered a watchpoint. In that case, on some @@ -2777,7 +2779,7 @@ save_stop_reason (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "CSBB: %s stopped by software breakpoint\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* Back up the PC if necessary. */ if (pc != sw_bp_pc) @@ -2791,14 +2793,14 @@ save_stop_reason (struct lwp_info *lp) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "CSBB: %s stopped by hardware breakpoint\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else if (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "CSBB: %s stopped by hardware watchpoint\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } lp->stop_pc = pc; @@ -2876,7 +2878,7 @@ select_event_lwp (ptid_t filter, struct lwp_info **orig_lp, int *status) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "SEL: Select single-step %s\n", - target_pid_to_str (event_lp->ptid)); + target_pid_to_str (event_lp->ptid).c_str ()); } } @@ -3030,7 +3032,7 @@ linux_nat_filter_event (int lwpid, int status) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LLW: %s exited.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* If there is at least one more LWP, then the exit signal was not the end of the debugged application and should be @@ -3069,7 +3071,7 @@ linux_nat_filter_event (int lwpid, int status) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LLW: resume_stop SIGSTOP caught for %s.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else { @@ -3080,7 +3082,7 @@ linux_nat_filter_event (int lwpid, int status) "LLW: %s %s, 0, 0 (discard delayed SIGSTOP)\n", lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); linux_resume_one_lwp (lp, lp->step, GDB_SIGNAL_0); gdb_assert (lp->resumed); @@ -3096,7 +3098,7 @@ linux_nat_filter_event (int lwpid, int status) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LLW: Delayed SIGINT caught for %s.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); /* This is a delayed SIGINT. */ lp->ignore_sigint = 0; @@ -3107,7 +3109,7 @@ linux_nat_filter_event (int lwpid, int status) "LLW: %s %s, 0, 0 (discard SIGINT)\n", lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); gdb_assert (lp->resumed); /* Discard the event. */ @@ -3157,7 +3159,7 @@ linux_nat_filter_event (int lwpid, int status) "LLW: %s %s, %s (preempt 'handle')\n", lp->step ? "PTRACE_SINGLESTEP" : "PTRACE_CONT", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), (signo != GDB_SIGNAL_0 ? strsignal (gdb_signal_to_host (signo)) : "0")); @@ -3286,7 +3288,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus, fprintf_unfiltered (gdb_stdlog, "LLW: Using pending wait status %s for %s.\n", status_to_str (lp->status), - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } /* But if we don't find a pending event, we'll have to wait. Always @@ -3443,7 +3445,7 @@ linux_nat_wait_1 (ptid_t ptid, struct target_waitstatus *ourstatus, if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LLW: trap ptid is %s.\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } if (lp->waitstatus.kind != TARGET_WAITKIND_IGNORE) @@ -3494,21 +3496,21 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RSRL: NOT resuming LWP %s, not stopped\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else if (!lp->resumed) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RSRL: NOT resuming LWP %s, not resumed\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else if (lwp_status_pending_p (lp)) { if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "RSRL: NOT resuming LWP %s, has pending status\n", - target_pid_to_str (lp->ptid)); + target_pid_to_str (lp->ptid).c_str ()); } else { @@ -3534,7 +3536,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data) fprintf_unfiltered (gdb_stdlog, "RSRL: resuming stopped-resumed LWP %s at " "%s: step=%d\n", - target_pid_to_str (lp->ptid), + target_pid_to_str (lp->ptid).c_str (), paddress (gdbarch, pc), lp->step); @@ -3563,7 +3565,7 @@ linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus, std::string options_string = target_options_to_string (target_options); fprintf_unfiltered (gdb_stdlog, "linux_nat_wait: [%s], [%s]\n", - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), options_string.c_str ()); } @@ -3931,18 +3933,13 @@ linux_nat_target::update_thread_list () } } -const char * +std::string linux_nat_target::pid_to_str (ptid_t ptid) { - static char buf[64]; - if (ptid.lwp_p () && (ptid.pid () != ptid.lwp () || num_lwps (ptid.pid ()) > 1)) - { - snprintf (buf, sizeof (buf), "LWP %ld", ptid.lwp ()); - return buf; - } + return string_printf ("LWP %ld", ptid.lwp ()); return normal_pid_to_str (ptid); } @@ -4422,7 +4419,7 @@ linux_nat_stop_lwp (struct lwp_info *lwp, void *data) if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LNSL: running -> suspending %s\n", - target_pid_to_str (lwp->ptid)); + target_pid_to_str (lwp->ptid).c_str ()); if (lwp->last_resume_kind == resume_stop) @@ -4447,12 +4444,12 @@ linux_nat_stop_lwp (struct lwp_info *lwp, void *data) if (find_thread_ptid (lwp->ptid)->stop_requested) fprintf_unfiltered (gdb_stdlog, "LNSL: already stopped/stop_requested %s\n", - target_pid_to_str (lwp->ptid)); + target_pid_to_str (lwp->ptid).c_str ()); else fprintf_unfiltered (gdb_stdlog, "LNSL: already stopped/no " "stop_requested yet %s\n", - target_pid_to_str (lwp->ptid)); + target_pid_to_str (lwp->ptid).c_str ()); } } return 0; diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 40e0f2cb29b..0c1695ad102 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -64,7 +64,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 *thread_name (struct thread_info *) override; diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 8d594138e55..77bc7142865 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -414,16 +414,11 @@ linux_has_shared_address_space (struct gdbarch *gdbarch) /* This is how we want PTIDs from core files to be printed. */ -static const char * +static std::string linux_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { - static char buf[80]; - if (ptid.lwp () != 0) - { - snprintf (buf, sizeof (buf), "LWP %ld", ptid.lwp ()); - return buf; - } + return string_printf ("LWP %ld", ptid.lwp ()); return normal_pid_to_str (ptid); } diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index fd67dcb17b2..186525a1e58 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -95,7 +95,7 @@ public: void resume (ptid_t, int, enum gdb_signal) override; void mourn_inferior () override; void update_thread_list () override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; CORE_ADDR get_thread_local_address (ptid_t ptid, CORE_ADDR load_module_addr, CORE_ADDR offset) override; @@ -1631,20 +1631,17 @@ thread_db_target::update_thread_list () this->beneath ()->update_thread_list (); } -const char * +std::string thread_db_target::pid_to_str (ptid_t ptid) { struct thread_info *thread_info = find_thread_ptid (ptid); if (thread_info != NULL && thread_info->priv != NULL) { - static char buf[64]; thread_db_thread_info *priv = get_thread_db_thread_info (thread_info); - snprintf (buf, sizeof (buf), "Thread 0x%lx (LWP %ld)", - (unsigned long) priv->tid, ptid.lwp ()); - - return buf; + return string_printf ("Thread 0x%lx (LWP %ld)", + (unsigned long) priv->tid, ptid.lwp ()); } return beneath ()->pid_to_str (ptid); diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 40959d7715d..79f44ab4838 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -115,7 +115,7 @@ struct nto_procfs_target : public inf_child_target void update_thread_list () override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; void interrupt () override; @@ -658,7 +658,7 @@ nto_procfs_target::files_info () printf_unfiltered ("\tUsing the running image of %s %s via %s.\n", inf->attach_flag ? "attached" : "child", - target_pid_to_str (inferior_ptid), + target_pid_to_str (inferior_ptid).c_str (), (nodestr != NULL) ? nodestr : "local node"); } @@ -708,10 +708,10 @@ nto_procfs_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 ()); gdb_flush (gdb_stdout); } @@ -1457,25 +1457,22 @@ nto_procfs_target::pass_signals } } -char * +std::string nto_procfs_target::pid_to_str (ptid_t ptid) { - static char buf[1024]; - int pid, tid, n; + int pid, tid; struct tidinfo *tip; pid = ptid.pid (); tid = ptid.tid (); - n = snprintf (buf, 1023, "process %d", pid); - #if 0 /* NYI */ tip = procfs_thread_info (pid, tid); if (tip != NULL) snprintf (&buf[n], 1023, " (state = 0x%02x)", tip->state); #endif - return buf; + return string_printf ("process %d", pid); } /* to_can_run implementation for "target procfs". Note this really diff --git a/gdb/obsd-nat.c b/gdb/obsd-nat.c index 2c8b2d47817..0a99bd021df 100644 --- a/gdb/obsd-nat.c +++ b/gdb/obsd-nat.c @@ -35,16 +35,11 @@ #ifdef PT_GET_THREAD_FIRST -const char * +std::sring obsd_nat_target::pid_to_str (ptid_t ptid) { if (ptid.lwp () != 0) - { - static char buf[64]; - - xsnprintf (buf, sizeof buf, "thread %ld", ptid.lwp ()); - return buf; - } + return string_printf ("thread %ld", ptid.lwp ()); return normal_pid_to_str (ptid); } diff --git a/gdb/obsd-nat.h b/gdb/obsd-nat.h index 7c35307c075..c8016ed9121 100644 --- a/gdb/obsd-nat.h +++ b/gdb/obsd-nat.h @@ -25,7 +25,7 @@ class obsd_nat_target : public inf_ptrace_target { /* Override some methods to support threads. */ - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; void update_thread_list () override; ptid_t wait (ptid_t, struct target_waitstatus *, int) override; }; diff --git a/gdb/process-stratum-target.c b/gdb/process-stratum-target.c index e2e8d6c4ff7..2c4b812f863 100644 --- a/gdb/process-stratum-target.c +++ b/gdb/process-stratum-target.c @@ -35,7 +35,7 @@ process_stratum_target::thread_address_space (ptid_t ptid) internal_error (__FILE__, __LINE__, _("Can't determine the current " "address space of thread %s\n"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); return inf->aspace; } diff --git a/gdb/procfs.c b/gdb/procfs.c index b790f112b26..28df985c6cd 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -127,7 +127,7 @@ public: bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; char *pid_to_exec_file (int pid) override; @@ -1879,10 +1879,10 @@ procfs_target::attach (const char *args, int from_tty) if (exec_file) printf_filtered (_("Attaching to program `%s', %s\n"), - exec_file, target_pid_to_str (ptid_t (pid))); + exec_file, target_pid_to_str (ptid_t (pid)).c_str ()); else printf_filtered (_("Attaching to %s\n"), - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); fflush (stdout); } @@ -1905,7 +1905,7 @@ procfs_target::detach (inferior *inf, int from_tty) exec_file = ""; printf_filtered (_("Detaching from program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); gdb_flush (gdb_stdout); } @@ -2059,7 +2059,7 @@ procfs_target::fetch_registers (struct regcache *regcache, int regnum) if (pi == NULL) error (_("procfs: fetch_registers failed to find procinfo for %s"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); gregs = proc_get_gregs (pi); if (gregs == NULL) @@ -2108,7 +2108,7 @@ procfs_target::store_registers (struct regcache *regcache, int regnum) if (pi == NULL) error (_("procfs: store_registers: failed to find procinfo for %s"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); gregs = proc_get_gregs (pi); if (gregs == NULL) @@ -2281,7 +2281,7 @@ wait_again: { if (print_thread_events) printf_unfiltered (_("[%s exited]\n"), - target_pid_to_str (retval)); + target_pid_to_str (retval).c_str ()); delete_thread (find_thread_ptid (retval)); status->kind = TARGET_WAITKIND_SPURIOUS; return retval; @@ -2402,7 +2402,7 @@ wait_again: { if (print_thread_events) printf_unfiltered (_("[%s exited]\n"), - target_pid_to_str (retval)); + target_pid_to_str (retval).c_str ()); delete_thread (find_thread_ptid (retval)); status->kind = TARGET_WAITKIND_SPURIOUS; return retval; @@ -2800,7 +2800,7 @@ procfs_target::files_info () printf_filtered (_("\tUsing the running image of %s %s via /proc.\n"), inf->attach_flag? "attached": "child", - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); } /* Make it die. Wait for it to die. Clean up after it. Note: this @@ -3185,20 +3185,15 @@ procfs_target::thread_alive (ptid_t ptid) return true; } -/* Convert PTID to a string. Returns the string in a static - buffer. */ +/* Convert PTID to a string. */ -const char * +std::string procfs_target::pid_to_str (ptid_t ptid) { - static char buf[80]; - if (ptid.lwp () == 0) - xsnprintf (buf, sizeof (buf), "process %d", ptid.pid ()); + return string_printf ("process %d", ptid.pid ()); else - xsnprintf (buf, sizeof (buf), "LWP %ld", ptid.lwp ()); - - return buf; + return string_printf ("LWP %ld", ptid.lwp ()); } /* Accepts an integer PID; Returns a string representing a file that diff --git a/gdb/progspace.c b/gdb/progspace.c index 9027087d734..1c749621ad6 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -293,12 +293,12 @@ print_program_space (struct ui_out *uiout, int requested) printed_header = 1; printf_filtered ("\n\tBound inferiors: ID %d (%s)", inf->num, - target_pid_to_str (ptid_t (inf->pid))); + target_pid_to_str (ptid_t (inf->pid)).c_str ()); } else printf_filtered (", ID %d (%s)", inf->num, - target_pid_to_str (ptid_t (inf->pid))); + target_pid_to_str (ptid_t (inf->pid)).c_str ()); } uiout->text ("\n"); diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index cb4f26a3472..6636a89554b 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -110,7 +110,7 @@ struct ravenscar_thread_target final : public target_ops const char *extra_thread_info (struct thread_info *) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; ptid_t get_ada_task_ptid (long lwp, long thread) override; @@ -406,13 +406,10 @@ ravenscar_thread_target::thread_alive (ptid_t ptid) return true; } -const char * +std::string ravenscar_thread_target::pid_to_str (ptid_t ptid) { - static char buf[30]; - - snprintf (buf, sizeof (buf), "Thread %#x", (int) ptid.tid ()); - return buf; + return string_printf ("Thread %#x", (int) ptid.tid ()); } void diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index dc26938f0b9..4c896944d7a 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -596,7 +596,8 @@ record_btrace_target::info_record () printf_unfiltered (_("Recorded %u instructions in %u functions (%u gaps) " "for thread %s (%s).\n"), insns, calls, gaps, - print_thread_id (tp), target_pid_to_str (tp->ptid)); + print_thread_id (tp), + target_pid_to_str (tp->ptid).c_str ()); if (btrace_is_replaying (tp)) printf_unfiltered (_("Replay in progress. At instruction %u.\n"), @@ -1949,7 +1950,8 @@ record_btrace_resume_thread (struct thread_info *tp, struct btrace_thread_info *btinfo; DEBUG ("resuming thread %s (%s): %x (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid), flag, btrace_thread_flag_to_str (flag)); + target_pid_to_str (tp->ptid).c_str (), flag, + btrace_thread_flag_to_str (flag)); btinfo = &tp->btrace; @@ -2127,7 +2129,7 @@ record_btrace_target::resume (ptid_t ptid, int step, enum gdb_signal signal) { enum btrace_thread_flag flag, cflag; - DEBUG ("resume %s: %s%s", target_pid_to_str (ptid), + DEBUG ("resume %s: %s%s", target_pid_to_str (ptid).c_str (), ::execution_direction == EXEC_REVERSE ? "reverse-" : "", step ? "step" : "cont"); @@ -2214,7 +2216,7 @@ record_btrace_cancel_resume (struct thread_info *tp) DEBUG ("cancel resume thread %s (%s): %x (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid), flags, + target_pid_to_str (tp->ptid).c_str (), flags, btrace_thread_flag_to_str (flags)); tp->btrace.flags &= ~(BTHR_MOVE | BTHR_STOP); @@ -2442,7 +2444,7 @@ record_btrace_step_thread (struct thread_info *tp) btinfo->flags &= ~(BTHR_MOVE | BTHR_STOP); DEBUG ("stepping thread %s (%s): %x (%s)", print_thread_id (tp), - target_pid_to_str (tp->ptid), flags, + target_pid_to_str (tp->ptid).c_str (), flags, btrace_thread_flag_to_str (flags)); /* We can't step without an execution history. */ @@ -2527,7 +2529,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status, std::vector moving; std::vector no_history; - DEBUG ("wait %s (0x%x)", target_pid_to_str (ptid), options); + DEBUG ("wait %s (0x%x)", target_pid_to_str (ptid).c_str (), options); /* As long as we're not replaying, just forward the request. */ if ((::execution_direction != EXEC_REVERSE) @@ -2545,7 +2547,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status, { *status = btrace_step_no_resumed (); - DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid), + DEBUG ("wait ended by %s: %s", target_pid_to_str (null_ptid).c_str (), target_waitstatus_to_string (status).c_str ()); return null_ptid; @@ -2636,7 +2638,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status, DEBUG ("wait ended by thread %s (%s): %s", print_thread_id (eventing), - target_pid_to_str (eventing->ptid), + target_pid_to_str (eventing->ptid).c_str (), target_waitstatus_to_string (status).c_str ()); return eventing->ptid; @@ -2647,7 +2649,7 @@ record_btrace_target::wait (ptid_t ptid, struct target_waitstatus *status, void record_btrace_target::stop (ptid_t ptid) { - DEBUG ("stop %s", target_pid_to_str (ptid)); + DEBUG ("stop %s", target_pid_to_str (ptid).c_str ()); /* As long as we're not replaying, just forward the request. */ if ((::execution_direction != EXEC_REVERSE) diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 2acfc715d31..ca8866e59ca 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -124,7 +124,7 @@ struct gdbsim_target final bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; bool has_all_memory () override; bool has_memory () override; @@ -1281,10 +1281,9 @@ gdbsim_target::thread_alive (ptid_t ptid) return false; } -/* 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 gdbsim_target::pid_to_str (ptid_t ptid) { return normal_pid_to_str (ptid); diff --git a/gdb/remote.c b/gdb/remote.c index 36136e3e3ee..e1cba44389f 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -485,7 +485,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; @@ -5822,10 +5822,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 ()); gdb_flush (gdb_stdout); } @@ -5846,14 +5846,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)); @@ -6648,7 +6648,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 ()); } @@ -7128,7 +7128,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; } @@ -7166,7 +7166,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); @@ -11434,13 +11434,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) @@ -11459,27 +11457,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
"); + return "Thread
"; 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 ()); } } @@ -13823,10 +13816,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); @@ -13871,10 +13864,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); diff --git a/gdb/sol-thread.c b/gdb/sol-thread.c index f8e8df53214..68fa85130a1 100644 --- a/gdb/sol-thread.c +++ b/gdb/sol-thread.c @@ -87,7 +87,7 @@ public: ptid_t wait (ptid_t, struct target_waitstatus *, int) override; void resume (ptid_t, int, enum gdb_signal) override; void mourn_inferior () override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; ptid_t get_ada_task_ptid (long lwp, long thread) override; void fetch_registers (struct regcache *, int) override; @@ -997,11 +997,9 @@ ps_lgetLDT (struct ps_prochandle *ph, lwpid_t lwpid, struct ssd *pldt) /* ARI: e /* Convert PTID to printable form. */ -const char * +std::string sol_thread_target::pid_to_str (ptid_t ptid) { - static char buf[100]; - if (ptid.tid_p ()) { ptid_t lwp; @@ -1009,21 +1007,19 @@ sol_thread_target::pid_to_str (ptid_t ptid) lwp = thread_to_lwp (ptid, -2); if (lwp.pid () == -1) - xsnprintf (buf, sizeof (buf), "Thread %ld (defunct)", - ptid.tid ()); + return string_printf ("Thread %ld (defunct)", + ptid.tid ()); else if (lwp.pid () != -2) - xsnprintf (buf, sizeof (buf), "Thread %ld (LWP %ld)", - ptid.tid (), lwp.lwp ()); + return string_printf ("Thread %ld (LWP %ld)", + ptid.tid (), lwp.lwp ()); else - xsnprintf (buf, sizeof (buf), "Thread %ld ", - ptid.tid ()); + return string_printf ("Thread %ld ", + ptid.tid ()); } else if (ptid.lwp () != 0) - xsnprintf (buf, sizeof (buf), "LWP %ld ", ptid.lwp ()); + return string_printf ("LWP %ld ", ptid.lwp ()); else - xsnprintf (buf, sizeof (buf), "process %d ", ptid.pid ()); - - return buf; + return string_printf ("process %d ", ptid.pid ()); } diff --git a/gdb/sol2-tdep.c b/gdb/sol2-tdep.c index 8bab8e268e2..014b7d79a73 100644 --- a/gdb/sol2-tdep.c +++ b/gdb/sol2-tdep.c @@ -40,10 +40,9 @@ sol2_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc) /* This is how we want PTIDs from Solaris core files to be printed. */ -const char * +std::string sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) { - static char buf[80]; struct inferior *inf; int pid; @@ -53,8 +52,7 @@ sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) if (pid != 0) { /* A thread. */ - xsnprintf (buf, sizeof buf, "LWP %ld", ptid.lwp ()); - return buf; + return string_printf ("LWP %ld", ptid.lwp ()); } /* GDB didn't use to put a NT_PSTATUS note in Solaris cores. If @@ -62,10 +60,7 @@ sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid) up. */ inf = find_inferior_ptid (ptid); if (inf == NULL || inf->fake_pid_p) - { - xsnprintf (buf, sizeof buf, ""); - return buf; - } + return ""; /* Not fake; print as usual. */ return normal_pid_to_str (ptid); diff --git a/gdb/sol2-tdep.h b/gdb/sol2-tdep.h index 381e62fb3cc..cdc4bbfbe88 100644 --- a/gdb/sol2-tdep.h +++ b/gdb/sol2-tdep.h @@ -24,6 +24,6 @@ struct gdbarch; CORE_ADDR sol2_skip_solib_resolver (struct gdbarch *, CORE_ADDR); -const char *sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); +std::string sol2_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid); #endif /* sol2-tdep.h */ diff --git a/gdb/target-debug.h b/gdb/target-debug.h index d9f7d46dd92..bef8a7f330d 100644 --- a/gdb/target-debug.h +++ b/gdb/target-debug.h @@ -184,6 +184,8 @@ target_debug_do_print (host_address_to_string (X)) #define target_debug_print_thread_info_pp(X) \ target_debug_do_print (host_address_to_string (X)) +#define target_debug_print_std_string(X) \ + target_debug_do_print ((X).c_str ()) static void target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status) diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index a25851e9cf7..3654f02e63b 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -66,7 +66,7 @@ struct dummy_target : public target_ops void program_signals (gdb::array_view arg0) override; bool thread_alive (ptid_t arg0) override; void update_thread_list () override; - const char *pid_to_str (ptid_t arg0) override; + std::string pid_to_str (ptid_t arg0) override; const char *extra_thread_info (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; @@ -233,7 +233,7 @@ struct debug_target : public target_ops void program_signals (gdb::array_view arg0) override; bool thread_alive (ptid_t arg0) override; void update_thread_list () override; - const char *pid_to_str (ptid_t arg0) override; + std::string pid_to_str (ptid_t arg0) override; const char *extra_thread_info (thread_info *arg0) override; const char *thread_name (thread_info *arg0) override; thread_info *thread_handle_to_thread_info (const gdb_byte *arg0, int arg1, inferior *arg2) override; @@ -1746,28 +1746,28 @@ debug_target::update_thread_list () fputs_unfiltered (")\n", gdb_stdlog); } -const char * +std::string target_ops::pid_to_str (ptid_t arg0) { return this->beneath ()->pid_to_str (arg0); } -const char * +std::string dummy_target::pid_to_str (ptid_t arg0) { return default_pid_to_str (this, arg0); } -const char * +std::string debug_target::pid_to_str (ptid_t arg0) { - const char * result; + std::string result; fprintf_unfiltered (gdb_stdlog, "-> %s->pid_to_str (...)\n", this->beneath ()->shortname ()); result = this->beneath ()->pid_to_str (arg0); fprintf_unfiltered (gdb_stdlog, "<- %s->pid_to_str (", this->beneath ()->shortname ()); target_debug_print_ptid_t (arg0); fputs_unfiltered (") = ", gdb_stdlog); - target_debug_print_const_char_p (result); + target_debug_print_std_string (result); fputs_unfiltered ("\n", gdb_stdlog); return result; } diff --git a/gdb/target.c b/gdb/target.c index d5ff932c748..c5141e1925c 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -92,7 +92,7 @@ static int dummy_find_memory_regions (struct target_ops *self, static char *dummy_make_corefile_notes (struct target_ops *self, bfd *ignore1, int *ignore2); -static const char *default_pid_to_str (struct target_ops *ops, ptid_t ptid); +static std::string default_pid_to_str (struct target_ops *ops, ptid_t ptid); static enum exec_direction_kind default_execution_direction (struct target_ops *self); @@ -741,24 +741,26 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset) " thread-local variables in\n" "the shared library `%s'\n" "for %s"), - objfile_name (objfile), target_pid_to_str (ptid)); + objfile_name (objfile), + target_pid_to_str (ptid).c_str ()); else error (_("The inferior has not yet allocated storage for" " thread-local variables in\n" "the executable `%s'\n" "for %s"), - objfile_name (objfile), target_pid_to_str (ptid)); + objfile_name (objfile), + target_pid_to_str (ptid).c_str ()); break; case TLS_GENERIC_ERROR: if (objfile_is_library) error (_("Cannot find thread-local storage for %s, " "shared library %s:\n%s"), - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), objfile_name (objfile), ex.message); else error (_("Cannot find thread-local storage for %s, " "executable file %s:\n%s"), - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), objfile_name (objfile), ex.message); break; default: @@ -2072,7 +2074,7 @@ default_target_wait (struct target_ops *ops, return minus_one_ptid; } -const char * +std::string target_pid_to_str (ptid_t ptid) { return current_top_target ()->pid_to_str (ptid); @@ -3167,7 +3169,7 @@ target_announce_detach (int from_tty) pid = inferior_ptid.pid (); printf_unfiltered (_("Detaching from program: %s, %s\n"), exec_file, - target_pid_to_str (ptid_t (pid))); + target_pid_to_str (ptid_t (pid)).c_str ()); gdb_flush (gdb_stdout); } @@ -3205,16 +3207,13 @@ generic_mourn_inferior (void) /* Convert a normal process ID to a string. Returns the string in a static buffer. */ -const char * +std::string normal_pid_to_str (ptid_t ptid) { - static char buf[32]; - - xsnprintf (buf, sizeof buf, "process %d", ptid.pid ()); - return buf; + return string_printf ("process %d", ptid.pid ()); } -static const char * +static std::string default_pid_to_str (struct target_ops *ops, ptid_t ptid) { return normal_pid_to_str (ptid); diff --git a/gdb/target.h b/gdb/target.h index c95151a4044..3d8e7c8a7ee 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -649,7 +649,7 @@ struct target_ops TARGET_DEFAULT_RETURN (false); virtual void update_thread_list () TARGET_DEFAULT_IGNORE (); - virtual const char *pid_to_str (ptid_t) + virtual std::string pid_to_str (ptid_t) TARGET_DEFAULT_FUNC (default_pid_to_str); virtual const char *extra_thread_info (thread_info *) TARGET_DEFAULT_RETURN (NULL); @@ -1829,9 +1829,9 @@ extern int target_is_non_stop_p (void); `process xyz', but on some systems it may contain `process xyz thread abc'. */ -extern const char *target_pid_to_str (ptid_t ptid); +extern std::string target_pid_to_str (ptid_t ptid); -extern const char *normal_pid_to_str (ptid_t ptid); +extern std::string normal_pid_to_str (ptid_t ptid); /* Return a short string describing extra information about PID, e.g. "sleeping", "runnable", "running on LWP 3". Null return value diff --git a/gdb/thread.c b/gdb/thread.c index 6c232529646..91741c76f0d 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -319,7 +319,7 @@ add_thread_with_info (ptid_t ptid, private_thread_info *priv) result->priv.reset (priv); if (print_thread_events) - printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid)); + printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid).c_str ()); annotate_new_thread (); return result; @@ -992,16 +992,17 @@ should_print_thread (const char *requested_threads, int default_inf_num, static std::string thread_target_id_str (thread_info *tp) { - const char *target_id = target_pid_to_str (tp->ptid); + std::string target_id = target_pid_to_str (tp->ptid); const char *extra_info = target_extra_thread_info (tp); const char *name = tp->name != nullptr ? tp->name : target_thread_name (tp); if (extra_info != nullptr && name != nullptr) - return string_printf ("%s \"%s\" (%s)", target_id, name, extra_info); + return string_printf ("%s \"%s\" (%s)", target_id.c_str (), name, + extra_info); else if (extra_info != nullptr) - return string_printf ("%s (%s)", target_id, extra_info); + return string_printf ("%s (%s)", target_id.c_str (), extra_info); else if (name != nullptr) - return string_printf ("%s \"%s\"", target_id, name); + return string_printf ("%s \"%s\"", target_id.c_str (), name); else return target_id; } @@ -1466,7 +1467,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty, if (!flags.quiet) printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (thr), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); printf_filtered ("%s", cmd_result.c_str ()); } } @@ -1477,7 +1478,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty, if (!flags.quiet) printf_filtered (_("\nThread %s (%s):\n"), print_thread_id (thr), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); if (flags.cont) printf_filtered ("%s\n", ex.message); else @@ -1675,11 +1676,11 @@ thread_command (const char *tidstr, int from_tty) if (tp->state == THREAD_EXITED) printf_filtered (_("[Current thread is %s (%s) (exited)]\n"), print_thread_id (tp), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); else printf_filtered (_("[Current thread is %s (%s)]\n"), print_thread_id (tp), - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); } else error (_("No stack.")); @@ -1756,11 +1757,11 @@ thread_find_command (const char *arg, int from_tty) match++; } - tmp = target_pid_to_str (tp->ptid); - if (tmp != NULL && re_exec (tmp)) + std::string name = target_pid_to_str (tp->ptid); + if (!name.empty () && re_exec (name.c_str ())) { printf_filtered (_("Thread %s has target id '%s'\n"), - print_thread_id (tp), tmp); + print_thread_id (tp), name.c_str ()); match++; } @@ -1824,7 +1825,7 @@ print_selected_thread_frame (struct ui_out *uiout, uiout->text ("[Switching to thread "); uiout->field_string ("new-thread-id", print_thread_id (tp)); uiout->text (" ("); - uiout->text (target_pid_to_str (inferior_ptid)); + uiout->text (target_pid_to_str (inferior_ptid).c_str ()); uiout->text (")]"); } } diff --git a/gdb/top.c b/gdb/top.c index 22e6f7e29ab..8eb40b94045 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1548,11 +1548,11 @@ print_inferior_quit_action (struct inferior *inf, void *arg) if (inf->attach_flag) fprintf_filtered (stb, _("\tInferior %d [%s] will be detached.\n"), inf->num, - target_pid_to_str (ptid_t (inf->pid))); + target_pid_to_str (ptid_t (inf->pid)).c_str ()); else fprintf_filtered (stb, _("\tInferior %d [%s] will be killed.\n"), inf->num, - target_pid_to_str (ptid_t (inf->pid))); + target_pid_to_str (ptid_t (inf->pid)).c_str ()); return 0; } diff --git a/gdb/tui/tui-stack.c b/gdb/tui/tui-stack.c index bd58fde1de3..b85b7a5d437 100644 --- a/gdb/tui/tui-stack.c +++ b/gdb/tui/tui-stack.c @@ -72,10 +72,14 @@ tui_make_status_line (struct tui_locator_element *loc) int pid_width; int line_width; + std::string pid_name_holder; if (inferior_ptid == null_ptid) pid_name = "No process"; else - pid_name = target_pid_to_str (inferior_ptid); + { + pid_name_holder = target_pid_to_str (inferior_ptid); + pid_name = pid_name_holder.c_str (); + } target_width = strlen (target_shortname); if (target_width > MAX_TARGET_WIDTH) diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index e47fcb1b40a..2dfd93eeb9e 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -341,7 +341,7 @@ struct windows_nat_target final : public x86_nat_target bool thread_alive (ptid_t ptid) override; - const char *pid_to_str (ptid_t) override; + std::string pid_to_str (ptid_t) override; void interrupt () override; @@ -525,10 +525,11 @@ windows_delete_thread (ptid_t ptid, DWORD exit_code, bool main_thread_p) here as well. */ if (info_verbose) - printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (ptid)); + printf_unfiltered ("[Deleting %s]\n", target_pid_to_str (ptid).c_str ()); else if (print_thread_events && !main_thread_p) printf_unfiltered (_("[%s exited with code %u]\n"), - target_pid_to_str (ptid), (unsigned) exit_code); + target_pid_to_str (ptid).c_str (), + (unsigned) exit_code); delete_thread (find_thread_ptid (ptid)); @@ -2011,10 +2012,10 @@ windows_nat_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 ()); gdb_flush (gdb_stdout); } @@ -2145,7 +2146,7 @@ windows_nat_target::files_info () printf_unfiltered ("\tUsing the running image of %s %s.\n", inf->attach_flag ? "attached" : "child", - target_pid_to_str (inferior_ptid)); + target_pid_to_str (inferior_ptid).c_str ()); } /* Modify CreateProcess parameters for use of a new separate console. @@ -2937,17 +2938,11 @@ windows_nat_target::close () } /* Convert pid to printable format. */ -const char * +std::string windows_nat_target::pid_to_str (ptid_t ptid) { - static char buf[80]; - if (ptid.tid () != 0) - { - snprintf (buf, sizeof (buf), "Thread %d.0x%lx", - ptid.pid (), ptid.tid ()); - return buf; - } + return string_printf ("Thread %d.0x%lx", ptid.pid (), ptid.tid ()); return normal_pid_to_str (ptid); } diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 2f223b3dfe9..42083e789a5 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -327,7 +327,7 @@ display_one_tib (ptid_t ptid) if (target_get_tib_address (ptid, &thread_local_base) == 0) { printf_filtered (_("Unable to get thread local base for %s\n"), - target_pid_to_str (ptid)); + target_pid_to_str (ptid).c_str ()); return -1; } @@ -336,13 +336,13 @@ display_one_tib (ptid_t ptid) { printf_filtered (_("Unable to read thread information " "block for %s at address %s\n"), - target_pid_to_str (ptid), - paddress (target_gdbarch (), thread_local_base)); + target_pid_to_str (ptid).c_str (), + paddress (target_gdbarch (), thread_local_base)); return -1; } printf_filtered (_("Thread Information Block %s at %s\n"), - target_pid_to_str (ptid), + target_pid_to_str (ptid).c_str (), paddress (target_gdbarch (), thread_local_base)); index = (gdb_byte *) tib; diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index fd15dc9b872..9a451e0e1aa 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -224,7 +224,7 @@ x86_linux_nat_target::enable_btrace (ptid_t ptid, CATCH (exception, RETURN_MASK_ERROR) { error (_("Could not enable branch tracing for %s: %s"), - target_pid_to_str (ptid), exception.message); + target_pid_to_str (ptid).c_str (), exception.message); } END_CATCH