From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nx205.node02.secure-mailgate.com (nx205.node02.secure-mailgate.com [192.162.87.205]) by sourceware.org (Postfix) with ESMTPS id 74AA93861828 for ; Thu, 11 Mar 2021 02:51:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 74AA93861828 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 node02.secure-mailgate.com with esmtps (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.92) (envelope-from ) id 1lKBPj-00BFkb-GN for gdb-patches@sourceware.org; Thu, 11 Mar 2021 03:51:04 +0100 X-SecureMailgate-Identity: host202.checkdomain.de Received: from Trande0001.fritz.box (x4db421df.dyn.telefonica.de [77.180.33.223]) (Authenticated sender: zied.guermazi@trande.de) by host202.checkdomain.de (Postfix) with ESMTPSA id E77332A35DB; Thu, 11 Mar 2021 03:51:02 +0100 (CET) X-SecureMailgate-Identity: host202.checkdomain.de From: Zied Guermazi To: gdb-patches@sourceware.org Cc: Zied Guermazi Subject: [PATCH v2 2/8] add btrace coresight related commands Date: Thu, 11 Mar 2021 03:50:33 +0100 Message-Id: <20210311025039.57112-3-zied.guermazi@trande.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210311025039.57112-1-zied.guermazi@trande.de> References: <20210311025039.57112-1-zied.guermazi@trande.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-PPP-Message-ID: <20210311025103.3191992.66627@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.000350370418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h9d13TvnYIJS 8uss0ueeSQv3iRNCdtD1uwyAKMADmSgTOnv22Aeeug8bgwJPDDg1BsZlJJwIRfFRTyc2vKtsh88u M6zHbDccOKMrUoTh9tkkYGx1qtbnIjA6A3MtdZ3kU7K9G0Sx0xT0TSw= X-Report-Abuse-To: spam@node04.secure-mailgate.com X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, 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: Thu, 11 Mar 2021 02:51:10 -0000 This patch extends the commands needed for using branch tracing with ARM CoreSight traces. Those commands are: set record btrace etm sink set record btrace etm buffer-size record btrace etm gdb/ChangeLog * record-btrace.c (record_btrace_print_etm_conf): New. (record_btrace_print_conf): handle BTRACE_FORMAT_ETM. (cmd_record_btrace_etm_start): New. (cmd_record_btrace_start): handle starting ETM tracing. (cmd_show_record_btrace_cpu): extend for ARM cpus. (show_record_etm_buffer_size_value): New. (_initialize_record_btrace): add commands for ETM traces. (record_start): add starting ETM traces. gdbsupport/ChangeLog * gdbsupport/btrace-common.h (btrace_format): add BTRACE_FORMAT_ETM to the enum. (btrace_cpu_vendor): add CV_ARM to the enum. (btrace_config_etm): new struct. (btrace_config): add btrace_config_etm etm. * gdbsupport/btrace-common.cc (btrace_format_string): add BTRACE_FORMAT_ETM. (btrace_format_short_string): add BTRACE_FORMAT_ETM. --- gdb/ChangeLog | 11 ++++ gdb/record-btrace.c | 118 +++++++++++++++++++++++++++++++++++- gdb/record.c | 2 + gdbsupport/ChangeLog | 10 +++ gdbsupport/btrace-common.cc | 7 +++ gdbsupport/btrace-common.h | 28 ++++++++- 6 files changed, 172 insertions(+), 4 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7178c30affb..a63fdfa1911 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,16 @@ 2021-02-25 Zied Guermazi + * record-btrace.c (record_btrace_print_etm_conf): New. + (record_btrace_print_conf): handle BTRACE_FORMAT_ETM. + (cmd_record_btrace_etm_start): New. + (cmd_record_btrace_start): handle starting ETM tracing. + (cmd_show_record_btrace_cpu): extend for ARM cpus. + (show_record_etm_buffer_size_value): New. + (_initialize_record_btrace): add commands for ETM traces. + * record.c (record_start): add starting ETM traces. + +2021-02-02 Zied Guermazi + * Makefile.in LIBOPENCSD_C_API: set the flag. * config.in LIBOPENCSD_C_API: undefine it if libopenocsd library is available. diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index d9cc7a3b6d8..4d6495d440d 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -201,6 +201,10 @@ static struct cmd_list_element *show_record_btrace_bts_cmdlist; static struct cmd_list_element *set_record_btrace_pt_cmdlist; static struct cmd_list_element *show_record_btrace_pt_cmdlist; +/* Command lists for "set/show record btrace etm". */ +static struct cmd_list_element *set_record_btrace_etm_cmdlist; +static struct cmd_list_element *show_record_btrace_etm_cmdlist; + /* Command list for "set record btrace cpu". */ static struct cmd_list_element *set_record_btrace_cpu_cmdlist; @@ -525,6 +529,22 @@ record_btrace_print_pt_conf (const struct btrace_config_pt *conf) } } +/* Print an ARM Processor Trace configuration. */ + +static void +record_btrace_print_etm_conf (const struct btrace_config_etm *conf) +{ + unsigned int size; + + size = conf->size; + if (size > 0) + { + const char *suffix; + suffix = record_btrace_adjust_size (&size); + printf_unfiltered (_("Buffer size: %u%s.\n"), size, suffix); + } +} + /* Print a branch tracing configuration. */ static void @@ -545,6 +565,10 @@ record_btrace_print_conf (const struct btrace_config *conf) case BTRACE_FORMAT_PT: record_btrace_print_pt_conf (&conf->pt); return; + + case BTRACE_FORMAT_ETM: + record_btrace_print_etm_conf (&conf->etm); + return; } internal_error (__FILE__, __LINE__, _("Unknown branch trace format.")); @@ -2675,7 +2699,7 @@ record_btrace_target::stop (ptid_t ptid) tp->btrace.flags |= BTHR_STOP; } } - } +} /* The can_execute_reverse method of target record-btrace. */ @@ -2936,6 +2960,27 @@ cmd_record_btrace_pt_start (const char *args, int from_tty) } } +/* Start recording in arm CoreSight ETM Trace format. */ + +static void +cmd_record_btrace_etm_start (const char *args, int from_tty) +{ + if (args != nullptr && *args != 0) + error (_("Invalid argument.")); + + record_btrace_conf.format = BTRACE_FORMAT_ETM; + + try + { + execute_command ("target record-btrace", from_tty); + } + catch (const gdb_exception &exception) + { + record_btrace_conf.format = BTRACE_FORMAT_NONE; + throw; + } +} + /* Alias for "target record". */ static void @@ -2950,10 +2995,18 @@ cmd_record_btrace_start (const char *args, int from_tty) { execute_command ("target record-btrace", from_tty); } - catch (const gdb_exception &exception) + catch (const gdb_exception &exception_pt) { record_btrace_conf.format = BTRACE_FORMAT_BTS; + try + { + execute_command ("target record-btrace", from_tty); + } + catch (const gdb_exception &exception_bts) + { + record_btrace_conf.format = BTRACE_FORMAT_ETM; + try { execute_command ("target record-btrace", from_tty); @@ -2964,8 +3017,10 @@ cmd_record_btrace_start (const char *args, int from_tty) throw; } } + } } + /* The "show record btrace replay-memory-access" command. */ static void @@ -3074,6 +3129,11 @@ cmd_show_record_btrace_cpu (const char *args, int from_tty) record_btrace_cpu.model, record_btrace_cpu.stepping); return; + + case CV_ARM: + printf_unfiltered ("btrace cpu is 'ARM'.\n"); + + return; } } @@ -3102,6 +3162,17 @@ show_record_pt_buffer_size_value (struct ui_file *file, int from_tty, value); } +/* The "record etm buffer-size" show value function. */ + +static void +show_record_etm_buffer_size_value (struct ui_file *file, int from_tty, + struct cmd_list_element *c, + const char *value) +{ + fprintf_filtered (file, _("The record/replay etm buffer size is %s.\n"), + value); +} + /* Initialize btrace commands. */ void _initialize_record_btrace (); @@ -3165,6 +3236,13 @@ When set to \"none\", errata workarounds are disabled."), "set record btrace cpu ", 1, &set_record_btrace_cmdlist); + add_cmd ("etm", class_obscure, cmd_record_btrace_etm_start, + _("\ +Start branch trace recording in ARM CoreSight ETM Trace format.\n\n\ +This format may not be available on all processors."), + &record_btrace_cmdlist); + add_alias_cmd ("etm", "btrace etm", class_obscure, 1, &record_cmdlist); + add_cmd ("auto", class_support, cmd_set_record_btrace_cpu_auto, _("\ Automatically determine the cpu to be used for trace decode."), &set_record_btrace_cpu_cmdlist); @@ -3226,6 +3304,41 @@ to see the actual buffer size."), NULL, show_record_pt_buffer_size_value, &set_record_btrace_pt_cmdlist, &show_record_btrace_pt_cmdlist); + add_basic_prefix_cmd ("etm", class_support, + _("Set record btrace etm options."), + &set_record_btrace_etm_cmdlist, + "set record btrace etm ", 0, &set_record_btrace_cmdlist); + + add_show_prefix_cmd ("etm", class_support, + _("Show record btrace etm options."), + &show_record_btrace_etm_cmdlist, + "show record btrace etm ", 0, &show_record_btrace_cmdlist); + + add_setshow_uinteger_cmd ("buffer-size", no_class, + &record_btrace_conf.etm.size, + _("Set the record/replay etm buffer size."), + _("Show the record/replay etm buffer size."), _("\ +Bigger buffers allow longer recording but also take more time to process \ +the recorded execution.\n\ +The actual buffer size may differ from the requested size. Use \"info record\" \ +to see the actual buffer size."), NULL, show_record_etm_buffer_size_value, + &set_record_btrace_etm_cmdlist, + &show_record_btrace_etm_cmdlist); + + add_setshow_string_cmd ("sink", no_class, + &record_btrace_conf.etm.sink, + _("Set the record/replay ETM sink device."), + _("Show the record/replay ETM sink device."), + _("\ +Sink device is the device that intercepts ETM traces and collects or routes \ +them out of the SoC.\n\ +The list of available sinks on linux targets correspond to the files in \ +the directory \"/sys/bus/event_source/devices/cs_etm/sinks/\".\n\ +value \"default\" reset it to default sink"), + NULL, NULL, + &set_record_btrace_etm_cmdlist, + &show_record_btrace_etm_cmdlist); + add_target (record_btrace_target_info, record_btrace_target_open); bfcache = htab_create_alloc (50, bfcache_hash, bfcache_eq, NULL, @@ -3233,4 +3346,5 @@ to see the actual buffer size."), NULL, show_record_pt_buffer_size_value, record_btrace_conf.bts.size = 64 * 1024; record_btrace_conf.pt.size = 16 * 1024; + record_btrace_conf.etm.size = 8 * 1024; } diff --git a/gdb/record.c b/gdb/record.c index cd541b56f43..43e5bb0874f 100644 --- a/gdb/record.c +++ b/gdb/record.c @@ -118,6 +118,8 @@ record_start (const char *method, const char *format, int from_tty) execute_command_to_string ("record btrace bts", from_tty, false); else if (strcmp (format, "pt") == 0) execute_command_to_string ("record btrace pt", from_tty, false); + else if (strcmp (format, "etm") == 0) + execute_command_to_string ("record btrace etm", from_tty, false); else error (_("Invalid format.")); } diff --git a/gdbsupport/ChangeLog b/gdbsupport/ChangeLog index f27b57c2fa9..ed4708b7028 100644 --- a/gdbsupport/ChangeLog +++ b/gdbsupport/ChangeLog @@ -1,3 +1,13 @@ +2021-02-25 Zied Guermazi + + * btrace-common.h (btrace_format): add BTRACE_FORMAT_ETM + to the enum. + (btrace_cpu_vendor): add CV_ARM to the enum. + (btrace_config_etm): new struct. + (btrace_config): add btrace_config_etm etm. + * btrace-common.cc (btrace_format_string): add BTRACE_FORMAT_ETM. + (btrace_format_short_string): add BTRACE_FORMAT_ETM. + 2021-02-25 Zied Guermazi * gdbsupport/common.m4: check --with-arm-cs configuration diff --git a/gdbsupport/btrace-common.cc b/gdbsupport/btrace-common.cc index 4f9ef855e74..461f769ed51 100644 --- a/gdbsupport/btrace-common.cc +++ b/gdbsupport/btrace-common.cc @@ -36,6 +36,9 @@ btrace_format_string (enum btrace_format format) case BTRACE_FORMAT_PT: return _("Intel Processor Trace"); + + case BTRACE_FORMAT_ETM: + return _("ARM Processor CoreSight ETM Trace"); } internal_error (__FILE__, __LINE__, _("Unknown branch trace format")); @@ -56,6 +59,10 @@ btrace_format_short_string (enum btrace_format format) case BTRACE_FORMAT_PT: return "pt"; + + case BTRACE_FORMAT_ETM: + return "etm"; + } internal_error (__FILE__, __LINE__, _("Unknown branch trace format")); diff --git a/gdbsupport/btrace-common.h b/gdbsupport/btrace-common.h index 26d26ec957f..4ac658b9946 100644 --- a/gdbsupport/btrace-common.h +++ b/gdbsupport/btrace-common.h @@ -63,7 +63,10 @@ enum btrace_format BTRACE_FORMAT_BTS, /* Branch trace is in Intel Processor Trace format. */ - BTRACE_FORMAT_PT + BTRACE_FORMAT_PT, + + /* Branch trace is ARM CoreSight ETM format. */ + BTRACE_FORMAT_ETM }; /* An enumeration of cpu vendors. */ @@ -77,7 +80,10 @@ enum btrace_cpu_vendor CV_INTEL, /* AMD. */ - CV_AMD + CV_AMD, + + /* ARM. */ + CV_ARM }; /* A cpu identifier. */ @@ -119,6 +125,20 @@ struct btrace_config_pt unsigned int size; }; +/* An ARM CoreSight ETM Trace configuration. */ + +struct btrace_config_etm +{ + /* The size of the branch trace buffer in bytes. + + This is unsigned int and not size_t since it is registered as + control variable for "set record btrace etm buffer-size". */ + unsigned int size; + + /* The sink used to collect the traces. */ + char *sink; +}; + /* A branch tracing configuration. This describes the requested configuration as well as the actually @@ -136,6 +156,10 @@ struct btrace_config /* The Intel Processor Trace format configuration. */ struct btrace_config_pt pt; + + /* The ARM CoreSight ETM Trace configuration. */ + struct btrace_config_etm etm; + }; /* Branch trace in BTS format. */ -- 2.25.1