From patchwork Mon Mar 20 08:18:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 66634 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F3093858407 for ; Mon, 20 Mar 2023 08:19:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F3093858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1679300359; bh=Xgj4XySYsZNLJcbqJhartfC0KRXn5DWgkZoz8q3tt60=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=obb0YEXsAZA7z15BwcKrHdZQh0yQ3+vdhSti/wa5VVmeGKdZYtSknmZXmDijsc6D3 FkzAP0i2SZCuyRPgGKzRjXB69+0mRjT0IqWYl1UwWhDLATw0r+E8/4stcvuIreoqxo iqnn10k6AN0gxmEsRSY2g9wVezN0u86dJ0OLaUf4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 37CE83858C2B for ; Mon, 20 Mar 2023 08:18:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37CE83858C2B Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-220-JLf1MShmPUWpHpGFF4A2Dg-1; Mon, 20 Mar 2023 04:18:39 -0400 X-MC-Unique: JLf1MShmPUWpHpGFF4A2Dg-1 Received: by mail-ed1-f71.google.com with SMTP id j21-20020a508a95000000b004fd82403c91so16099657edj.3 for ; Mon, 20 Mar 2023 01:18:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679300318; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Xgj4XySYsZNLJcbqJhartfC0KRXn5DWgkZoz8q3tt60=; b=j4AYeW8qYNou2llAqNdWHC1NFWF6wRi5AvzIi9kv+fsIHZMyCjwftP/gIRltplXD4P UD08jnlPYl0G9PvSzJgQtS1WCh2QchA9CzidAMpiTx7VjTyknLBTUa0jKkMPvp9ddZtf GyrNoDMa/ti0flk+Qn4bSi58sAJwn3yjr3HkGar6IOQS8KxvXbC6dxdKsFI6COsLgJSJ Pj2CzEttvPMej/AAFkOSCUb6RT6F0hcQuzGaj5uYjTzmd/B3lezYB3B4KMxXi1imOgYq PsSS5n04IVAmpjqvDVTVqt/gG2447k2E1/d7o9sBEuB4jmM7ucCChR3IKEoIz2W80sQZ fSQQ== X-Gm-Message-State: AO0yUKVpyTbzQxPV/8RyCt2FIwBHyWF9uuE+SZCZQvFH6kOOhQdHdZTJ rSqA5AuLQQE+jZ7iTRVpcqZ8DS+eRbMTz8c00NPYF6JIk7FwpsbA1oV7O4VHVkZBjC+Hyqocoe5 /8JFHCtC7jXilMhaZPmwgb8+Y4P2sHrgbbK7a3iVjBuKecQAf0NjwzpRKfrKCvxvwXwqv5UxRDb pIdyyYoQ== X-Received: by 2002:aa7:cb10:0:b0:4fd:14d5:bb4b with SMTP id s16-20020aa7cb10000000b004fd14d5bb4bmr10879782edt.23.1679300318068; Mon, 20 Mar 2023 01:18:38 -0700 (PDT) X-Google-Smtp-Source: AK7set9Wq61Rbjd6EjmB1nnFlqutofwbLGGFh56jcMIHLkNzevCmXtayMKS+MMisDu5oZNvXI0IqQA== X-Received: by 2002:aa7:cb10:0:b0:4fd:14d5:bb4b with SMTP id s16-20020aa7cb10000000b004fd14d5bb4bmr10879759edt.23.1679300317672; Mon, 20 Mar 2023 01:18:37 -0700 (PDT) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id k15-20020a50ce4f000000b004bef1187754sm4445335edj.95.2023.03.20.01.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 01:18:37 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/riscv: add systemtap support Date: Mon, 20 Mar 2023 08:18:34 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This commit is initial support for SystemTap for RISC-V Linux. The following two tests exercise SystemTap functionality, and are showing many failures, which are all fixed by this commit: gdb.cp/exceptprint.exp gdb.base/stap-probe.exp One thing I wasn't sure about is if the SystemTap support should be Linux specific, or architecture specific. For aarch64, arm, ia64, and ppc, the SystemTap support seems to libe in the ARCH-linux-tdep.c file, while for amd64, i386, and s390 the implementation lives in ARCH-tdep.c. I have no idea which of these is the better choice -- or maybe both choices are correct in the right circumstances, and I'm just not aware of how to choose between them. Anyway, for this patch I selected riscv-linux-tdep.c (though clearly, moving the changes to riscv-tdep.c is trivial if anyone can why that's a more appropriate location). It makes sense to me that SystemTap might be a Linux only tool, which is why I picked the Linux tdep file. The stap-probe.exp file tests immediate, register, and register indirect operands, all of which appear to be working fine with this commit. The generic expression support doesn't appear to be architecture specific, so I'd expect that to work fine too. --- gdb/riscv-linux-tdep.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) base-commit: 57d67e5883732ec5bc14f02c312d2000d75c1a10 diff --git a/gdb/riscv-linux-tdep.c b/gdb/riscv-linux-tdep.c index 292d7a4ef7c..f1a8dbbb71e 100644 --- a/gdb/riscv-linux-tdep.c +++ b/gdb/riscv-linux-tdep.c @@ -26,6 +26,7 @@ #include "tramp-frame.h" #include "trad-frame.h" #include "gdbarch.h" +#include "safe-ctype.h" /* The following value is derived from __NR_rt_sigreturn in from the Linux source tree. */ @@ -174,6 +175,33 @@ riscv_linux_syscall_next_pc (frame_info_ptr frame) return pc + 4 /* Length of the ECALL insn. */; } +/* Implementation of `gdbarch_stap_is_single_operand', as defined in + gdbarch.h. */ + +static int +riscv_stap_is_single_operand (struct gdbarch *gdbarch, const char *s) +{ + return (ISDIGIT (*s) /* Literal number. */ + || *s == '(' /* Register indirection. */ + || ISALPHA (*s)); /* Register value. */ +} + +/* String that appears before a register name in a SystemTap register + indirect expression. */ + +static const char *const stap_register_indirection_prefixes[] = +{ + "(", nullptr +}; + +/* String that appears after a register name in a SystemTap register + indirect expression. */ + +static const char *const stap_register_indirection_suffixes[] = +{ + ")", nullptr +}; + /* Initialize RISC-V Linux ABI info. */ static void @@ -206,6 +234,13 @@ riscv_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) tramp_frame_prepend_unwinder (gdbarch, &riscv_linux_sigframe); tdep->syscall_next_pc = riscv_linux_syscall_next_pc; + + /* SystemTap Support. */ + set_gdbarch_stap_is_single_operand (gdbarch, riscv_stap_is_single_operand); + set_gdbarch_stap_register_indirection_prefixes + (gdbarch, stap_register_indirection_prefixes); + set_gdbarch_stap_register_indirection_suffixes + (gdbarch, stap_register_indirection_suffixes); } /* Initialize RISC-V Linux target support. */