diff options
author | Markus Metzger <markus.t.metzger@intel.com> | 2018-02-02 12:29:48 +0100 |
---|---|---|
committer | Markus Metzger <markus.t.metzger@intel.com> | 2018-04-13 11:35:55 +0200 |
commit | 4a4495d62d185bdae17ed6aae6ea8249ad07c799 (patch) | |
tree | 94046fea4522f3ca526e3ed6d21cb79b0f7cc95f /gdb/btrace.c | |
parent | 69f90c75b369cd2d66988a67bbc2a000dd6b9816 (diff) | |
download | fsf-binutils-gdb-4a4495d62d185bdae17ed6aae6ea8249ad07c799.zip fsf-binutils-gdb-4a4495d62d185bdae17ed6aae6ea8249ad07c799.tar.gz fsf-binutils-gdb-4a4495d62d185bdae17ed6aae6ea8249ad07c799.tar.bz2 |
btrace: set/show record btrace cpu
Add new set/show commands to set the processor that is used for enabling
errata workarounds when decoding branch trace.
The general format is "<vendor>:<identifier>" but we also allow two
special values "auto" and "none".
The default is "auto", which is the current behaviour of having GDB
determine the processor on which the trace was recorded.
If that cpu is not known to the trace decoder, e.g. when using an old
decoder on a new system, decode may fail with "unknown cpu". In most
cases it should suffice to 'downgrade' decode to assume an older cpu.
Unfortunately, we can't do this automatically.
The other special value, "none", disables errata workarounds.
gdb/
* NEWS (New options): announce set/show record btrace cpu.
* btrace.c: Include record-btrace.h.
(btrace_compute_ftrace_pt): Skip enabling errata workarounds if
the vendor is unknown.
(btrace_compute_ftrace_1): Add cpu parameter. Update callers.
Maybe overwrite the btrace configuration's cpu.
(btrace_compute_ftrace): Add cpu parameter. Update callers.
(btrace_fetch): Add cpu parameter. Update callers.
(btrace_maint_update_pt_packets): Call record_btrace_get_cpu.
Maybe overwrite the btrace configuration's cpu. Skip enabling
errata workarounds if the vendor is unknown.
* python/py-record-btrace.c: Include record-btrace.h.
(recpy_bt_begin, recpy_bt_end, recpy_bt_instruction_history)
(recpy_bt_function_call_history): Call record_btrace_get_cpu.
* record-btrace.c (record_btrace_cpu_state_kind): New.
(record_btrace_cpu): New.
(set_record_btrace_cpu_cmdlist): New.
(record_btrace_get_cpu): New.
(require_btrace_thread, record_btrace_info)
(record_btrace_resume_thread): Call record_btrace_get_cpu.
(cmd_set_record_btrace_cpu_none): New.
(cmd_set_record_btrace_cpu_auto): New.
(cmd_set_record_btrace_cpu): New.
(cmd_show_record_btrace_cpu): New.
(_initialize_record_btrace): Initialize set/show record btrace cpu
commands.
* record-btrace.h (record_btrace_get_cpu): New.
testsuite/
* gdb.btrace/cpu.exp: New.
doc/
* gdb.texinfo: Document set/show record btrace cpu.
Diffstat (limited to 'gdb/btrace.c')
-rw-r--r-- | gdb/btrace.c | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/gdb/btrace.c b/gdb/btrace.c index 158d03c..269ee51 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -35,6 +35,9 @@ #include "gdbcmd.h" #include "cli/cli-utils.h" +/* For maintenance commands. */ +#include "record-btrace.h" + #include <inttypes.h> #include <ctype.h> #include <algorithm> @@ -1428,15 +1431,20 @@ btrace_compute_ftrace_pt (struct thread_info *tp, config.begin = btrace->data; config.end = btrace->data + btrace->size; - config.cpu.vendor = pt_translate_cpu_vendor (btrace->config.cpu.vendor); - config.cpu.family = btrace->config.cpu.family; - config.cpu.model = btrace->config.cpu.model; - config.cpu.stepping = btrace->config.cpu.stepping; + /* We treat an unknown vendor as 'no errata'. */ + if (btrace->config.cpu.vendor != CV_UNKNOWN) + { + config.cpu.vendor + = pt_translate_cpu_vendor (btrace->config.cpu.vendor); + config.cpu.family = btrace->config.cpu.family; + config.cpu.model = btrace->config.cpu.model; + config.cpu.stepping = btrace->config.cpu.stepping; - errcode = pt_cpu_errata (&config.errata, &config.cpu); - if (errcode < 0) - error (_("Failed to configure the Intel Processor Trace decoder: %s."), - pt_errstr (pt_errcode (errcode))); + errcode = pt_cpu_errata (&config.errata, &config.cpu); + if (errcode < 0) + error (_("Failed to configure the Intel Processor Trace " + "decoder: %s."), pt_errstr (pt_errcode (errcode))); + } decoder = pt_insn_alloc_decoder (&config); if (decoder == NULL) @@ -1485,10 +1493,14 @@ btrace_compute_ftrace_pt (struct thread_info *tp, #endif /* defined (HAVE_LIBIPT) */ /* Compute the function branch trace from a block branch trace BTRACE for - a thread given by BTINFO. */ + a thread given by BTINFO. If CPU is not NULL, overwrite the cpu in the + branch trace configuration. This is currently only used for the PT + format. */ static void -btrace_compute_ftrace_1 (struct thread_info *tp, struct btrace_data *btrace, +btrace_compute_ftrace_1 (struct thread_info *tp, + struct btrace_data *btrace, + const struct btrace_cpu *cpu, std::vector<unsigned int> &gaps) { DEBUG ("compute ftrace"); @@ -1503,6 +1515,10 @@ btrace_compute_ftrace_1 (struct thread_info *tp, struct btrace_data *btrace, return; case BTRACE_FORMAT_PT: + /* Overwrite the cpu we use for enabling errata workarounds. */ + if (cpu != nullptr) + btrace->variant.pt.config.cpu = *cpu; + btrace_compute_ftrace_pt (tp, &btrace->variant.pt, gaps); return; } @@ -1521,13 +1537,14 @@ btrace_finalize_ftrace (struct thread_info *tp, std::vector<unsigned int> &gaps) } static void -btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace) +btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace, + const struct btrace_cpu *cpu) { std::vector<unsigned int> gaps; TRY { - btrace_compute_ftrace_1 (tp, btrace, gaps); + btrace_compute_ftrace_1 (tp, btrace, cpu, gaps); } CATCH (error, RETURN_MASK_ALL) { @@ -1564,7 +1581,7 @@ btrace_add_pc (struct thread_info *tp) block->begin = pc; block->end = pc; - btrace_compute_ftrace (tp, &btrace); + btrace_compute_ftrace (tp, &btrace, NULL); do_cleanups (cleanup); } @@ -1872,7 +1889,7 @@ btrace_decode_error (enum btrace_format format, int errcode) /* See btrace.h. */ void -btrace_fetch (struct thread_info *tp) +btrace_fetch (struct thread_info *tp, const struct btrace_cpu *cpu) { struct btrace_thread_info *btinfo; struct btrace_target_info *tinfo; @@ -1948,7 +1965,7 @@ btrace_fetch (struct thread_info *tp) btrace_maint_clear (btinfo); btrace_clear_history (btinfo); - btrace_compute_ftrace (tp, &btrace); + btrace_compute_ftrace (tp, &btrace, cpu); } do_cleanups (cleanup); @@ -3028,6 +3045,7 @@ static void btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo) { struct pt_packet_decoder *decoder; + const struct btrace_cpu *cpu; struct btrace_data_pt *pt; struct pt_config config; int errcode; @@ -3044,15 +3062,23 @@ btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo) config.begin = pt->data; config.end = pt->data + pt->size; - config.cpu.vendor = pt_translate_cpu_vendor (pt->config.cpu.vendor); - config.cpu.family = pt->config.cpu.family; - config.cpu.model = pt->config.cpu.model; - config.cpu.stepping = pt->config.cpu.stepping; + cpu = record_btrace_get_cpu (); + if (cpu == nullptr) + cpu = &pt->config.cpu; + + /* We treat an unknown vendor as 'no errata'. */ + if (cpu->vendor != CV_UNKNOWN) + { + config.cpu.vendor = pt_translate_cpu_vendor (cpu->vendor); + config.cpu.family = cpu->family; + config.cpu.model = cpu->model; + config.cpu.stepping = cpu->stepping; - errcode = pt_cpu_errata (&config.errata, &config.cpu); - if (errcode < 0) - error (_("Failed to configure the Intel Processor Trace decoder: %s."), - pt_errstr (pt_errcode (errcode))); + errcode = pt_cpu_errata (&config.errata, &config.cpu); + if (errcode < 0) + error (_("Failed to configure the Intel Processor Trace " + "decoder: %s."), pt_errstr (pt_errcode (errcode))); + } decoder = pt_pkt_alloc_decoder (&config); if (decoder == NULL) |