Skip to content

Commit 69a3ce4

Browse files
committed
btf: add BTF_KIND_FUNC traversal function.
The patch adds a traversal function to traverse all BTF_KIND_FUNC nodes with a callback function. Used for .BTF.ext section content creation. gcc/ChangeLog: * btfout.cc (output_btf_func_types): Use FOR_EACH_VEC_ELT. (traverse_btf_func_types): Define function. * ctfc.h (funcs_traverse_callback): Typedef for function prototype. (traverse_btf_func_types): Add prototype.
1 parent 0198cad commit 69a3ce4

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

gcc/btfout.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,10 @@ output_btf_types (ctf_container_ref ctfc)
12761276
static void
12771277
output_btf_func_types (ctf_container_ref ctfc)
12781278
{
1279-
for (size_t i = 0; i < vec_safe_length (funcs); i++)
1280-
btf_asm_func_type (ctfc, (*funcs)[i], i);
1279+
ctf_dtdef_ref ref;
1280+
unsigned i;
1281+
FOR_EACH_VEC_ELT (*funcs, i, ref)
1282+
btf_asm_func_type (ctfc, ref, i);
12811283
}
12821284

12831285
/* Output all BTF_KIND_DATASEC records. */
@@ -1452,4 +1454,20 @@ btf_finalize (void)
14521454
tu_ctfc = NULL;
14531455
}
14541456

1457+
/* Traversal function for all BTF_KIND_FUNC type records. */
1458+
1459+
bool
1460+
traverse_btf_func_types (funcs_traverse_callback callback, void *data)
1461+
{
1462+
ctf_dtdef_ref ref;
1463+
unsigned i;
1464+
FOR_EACH_VEC_ELT (*funcs, i, ref)
1465+
{
1466+
bool stop = callback (ref, data);
1467+
if (stop == true)
1468+
return true;
1469+
}
1470+
return false;
1471+
}
1472+
14551473
#include "gt-btfout.h"

gcc/ctfc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,9 @@ extern int ctf_add_variable (ctf_container_ref, const char *, ctf_id_t,
441441
extern ctf_id_t ctf_lookup_tree_type (ctf_container_ref, const tree);
442442
extern ctf_id_t get_btf_id (ctf_id_t);
443443

444+
typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *);
445+
bool traverse_btf_func_types (funcs_traverse_callback, void *);
446+
444447
/* CTF section does not emit location information; at this time, location
445448
information is needed for BTF CO-RE use-cases. */
446449

0 commit comments

Comments
 (0)