From 696c0d5ef2a6edaa2094e808f53acd502a157641 Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Thu, 25 Nov 2021 15:15:52 +0100 Subject: [PATCH] gdb, gdbserver: update thread identifier in enable_btrace target method The enable_btrace target method takes a ptid_t to identify the thread on which tracing shall be enabled. Change this to thread_info * to avoid translating back and forth between the two. This will be used in a subsequent patch. --- gdb/btrace.c | 2 +- gdb/ravenscar-thread.c | 10 +++++++--- gdb/remote.c | 8 +++++--- gdb/target-delegates.c | 12 ++++++------ gdb/target.c | 4 ++-- gdb/target.h | 6 +++--- gdb/x86-linux-nat.c | 3 ++- gdb/x86-linux-nat.h | 2 +- gdbserver/linux-low.cc | 4 ++-- gdbserver/linux-low.h | 2 +- gdbserver/server.cc | 4 ++-- gdbserver/target.cc | 3 ++- gdbserver/target.h | 8 ++++---- 13 files changed, 38 insertions(+), 30 deletions(-) diff --git a/gdb/btrace.c b/gdb/btrace.c index dc4d686ac4b..ea733fe36b9 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -1618,7 +1618,7 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf) DEBUG ("enable thread %s (%s)", print_thread_id (tp), tp->ptid.to_string ().c_str ()); - tp->btrace.target = target_enable_btrace (tp->ptid, conf); + tp->btrace.target = target_enable_btrace (tp, conf); if (tp->btrace.target == NULL) error (_("Failed to enable recording on thread %s (%s)."), diff --git a/gdb/ravenscar-thread.c b/gdb/ravenscar-thread.c index 5f040cece07..60fc3530ce2 100644 --- a/gdb/ravenscar-thread.c +++ b/gdb/ravenscar-thread.c @@ -120,12 +120,16 @@ struct ravenscar_thread_target final : public target_ops ptid_t get_ada_task_ptid (long lwp, ULONGEST thread) override; - struct btrace_target_info *enable_btrace (ptid_t ptid, + struct btrace_target_info *enable_btrace (thread_info *tp, const struct btrace_config *conf) override { - ptid = get_base_thread_from_ravenscar_task (ptid); - return beneath ()->enable_btrace (ptid, conf); + process_stratum_target *proc_target + = as_process_stratum_target (this->beneath ()); + ptid_t underlying = get_base_thread_from_ravenscar_task (tp->ptid); + tp = find_thread_ptid (proc_target, underlying); + + return beneath ()->enable_btrace (tp, conf); } void mourn_inferior () override; diff --git a/gdb/remote.c b/gdb/remote.c index f19a2f7c1f9..9f2c63b2141 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -658,8 +658,8 @@ public: bool use_agent (bool use) override; bool can_use_agent () override; - struct btrace_target_info *enable_btrace (ptid_t ptid, - const struct btrace_config *conf) override; + struct btrace_target_info * + enable_btrace (thread_info *tp, const struct btrace_config *conf) override; void disable_btrace (struct btrace_target_info *tinfo) override; @@ -14178,7 +14178,8 @@ remote_target::remote_btrace_maybe_reopen () /* Enable branch tracing. */ struct btrace_target_info * -remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf) +remote_target::enable_btrace (thread_info *tp, + const struct btrace_config *conf) { struct btrace_target_info *tinfo = NULL; struct packet_config *packet = NULL; @@ -14202,6 +14203,7 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf) btrace_sync_conf (conf); + ptid_t ptid = tp->ptid; set_general_thread (ptid); buf += xsnprintf (buf, endbuf - buf, "%s", packet->name); diff --git a/gdb/target-delegates.c b/gdb/target-delegates.c index 9636e3212bc..ca1734f86ba 100644 --- a/gdb/target-delegates.c +++ b/gdb/target-delegates.c @@ -145,7 +145,7 @@ struct dummy_target : public target_ops traceframe_info_up traceframe_info () override; bool use_agent (bool arg0) override; bool can_use_agent () override; - struct btrace_target_info *enable_btrace (ptid_t arg0, const struct btrace_config *arg1) override; + struct btrace_target_info *enable_btrace (thread_info *arg0, const struct btrace_config *arg1) override; void disable_btrace (struct btrace_target_info *arg0) override; void teardown_btrace (struct btrace_target_info *arg0) override; enum btrace_error read_btrace (struct btrace_data *arg0, struct btrace_target_info *arg1, enum btrace_read_type arg2) override; @@ -319,7 +319,7 @@ struct debug_target : public target_ops traceframe_info_up traceframe_info () override; bool use_agent (bool arg0) override; bool can_use_agent () override; - struct btrace_target_info *enable_btrace (ptid_t arg0, const struct btrace_config *arg1) override; + struct btrace_target_info *enable_btrace (thread_info *arg0, const struct btrace_config *arg1) override; void disable_btrace (struct btrace_target_info *arg0) override; void teardown_btrace (struct btrace_target_info *arg0) override; enum btrace_error read_btrace (struct btrace_data *arg0, struct btrace_target_info *arg1, enum btrace_read_type arg2) override; @@ -3761,25 +3761,25 @@ debug_target::can_use_agent () } struct btrace_target_info * -target_ops::enable_btrace (ptid_t arg0, const struct btrace_config *arg1) +target_ops::enable_btrace (thread_info *arg0, const struct btrace_config *arg1) { return this->beneath ()->enable_btrace (arg0, arg1); } struct btrace_target_info * -dummy_target::enable_btrace (ptid_t arg0, const struct btrace_config *arg1) +dummy_target::enable_btrace (thread_info *arg0, const struct btrace_config *arg1) { tcomplain (); } struct btrace_target_info * -debug_target::enable_btrace (ptid_t arg0, const struct btrace_config *arg1) +debug_target::enable_btrace (thread_info *arg0, const struct btrace_config *arg1) { struct btrace_target_info * result; fprintf_unfiltered (gdb_stdlog, "-> %s->enable_btrace (...)\n", this->beneath ()->shortname ()); result = this->beneath ()->enable_btrace (arg0, arg1); fprintf_unfiltered (gdb_stdlog, "<- %s->enable_btrace (", this->beneath ()->shortname ()); - target_debug_print_ptid_t (arg0); + target_debug_print_thread_info_p (arg0); fputs_unfiltered (", ", gdb_stdlog); target_debug_print_const_struct_btrace_config_p (arg1); fputs_unfiltered (") = ", gdb_stdlog); diff --git a/gdb/target.c b/gdb/target.c index f3f1c80391f..548cfad06b2 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -4060,9 +4060,9 @@ target_ranged_break_num_registers (void) /* See target.h. */ struct btrace_target_info * -target_enable_btrace (ptid_t ptid, const struct btrace_config *conf) +target_enable_btrace (thread_info *tp, const struct btrace_config *conf) { - return current_inferior ()->top_target ()->enable_btrace (ptid, conf); + return current_inferior ()->top_target ()->enable_btrace (tp, conf); } /* See target.h. */ diff --git a/gdb/target.h b/gdb/target.h index 1ac7a4554dc..4cc79df05b4 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -1151,10 +1151,10 @@ struct target_ops virtual bool can_use_agent () TARGET_DEFAULT_RETURN (false); - /* Enable branch tracing for PTID using CONF configuration. + /* Enable branch tracing for TP using CONF configuration. Return a branch trace target information struct for reading and for disabling branch trace. */ - virtual struct btrace_target_info *enable_btrace (ptid_t ptid, + virtual struct btrace_target_info *enable_btrace (thread_info *tp, const struct btrace_config *conf) TARGET_DEFAULT_NORETURN (tcomplain ()); @@ -2502,7 +2502,7 @@ extern void update_target_permissions (void); /* See to_enable_btrace in struct target_ops. */ extern struct btrace_target_info * - target_enable_btrace (ptid_t ptid, const struct btrace_config *); + target_enable_btrace (thread_info *tp, const struct btrace_config *); /* See to_disable_btrace in struct target_ops. */ extern void target_disable_btrace (struct btrace_target_info *btinfo); diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c index 55d2a1d9ab0..80be9733310 100644 --- a/gdb/x86-linux-nat.c +++ b/gdb/x86-linux-nat.c @@ -212,10 +212,11 @@ x86_linux_nat_target::read_description () /* Enable branch tracing. */ struct btrace_target_info * -x86_linux_nat_target::enable_btrace (ptid_t ptid, +x86_linux_nat_target::enable_btrace (thread_info *tp, const struct btrace_config *conf) { struct btrace_target_info *tinfo = nullptr; + ptid_t ptid = tp->ptid; try { tinfo = linux_enable_btrace (ptid, conf); diff --git a/gdb/x86-linux-nat.h b/gdb/x86-linux-nat.h index e0a78bf9f00..1a562349691 100644 --- a/gdb/x86-linux-nat.h +++ b/gdb/x86-linux-nat.h @@ -32,7 +32,7 @@ struct x86_linux_nat_target : public x86_nat_target /* Add the description reader. */ const struct target_desc *read_description () override; - struct btrace_target_info *enable_btrace (ptid_t ptid, + struct btrace_target_info *enable_btrace (thread_info *tp, const struct btrace_config *conf) override; void disable_btrace (struct btrace_target_info *tinfo) override; void teardown_btrace (struct btrace_target_info *tinfo) override; diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 9e571a4d771..cf73bbc70ee 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -6669,10 +6669,10 @@ linux_process_target::qxfer_libraries_svr4 (const char *annex, #ifdef HAVE_LINUX_BTRACE btrace_target_info * -linux_process_target::enable_btrace (ptid_t ptid, +linux_process_target::enable_btrace (thread_info *tp, const btrace_config *conf) { - return linux_enable_btrace (ptid, conf); + return linux_enable_btrace (tp->id, conf); } /* See to_disable_btrace target method. */ diff --git a/gdbserver/linux-low.h b/gdbserver/linux-low.h index 6ee72d7bd39..27cc9641f12 100644 --- a/gdbserver/linux-low.h +++ b/gdbserver/linux-low.h @@ -276,7 +276,7 @@ public: bool supports_agent () override; #ifdef HAVE_LINUX_BTRACE - btrace_target_info *enable_btrace (ptid_t ptid, + btrace_target_info *enable_btrace (thread_info *tp, const btrace_config *conf) override; int disable_btrace (btrace_target_info *tinfo) override; diff --git a/gdbserver/server.cc b/gdbserver/server.cc index 4177239f4a6..8e53f226d3c 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -409,7 +409,7 @@ handle_btrace_enable_bts (struct thread_info *thread) error (_("Btrace already enabled.")); current_btrace_conf.format = BTRACE_FORMAT_BTS; - thread->btrace = target_enable_btrace (thread->id, ¤t_btrace_conf); + thread->btrace = target_enable_btrace (thread, ¤t_btrace_conf); } /* Handle btrace enabling in Intel Processor Trace format. */ @@ -421,7 +421,7 @@ handle_btrace_enable_pt (struct thread_info *thread) error (_("Btrace already enabled.")); current_btrace_conf.format = BTRACE_FORMAT_PT; - thread->btrace = target_enable_btrace (thread->id, ¤t_btrace_conf); + thread->btrace = target_enable_btrace (thread, ¤t_btrace_conf); } /* Handle btrace disabling. */ diff --git a/gdbserver/target.cc b/gdbserver/target.cc index 5165957aed7..5009146d663 100644 --- a/gdbserver/target.cc +++ b/gdbserver/target.cc @@ -736,7 +736,8 @@ process_stratum_target::supports_agent () } btrace_target_info * -process_stratum_target::enable_btrace (ptid_t ptid, const btrace_config *conf) +process_stratum_target::enable_btrace (thread_info *tp, + const btrace_config *conf) { error (_("Target does not support branch tracing.")); } diff --git a/gdbserver/target.h b/gdbserver/target.h index f58ed9d08ff..aaa9dab742c 100644 --- a/gdbserver/target.h +++ b/gdbserver/target.h @@ -403,9 +403,9 @@ public: /* Return true if target supports debugging agent. */ virtual bool supports_agent (); - /* Enable branch tracing for PTID based on CONF and allocate a branch trace + /* Enable branch tracing for TP based on CONF and allocate a branch trace target information struct for reading and for disabling branch trace. */ - virtual btrace_target_info *enable_btrace (ptid_t ptid, + virtual btrace_target_info *enable_btrace (thread_info *tp, const btrace_config *conf); /* Disable branch tracing. @@ -635,9 +635,9 @@ int kill_inferior (process_info *proc); the_target->supports_agent () static inline struct btrace_target_info * -target_enable_btrace (ptid_t ptid, const struct btrace_config *conf) +target_enable_btrace (thread_info *tp, const struct btrace_config *conf) { - return the_target->enable_btrace (ptid, conf); + return the_target->enable_btrace (tp, conf); } static inline int -- 2.30.2