From: Tom Tromey Date: Thu, 23 Jun 2022 17:23:43 +0000 (-0600) Subject: Use function_view in traceframe_walk_blocks X-Git-Tag: binutils-2_41-release~243 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ebd4fd0a4fe6b35560cdf94d6d0b30801d954126;p=thirdparty%2Fbinutils-gdb.git 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 --- diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index 364f8c1f08e..d3304b0b355 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 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; }