aboutsummaryrefslogtreecommitdiff
path: root/gdb/tracefile-tfile.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-06-23 11:23:43 -0600
committerTom Tromey <tom@tromey.com>2023-07-10 13:02:11 -0600
commitebd4fd0a4fe6b35560cdf94d6d0b30801d954126 (patch)
tree94efc16877133eea068acd85e853130dcc76804b /gdb/tracefile-tfile.c
parentd4ea64fb5dd7bb79026c3bfacd06495d5f8e6702 (diff)
downloadbinutils-ebd4fd0a4fe6b35560cdf94d6d0b30801d954126.zip
binutils-ebd4fd0a4fe6b35560cdf94d6d0b30801d954126.tar.gz
binutils-ebd4fd0a4fe6b35560cdf94d6d0b30801d954126.tar.bz2
Use function_view in traceframe_walk_blocks
This change traceframe_walk_blocks to take a function_view. This simplifies the code somewhat and lets us entirely remove one helper function. Reviewed-by: Keith Seitz <keiths@redhat.com>
Diffstat (limited to 'gdb/tracefile-tfile.c')
-rw-r--r--gdb/tracefile-tfile.c50
1 files changed, 18 insertions, 32 deletions
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 364f8c1..d3304b0 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -773,33 +773,15 @@ tfile_target::trace_find (enum trace_find_type type, int num,
return -1;
}
-/* Prototype of the callback passed to tframe_walk_blocks. */
-typedef int (*walk_blocks_callback_func) (char blocktype, void *data);
-
-/* Callback for traceframe_walk_blocks, used to find a given block
- type in a traceframe. */
-
-static int
-match_blocktype (char blocktype, void *data)
-{
- char *wantedp = (char *) data;
-
- if (*wantedp == blocktype)
- return 1;
-
- return 0;
-}
-
/* Walk over all traceframe block starting at POS offset from
- CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
- unmodified. If CALLBACK returns true, this returns the position in
- the traceframe where the block is found, relative to the start of
- the traceframe (cur_offset). Returns -1 if no callback call
- returned true, indicating that all blocks have been walked. */
+ CUR_OFFSET, and call CALLBACK for each block found. If CALLBACK
+ returns true, this returns the position in the traceframe where the
+ block is found, relative to the start of the traceframe
+ (cur_offset). Returns -1 if no callback call returned true,
+ indicating that all blocks have been walked. */
static int
-traceframe_walk_blocks (walk_blocks_callback_func callback,
- int pos, void *data)
+traceframe_walk_blocks (gdb::function_view<bool (char)> callback, int pos)
{
/* Iterate through a traceframe's blocks, looking for a block of the
requested type. */
@@ -814,7 +796,7 @@ traceframe_walk_blocks (walk_blocks_callback_func callback,
++pos;
- if ((*callback) (block_type, data))
+ if (callback (block_type))
return pos;
switch (block_type)
@@ -854,7 +836,10 @@ traceframe_walk_blocks (walk_blocks_callback_func callback,
static int
traceframe_find_block_type (char type_wanted, int pos)
{
- return traceframe_walk_blocks (match_blocktype, pos, &type_wanted);
+ return traceframe_walk_blocks ([&] (char blocktype)
+ {
+ return blocktype == type_wanted;
+ }, pos);
}
/* Look for a block of saved registers in the traceframe, and get the
@@ -1060,11 +1045,9 @@ tfile_target::get_trace_state_variable_value (int tsvnum, LONGEST *val)
/* Callback for traceframe_walk_blocks. Builds a traceframe_info
object for the tfile target's current traceframe. */
-static int
-build_traceframe_info (char blocktype, void *data)
+static bool
+build_traceframe_info (char blocktype, struct traceframe_info *info)
{
- struct traceframe_info *info = (struct traceframe_info *) data;
-
switch (blocktype)
{
case 'M':
@@ -1104,7 +1087,7 @@ build_traceframe_info (char blocktype, void *data)
break;
}
- return 0;
+ return false;
}
traceframe_info_up
@@ -1112,7 +1095,10 @@ tfile_target::traceframe_info ()
{
traceframe_info_up info (new struct traceframe_info);
- traceframe_walk_blocks (build_traceframe_info, 0, info.get ());
+ traceframe_walk_blocks ([&] (char blocktype)
+ {
+ return build_traceframe_info (blocktype, info.get ());
+ }, 0);
return info;
}