From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nx207.node01.secure-mailgate.com (nx207.node01.secure-mailgate.com [89.22.108.207]) by sourceware.org (Postfix) with ESMTPS id C752A3857C63 for ; Sat, 10 Apr 2021 21:17:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C752A3857C63 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=trande.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zied.guermazi@trande.de Received: from host202.checkdomain.de ([185.137.168.148]) by node01.secure-mailgate.com with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1lVKzN-00ER5H-5q for gdb-patches@sourceware.org; Sat, 10 Apr 2021 23:17:57 +0200 X-SecureMailgate-Identity: zied.guermazi@trande.de;host202.checkdomain.de Received: from Trande0001.fritz.box (x4db55ac6.dyn.telefonica.de [77.181.90.198]) (Authenticated sender: zied.guermazi@trande.de) by host202.checkdomain.de (Postfix) with ESMTPSA id 7CC4B39031F; Sat, 10 Apr 2021 23:17:56 +0200 (CEST) X-SecureMailgate-Identity: zied.guermazi@trande.de;host202.checkdomain.de From: Zied Guermazi To: gdb-patches@sourceware.org Cc: Zied Guermazi Subject: [PATCH v4 6/7] add support for coresight btrace via remote protocol Date: Sat, 10 Apr 2021 23:17:43 +0200 Message-Id: <20210410211744.7662-7-zied.guermazi@trande.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210410211744.7662-1-zied.guermazi@trande.de> References: <20210410211744.7662-1-zied.guermazi@trande.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-PPP-Message-ID: <20210410211756.2587323.31458@host202.checkdomain.de> X-PPP-Vhost: trande.de X-Originating-IP: 185.137.168.148 X-SecureMailgate-Domain: host202.checkdomain.de X-SecureMailgate-Username: 185.137.168.148 Authentication-Results: secure-mailgate.com; auth=pass smtp.auth=185.137.168.148@host202.checkdomain.de X-SecureMailgate-Outgoing-Class: ham X-SecureMailgate-Outgoing-Evidence: SB/global_tokens (0.00436961948126) X-Recommended-Action: accept X-Filter-ID: Pt3MvcO5N4iKaDQ5O6lkdGlMVN6RH8bjRMzItlySaT9Pj7P5c5Sb5O7eTr8ZqNucPUtbdvnXkggZ 3YnVId/Y5jcf0yeVQAvfjHznO7+bT5wgSQOko5ya3orWH1MkzQXa2oPZqVS5i0KNMNtVCi0tRw/C h5SE4jAyhe1COeASyU9Cn5CeFR9tA/fMgdsLtKlU4ld5rdi2ZxohSIq+dqifZoVY3IcDeckxfee+ NDQ6wUl3g/WbBekzB3IK8RY7uNAEcY1i02TJefD768F5oV2iM8C0xB8SW32wy2mbLZXD/P+t8ebU KGAHl/zKrzp4ep5Out5PpkrBQueV+Yg5wqLK/DPxZnad5mPqz8E0hUQw3qwLMK9HC+pUQBAyR03+ Yzd8ARsynxDH0D+SLDJWdESXziw50BoEYB44qFPH6be8XgtMhiMRK0C70oXENkWqJaNtpfX1h/uL cDQJCG2naSen4S0KEAnwyE9dte+FkDKSV99EDBffVZVjmVaNbG4ZJG7F2RgQw3d3zmVen9wp80qQ nk5/t+UnI24Hleg6UWHjmGlvyMjbyNpr4xR6RL2C9+qlIny++hg9dJLqN5zmWqF/oNe6FVV7drXD mtOldfpWzeXX3Vs0+OVZ6o01Ur0UfsSgVqahaS1Xn3nbmTfiR5jKRrn6qQ/in5NA6oG3bP7L0DnU JleWftUulkbC12DciiOUAQy3WRoWhjJ4ABRp4spTBKsH/WzE78WB+6LKJkk4wWAos7Vk+4I720v2 H9/mQnco6do4wvfNMSsfBzHuYol+ApWKHr6EtwoK04gIiWNLbShFXdcOXXm38/++NKnQrU/tOnYQ psOL3D4WKYPb9hiQqsMR3pimW+H6hrLs7bihM+ep7Sq+vnK5vq335GkOmYDoHPDsFqo1t5bEBI0m 4NsB3v57rn7svr0CR7c5hAqOktwf0pFELgZzpj7YZ1nZbFwm7/tfZJUk3rS7RIYmQhr7cDwJWw42 swm4bO6gacpMpzI93NKmpOx249IDJgHZhSqYgJJFthw94zyDVRbqPxaxhXoarW2MF3gazIzgmJi5 UydShOH22SRgbHWq1uciMDoDhcd9NG1JDoOknqc6qrb4AiZPF6HXPq5gLm4Q4ElmvUALMK9HC+pU QBAyR03+Yzd87yCUgX8YuF5WBQr1Bq861zvA3BXN5HBbApl4eIrLaWewxjLyThsLecb51qdaSQev MS+4ayUpOtEhdxekWDmK9g== X-Report-Abuse-To: spam@node04.secure-mailgate.com X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Apr 2021 21:18:03 -0000 This patch extends the remote protocol to use ARM CoreSight traces for btrace. This patch adds the capabilities enumeration as well as the required protocol extentions for configuring traces collection, starting and stopping tracing, and transferring the traces as well as the parameters needed for decoding them. gdb/ChangeLog * NEWS: list new remote packets for extending btrace to support using ARM CoreSight Traces. * btrace.c (check_xml_btrace_version): add version 1.1 (parse_xml_btrace_etm_config_source_config_cpu_etmv4_config): New. (parse_xml_btrace_etm_config_source_config_cpu_etmv3_config): New. (parse_xml_btrace_etm_config_source_config_cpu_etm_config): New. (parse_xml_btrace_etm_config_source_config): New. (parse_xml_btrace_etm_config_source_config_end): New (parse_xml_btrace_etm_config_sink_config): New. (parse_xml_btrace_etm_raw): New. (parse_xml_btrace_etm): New. (parse_xml_btrace_conf_etm): New. * btrace.dtd: add etm data and decoding parameters. * btrace-conf.dtd: add etm configuration. * remote.c (remote_target::btrace_sync_conf): add etm configuration. (remote_target::remote_btrace_maybe_reopen): warn if ETM was disabled. (remote_target::enable_btrace): add coresight etm. (_initialize_remote): add etm related packets. gdb/doc/ChangeLog * gdb.texinfo (General Query Packets) Document extending GDB remote protocol packets to support using ARM CoreSight traces for btrace. gdbserver/ChangeLog * configure.srv: add btrace for aarch64*-*-linux* and arm*-*-linux*. * linux-low.c (linux_low_encode_etm_config): New. (linux_process_target::read_btrace): encode CoreSight traces and related decoding parameters. (linux_process_target::read_btrace_conf): encode CoreSight configuration. * server.cc (handle_btrace_enable_etm): New. (handle_btrace_general_set): add etm handling. (handle_btrace_conf_general_set): add etm handling. (supported_btrace_packets): add etm related packets. --- gdb/NEWS | 14 ++ gdb/btrace.c | 366 ++++++++++++++++++++++++++++++++++- gdb/doc/gdb.texinfo | 64 ++++++ gdb/features/btrace-conf.dtd | 10 +- gdb/features/btrace.dtd | 38 +++- gdb/remote.c | 66 ++++++- gdbserver/configure.srv | 4 + gdbserver/linux-low.cc | 100 +++++++++- gdbserver/server.cc | 34 +++- 9 files changed, 688 insertions(+), 8 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 0dbd89eb360..0c31af6ed0b 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -114,6 +114,20 @@ maintenance info sections ARM Symbian arm*-*-symbianelf* +* New remote packets + +Qbtrace:etm + Enable ARM CoreSight ETM Trace-based branch tracing for the current + process. The remote stub reports support for this packet to GDB's + qSupported query. + +Qbtrace-conf:etm:size + Set the requested ring buffer size for branch tracing in + ARM CoreSight ETM Trace format. + +Qbtrace-conf:etm:sink + Set the trace sink for branch tracing in ARM CoreSight ETM Trace format. + *** Changes in GDB 10 * There are new feature names for ARC targets: "org.gnu.gdb.arc.core" diff --git a/gdb/btrace.c b/gdb/btrace.c index 869f57721df..cb76ed34645 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -2611,7 +2611,7 @@ check_xml_btrace_version (struct gdb_xml_parser *parser, const char *version = (const char *) xml_find_attribute (attributes, "version")->value.get (); - if (strcmp (version, "1.0") != 0) + if ((strcmp (version, "1.0") != 0) && (strcmp (version, "1.1") != 0)) gdb_xml_error (parser, _("Unsupported btrace version: \"%s\""), version); } @@ -2746,6 +2746,251 @@ parse_xml_btrace_pt (struct gdb_xml_parser *parser, btrace->variant.pt.size = 0; } +/* Parse a btrace etm "cpu-etm-config-etmv4_config" xml record. */ + +static void +parse_xml_btrace_etm_config_source_config_cpu_etmv4_config ( + struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + cs_etm_trace_params *etm_trace_params; + + DEBUG ("parse_xml_btrace_etm_config_source_config_cpu_etmv4_config"); + + btrace = (struct btrace_data *) user_data; + etm_trace_params = & (btrace->variant.etm.config.etm_trace_params->back ()); + + struct gdb_xml_value *reg_idr0; + reg_idr0 + = xml_find_attribute (attributes, "reg_idr0"); + + struct gdb_xml_value *reg_idr1; + reg_idr1 + = xml_find_attribute (attributes, "reg_idr1"); + + struct gdb_xml_value *reg_idr2; + reg_idr2 + = xml_find_attribute (attributes, "reg_idr2"); + + struct gdb_xml_value *reg_idr8; + reg_idr8 + = xml_find_attribute (attributes, "reg_idr8"); + + struct gdb_xml_value *reg_configr; + reg_configr + = xml_find_attribute (attributes, "reg_configr"); + + struct gdb_xml_value *reg_traceidr; + reg_traceidr + = xml_find_attribute (attributes, "reg_traceidr"); + + etm_trace_params->etmv4.reg_idr0 + = (unsigned int) *(ULONGEST *) reg_idr0->value.get (); + etm_trace_params->etmv4.reg_idr1 + = (unsigned int) *(ULONGEST *) reg_idr1->value.get (); + etm_trace_params->etmv4.reg_idr2 + = (unsigned int) *(ULONGEST *) reg_idr2->value.get (); + etm_trace_params->etmv4.reg_idr8 + = (unsigned int) *(ULONGEST *) reg_idr8->value.get (); + etm_trace_params->etmv4.reg_configr + = (unsigned int) *(ULONGEST *) reg_configr->value.get (); + etm_trace_params->etmv4.reg_traceidr + = (unsigned int) *(ULONGEST *) reg_traceidr->value.get (); + +} + +/* Parse a btrace etm "cpu-etm-config-etmv3_config" xml record. */ + +static void +parse_xml_btrace_etm_config_source_config_cpu_etmv3_config ( + struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + cs_etm_trace_params *etm_trace_params; + + DEBUG ("parse_xml_btrace_etm_config_source_config_cpu_etmv3_config"); + + btrace = (struct btrace_data *) user_data; + etm_trace_params = & (btrace->variant.etm.config.etm_trace_params->back ()); + + struct gdb_xml_value *reg_ctrl; + reg_ctrl + = xml_find_attribute (attributes, "reg_ctrl"); + + struct gdb_xml_value *reg_trc_id; + reg_trc_id + = xml_find_attribute (attributes, "reg_trc_id"); + + struct gdb_xml_value *reg_ccer; + reg_ccer + = xml_find_attribute (attributes, "reg_ccer"); + + struct gdb_xml_value *reg_idr; + reg_idr + = xml_find_attribute (attributes, "reg_idr"); + + etm_trace_params->etmv3.reg_ctrl + = (unsigned int) *(ULONGEST *) reg_ctrl->value.get (); + etm_trace_params->etmv3.reg_trc_id + = (unsigned int) *(ULONGEST *) reg_trc_id->value.get (); + etm_trace_params->etmv3.reg_ccer + = (unsigned int) *(ULONGEST *) reg_ccer->value.get (); + etm_trace_params->etmv3.reg_idr + = (unsigned int) *(ULONGEST *) reg_idr->value.get (); +} + + +/* Parse a btrace etm "cpu-etm-config" xml record. */ + +static void +parse_xml_btrace_etm_config_source_config_cpu_etm_config ( + struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + cs_etm_trace_params etm_trace_params; + + DEBUG ("parse_xml_btrace_etm_config_source_config_cpu_etm_config"); + + btrace = (struct btrace_data *) user_data; + + struct gdb_xml_value *arch_ver; + arch_ver + = xml_find_attribute (attributes, "arch_ver"); + + struct gdb_xml_value *core_prof; + core_prof + = xml_find_attribute (attributes, "core_prof"); + + struct gdb_xml_value *protocol; + protocol + = xml_find_attribute (attributes, "protocol"); + + etm_trace_params.arch_ver = (int) *(ULONGEST *) arch_ver->value.get (); + etm_trace_params.core_profile = (int) *(ULONGEST *) core_prof->value.get (); + etm_trace_params.protocol = (int) *(ULONGEST *) protocol->value.get (); + + btrace->variant.etm.config.etm_trace_params->push_back (etm_trace_params); +} + +/* Parse a btrace etm "source-config" xml record. */ + +static void +parse_xml_btrace_etm_config_source_config (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + struct gdb_xml_value *trace_id; + + DEBUG ("parse_xml_btrace_etm_config_source_config"); + btrace = (struct btrace_data *) user_data; + + trace_id = xml_find_attribute (attributes, "trace_id"); + if (trace_id != NULL) + btrace->variant.etm.trace_id + = (unsigned int) *(ULONGEST *) trace_id->value.get (); + btrace->variant.etm.config.etm_trace_params + = new std::vector; +} + +/* Get the number of cpus. */ + +static void +parse_xml_btrace_etm_config_source_config_end (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, const char *body_text) +{ + struct btrace_data *btrace; + + DEBUG ("parse_xml_btrace_etm_config_source_config_end"); + btrace = (struct btrace_data *) user_data; + + btrace->variant.etm.config.cpu_count + = btrace->variant.etm.config.etm_trace_params->size (); +} + +/* Parse a btrace etm "sink-config" xml record. */ + +static void +parse_xml_btrace_etm_config_sink_config (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + + DEBUG ("parse_xml_btrace_etm_config_sink_config"); + + btrace = (struct btrace_data *) user_data; + + struct gdb_xml_value *formatted; + formatted = xml_find_attribute (attributes, "formatted"); + + struct gdb_xml_value *fsyncs; + fsyncs = xml_find_attribute (attributes, "fsyncs"); + + struct gdb_xml_value *hsyncs; + hsyncs = xml_find_attribute (attributes, "hsyncs"); + + struct gdb_xml_value *frame_aligned; + frame_aligned = xml_find_attribute (attributes, "frame_aligned"); + + struct gdb_xml_value *reset_on_4x_sync; + reset_on_4x_sync = xml_find_attribute (attributes, "reset_on_4x_sync"); + + btrace->variant.etm.config.etm_decoder_params.formatted + = (uint8_t) *(ULONGEST *) formatted->value.get (); + btrace->variant.etm.config.etm_decoder_params.fsyncs + = (uint8_t) *(ULONGEST *) fsyncs->value.get (); + btrace->variant.etm.config.etm_decoder_params.hsyncs + = (uint8_t) *(ULONGEST *) hsyncs->value.get (); + btrace->variant.etm.config.etm_decoder_params.frame_aligned + = (uint8_t) *(ULONGEST *) frame_aligned->value.get (); + btrace->variant.etm.config.etm_decoder_params.reset_on_4x_sync + = (uint8_t) *(ULONGEST *) reset_on_4x_sync->value.get (); +} + + +/* Parse a btrace etm "raw" xml record. */ + +static void +parse_xml_btrace_etm_raw (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, const char *body_text) +{ + struct btrace_data *btrace; + DEBUG ("parse_xml_btrace_etm_raw"); + btrace = (struct btrace_data *) user_data; + parse_xml_raw (parser, body_text, &btrace->variant.etm.data, + &btrace->variant.etm.size); +} + +/* Parse a btrace "etm" xml record. */ + +static void +parse_xml_btrace_etm (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + struct btrace_data *btrace; + DEBUG ("parse_xml_btrace_etm"); + btrace = (struct btrace_data *) user_data; + btrace->format = BTRACE_FORMAT_ETM; + btrace->variant.etm.data = NULL; + btrace->variant.etm.size = 0; +} + static const struct gdb_xml_attribute block_attributes[] = { { "begin", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, { "end", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, @@ -2773,6 +3018,91 @@ static const struct gdb_xml_element btrace_pt_children[] = { { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } }; +static const struct gdb_xml_attribute +btrace_etm_config_source_config_cpu_config_etmv3_config_attributes[] = { + { "reg_ctrl", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_trc_id", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_ccer", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_idr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_attribute +btrace_etm_config_source_config_cpu_config_etmv4_config_attributes[] = { + { "reg_idr0", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_idr1", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_idr2", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_idr8", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_configr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reg_traceidr", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element +btrace_etm_config_source_config_cpu_etm_config_children[] = { + { "etmv3-config", + btrace_etm_config_source_config_cpu_config_etmv3_config_attributes, + NULL, GDB_XML_EF_OPTIONAL, + parse_xml_btrace_etm_config_source_config_cpu_etmv3_config, NULL }, + { "etmv4-config", + btrace_etm_config_source_config_cpu_config_etmv4_config_attributes, + NULL, GDB_XML_EF_OPTIONAL, + parse_xml_btrace_etm_config_source_config_cpu_etmv4_config, NULL }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_attribute +btrace_etm_config_source_config_etm_config_attributes[] = { + { "cpu_id", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "arch_ver", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "core_prof", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "protocol", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element +btrace_etm_config_source_config_children[] = { + { "cpu-etm-config", btrace_etm_config_source_config_etm_config_attributes, + btrace_etm_config_source_config_cpu_etm_config_children, + GDB_XML_EF_REPEATABLE, + parse_xml_btrace_etm_config_source_config_cpu_etm_config, NULL }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_attribute +btrace_etm_config_sink_config_attributes[] = { + { "formatted", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "fsyncs", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "hsyncs", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "frame_aligned", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "reset_on_4x_sync", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_attribute +btrace_etm_config_source_config_attributes[] = { + { "trace_id", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element btrace_etm_config_children[] = { + { "source-config", btrace_etm_config_source_config_attributes, + btrace_etm_config_source_config_children, GDB_XML_EF_NONE, + parse_xml_btrace_etm_config_source_config, + parse_xml_btrace_etm_config_source_config_end }, + { "sink-config", btrace_etm_config_sink_config_attributes, NULL, + GDB_XML_EF_NONE, parse_xml_btrace_etm_config_sink_config, NULL }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element btrace_etm_children[] = { + { "etm-config", NULL, btrace_etm_config_children, GDB_XML_EF_NONE, NULL, + NULL }, + { "raw", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, + parse_xml_btrace_etm_raw }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + static const struct gdb_xml_attribute btrace_attributes[] = { { "version", GDB_XML_AF_NONE, NULL, NULL }, { NULL, GDB_XML_AF_NONE, NULL, NULL } @@ -2783,6 +3113,8 @@ static const struct gdb_xml_element btrace_children[] = { GDB_XML_EF_REPEATABLE | GDB_XML_EF_OPTIONAL, parse_xml_btrace_block, NULL }, { "pt", NULL, btrace_pt_children, GDB_XML_EF_OPTIONAL, parse_xml_btrace_pt, NULL }, + { "etm", NULL, btrace_etm_children, GDB_XML_EF_OPTIONAL, + parse_xml_btrace_etm, NULL }, { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } }; @@ -2863,6 +3195,30 @@ parse_xml_btrace_conf_pt (struct gdb_xml_parser *parser, conf->pt.size = (unsigned int) *(ULONGEST *) size->value.get (); } +/* Parse a btrace-conf "etm" xml record. */ + +static void +parse_xml_btrace_conf_etm (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + std::vector &attributes) +{ + DEBUG ("parse_xml_btrace_conf_etm"); + + struct btrace_config *conf = (struct btrace_config *) user_data; + conf->format = BTRACE_FORMAT_ETM; + conf->etm.size = 0; + + struct gdb_xml_value *size = xml_find_attribute (attributes, "size"); + if (size != nullptr) + conf->etm.size = (unsigned int) *(ULONGEST *) size->value.get (); + + struct gdb_xml_value *sink; + sink = xml_find_attribute (attributes, "sink"); + if (sink != nullptr) + conf->etm.sink = (char*) sink->value.get (); +} + static const struct gdb_xml_attribute btrace_conf_pt_attributes[] = { { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL }, { NULL, GDB_XML_AF_NONE, NULL, NULL } @@ -2873,11 +3229,19 @@ static const struct gdb_xml_attribute btrace_conf_bts_attributes[] = { { NULL, GDB_XML_AF_NONE, NULL, NULL } }; +static const struct gdb_xml_attribute btrace_conf_etm_attributes[] = { + { "size", GDB_XML_AF_OPTIONAL, gdb_xml_parse_attr_ulongest, NULL }, + { "sink", GDB_XML_AF_OPTIONAL, NULL, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + static const struct gdb_xml_element btrace_conf_children[] = { { "bts", btrace_conf_bts_attributes, NULL, GDB_XML_EF_OPTIONAL, parse_xml_btrace_conf_bts, NULL }, { "pt", btrace_conf_pt_attributes, NULL, GDB_XML_EF_OPTIONAL, parse_xml_btrace_conf_pt, NULL }, + { "etm", btrace_conf_etm_attributes, NULL, GDB_XML_EF_OPTIONAL, + parse_xml_btrace_conf_etm, NULL }, { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } }; diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index bd5b2c91869..709b4e4f09d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41708,6 +41708,21 @@ These are the currently defined stub features and their properties: @tab @samp{-} @tab No +@item @samp{Qbtrace:etm} +@tab Yes +@tab @samp{-} +@tab Yes + +@item @samp{Qbtrace-conf:etm:size} +@tab Yes +@tab @samp{-} +@tab Yes + + +@item @samp{Qbtrace-conf:etm:sink} +@tab Yes +@tab @samp{-} +@tab Yes @end multitable These are the currently defined stub features, in more detail: @@ -41884,9 +41899,11 @@ The remote stub understands the @samp{Qbtrace:off} packet. @item Qbtrace:bts The remote stub understands the @samp{Qbtrace:bts} packet. +(@pxref{bts}). @item Qbtrace:pt The remote stub understands the @samp{Qbtrace:pt} packet. +(@pxref{pt}). @item Qbtrace-conf:bts:size The remote stub understands the @samp{Qbtrace-conf:bts:size} packet. @@ -41922,6 +41939,16 @@ The remote stub understands the @samp{QThreadEvents} packet. @item no-resumed The remote stub reports the @samp{N} stop reply. +@item Qbtrace:etm +The remote stub understands the @samp{Qbtrace:etm} packet. +(@pxref{etm}). + +@item Qbtrace-conf:etm:size +The remote stub understands the @samp{Qbtrace-conf:etm:size} packet. + +@item Qbtrace-conf:etm:sink +The remote stub understands the @samp{Qbtrace-conf:etm:sink} packet. + @end table @item qSymbol:: @@ -42328,6 +42355,7 @@ A badly formed request or an error was encountered. @end table @item Qbtrace:bts +@anchor{bts} Enable branch tracing for the current thread using Branch Trace Store. Reply: @@ -42339,6 +42367,7 @@ A badly formed request or an error was encountered. @end table @item Qbtrace:pt +@anchor{pt} Enable branch tracing for the current thread using Intel Processor Trace. Reply: @@ -42384,6 +42413,41 @@ The ring buffer size has been set. A badly formed request or an error was encountered. @end table +@item Qbtrace:etm +@anchor{etm} +Enable branch tracing for the current thread using ARM CoreSight ETM Trace. + +Reply: +@table @samp +@item OK +Branch tracing has been enabled. +@item E.errtext +A badly formed request or an error was encountered. +@end table + +@item Qbtrace-conf:etm:size=@var{value} +Set the requested ring buffer size for new threads that use the +btrace recording method in etm format. + +Reply: +@table @samp +@item OK +The ring buffer size has been set. +@item E.errtext +A badly formed request or an error was encountered. +@end table + +@item Qbtrace-conf:etm:sink=@var{value} +Set the requested trace sink for new threads that use the +btrace recording method in etm format. + +Reply: +@table @samp +@item OK +The ring buffer size has been set. +@item E.errtext +A badly formed request or an error was encountered. +@end table @end table @node Architecture-Specific Protocol Details diff --git a/gdb/features/btrace-conf.dtd b/gdb/features/btrace-conf.dtd index 4b060bb408c..7334d035f34 100644 --- a/gdb/features/btrace-conf.dtd +++ b/gdb/features/btrace-conf.dtd @@ -4,11 +4,17 @@ are permitted in any medium without royalty provided the copyright notice and this notice are preserved. --> - - + + + + + diff --git a/gdb/features/btrace.dtd b/gdb/features/btrace.dtd index 9bb930d7d3b..001b77f35d0 100644 --- a/gdb/features/btrace.dtd +++ b/gdb/features/btrace.dtd @@ -4,8 +4,8 @@ are permitted in any medium without royalty provided the copyright notice and this notice are preserved. --> - - + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb/remote.c b/gdb/remote.c index 2c85bdcffbc..e6f0aeceb11 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -2167,6 +2167,15 @@ enum { /* Support TARGET_WAITKIND_NO_RESUMED. */ PACKET_no_resumed, + /* Support for the Qbtrace-etm packet. */ + PACKET_Qbtrace_etm, + + /* Support for the Qbtrace-conf:etm:size packet. */ + PACKET_Qbtrace_conf_etm_size, + + /* Support for the Qbtrace-conf:etm:sink packet. */ + PACKET_Qbtrace_conf_etm_sink, + PACKET_MAX }; @@ -5302,6 +5311,12 @@ static const struct protocol_feature remote_protocol_features[] = { { "vContSupported", PACKET_DISABLE, remote_supported_packet, PACKET_vContSupported }, { "QThreadEvents", PACKET_DISABLE, remote_supported_packet, PACKET_QThreadEvents }, { "no-resumed", PACKET_DISABLE, remote_supported_packet, PACKET_no_resumed }, + { "Qbtrace:etm", PACKET_DISABLE, remote_supported_packet, + PACKET_Qbtrace_etm }, + { "Qbtrace-conf:etm:size", PACKET_DISABLE, remote_supported_packet, + PACKET_Qbtrace_conf_etm_size }, + { "Qbtrace-conf:etm:sink", PACKET_DISABLE, remote_supported_packet, + PACKET_Qbtrace_conf_etm_sink }, }; static char *remote_support_xml; @@ -13882,6 +13897,28 @@ remote_target::btrace_sync_conf (const btrace_config *conf) rs->btrace_config.pt.size = conf->pt.size; } + + packet = &remote_protocol_packets[PACKET_Qbtrace_conf_etm_size]; + if (packet_config_support (packet) == PACKET_ENABLE + && conf->etm.size != rs->btrace_config.etm.size) + { + pos = buf; + pos += xsnprintf (pos, endbuf - pos, "%s=0x%x", packet->name, + conf->etm.size); + + putpkt (buf); + getpkt (&rs->buf, 0); + + if (packet_ok (buf, packet) == PACKET_ERROR) + { + if (buf[0] == 'E' && buf[1] == '.') + error (_("Failed to configure the trace buffer size: %s"), buf + 2); + else + error (_("Failed to configure the trace buffer size.")); + } + + rs->btrace_config.etm.size = conf->etm.size; + } } /* Read the current thread's btrace configuration from the target and @@ -13903,7 +13940,7 @@ remote_target::remote_btrace_maybe_reopen () { struct remote_state *rs = get_remote_state (); int btrace_target_pushed = 0; -#if !defined (HAVE_LIBIPT) +#if !defined (HAVE_LIBIPT) || !defined (HAVE_LIBOPENCSD_C_API) int warned = 0; #endif @@ -13938,6 +13975,20 @@ remote_target::remote_btrace_maybe_reopen () } #endif /* !defined (HAVE_LIBIPT) */ +#if !defined (HAVE_LIBOPENCSD_C_API) + if (rs->btrace_config.format == BTRACE_FORMAT_ETM) + { + if (!warned) + { + warned = 1; + warning (_("Target is recording using ARM CoreSight Processor " + "Trace but support was disabled at compile time.")); + } + + continue; + } +#endif /* !defined (HAVE_LIBOPENCSD_C_API) */ + /* Push target, once, but before anything else happens. This way our changes to the threads will be cleaned up by unpushing the target in case btrace_read_config () throws. */ @@ -13975,6 +14026,10 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf) case BTRACE_FORMAT_PT: packet = &remote_protocol_packets[PACKET_Qbtrace_pt]; break; + + case BTRACE_FORMAT_ETM: + packet = &remote_protocol_packets[PACKET_Qbtrace_etm]; + break; } if (packet == NULL || packet_config_support (packet) != PACKET_ENABLE) @@ -14883,6 +14938,15 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (&remote_protocol_packets[PACKET_no_resumed], "N stop reply", "no-resumed-stop-reply", 0); + add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_etm], + "Qbtrace:etm", "enable-btrace-etm", 0); + + add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_conf_etm_size], + "Qbtrace-conf:etm:size", "btrace-conf-etm-size", 0); + + add_packet_config_cmd (&remote_protocol_packets[PACKET_Qbtrace_conf_etm_sink], + "Qbtrace-conf:etm:sink", "btrace-conf-etm-sink", 0); + /* Assert that we've registered "set remote foo-packet" commands for all packet configs. */ { diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv index 833ad27c4c4..5f900d80d66 100644 --- a/gdbserver/configure.srv +++ b/gdbserver/configure.srv @@ -54,12 +54,14 @@ case "${gdbserver_host}" in srv_tgtobj="$srv_tgtobj arch/aarch64.o" srv_tgtobj="$srv_tgtobj linux-aarch64-tdesc.o" srv_tgtobj="$srv_tgtobj nat/aarch64-sve-linux-ptrace.o" + srv_tgtobj="${srv_tgtobj} nat/linux-btrace.o" srv_tgtobj="${srv_tgtobj} $srv_linux_obj" srv_linux_regsets=yes srv_linux_thread_db=yes ipa_obj="linux-aarch64-ipa.o" ipa_obj="${ipa_obj} linux-aarch64-tdesc-ipa.o" ipa_obj="${ipa_obj} arch/aarch64-ipa.o" + srv_linux_btrace=yes ;; aarch64*-*-netbsd*) srv_regobj="" srv_tgtobj="netbsd-low.o netbsd-aarch64-low.o fork-child.o" @@ -82,6 +84,7 @@ case "${gdbserver_host}" in srv_tgtobj="$srv_tgtobj linux-arm-tdesc.o" srv_tgtobj="$srv_tgtobj linux-aarch32-low.o" srv_tgtobj="$srv_tgtobj linux-aarch32-tdesc.o" + srv_tgtobj="${srv_tgtobj} nat/linux-btrace.o" srv_tgtobj="${srv_tgtobj} arch/aarch32.o" srv_tgtobj="${srv_tgtobj} arch/arm.o" srv_tgtobj="${srv_tgtobj} arch/arm-linux.o" @@ -89,6 +92,7 @@ case "${gdbserver_host}" in srv_linux_usrregs=yes srv_linux_regsets=yes srv_linux_thread_db=yes + srv_linux_btrace=yes ;; i[34567]86-*-cygwin*) srv_regobj="" srv_tgtobj="x86-low.o nat/x86-dregs.o win32-low.o" diff --git a/gdbserver/linux-low.cc b/gdbserver/linux-low.cc index 0baac013129..05eb0afd7ff 100644 --- a/gdbserver/linux-low.cc +++ b/gdbserver/linux-low.cc @@ -51,6 +51,9 @@ #include "gdbsupport/environ.h" #include "gdbsupport/gdb-sigmask.h" #include "gdbsupport/scoped_restore.h" +#if defined (HAVE_LIBOPENCSD_C_API) +# include +#endif #ifndef ELFMAG0 /* Don't include here. If it got included by gdb_proc_service.h then ELFMAG0 will have been defined. If it didn't get included by @@ -6994,6 +6997,73 @@ linux_low_encode_pt_config (struct buffer *buffer, buffer_grow_str (buffer, "\n"); } +/* Encode ARM CoreSight Processor Trace configuration. */ + +static void +linux_low_encode_etm_config (struct buffer *buffer, + const struct btrace_data_etm_config *config) +{ + int architecture; + buffer_grow_str (buffer, "\n"); + buffer_grow_str (buffer, "\n"); + for (int i=0; i< config->cpu_count;i++) + { + if ((config->etm_trace_params->at (i).protocol == OCSD_PROTOCOL_ETMV3) + ||(config->etm_trace_params->at (i).protocol == OCSD_PROTOCOL_PTM)) + { + architecture = ARCH_V7; + } + else if (config->etm_trace_params->at (i).protocol == OCSD_PROTOCOL_ETMV4I) + { + architecture = ARCH_V8; + } + else + { + architecture = ARCH_UNKNOWN; + } + + buffer_xml_printf (buffer,"\n", + architecture, profile_CortexA, + i, config->etm_trace_params->at (i).protocol); + if (architecture == ARCH_V7) + { + buffer_xml_printf (buffer, + "\n", + config->etm_trace_params->at (i).etmv3.reg_idr, + config->etm_trace_params->at (i).etmv3.reg_ctrl, + config->etm_trace_params->at (i).etmv3.reg_ccer, + config->etm_trace_params->at (i).etmv3.reg_trc_id); + } + if (architecture == ARCH_V8) + { + buffer_xml_printf (buffer, + "\n", + config->etm_trace_params->at (i).etmv4.reg_idr0, + config->etm_trace_params->at (i).etmv4.reg_idr1, + config->etm_trace_params->at (i).etmv4.reg_idr2, + config->etm_trace_params->at (i).etmv4.reg_idr8, + config->etm_trace_params->at (i).etmv4.reg_configr, + config->etm_trace_params->at (i).etmv4.reg_traceidr); + } + buffer_xml_printf (buffer,"\n"); + } + buffer_grow_str (buffer,"\n"); + buffer_xml_printf (buffer, + "\n", + config->etm_decoder_params.formatted, + config->etm_decoder_params.fsyncs, + config->etm_decoder_params.hsyncs, + config->etm_decoder_params.frame_aligned, + config->etm_decoder_params.reset_on_4x_sync); + buffer_grow_str (buffer,"\n"); +} + /* Encode a raw buffer. */ static void @@ -7071,6 +7141,20 @@ linux_process_target::read_btrace (btrace_target_info *tinfo, buffer_grow_str0 (buffer, "\n"); break; + case BTRACE_FORMAT_ETM: + buffer_grow_str (buffer, "\n"); + buffer_grow_str (buffer, "\n"); + buffer_grow_str (buffer, "\n"); + + linux_low_encode_etm_config (buffer, &btrace.variant.etm.config); + + linux_low_encode_raw (buffer, btrace.variant.etm.data, + btrace.variant.etm.size); + + buffer_grow_str (buffer, "\n"); + buffer_grow_str0 (buffer, "\n"); + break; + default: buffer_grow_str0 (buffer, "E.Unsupported Trace Format."); return -1; @@ -7088,7 +7172,7 @@ linux_process_target::read_btrace_conf (const btrace_target_info *tinfo, const struct btrace_config *conf; buffer_grow_str (buffer, "\n"); - buffer_grow_str (buffer, "\n"); + buffer_grow_str (buffer, "\n"); conf = linux_btrace_conf (tinfo); if (conf != NULL) @@ -7109,6 +7193,20 @@ linux_process_target::read_btrace_conf (const btrace_target_info *tinfo, buffer_xml_printf (buffer, " size=\"0x%x\"", conf->pt.size); buffer_xml_printf (buffer, "/>\n"); break; + + case BTRACE_FORMAT_ETM: + buffer_xml_printf (buffer, "etm.size); + if (conf->etm.sink !=NULL) + { + buffer_xml_printf (buffer, " sink=\"%s\"", conf->etm.sink); + } + else + { + buffer_xml_printf (buffer, " sink=\"default\""); + } + buffer_xml_printf (buffer, "/>\n"); + break; } } diff --git a/gdbserver/server.cc b/gdbserver/server.cc index a5497e93cee..d270cf7d370 100644 --- a/gdbserver/server.cc +++ b/gdbserver/server.cc @@ -424,6 +424,18 @@ handle_btrace_enable_pt (struct thread_info *thread) thread->btrace = target_enable_btrace (thread->id, ¤t_btrace_conf); } +/* Handle btrace enabling in ARM CoreSight Trace format. */ + +static void +handle_btrace_enable_etm (struct thread_info *thread) +{ + if (thread->btrace != NULL) + error (_("Btrace already enabled.")); + + current_btrace_conf.format = BTRACE_FORMAT_ETM; + thread->btrace = target_enable_btrace (thread->id, ¤t_btrace_conf); +} + /* Handle btrace disabling. */ static void @@ -473,10 +485,12 @@ handle_btrace_general_set (char *own_buf) handle_btrace_enable_bts (thread); else if (strcmp (op, "pt") == 0) handle_btrace_enable_pt (thread); + else if (strcmp (op, "etm") == 0) + handle_btrace_enable_etm (thread); else if (strcmp (op, "off") == 0) handle_btrace_disable (thread); else - error (_("Bad Qbtrace operation. Use bts, pt, or off.")); + error (_("Bad Qbtrace operation. Use bts, pt, etm, or off.")); write_ok (own_buf); } @@ -546,6 +560,21 @@ handle_btrace_conf_general_set (char *own_buf) current_btrace_conf.pt.size = (unsigned int) size; } + else if (strncmp (op, "etm:size=", strlen ("etm:size=")) == 0) + { + unsigned long size; + char *endp = NULL; + + errno = 0; + size = strtoul (op + strlen ("etm:size="), &endp, 16); + if (endp == NULL || *endp != 0 || errno != 0 || size > UINT_MAX) + { + strcpy (own_buf, "E.Bad size value."); + return -1; + } + + current_btrace_conf.etm.size = (unsigned int) size; + } else { strcpy (own_buf, "E.Bad Qbtrace configuration option."); @@ -2084,6 +2113,9 @@ supported_btrace_packets (char *buf) strcat (buf, ";Qbtrace-conf:bts:size+"); strcat (buf, ";Qbtrace:pt+"); strcat (buf, ";Qbtrace-conf:pt:size+"); + strcat (buf, ";Qbtrace:etm+"); + strcat (buf, ";Qbtrace-conf:etm:size+"); + strcat (buf, ";Qbtrace-conf:etm:sink+"); strcat (buf, ";Qbtrace:off+"); strcat (buf, ";qXfer:btrace:read+"); strcat (buf, ";qXfer:btrace-conf:read+"); -- 2.25.1