aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2026-04-16 16:16:13 -0400
committerSimon Marchi <simon.marchi@efficios.com>2026-04-17 15:30:29 -0400
commitea4bacd354c1eb02c2e4faaa8096e69be6f0177f (patch)
tree51f3b0a59d3da5aa15bb649e0fcc4ea3e2431437 /gdb/python
parent85d417c37274603f5265ce67e348789e5c8417cf (diff)
downloadbinutils-ea4bacd354c1eb02c2e4faaa8096e69be6f0177f.tar.gz
binutils-ea4bacd354c1eb02c2e4faaa8096e69be6f0177f.tar.bz2
binutils-ea4bacd354c1eb02c2e4faaa8096e69be6f0177f.zip
gdb: introduce iteration_status enum, use it for search callbacks
There are a bunch of iteration functions that take a callback returning true or false to indicate whether to continue or stop iterating. These functions then return the same value, indicate whether the iteration was done until the end of interrupted. I think this is confusing and error-prone, as I never know which value means what. It is especially confusing when two opposite conventions collide, such as in objfile::map_symtabs_matching_filename. I propose to make that more obvious by introducing a new iteration_status enum with self-documenting values. I started to change the callback type compunit_symtab_iteration_callback, taken by quick_symbol_functions::search, and then followed that path to update a bunch of other functions. I chose the name to be kind of generic, so that it can be used for other similar iteration patterns. I also put it in gdbsupport, in case we want to use it in gdbserver too. Change-Id: I55d84d0c1af8ac0b82cc9f49ccf0d6b60e1769e0 Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-symbol.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index e74c8e4b368..6293b658ea1 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -599,7 +599,7 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
/* Skip included compunits to prevent including compunits from
being searched twice. */
if (cust->user != nullptr)
- return true;
+ return iteration_status::keep_going;
const struct blockvector *bv = cust->blockvector ();
const struct block *block = bv->static_block ();
@@ -615,16 +615,22 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
if (sym_obj == nullptr
|| PyList_Append (return_list.get (),
sym_obj.get ()) == -1)
- return false;
+ return iteration_status::stop;
}
}
- return true;
+ return iteration_status::keep_going;
};
- if (!objfile.search (nullptr, &lookup_name, nullptr, callback,
- SEARCH_STATIC_BLOCK, flags))
- return nullptr;
+ /* The only reason why the iteration would stop is if an error was
+ encountered during the callback execution. */
+ if (objfile.search (nullptr, &lookup_name, nullptr, callback,
+ SEARCH_STATIC_BLOCK, flags)
+ == iteration_status::stop)
+ {
+ gdb_assert (PyErr_Occurred ());
+ return nullptr;
+ }
}
}
catch (const gdb_exception &except)