From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/10] [gdb] Use block::containing_function_block
Date: Fri, 1 May 2026 14:44:57 +0200 [thread overview]
Message-ID: <20260501124504.2233495-4-tdevries@suse.de> (raw)
In-Reply-To: <20260501124504.2233495-1-tdevries@suse.de>
Add uses of block::containing_function_block.
---
gdb/guile/scm-frame.c | 13 ++++++-------
gdb/linespec.c | 15 +++++++--------
gdb/python/py-frame.c | 13 ++++++-------
gdb/python/py-unwind.c | 13 +++++--------
4 files changed, 24 insertions(+), 30 deletions(-)
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 722a754caab..ffcc3049074 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -598,7 +598,7 @@ static SCM
gdbscm_frame_block (SCM self)
{
frame_smob *f_smob;
- const struct block *block = NULL, *fn_block;
+ const struct block *block = nullptr;
bool found = false;
f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
@@ -625,12 +625,11 @@ gdbscm_frame_block (SCM self)
_("<gdb:frame>"));
}
- for (fn_block = block;
- fn_block != NULL && fn_block->function () == NULL;
- fn_block = fn_block->superblock ())
- continue;
-
- if (block == NULL || fn_block == NULL || fn_block->function () == NULL)
+ const struct block *fn_block
+ = (block != nullptr
+ ? block->containing_function_block ()
+ : nullptr);
+ if (fn_block == nullptr)
{
scm_misc_error (FUNC_NAME, _("cannot find block for frame"),
scm_list_1 (self));
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 45e12e09272..6ed4b4553d3 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3860,17 +3860,16 @@ find_label_symbols (struct linespec_state *self,
set_current_program_space (self->program_space);
block = get_current_search_block ();
- for (;
- block && !block->function ();
- block = block->superblock ())
- ;
-
- if (!block)
+ const struct block *fn_block
+ = (block != nullptr
+ ? block->containing_function_block ()
+ : nullptr);
+ if (fn_block == nullptr)
return {};
- fn_sym = block->function ();
+ fn_sym = fn_block->function ();
- find_label_symbols_in_block (block, name, fn_sym, completion_mode,
+ find_label_symbols_in_block (fn_block, name, fn_sym, completion_mode,
&result, label_funcs_ret);
}
else
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 1420d2ac5b9..42a281b9712 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -299,7 +299,7 @@ static PyObject *
frapy_block (PyObject *self, PyObject *args)
{
frame_info_ptr frame;
- const struct block *block = NULL, *fn_block;
+ const struct block *block = nullptr;
try
{
@@ -311,12 +311,11 @@ frapy_block (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- for (fn_block = block;
- fn_block != NULL && fn_block->function () == NULL;
- fn_block = fn_block->superblock ())
- ;
-
- if (block == NULL || fn_block == NULL || fn_block->function () == NULL)
+ const struct block *fn_block
+ = (block != nullptr
+ ? block->containing_function_block ()
+ : nullptr);
+ if (fn_block == nullptr)
{
PyErr_SetString (PyExc_RuntimeError,
_("Cannot locate block for frame."));
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index dcf86f7db3d..6dc5e11cf87 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -646,14 +646,11 @@ pending_framepy_block (PyObject *self, PyObject *args)
return gdbpy_handle_gdb_exception (nullptr, except);
}
- for (fn_block = block;
- fn_block != nullptr && fn_block->function () == nullptr;
- fn_block = fn_block->superblock ())
- ;
-
- if (block == nullptr
- || fn_block == nullptr
- || fn_block->function () == nullptr)
+ const struct block *fn_block
+ = (block != nullptr
+ ? block->containing_function_block ()
+ : nullptr);
+ if (fn_block == nullptr)
{
PyErr_SetString (PyExc_RuntimeError,
_("Cannot locate block for frame."));
--
2.51.0
next prev parent reply other threads:[~2026-05-01 12:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-01 12:44 [PATCH 00/10] [gdb] Add superblocks range loops Tom de Vries
2026-05-01 12:44 ` [PATCH 01/10] [gdb] Use block::containing_function Tom de Vries
2026-05-01 12:44 ` [PATCH 02/10] [gdb] Factor out block::containing_function_block Tom de Vries
2026-05-01 12:44 ` Tom de Vries [this message]
2026-05-01 12:44 ` [PATCH 04/10] [gdb] Add unit test for next_iterator Tom de Vries
2026-05-01 12:44 ` [PATCH 05/10] [gdbsupport] Use using instead of typedef in next_iterator Tom de Vries
2026-05-01 12:45 ` [PATCH 06/10] [gdbsupport] Factor out base_next_iterator Tom de Vries
2026-05-08 19:17 ` Tom Tromey
2026-05-01 12:45 ` [PATCH 07/10] [gdb] Add block::block_and_superblocks Tom de Vries
2026-05-01 12:45 ` [PATCH 08/10] [gdb] Use block::block_and_superblocks Tom de Vries
2026-05-08 19:41 ` Tom Tromey
2026-05-01 12:45 ` [PATCH 09/10] [gdb] Add block::block_and_superblocks_in_fn Tom de Vries
2026-05-01 12:45 ` [PATCH 10/10] [gdb] Use block::block_and_superblocks_in_fn Tom de Vries
2026-06-09 12:40 ` [PATCH 00/10] [gdb] Add superblocks range loops Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260501124504.2233495-4-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox