From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3zVJ0YAkKC04874u99wu7w44w1u.s42wtr-5q9sxu884A7suCq7u.47w@flex--sroettger.bounces.google.com> Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by sourceware.org (Postfix) with ESMTPS id 58BE63898528 for ; Mon, 12 Apr 2021 14:01:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 58BE63898528 Received: by mail-qv1-xf49.google.com with SMTP id r14so5586485qvr.14 for ; Mon, 12 Apr 2021 07:01:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=b7d4YIQf40fu1tyPpk2ItiNbf479wF+XhWuRQlrjA18=; b=HFS46V8X9ZI8FokYCqiEn0FD/w8Dn6lFHEIA9HRPsO1idJjA8PcYvcv+jZS2tncD97 dQXCCIt0I570+yDRLOQD0cFry2jozXUxyiNABLw8KBak6x4vLWWAkK2RV39uhzTOrGEP V3WzML+9m07qwMoovHO0SK9IKH0f/S5PwHCeeiVhDoyL6xnV7wpKBy9BwhNfRES8invx OTPuDk0cYMZGMcYU/hjDBOr1O6CffdpiCk4ITk5fq/yBgHnj1iYeNHX6Q+ajjzY4yqbO f8ihUxYk7ApuZ/pj/TwYDD416ti9wPzi7S9e/N2t4QfyfYQ6y0hn3pgTXrRZsk1SeNMY Z0JA== X-Gm-Message-State: AOAM531wII3T1FehO9Vn5RUOirkrVQgGywLTf6i+JcVH7uZSd4JvhdYR wnw21sUWyiQuQMGeuGJPVdCymlgoCB4HiLxOdsw+M5E7n5q2nPMnwTwxqybYRSNx9fVtpKvXQCB UuvG5/ed5QWUMD16qPRMdzz1+6L1+sMaxVlnU2p1ZDqHaO/ramh0WAAm+Q/Ex4rn4IEPDcxuc+M w= X-Google-Smtp-Source: ABdhPJz/ytTDYow6VQzEijs4qadXotlUZAjCkGsWQLuKX9Prtep8jxXdvweptcwIfFYjGryNDLC19ADRl44ii8E= X-Received: from sroettger.zrh.corp.google.com ([2a00:79e0:1b:1:b12b:f4b7:8fde:1793]) (user=sroettger job=sendgmr) by 2002:a0c:9b88:: with SMTP id o8mr27939549qve.28.1618236109837; Mon, 12 Apr 2021 07:01:49 -0700 (PDT) Date: Mon, 12 Apr 2021 16:01:28 +0200 Message-Id: <20210412140128.296921-1-sroettger@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH] Update btrace data in maintenance btrace commands From: "=?UTF-8?q?Stephen=20R=C3=B6ttger?=" To: gdb-patches@sourceware.org Cc: Stephen Roettger Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-21.5 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL 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: Mon, 12 Apr 2021 14:01:51 -0000 From: Stephen Roettger When calling `maintenance btrace packet-history` or `maintenance info btrace`, the commands wouldn't show any data unless it was updated previously by some other means, for example by running `info record`. To fix this, use the require_btrace function from record-brace.h which will update the data before returning the btrace_thread_info pointer. Here's an example of the issue: ``` $ gdb -nx /usr/bin/ls (gdb) break malloc Breakpoint 1 at 0x46c8 (gdb) run Starting program: /usr/bin/ls Breakpoint 1, 0x00007ffff7fec240 in malloc () from /lib64/ld-linux-x86-64.so.2 (gdb) record btrace bts (gdb) c Continuing. Breakpoint 1, 0x00007ffff7fec240 in malloc () from /lib64/ld-linux-x86-64.so.2 (gdb) maintenance btrace packet-history No trace. (gdb) maintenance info btrace Format: Branch Trace Store. Aborted ``` gdb/ChangeLog: * btrace.c (maint_btrace_packet_history_cmd): use require_btrace (maint_info_btrace_cmd): use require_btrace * record-btrace.c (struct btrace_thread_info): mark non-static * record-btrace.h (require_btrace): export function --- gdb/btrace.c | 13 ++----------- gdb/record-btrace.c | 2 +- gdb/record-btrace.h | 7 +++++++ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gdb/btrace.c b/gdb/btrace.c index c697f37f46c..177e818f0cf 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -3231,12 +3231,8 @@ maint_btrace_packet_history_cmd (const char *arg, int from_tty) struct btrace_thread_info *btinfo; unsigned int size, begin, end, from, to; - thread_info *tp = find_thread_ptid (current_inferior (), inferior_ptid); - if (tp == NULL) - error (_("No thread.")); - + btinfo = require_btrace (); size = 10; - btinfo = &tp->btrace; btrace_maint_update_packets (btinfo, &begin, &end, &from, &to); if (begin == end) @@ -3372,12 +3368,7 @@ maint_info_btrace_cmd (const char *args, int from_tty) if (args != NULL && *args != 0) error (_("Invalid argument.")); - if (inferior_ptid == null_ptid) - error (_("No thread.")); - - thread_info *tp = inferior_thread (); - - btinfo = &tp->btrace; + btinfo = require_btrace (); conf = btrace_conf (btinfo); if (conf == NULL) diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c index b7b3c91f85d..79a6e47a4a6 100644 --- a/gdb/record-btrace.c +++ b/gdb/record-btrace.c @@ -269,7 +269,7 @@ require_btrace_thread (void) Throws an error if there is no thread or no trace. This function never returns NULL. */ -static struct btrace_thread_info * +struct btrace_thread_info * require_btrace (void) { struct thread_info *tp; diff --git a/gdb/record-btrace.h b/gdb/record-btrace.h index 8e7bbd90e60..b56e720e5a5 100644 --- a/gdb/record-btrace.h +++ b/gdb/record-btrace.h @@ -29,4 +29,11 @@ extern void record_btrace_push_target (void); NULL if the cpu was configured as auto. */ extern const struct btrace_cpu *record_btrace_get_cpu (void); +/* Update the branch trace for the current thread and return a pointer to its + branch trace information struct. + + Throws an error if there is no thread or no trace. This function never + returns NULL. */ +extern struct btrace_thread_info * require_btrace (void); + #endif /* RECORD_BTRACE_H */ -- 2.31.1.295.g9ea45b61b8-goog