From patchwork Tue Aug 20 14:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 96163 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 C4E043842FEB for ; Tue, 20 Aug 2024 14:43:54 +0000 (GMT) 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 ESMTP id 33201384602A for ; Tue, 20 Aug 2024 14:43:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33201384602A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 33201384602A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165002; cv=none; b=u+G6ui5NDPF/Zot5TuYaO+m3r3GBrguBg1bXdEghD6isZdQPPVROD/1hqShvtbL2LYohmviYfNCyCcNfek2aiYa4Kq55L702c0COaWN3nF+44OpXt31Mtp5G/6JSLj+v7xwUfllhz8JvXa9RoZQcEuAmwAjw0IdXmMqryYeADFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165002; c=relaxed/simple; bh=2PgZ+46ku1EOLhsotHdEHdbDFk6Ual/TCqzXDNKY19s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=WGlVw5zM/RSXUXXFg7RprkEkDgMcTMwbmND+yJCjLVHqkZ/BWVAvjowDGtxtnwvsZNAAl9CzFXJnRrRzVzU2SrJfPl0OuC5iPxFG6wvYMJRpaiULP0fjxC+0RbqKhKcAhdp3RlElkSSJ3wLOov5eNUjo5B81R9G7r7PatizWWZ0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724165000; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eeGmRxX24aJxAb/Bi6QqxsHSLxhL8ku3tEs6ZK35bwc=; b=UvSaQDef2NEdl1aCCIbgJ9RA3zwKYVx2yPTRBcKv7dTqVJqK8Q8a7ElswDtZKiCq7xVMtQ MM1jGgkCOe+hNkm0ITyQtnFGjIMBSqYuN5L98uBOhX9LgXDcR4Y7Kivnv3v0Euf026VLNS ptK8AuMA1kyoVxBh2WB1dFZqFzYg7ns= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-482-BMwELkNzORSknfWbijin_w-1; Tue, 20 Aug 2024 10:43:18 -0400 X-MC-Unique: BMwELkNzORSknfWbijin_w-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-367962f0cb0so3178228f8f.1 for ; Tue, 20 Aug 2024 07:43:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724164997; x=1724769797; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eeGmRxX24aJxAb/Bi6QqxsHSLxhL8ku3tEs6ZK35bwc=; b=R8iPKWf9rIVewoiD07zDz4S5VbexD4CIcFtiK2h0C4Rjwxj+Cx0IF6UzeYZiS6ja7e qEX+OKedS1tyfM9wbA6A0slCgpg2y6ZeSDx6A9qw9TJjxGdx3iu/ueI5+GU6eDVqevEA /c2Q4x7lL0f+1knHe9r1jcxOsjzLJ8VmlOh//lj5uLgwvBO/4apDb7pEFUoS+73i5Wmb ltk4DGpUnTxQSSBjQ7HVR4HaOPEal6aGZyX/lk/GGDcDxdTZ/hhdWQ3YWic4/ZEi0Btz sYXfxetLjrzbqWIDnussuPaeY7fSKALO6nZ0gCo4pRgEvevs3Db8Y82l4Fmlbfnwa/oO I11A== X-Gm-Message-State: AOJu0Yw89qTHXWWc1eY75kjEPImeXRa9wktTnsFXUxTGMtMJjhF6Ss27 U3A+AYCggtu+m/Op/1SwZv6vRAc24IrGjaZ/4ItdRBm4weZTU8It6grkLZK+Q4+5O6sM5tjk5ZZ Tl6QFAYGH9eIT6zoLHG2u2O8fg6H+b0Fzj8Pwy/JGB7gK9RprVtF5X7trbec9u+lQwX+rUKkbVx zndRtKlvOja2FEG5Q6O2CQDVtUCIaCSeWF8IcrBStuFzI= X-Received: by 2002:a05:6000:11c8:b0:368:445e:91cc with SMTP id ffacd0b85a97d-3719464c52cmr7625286f8f.21.1724164997259; Tue, 20 Aug 2024 07:43:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmuNszwxAlGMOtilfGj88JwA0bGb07/yhjjpZ+fIdpm3Wsw7reBXEw2GzLlQSeBdmcxzsPdg== X-Received: by 2002:a05:6000:11c8:b0:368:445e:91cc with SMTP id ffacd0b85a97d-3719464c52cmr7625250f8f.21.1724164996275; Tue, 20 Aug 2024 07:43:16 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded7c93esm197481325e9.41.2024.08.20.07.43.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:43:16 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Simon Marchi Subject: [PATCHv5 1/4] Revert "gdb: remove inline_frame::skipped_frames" Date: Tue, 20 Aug 2024 15:43:09 +0100 Message-Id: <6aca08775f7911dcb55481b73b0a3d521ad62bf7.1724164804.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org This reverts commit 713e89012e43c83a6c1bb957c43ff58e5433336c. Having inline_state::skipped_frames back will make a later patch in this series easier. --- gdb/inline-frame.c | 51 ++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c index bed99dc3cf9..f65f39be40d 100644 --- a/gdb/inline-frame.c +++ b/gdb/inline-frame.c @@ -35,9 +35,9 @@ keep our own list. */ struct inline_state { - inline_state (thread_info *thread_, CORE_ADDR saved_pc_, + inline_state (thread_info *thread_, int skipped_frames_, CORE_ADDR saved_pc_, std::vector &&skipped_symbols_) - : thread (thread_), saved_pc (saved_pc_), + : thread (thread_), skipped_frames (skipped_frames_), saved_pc (saved_pc_), skipped_symbols (std::move (skipped_symbols_)) {} @@ -45,14 +45,19 @@ struct inline_state stopped thread. */ thread_info *thread; - /* Only valid if SKIPPED_SYMBOLS is not empty. This is the PC used - when calculating SKIPPED_SYMBOLS; used to check whether we have + /* The number of inlined functions we are skipping. Each of these + functions can be stepped in to. */ + int skipped_frames; + + /* Only valid if SKIPPED_FRAMES is non-zero. This is the PC used + when calculating SKIPPED_FRAMES; used to check whether we have moved to a new location by user request. If so, we invalidate any skipped frames. */ CORE_ADDR saved_pc; - /* The list of all function symbols that have been skipped, from inner most - to outer most. It is used to find the call site of the current frame. */ + /* Only valid if SKIPPED_FRAMES is non-zero. This is the list of all + function symbols that have been skipped, from inner most to outer + most. It is used to find the call site of the current frame. */ std::vector skipped_symbols; }; @@ -242,12 +247,10 @@ inline_frame_sniffer (const struct frame_unwind *self, /* If this is the topmost frame, or all frames above us are inlined, then check whether we were requested to skip some frames (so they can be stepped into later). */ - if (state != nullptr - && !state->skipped_symbols.empty () - && next_frame == nullptr) + if (state != NULL && state->skipped_frames > 0 && next_frame == NULL) { - gdb_assert (depth >= state->skipped_symbols.size ()); - depth -= state->skipped_symbols.size (); + gdb_assert (depth >= state->skipped_frames); + depth -= state->skipped_frames; } /* If all the inlined functions here already have frames, then pass @@ -340,6 +343,7 @@ skip_inline_frames (thread_info *thread, bpstat *stop_chain) { const struct block *frame_block, *cur_block; std::vector skipped_syms; + int skip_count = 0; /* This function is called right after reinitializing the frame cache. We try not to do more unwinding than absolutely @@ -365,6 +369,7 @@ skip_inline_frames (thread_info *thread, bpstat *stop_chain) if (stopped_by_user_bp_inline_frame (cur_block, stop_chain)) break; + skip_count++; skipped_syms.push_back (cur_block->function ()); } else @@ -378,11 +383,11 @@ skip_inline_frames (thread_info *thread, bpstat *stop_chain) } gdb_assert (find_inline_frame_state (thread) == NULL); + inline_states.emplace_back (thread, skip_count, this_pc, + std::move (skipped_syms)); - if (!skipped_syms.empty ()) + if (skip_count != 0) reinit_frame_cache (); - - inline_states.emplace_back (thread, this_pc, std::move (skipped_syms)); } /* Step into an inlined function by unhiding it. */ @@ -392,10 +397,8 @@ step_into_inline_frame (thread_info *thread) { inline_state *state = find_inline_frame_state (thread); - gdb_assert (state != nullptr); - gdb_assert (!state->skipped_symbols.empty ()); - - state->skipped_symbols.pop_back (); + gdb_assert (state != NULL && state->skipped_frames > 0); + state->skipped_frames--; reinit_frame_cache (); } @@ -410,7 +413,7 @@ inline_skipped_frames (thread_info *thread) if (state == NULL) return 0; else - return state->skipped_symbols.size (); + return state->skipped_frames; } /* If one or more inlined functions are hidden, return the symbol for @@ -423,9 +426,13 @@ inline_skipped_symbol (thread_info *thread) gdb_assert (state != NULL); /* This should only be called when we are skipping at least one frame, - hence SKIPPED_SYMBOLS will have at least one item when we get here. */ - gdb_assert (!state->skipped_symbols.empty ()); - return state->skipped_symbols.back (); + hence SKIPPED_FRAMES will be greater than zero when we get here. + We initialise SKIPPED_FRAMES at the same time as we build + SKIPPED_SYMBOLS, hence it should be true that SKIPPED_FRAMES never + indexes outside of the SKIPPED_SYMBOLS vector. */ + gdb_assert (state->skipped_frames > 0); + gdb_assert (state->skipped_frames <= state->skipped_symbols.size ()); + return state->skipped_symbols[state->skipped_frames - 1]; } /* Return the number of functions inlined into THIS_FRAME. Some of From patchwork Tue Aug 20 14:43:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 96164 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 72425386D609 for ; Tue, 20 Aug 2024 14:44:01 +0000 (GMT) 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 ESMTP id 92B3D384515D for ; Tue, 20 Aug 2024 14:43:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92B3D384515D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92B3D384515D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165003; cv=none; b=a5M2+l/24vrnYmdjVyknJ3fDhZi8fDdUn18RljQRLN0NRne/bVpuWaK8XfZQZvw8/My1Uv+xJCFxGAJLAbMGDAas5UJVcx15z60fYkoYhksj4olktgJlp/C0O2w33BXJOOM6bPQg12bb8TcHhGZ2IUl1Me6fIuVX2hNrBRsC+qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165003; c=relaxed/simple; bh=iPa59MCjgmtWctAoT1oRqwuWQyAqRyUQsPuZfYyjML4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=ogO2inUwZiFd0huD1xbkKFpVb1H5USGfUCbK6ku8wlZNXcDvaMP4B7aMAxINj7qpGRwDe3wqv5uvSJA4KNZD0V9aqy6yowcuqG/tS6C9S4ibv9Yw4hfAqVKAFwmKhn88Qr3ZoKiwzrxHJ0mZHu68nKJ+LSv/B3flvHR09W7ljiE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724165001; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=abLrPIStrW5DDPIK3L8TGoTy07FzBqDsPS1NMx8WtrE=; b=YrxO3p7WP6diMtACADXGzeELGejaUwmVhk5Kboo1qrPQGsgPXfClAaHjx1EnzLQios699V sd26ip1sb17tbVac0TB2E//Cwb1s4ivIrzSIaoZLjzQ4yrcqmXwqYJRauBkZxyrILM6R2A SiLwH7MNefAaZOmu6Q8xyx7PLX3xUQY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-wyfOsa3yPl6BLQVfflAmIQ-1; Tue, 20 Aug 2024 10:43:20 -0400 X-MC-Unique: wyfOsa3yPl6BLQVfflAmIQ-1 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-371a804f191so2555349f8f.3 for ; Tue, 20 Aug 2024 07:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724164998; x=1724769798; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=abLrPIStrW5DDPIK3L8TGoTy07FzBqDsPS1NMx8WtrE=; b=O3vIFBq3uld/3SOihsOfnhZkdf8Jj5UpsSlqkEsIP8Vu2LAjJN0rAK4PRAeY/yfGgh kXFhby9VdXEDclfyxjbRAKsrw6HSMvXceph9xXOOcjWyV2lxjYg3YtzH0I6Vu9Fs7gl+ R3tPOuJupDmBYXlzC4wfh7CNNEOYcl4qcm9I4m1/EekbaumB0SAH9s1qoNgxWvPZmytA CaJLMzCjxmUE6RJCXnTw8ngM4uRyWb1Y+pw9WsL3AUm/ZLeZ90Jzhcc1c2M6RZg+sGYt nkkRIC/i2k7uVCxGZ2mZn7/HAUNRO2aqiM1jsnFooZtp4Ue9HNjerGSITvJITCRDqoTz PNlg== X-Gm-Message-State: AOJu0YxakSXsDQ1Mi0hlsJXKEuQsRg8OuUc9jrwwbqJEbmqM8UVfxwLI 4YBnwLIum3CKdLbc/QVv2XZottWI7hgU0+X/KfgAjmU9EkouY3aaxU07FImO/m+Yta9Z7o511AQ xb3VBE7CK0zv2Xxj85Lku0yGnGGc8hqzpApaWwSwHHFfumQSebs3tGqsAPnisv4Aj1AC4+2WSh6 tHLiuGBxD/f0boNTHGcCnpQ7kJ1sUHwi38T9N5vuRDoFw= X-Received: by 2002:a5d:5b85:0:b0:368:74a8:6c34 with SMTP id ffacd0b85a97d-37194656046mr7196788f8f.36.1724164998283; Tue, 20 Aug 2024 07:43:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEXZeKecSiemrMwEow4dSxPoeIk03y8WiP5Z+uHs9Z5uJumS9Ar81XnYRcy1FPfmeA9AhHBQ== X-Received: by 2002:a5d:5b85:0:b0:368:74a8:6c34 with SMTP id ffacd0b85a97d-37194656046mr7196760f8f.36.1724164997315; Tue, 20 Aug 2024 07:43:17 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-371898aad93sm13258907f8f.95.2024.08.20.07.43.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:43:17 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Simon Marchi , Simon Marchi Subject: [PATCHv5 2/4] gdb: make symbols const in struct inline_state Date: Tue, 20 Aug 2024 15:43:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org Make the inline_state::skipped_symbols a vector of 'const symbol *', adding the const qualifier. There's only a couple of places this leaks into the rest of GDB and in both places its fine for the symbol to become const. There should be no functional change after this commit. Approved-By: Simon Marchi --- gdb/frame.c | 2 +- gdb/infcmd.c | 2 +- gdb/inline-frame.c | 8 ++++---- gdb/inline-frame.h | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gdb/frame.c b/gdb/frame.c index 4d092d0e8c8..a6900b28072 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -2859,7 +2859,7 @@ find_frame_sal (const frame_info_ptr &frame) if (frame_inlined_callees (frame) > 0) { - struct symbol *sym; + const symbol *sym; /* If the current frame has some inlined callees, and we have a next frame, then that frame must be an inlined frame. In this case diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 347684a0be1..90fa4f6c969 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -992,7 +992,7 @@ prepare_one_step (thread_info *tp, struct step_command_fsm *sm) Use inlined_subroutine info to make the range more narrow. */ if (inline_skipped_frames (tp) > 0) { - symbol *sym = inline_skipped_symbol (tp); + const symbol *sym = inline_skipped_symbol (tp); if (sym->aclass () == LOC_BLOCK) { const block *block = sym->value_block (); diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c index f65f39be40d..56b295520f9 100644 --- a/gdb/inline-frame.c +++ b/gdb/inline-frame.c @@ -36,7 +36,7 @@ struct inline_state { inline_state (thread_info *thread_, int skipped_frames_, CORE_ADDR saved_pc_, - std::vector &&skipped_symbols_) + std::vector &&skipped_symbols_) : thread (thread_), skipped_frames (skipped_frames_), saved_pc (saved_pc_), skipped_symbols (std::move (skipped_symbols_)) {} @@ -58,7 +58,7 @@ struct inline_state /* Only valid if SKIPPED_FRAMES is non-zero. This is the list of all function symbols that have been skipped, from inner most to outer most. It is used to find the call site of the current frame. */ - std::vector skipped_symbols; + std::vector skipped_symbols; }; static std::vector inline_states; @@ -342,7 +342,7 @@ void skip_inline_frames (thread_info *thread, bpstat *stop_chain) { const struct block *frame_block, *cur_block; - std::vector skipped_syms; + std::vector skipped_syms; int skip_count = 0; /* This function is called right after reinitializing the frame @@ -419,7 +419,7 @@ inline_skipped_frames (thread_info *thread) /* If one or more inlined functions are hidden, return the symbol for the function inlined into the current frame. */ -struct symbol * +const symbol * inline_skipped_symbol (thread_info *thread) { inline_state *state = find_inline_frame_state (thread); diff --git a/gdb/inline-frame.h b/gdb/inline-frame.h index bbe617c7c5b..3ddc9cf2335 100644 --- a/gdb/inline-frame.h +++ b/gdb/inline-frame.h @@ -62,7 +62,7 @@ int inline_skipped_frames (thread_info *thread); /* If one or more inlined functions are hidden, return the symbol for the function inlined into the current frame. */ -struct symbol *inline_skipped_symbol (thread_info *thread); +const symbol *inline_skipped_symbol (thread_info *thread); /* Return the number of functions inlined into THIS_FRAME. Some of the callees may not have associated frames (see From patchwork Tue Aug 20 14:43:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 96166 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 72AC43844777 for ; Tue, 20 Aug 2024 14:44:48 +0000 (GMT) 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 ESMTP id 98ADD38449C8 for ; Tue, 20 Aug 2024 14:43:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98ADD38449C8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 98ADD38449C8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165007; cv=none; b=e4FBSnLawCYlr69SnVICEt4mGmgDUrteIyVkWl7zM4+ZVPLrBKO+I/c6BG3cD9MDuRWKDQSnS7WS9hxnQhBZA3UDP7pUR1bCuB9G56mU8EjVsRGH5HJLHnmYz1v76mBz2+OvRm93xn0fopXk5yGIh8+i5pW/PRb/LiUEYJovCYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165007; c=relaxed/simple; bh=71Aeq94XHsd8C17yTrnTf1K73F8gevrYIQlXT3TALkE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Wk48FCeTGmhbSbjgvveDcl1ibCTknibjGSqET4x40PPMmaMpgXghjddRNQ8J4nb4CXA1e2AiQ6PhWT+deDktcU1Hj0pj3b1NeI6lRnWW5W7NmwbdfXMZ4yqC6J3d37j8ON0suFSJusaLWLlnn9y1qEv+0SUOJmakJtWWdr+M3Tg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724165003; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SBZqbm/hia1DdXMbUQeFzSb1Xlj8TqixWT3nSb3I0Kg=; b=fo4jDdfkMyfToj3Jb9ZutGNl8wpTEeoIiICrcENhFdoSFokeLllSsPCvzYRdgut1W2dzib Ywb1CWp8jJqZD+RClzu0/7FAUurnp0nnDbHPlqhBdker+iGKRJURFjQhRfw2/lPoDrWLqA AWBW36So64mEkZ9y2fpp/VAY5e1pJIQ= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-286-1gi05r_LMTKM0Ckp5OmWPQ-1; Tue, 20 Aug 2024 10:43:21 -0400 X-MC-Unique: 1gi05r_LMTKM0Ckp5OmWPQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-42809eb7b99so30029085e9.0 for ; Tue, 20 Aug 2024 07:43:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165000; x=1724769800; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hfEwFRQpMqdsUrB80dl4T8jW25UGKkHzomYufRu8uaU=; b=MVx49y17nqdvpjbcVVrrEiN33fQHdXHq5R0hQTHIidXTiI0W2BC0WXGuye6eBPHZve IpSXCBCCM4zDzAK2A/UUukn/N+2zV3C+PeH/zUDJglQJQCDNKwSTzBBQxJELaAdkRnmx NVkowTkPE2mpoYkw7kh7dKX7TQTmY0cm/ZnN61Yhf0NUbUhM7zTsmkIKfHLL3wdEMozd RILpk8wiOCx+aU3NrIVDuWKo0tJ2Kyh05JSGhVOmlILACkBxKWBCEaosZfqucOkqgU0j oF95AmP2ZpN1NV7wwGVrfWZc7R6x+eWtkxQT4m1x8P2fulwFBRXNRwOoiWB2rq6kTsSU N+AQ== X-Gm-Message-State: AOJu0YwahaNSU34DvwoRS/O6fWs+sqaVYIUs7WHoCLypLjlTPWneG7iL nYAVmo7jcLkL70q3MtYIYgIEjvOGSFu+V5N7Cw8xU3mSsnbPI4d4lnu8aSz7/rZ/pe6bNqH1XlU ponI+5QdUnQnJiMTi1MAxghtYxd8YFimALW93m96EYWdwKwBt7pA/KwSeS1qQ0yfrnNCQDLHqYP Kb8gz+lehJSl/7umnWyQfAw1WdsY6Iw915GAXzTMBZdB0= X-Received: by 2002:a05:600c:46c5:b0:424:71f7:77f2 with SMTP id 5b1f17b1804b1-42ab57e37b6mr17814705e9.16.1724164999753; Tue, 20 Aug 2024 07:43:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFHsdsj6noDjMyW6z5tlEyRweP8gLfyx0RVs06j/o4qIZFsfhyYi1YAyRJ2hwgMXuPVP8dlw== X-Received: by 2002:a05:600c:46c5:b0:424:71f7:77f2 with SMTP id 5b1f17b1804b1-42ab57e37b6mr17814355e9.16.1724164998462; Tue, 20 Aug 2024 07:43:18 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ed658651sm147951825e9.26.2024.08.20.07.43.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:43:18 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Simon Marchi , Eli Zaretskii Subject: [PATCHv5 3/4] gdb: Add 'maint info inline-frames' command Date: Tue, 20 Aug 2024 15:43:11 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org While reviewing a patch I wanted to view GDB's inline frame state. I don't believe there's currently a maintenance command to view this information, so in this commit I've added one. The new command is: maintenance info inline-frames maintenance info inline-frames ADDRESS The command lists the inline frames that start at ADDRESS, or at the current $pc if no ADDRESS is given. The command also displays the "outer" function in which the inline functions are present. An example of the command output: (gdb) maintenance info inline-frames Cached inline state information for thread 1. program counter = 0x401137 skipped frames = 1 bar > foo main (gdb) This tells us that function 'main' called 'foo' which called 'bar'. The functions 'foo' and 'bar' are both inline and both start at the address 0x401137. Currently GDB considers the inferior to be stopped in frame 'foo' (note the '>' marker), this means that there is 1 skipped frame (function 'bar'). The function 'main' is the outer function. The outer function might not start at 0x401137, it is simply the function that contains the inline functions. If the user does a 'step' then GDB will not actually move the inferior forward, but will instead simply tell the user that the inferior entered 'bar'. The output of 'maint info inline-frames' will change like this: (gdb) step bar () at inline.c:6 6 ++global_counter; (gdb) maintenance info inline-frames Cached inline state information for thread 1. program counter = 0x401137 skipped frames = 0 > bar foo main (gdb) Now GDB is in function 'bar' and there are no skipped frames. I have renamed skipped_symbols to function symbols within the inline_state class. We are now going to carry the "outer" function (the function that contains all the inlined functions) within this list (as the last entry), so the old name didn't really make sense. As a consequence of this rename I've updated some comments. I've changed stopped_by_user_bp_inline_frame to take a symbol rather than a block. Previously we just used the block to access the associated function symbol. After this commit we can just pass in the function symbol directly, so lets do that. New function gather_inline_frames contains some of the logic pulled from skip_inline_frames. This new function builds the list of all symbols of inlined functions that start at a given $pc value and also the "outer" function that contains all of the inlined functions. In skip_inline_frames I've split the loop logic into two. The loop to build the function symbol list has moved to gather_inline_frames. The loop to figure out how many of the inlined functions we are skipping remains in skip_inline_frames and uses the result of calling gather_inline_frames. In inline_skipped_symbol there are some minor updates to the comment, and I've tweaked one of the asserts now that the function symbols list also contains the "outer" function (a <= becomes <). The maintenance_info_inline_frames function is now and implements the new maintenance command. And _initialize_inline_frame is updated to register the new command. I've added a basic test for the new command. Please excuse the file name for the new test, in the next commit I'll be adding additional tests and at that point the file name will make sense. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 7 + gdb/doc/gdb.texinfo | 111 ++++++++ gdb/inline-frame.c | 236 +++++++++++++----- .../maint-info-inline-frames-and-blocks.c | 57 +++++ .../maint-info-inline-frames-and-blocks.exp | 151 +++++++++++ 5 files changed, 505 insertions(+), 57 deletions(-) create mode 100644 gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.c create mode 100644 gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp diff --git a/gdb/NEWS b/gdb/NEWS index 81aa8af2338..9ffc9c31420 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -35,6 +35,13 @@ * Remove support (native and remote) for QNX Neutrino (triplet `i[3456]86-*-nto*`). +* New commands + +maintenance info inline-frames [ADDRESS] + New command which displays GDB's inline-frame information for the + current address, or for ADDRESS if specified. The output identifies + inlined frames which start at the specified address. + *** Changes in GDB 15 * The MPX commands "show/set mpx bound" have been deprecated, as Intel diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 7938b0799f9..e85099f7d65 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -41858,6 +41858,117 @@ frame-id for frame #2: @{stack=0x7fffffffac90,code=0x000000000040111c,!special@} @end smallexample +@item maint info inline-frames +@itemx maint info inline-frames @var{address} +@cindex frames of inlined functions +@kindex maint info inline-frames +Print information about inlined frames which start at the current +address, or @var{address} if specified. + +In order to allow the user to correctly step into inlined functions, +@value{GDBN} needs to identify which inlined functions start at a +particular address, and @value{GDBN} also needs to track which of +these functions was last displayed to the user as the current frame. + +Imagine a situation where function @code{main} calls @code{foo}, which +then calls @code{bar}, something like this: + +@smallexample +@group +int +main () +@{ + /* Some interesting code here... */ + + foo (); + + /* More interesting code here... */ +@} + +void +foo () +@{ + bar (); +@} + +void +bar () +@{ + /* Some interesting code here... */ +@} +@end group +@end smallexample + +As both @code{foo} and @code{bar} are inlined within @code{main} then +there could be one address within @code{main} which is also the start +of @code{foo} and also the start of @code{bar}. When the user stops +at this address they will initially be told the inferior is in +@code{main}, if the user does a @kbd{step} then @value{GDBN} doesn't +actually step the inferior, instead the user is told the inferior +entered @code{foo}. After the next @kbd{step} the user is told the +inferior entered @code{bar}. The @kbd{maint info inline-frames} +command can be used to view this internal @value{GDBN} state, like +this: + +@smallexample +@group +(@value{GDBP}) step +24 foo (); +(@value{GDBP}) maintenance info inline-frames +Cached inline state information for thread 1. +program counter = 0x401137 +skipped frames = 2 + bar + foo +> main +@end group +@end smallexample + +Here the user is stopped in @code{main} at the call to @code{foo}. The +inline-frames information shows that at this address @value{GDBN} has +found the start of inlined functions @code{bar} and @code{foo}, but +currently @value{GDBN} has skipped 2 frames and considers @code{main} +to be the current frame, this is indicated with the @samp{>}. + +If the user performs a @kbd{step} to enter @code{foo} then the +situation is updated: + +@smallexample +@group +(@value{GDBP}) step +foo () at inline.c:14 +14 bar (); +(@value{GDBP}) maintenance info inline-frames +Cached inline state information for thread 1. +program counter = 0x401137 +skipped frames = 1 + bar +> foo + main +@end group +@end smallexample + +Notice that the program counter value @code{0x401137} hasn't change, +but now @value{GDBN} considers @code{foo} to be the current frame, and +it is marked as such with the @samp{>}. + +Finally, the user performs another @kbd{step} to enter @code{bar}: + +@smallexample +@group +(@value{GDBP}) step +bar () at inline.c:6 +6 ++global_counter; +(@value{GDBP}) maintenance info inline-frames +Cached inline state information for thread 1. +program counter = 0x401137 +skipped frames = 0 +> bar + foo + main +@end group +@end smallexample + @kindex maint print registers @kindex maint print raw-registers @kindex maint print cooked-registers diff --git a/gdb/inline-frame.c b/gdb/inline-frame.c index 56b295520f9..41c865e2b9f 100644 --- a/gdb/inline-frame.c +++ b/gdb/inline-frame.c @@ -27,6 +27,8 @@ #include "regcache.h" #include "symtab.h" #include "frame.h" +#include "cli/cli-cmds.h" +#include "cli/cli-style.h" #include /* We need to save a few variables for every thread stopped at the @@ -36,9 +38,9 @@ struct inline_state { inline_state (thread_info *thread_, int skipped_frames_, CORE_ADDR saved_pc_, - std::vector &&skipped_symbols_) + std::vector &&function_symbols_) : thread (thread_), skipped_frames (skipped_frames_), saved_pc (saved_pc_), - skipped_symbols (std::move (skipped_symbols_)) + function_symbols (std::move (function_symbols_)) {} /* The thread this data relates to. It should be a currently @@ -49,16 +51,16 @@ struct inline_state functions can be stepped in to. */ int skipped_frames; - /* Only valid if SKIPPED_FRAMES is non-zero. This is the PC used - when calculating SKIPPED_FRAMES; used to check whether we have - moved to a new location by user request. If so, we invalidate - any skipped frames. */ + /* This is the PC used when calculating FUNCTION_SYMBOLS; used to check + whether we have moved to a new location by user request. If so, we + invalidate any skipped frames. */ CORE_ADDR saved_pc; - /* Only valid if SKIPPED_FRAMES is non-zero. This is the list of all - function symbols that have been skipped, from inner most to outer - most. It is used to find the call site of the current frame. */ - std::vector skipped_symbols; + /* The list of all inline functions that start at SAVED_PC, except for + the last entry which will either be a non-inline function, or an + inline function that doesn't start at SAVED_PC. This last entry is + the function that "contains" all of the earlier functions. */ + std::vector function_symbols; }; static std::vector inline_states; @@ -303,10 +305,11 @@ block_starting_point_at (CORE_ADDR pc, const struct block *block) /* Loop over the stop chain and determine if execution stopped in an inlined frame because of a breakpoint with a user-specified location - set at FRAME_BLOCK. */ + set at FRAME_SYMBOL. */ static bool -stopped_by_user_bp_inline_frame (const block *frame_block, bpstat *stop_chain) +stopped_by_user_bp_inline_frame (const symbol *frame_symbol, + bpstat *stop_chain) { for (bpstat *s = stop_chain; s != nullptr; s = s->next) { @@ -327,7 +330,7 @@ stopped_by_user_bp_inline_frame (const block *frame_block, bpstat *stop_chain) to presenting the stop at the innermost inline function. */ if (loc->symbol == nullptr - || frame_block == loc->symbol->value_block ()) + || frame_symbol == loc->symbol) return true; } } @@ -336,58 +339,86 @@ stopped_by_user_bp_inline_frame (const block *frame_block, bpstat *stop_chain) return false; } +/* Return a list of all the inline function symbols that start at THIS_PC + and the symbol for the function which contains all of the inline + functions. + + The function symbols are ordered such that the most inner function is + first. + + The returned list can be empty if there are no function at THIS_PC. Or + the returned list may have only a single entry if there are no inline + functions starting at THIS_PC. */ + +static std::vector +gather_inline_frames (CORE_ADDR this_pc) +{ + /* Build the list of inline frames starting at THIS_PC. After the loop, + CUR_BLOCK is expected to point at the first function symbol (inlined or + not) "containing" the inline frames starting at THIS_PC. */ + std::vector function_symbols; + const block *cur_block = block_for_pc (this_pc); + + while (cur_block != nullptr) + { + if (cur_block->inlined_p ()) + { + /* See comments in inline_frame_this_id about this use + of BLOCK_ENTRY_PC. */ + if (cur_block->entry_pc () == this_pc + || block_starting_point_at (this_pc, cur_block)) + function_symbols.push_back (cur_block->function ()); + else + break; + } + else if (cur_block->function () != nullptr) + break; + + cur_block = cur_block->superblock (); + } + + if (cur_block != nullptr) + function_symbols.push_back (cur_block->function ()); + + return function_symbols; +} + /* See inline-frame.h. */ void skip_inline_frames (thread_info *thread, bpstat *stop_chain) { - const struct block *frame_block, *cur_block; - std::vector skipped_syms; - int skip_count = 0; + gdb_assert (find_inline_frame_state (thread) == nullptr); - /* This function is called right after reinitializing the frame - cache. We try not to do more unwinding than absolutely - necessary, for performance. */ CORE_ADDR this_pc = get_frame_pc (get_current_frame ()); - frame_block = block_for_pc (this_pc); - if (frame_block != NULL) + std::vector function_symbols + = gather_inline_frames (this_pc); + + /* Figure out how many of the inlined frames to skip. Do not skip an + inlined frame (and its callers) if execution stopped because of a user + breakpoint for this specific function. + + By default, skip all the found inlined frames. + + The last entry in FUNCTION_SYMBOLS is special, this is the function + which contains all of the inlined functions, we never skip this. */ + int skipped_frames = 0; + + for (const auto sym : function_symbols) { - cur_block = frame_block; - while (cur_block->superblock ()) - { - if (cur_block->inlined_p ()) - { - /* See comments in inline_frame_this_id about this use - of BLOCK_ENTRY_PC. */ - if (cur_block->entry_pc () == this_pc - || block_starting_point_at (this_pc, cur_block)) - { - /* Do not skip the inlined frame if execution - stopped in an inlined frame because of a user - breakpoint for this inline function. */ - if (stopped_by_user_bp_inline_frame (cur_block, stop_chain)) - break; - - skip_count++; - skipped_syms.push_back (cur_block->function ()); - } - else - break; - } - else if (cur_block->function () != NULL) - break; + if (stopped_by_user_bp_inline_frame (sym, stop_chain) + || sym == function_symbols.back ()) + break; - cur_block = cur_block->superblock (); - } + ++skipped_frames; } - gdb_assert (find_inline_frame_state (thread) == NULL); - inline_states.emplace_back (thread, skip_count, this_pc, - std::move (skipped_syms)); - - if (skip_count != 0) + if (skipped_frames > 0) reinit_frame_cache (); + + inline_states.emplace_back (thread, skipped_frames, this_pc, + std::move (function_symbols)); } /* Step into an inlined function by unhiding it. */ @@ -426,13 +457,14 @@ inline_skipped_symbol (thread_info *thread) gdb_assert (state != NULL); /* This should only be called when we are skipping at least one frame, - hence SKIPPED_FRAMES will be greater than zero when we get here. + hence FUNCTION_SYMBOLS will be greater than zero when we get here. We initialise SKIPPED_FRAMES at the same time as we build - SKIPPED_SYMBOLS, hence it should be true that SKIPPED_FRAMES never - indexes outside of the SKIPPED_SYMBOLS vector. */ + FUNCTION_SYMBOLS, hence it should be true that SKIPPED_FRAMES never + indexes outside of the FUNCTION_SYMBOLS vector. */ + gdb_assert (!state->function_symbols.empty ()); gdb_assert (state->skipped_frames > 0); - gdb_assert (state->skipped_frames <= state->skipped_symbols.size ()); - return state->skipped_symbols[state->skipped_frames - 1]; + gdb_assert (state->skipped_frames < state->function_symbols.size ()); + return state->function_symbols[state->skipped_frames - 1]; } /* Return the number of functions inlined into THIS_FRAME. Some of @@ -460,3 +492,93 @@ frame_inlined_callees (const frame_info_ptr &this_frame) return inline_count; } + +/* The 'maint info inline-frames' command. Takes an optional address + expression and displays inline frames that start at the given address, + or at the address of the current thread if no address is given. */ + +static void +maintenance_info_inline_frames (const char *arg, int from_tty) +{ + std::optional> local_function_symbols; + std::vector *function_symbols; + int skipped_frames; + CORE_ADDR addr; + + if (arg == nullptr) + { + /* With no argument then the user wants to know about the current + inline frame information. This information is cached per-thread + and can be updated as the user steps between inline functions at + the current address. */ + + if (inferior_ptid == null_ptid) + error (_("no inferior thread")); + + thread_info *thread = inferior_thread (); + auto it = std::find_if (inline_states.begin (), inline_states.end (), + [thread] (const inline_state &istate) + { + return thread == istate.thread; + }); + + /* Stopped threads always have cached inline_state information. */ + gdb_assert (it != inline_states.end ()); + + gdb_printf (_("Cached inline state information for thread %s.\n"), + print_thread_id (thread)); + + function_symbols = &it->function_symbols; + skipped_frames = it->skipped_frames; + addr = it->saved_pc; + } + else + { + /* If there is an argument then parse it as an address, the user is + asking about inline functions that start at the given address. */ + + addr = parse_and_eval_address (arg); + local_function_symbols.emplace (gather_inline_frames (addr)); + + function_symbols = &(local_function_symbols.value ()); + skipped_frames = function_symbols->size () - 1; + } + + /* The address we're analysing. */ + gdb_printf (_("program counter = %ps\n"), + styled_string (address_style.style (), + core_addr_to_string_nz (addr))); + + gdb_printf (_("skipped frames = %d\n"), skipped_frames); + + /* Print the full list of function symbols in STATE. Highlight the + current function as indicated by the skipped frames counter. */ + for (size_t i = 0; i < function_symbols->size (); ++i) + gdb_printf (_("%c %ps\n"), + (i == skipped_frames ? '>' : ' '), + styled_string (function_name_style.style (), + (*function_symbols)[i]->print_name ())); +} + + + +void _initialize_inline_frame (); +void +_initialize_inline_frame () +{ + add_cmd ("inline-frames", class_maintenance, maintenance_info_inline_frames, + _("\ +Display inline frame information for current thread.\n\ +\n\ +Usage:\n\ +\n\ + maintenance info inline-frames [ADDRESS]\n\ +\n\ +With no ADDRESS show all inline frames starting at the current program\n\ +counter address. When ADDRESS is given, list all inline frames starting\n\ +at ADDRESS.\n\ +\n\ +The last frame listed might not start at ADDRESS, this is the frame that\n\ +contains the other inline frames."), + &maintenanceinfolist); +} diff --git a/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.c b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.c new file mode 100644 index 00000000000..35b20648cd5 --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.c @@ -0,0 +1,57 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +static void inline_func_a (void); +static void inline_func_b (void); +static void normal_func (void); + +volatile int global_var = 0; + +static void __attribute__((noinline)) +normal_func (void) +{ + /* Do some work. */ + ++global_var; + ++global_var; + + /* Now the inline function. */ + inline_func_a (); + + /* Do some work. */ + ++global_var; /* After inline function. */ + ++global_var; +} + +static inline void __attribute__((__always_inline__)) +inline_func_a (void) +{ + inline_func_b (); +} + +static inline void __attribute__((__always_inline__)) +inline_func_b (void) +{ + ++global_var; + ++global_var; +} + +int +main () +{ + normal_func (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp new file mode 100644 index 00000000000..cbf090deba2 --- /dev/null +++ b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp @@ -0,0 +1,151 @@ +# Copyright (C) 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Check the 'maint info inline-frames' command. + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug nopie}]} { + return -1 +} + +if {![runto normal_func]} { + return 0 +} + +# Next forward until we find the call to inline_func_a(). The hope is +# that when we see the 'inline_func_a()' line this will be the start of +# the inlined function. This might not be the case on all +# architectures if the compiler needs to perform some preamble. +gdb_test_multiple "next" "next forward to inline_func_a" { + -re "^$decimal\\s+inline_func_a \\(\\);\r\n" { + # Consume the next prompt. + gdb_expect { + -re "^$gdb_prompt $" {} + } + pass $gdb_test_name + } + + -re "^$decimal\\s+\[^\r\n\]+After inline function\[^\r\n\]+\r\n" { + # We've gone too far! + fail $gdb_test_name + } + + -re "^$decimal\\s+\[^\r\n\]+\r\n" { + send_gdb "next\n" + exp_continue + } + + -re "^\[^\r\n\]+\r\n" { + exp_continue + } +} + +# View the inline frame information. This should display that we are +# at the start of inline_func_a() within normal_func(). +gdb_test "maint info inline-frames" \ + [multi_line \ + "^Cached inline state information for thread $decimal\\." \ + "program counter = $hex" \ + "skipped frames = 2" \ + " inline_func_b" \ + " inline_func_a" \ + "> normal_func"] \ + "check inline-frames state when in normal_func" + +# Step, we should now enter the inlined function. +gdb_test "step" ".*" \ + "step to enter inline_func" + +# And the inline-frames information should update. +gdb_test "maint info inline-frames" \ + [multi_line \ + "^Cached inline state information for thread $decimal\\." \ + "program counter = $hex" \ + "skipped frames = 1" \ + " inline_func_b" \ + "> inline_func_a" \ + " normal_func"] \ + "check inline-frames state when just entered inline_func_a" + +# Record the current program counter. +set pc [get_hexadecimal_valueof "\$pc" "UNKNOWN"] + +# Use the recorded $pc value to check inline frames. +gdb_test "maint info inline-frames $pc" \ + [multi_line \ + "^program counter = $hex" \ + "skipped frames = 2" \ + " inline_func_b" \ + " inline_func_a" \ + "> normal_func"] \ + "check inline-frames state at recorded \$pc while at the \$pc" + +# Step again, we should now enter inlined_func_b(). +gdb_test "step" ".*" \ + "step into inline_func_b" + +gdb_test "maint info inline-frames" \ + [multi_line \ + "^Cached inline state information for thread $decimal\\." \ + "program counter = $hex" \ + "skipped frames = 0" \ + "> inline_func_b" \ + " inline_func_a" \ + " normal_func"] \ + "check inline-frames state when just entered inline_func_b" + +gdb_test "step" ".*" \ + "step into the body of inline_func_b" + +# Now we are no longer at the start of the inlined function we should +# no longer see normal_func() in the inline-frames information. +gdb_test "maint info inline-frames" \ + [multi_line \ + "^Cached inline state information for thread $decimal\\." \ + "program counter = $hex" \ + "skipped frames = 0" \ + "> inline_func_b"] \ + "check inline-frames state when within inline_func_b" + +# Use the recorded $pc value to check inline frames. +gdb_test "maint info inline-frames $pc" \ + [multi_line \ + "^program counter = $hex" \ + "skipped frames = 2" \ + " inline_func_b" \ + " inline_func_a" \ + "> normal_func"] \ + "check inline-frames state at recorded \$pc" + +clean_restart $binfile + +# Use the recorded $pc value to check inline frames when the inferior +# is not executing. +gdb_test "maint info inline-frames $pc" \ + [multi_line \ + "^program counter = $hex" \ + "skipped frames = 2" \ + " inline_func_b" \ + " inline_func_a" \ + "> normal_func"] \ + "check inline-frames state at recorded \$pc before execution starts" + +# Trying to read the $pc from the current thread should fail if the +# inferior is not yet running. +gdb_test "maint info inline-frames" \ + "^no inferior thread" \ + "check inline-frames state of current thread before execution starts" From patchwork Tue Aug 20 14:43:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 96165 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 5F8F8384477D for ; Tue, 20 Aug 2024 14:44:12 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTP id 41E563844778 for ; Tue, 20 Aug 2024 14:43:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41E563844778 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 41E563844778 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165007; cv=none; b=wDkEymfBQxORVWaU4qs3CMfu3CgQ5fB5ePG0ELr6DVetJ7Th9YEs8LbThUTi/q/bzOpDGO0uAu1nzsu5ajRWFj+sxiGT8oaoJPfggePKgMJEYKcQsjESPMIC/AsLa1ilLp4XZk0CxzM4SAccN6HWFwjOXyELZ5LX08TU6WD9qeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724165007; c=relaxed/simple; bh=9lPCmhAirRucEgx3+vX5rwC99LLoVQ1+XR0V1+wNQlQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=aRPSXepIyrhU8hp6QV0pU3tLgSPVSjiqW5M3HOwBEuMu7gasO60mluOO1Zkw5OaCPb99LfGIvSaxkSo5N1iO4ub7VnNv0qqvMLeI7/dz5d6cDhIlyjtBGSdSHj+WVbTfm5wsIRUsvJo3hB/QSjfFZ/9X4bY3uXkuoH9CgG2Obhg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724165004; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BLucWgs07Ap1GsMAR7iygGR9Aj9ICO32j0QJ1anVFZw=; b=DxYEVz9H2/f/+ezvzrLSLZnuS7c5zRDs0Dq5pXnQ3gUZ4lyw25dV41emr7HU5ot5OwiTPd ZlZdVM4hzlAA3RsbAoc4HnKkJ8xiNpIs339p2Ld070KC3nepFchnOahqqbp2cq6ceugfCK vtrLa01Q7OvggqEoivhGIpSJ1Rdhqag= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-9-zjkfrjegPcKMbXN_efuomQ-1; Tue, 20 Aug 2024 10:43:22 -0400 X-MC-Unique: zjkfrjegPcKMbXN_efuomQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-429097df54bso45147405e9.1 for ; Tue, 20 Aug 2024 07:43:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724165001; x=1724769801; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=im4ofoA/WEZP5YnviR+rFNPgP47iE2nSwA9m6UgLyVc=; b=guDsEYbHu5zBcfLb4go4joUPuxbH4vk6wIJ4CHHGQxBql+IvhNrSdX90227mSqdvpS Qlq2AsGYJzYNEG0bYswRe60nUAR1zoJK+ygvLKFUP3tih5pU8eWMHx/0O4q0Q+YdoXQT /1MsOeDnbgtZARR2+f+Ndl2u4HnXOU9+9GbV80j8WTVJ5ZqTbQPfJckvfcrREeOTLLjx iyu+3swkMACB0KLGW1Rsbb26lQFMS0IY6vl1NzaFobvZR0zny034ol7EPk3xHIuu+tgN KFp3LLge42NiOIUtTrExJdMHSI/yleypL3uhoiKPvQzmpf5yRkfxO/Qy9aCy9kixw/Ce ExbA== X-Gm-Message-State: AOJu0YyVTligFENV9YCOJrtnLm7/3PQW7hYlvBx6cGMVbqvsOmiV4kCF U6Vt9/Cf6UAJiiY1HCEq241mF1Uzp5/XygBuGmGFtKK0XWF4c19/SlsGMrnSTT6ZDd6LKImgZqT 09GeDj9IJgwNHMn77NjM/jnsTVEkKjBzRHDoXo8zH3iRR5oHjHKhkLNpFJg0B/D5OyQKV79a0i6 Ho6QSjQeB9Yn4NQQjofBtc2QhxHjioJ6cYlflwHC1Oxrk= X-Received: by 2002:a05:600c:46c9:b0:426:5d0d:a2c9 with SMTP id 5b1f17b1804b1-429ed7ba991mr104492315e9.10.1724165000970; Tue, 20 Aug 2024 07:43:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEu/1kldF8o4LAviQNzOan8TS5YepQe3vTaj9vo4TuRlcqvaJ0zfvtGdK3iYFqwB3WRpxh4SA== X-Received: by 2002:a05:600c:46c9:b0:426:5d0d:a2c9 with SMTP id 5b1f17b1804b1-429ed7ba991mr104491875e9.10.1724164999867; Tue, 20 Aug 2024 07:43:19 -0700 (PDT) Received: from localhost (178.126.90.146.dyn.plus.net. [146.90.126.178]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37189896be4sm13394727f8f.77.2024.08.20.07.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 07:43:19 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Simon Marchi , Eli Zaretskii , Simon Marchi Subject: [PATCHv5 4/4] gdb: add 'maint info blocks' command Date: Tue, 20 Aug 2024 15:43:12 +0100 Message-Id: <9922974be67022e6d03041ce5d4330ae86ae1c91.1724164804.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.1 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org While reviewing a patch I wanted to understand which blocks existed at a given address. The 'maint print symbols' command does provide some of this information, but that command displays all blocks within a given symtab. If I want to know which blocks are at a given address I have to figure that out for myself based on the output of 'maint print symbols' ... and I'm too lazy for that! So this command lists just those blocks at a given address, along with information about the blocks type. This new command doesn't list the symbols within each block, for that my expectation is that you'd cross reference the output with that of 'maint print symbols'. The new command format is: maintenance info blocks maintenance info blocks ADDRESS This lists the blocks at ADDRESS, or at the current $pc if ADDRESS is not given. Blocks are listed starting at the global block, then the static block, and then the progressively narrower scoped blocks. For each block we list the internal block pointer (which allows easy cross referencing with 'maint print symbols'), the inferior address range, along with other useful information. Reviewed-By: Eli Zaretskii Approved-By: Simon Marchi --- gdb/NEWS | 6 + gdb/block.c | 123 ++++++++++++++++++ gdb/doc/gdb.texinfo | 60 +++++++++ .../maint-info-inline-frames-and-blocks.exp | 65 ++++++++- 4 files changed, 253 insertions(+), 1 deletion(-) diff --git a/gdb/NEWS b/gdb/NEWS index 9ffc9c31420..3f89f98b771 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -42,6 +42,12 @@ maintenance info inline-frames [ADDRESS] current address, or for ADDRESS if specified. The output identifies inlined frames which start at the specified address. +maintenance info blocks [ADDRESS] + New command which displays information about all of the blocks at + ADDRESS, or at the current address if ADDRESS is not given. Blocks + are listed starting at the inner global block out to the most inner + block. + *** Changes in GDB 15 * The MPX commands "show/set mpx bound" have been deprecated, as Intel diff --git a/gdb/block.c b/gdb/block.c index acf21e26fc8..124fdc1bb9d 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -25,6 +25,8 @@ #include "addrmap.h" #include "gdbtypes.h" #include "objfiles.h" +#include "cli/cli-cmds.h" +#include "inferior.h" /* This is used by struct block to store namespace-related info for C++ files, namely using declarations and the current namespace in @@ -834,3 +836,124 @@ make_blockranges (struct objfile *objfile, return blr; } +/* Implement 'maint info blocks' command. If passed an argument then + print a list of all blocks at the given address. With no arguments + then list all blocks at the current address of the current inferior. */ + +static void +maintenance_info_blocks (const char *arg, int from_tty) +{ + CORE_ADDR address; + + /* With no argument use the program counter of the current thread. If + there is an argument then use this as the address to examine. */ + if (arg == nullptr) + { + if (inferior_ptid == null_ptid) + error (_("no inferior thread")); + + struct regcache *regcache = get_thread_regcache (inferior_thread ()); + address = regcache_read_pc (regcache); + } + else + address = parse_and_eval_address (arg); + + /* Find the inner most block for ADDRESS. */ + const struct block *cur_block = block_for_pc (address); + if (cur_block == nullptr) + { + gdb_printf (_("No blocks at %s\n"), core_addr_to_string_nz (address)); + return; + } + + gdb_printf (_("Blocks at %s:\n"), core_addr_to_string_nz (address)); + + const struct objfile *toplevel_objfile = cur_block->objfile (); + if (toplevel_objfile != nullptr) + gdb_printf (_(" from objfile: [(objfile *) %s] %s\n"), + host_address_to_string (toplevel_objfile), + objfile_name (toplevel_objfile)); + + gdb_printf ("\n"); + + /* List the blocks backwards; global block (widest scope) first, down to + the smallest scoped block last. To do this we need to build the list + of blocks starting from the inner block, then print that list + backwards. */ + std::vector blocks; + while (cur_block != nullptr) + { + blocks.emplace_back (cur_block); + cur_block = cur_block->superblock (); + } + + for (auto it = blocks.rbegin (); it != blocks.rend (); ++it) + { + cur_block = *it; + + gdb_assert (cur_block->objfile () == toplevel_objfile); + + gdb_printf (_("[(block *) %s] %s..%s\n"), + host_address_to_string (cur_block), + core_addr_to_string_nz (cur_block->start ()), + core_addr_to_string_nz (cur_block->end ())); + gdb_printf (_(" entry pc: %s\n"), + core_addr_to_string_nz (cur_block->entry_pc ())); + + if (cur_block->is_static_block ()) + gdb_printf (_(" is static block\n")); + + if (cur_block->is_global_block ()) + gdb_printf (_(" is global block\n")); + + if (cur_block->function () != nullptr) + { + if (cur_block->inlined_p ()) + gdb_printf (_(" inline function: %s\n"), + cur_block->function ()->print_name ()); + else + gdb_printf (_(" function: %s\n"), + cur_block->function ()->print_name ()); + } + + if (cur_block->scope () != nullptr + && *cur_block->scope () != '\0') + gdb_printf (_(" scope: %s\n"), cur_block->scope ()); + + if (int symbol_count = mdict_size (cur_block->multidict ()); + symbol_count > 0) + gdb_printf (_(" symbol count: %d\n"), symbol_count); + + if (cur_block->is_contiguous ()) + gdb_printf (_(" is contiguous\n")); + else + { + gdb_printf (_(" address ranges:\n")); + for (const blockrange &rng : cur_block->ranges ()) + gdb_printf (_(" %s..%s\n"), + core_addr_to_string_nz (rng.start ()), + core_addr_to_string_nz (rng.end ())); + } + } +} + + + +void _initialize_block (); +void +_initialize_block () +{ + add_cmd ("blocks", class_maintenance, maintenance_info_blocks, + _("\ +Display block information for current thread.\n\ +\n\ +Usage:\n\ +\n\ + maintenance info blocks [ADDRESS]\n\ +\n\ +With no ADDRESS show all blocks at the current address, starting with the\n\ +global block and working down to the inner most block.\n\ +\n\ +When ADDRESS is given, list the blocks at ADDRESS."), + &maintenanceinfolist); +} diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index e85099f7d65..8cde2f22637 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -20419,6 +20419,7 @@ Show whether messages will be printed when a @value{GDBN} command entered from the keyboard causes symbol information to be loaded. +@anchor{maint print symbols} @kindex maint print symbols @cindex symbol dump @kindex maint print psymbols @@ -41969,6 +41970,65 @@ @end group @end smallexample +@kindex maint info blocks +@item maint info blocks +@itemx maint info blocks @var{address} +Print information about all blocks at @var{address}, or at the current +@code{$pc} if @var{address} is not given. + +For information about what blocks are in @value{GDBN} see @ref{Blocks +In Python}. + +Blocks are listed starting from the global block, then the static +block, and then proceeding through progressively narrower scopes. + +Here is an example of the command's output: +@smallexample +@group +(@value{GDBP}) maintenance info blocks +Blocks at 0x401137: + from objfile: [(objfile *) 0x50507d0] /tmp/inline_func_demo + +[(block *) 0x504da90] 0x401106..0x40119a + entry pc: 0x401106 + is global block + symbol count: 2 + is contiguous +@end group +@group +[(block *) 0x504d9f0] 0x401106..0x40119a + entry pc: 0x401106 + is static block + symbol count: 1 + is contiguous +@end group +@group +[(block *) 0x504d9a0] 0x401106..0x40119a + entry pc: 0x401106 + function: main + is contiguous +@end group +@group +[(block *) 0x504d900] 0x401137..0x401166 + entry pc: 0x401137 + inline function: foo + symbol count: 1 + is contiguous +@end group +@group +[(block *) 0x504d860] 0x401137..0x401165 + entry pc: 0x401137 + inline function: bar + symbol count: 1 + is contiguous +@end group +@end smallexample + +The command @kbd{maint info blocks} lists the symbol count for each +block but doesn't print the symbols themselves. The symbol names can +be found using @kbd{maint print symbols} (@pxref{maint print +symbols}). + @kindex maint print registers @kindex maint print raw-registers @kindex maint print cooked-registers diff --git a/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp index cbf090deba2..16be22a9963 100644 --- a/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp +++ b/gdb/testsuite/gdb.base/maint-info-inline-frames-and-blocks.exp @@ -13,7 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -# Check the 'maint info inline-frames' command. +# Check the 'maint info inline-frames' and 'maint info blocks' +# commands. standard_testfile @@ -26,6 +27,45 @@ if {![runto normal_func]} { return 0 } +# Make a pattern to match 'maint info blocks' output. ARGS is the +# list of function names we expect to see. If the function name +# starts with 'inline_func' then we expect to see an inline block, +# otherwise blocks are not expected to be inline. +proc make_blocks_result { args } { + set result \ + [list \ + "Blocks at $::hex:" \ + " from objfile: \\\[\\(objfile \\*\\) $::hex\\\] [string_to_regexp $::binfile]" \ + ""\ + "\\\[\\(block \\*\\) $::hex\\\] $::hex\\.\\.$::hex" \ + " entry pc: $::hex" \ + " is global block" \ + ".*" \ + "\\\[\\(block \\*\\) $::hex\\\] $::hex\\.\\.$::hex" \ + " entry pc: $::hex" \ + " is static block" \ + ".*" ] + + foreach func $args { + lappend result \ + "\\\[\\(block \\*\\) $::hex\\\] $::hex\\.\\.$::hex" \ + " entry pc: $::hex" + + if { [string range $func 0 10] eq "inline_func" } { + lappend result" inline function: $func" + } else { + lappend result" function: $func" + } + + lappend result ".*" + } + + return [multi_line {*}$result] +} + +gdb_test "maint info blocks" [make_blocks_result normal_func] \ + "maint info blocks in normal_func only" + # Next forward until we find the call to inline_func_a(). The hope is # that when we see the 'inline_func_a()' line this will be the start of # the inlined function. This might not be the case on all @@ -54,6 +94,10 @@ gdb_test_multiple "next" "next forward to inline_func_a" { } } +gdb_test "maint info blocks" [make_blocks_result normal_func \ + inline_func_a inline_func_b] \ + "maint info blocks when all blocks visible" + # View the inline frame information. This should display that we are # at the start of inline_func_a() within normal_func(). gdb_test "maint info inline-frames" \ @@ -108,6 +152,10 @@ gdb_test "maint info inline-frames" \ " normal_func"] \ "check inline-frames state when just entered inline_func_b" +gdb_test "maint info blocks" [make_blocks_result normal_func \ + inline_func_a inline_func_b] \ + "maint info blocks when all blocks still visible" + gdb_test "step" ".*" \ "step into the body of inline_func_b" @@ -121,6 +169,10 @@ gdb_test "maint info inline-frames" \ "> inline_func_b"] \ "check inline-frames state when within inline_func_b" +gdb_test "maint info blocks" [make_blocks_result normal_func \ + inline_func_a inline_func_b] \ + "maint info blocks within inline function, all blocks still visible" + # Use the recorded $pc value to check inline frames. gdb_test "maint info inline-frames $pc" \ [multi_line \ @@ -131,6 +183,10 @@ gdb_test "maint info inline-frames $pc" \ "> normal_func"] \ "check inline-frames state at recorded \$pc" +gdb_test "maint info blocks" [make_blocks_result normal_func \ + inline_func_a inline_func_b] \ + "maint info blocks using stored \$pc, inferior still running" + clean_restart $binfile # Use the recorded $pc value to check inline frames when the inferior @@ -144,8 +200,15 @@ gdb_test "maint info inline-frames $pc" \ "> normal_func"] \ "check inline-frames state at recorded \$pc before execution starts" +gdb_test "maint info blocks $pc" [make_blocks_result normal_func \ + inline_func_a inline_func_b] \ + "maint info blocks using stored \$pc, inferior not running" + # Trying to read the $pc from the current thread should fail if the # inferior is not yet running. gdb_test "maint info inline-frames" \ "^no inferior thread" \ "check inline-frames state of current thread before execution starts" + +gdb_test "maint info blocks" "^no inferior thread" \ + "maint info blocks with no \$pc and inferior not running"