scripts/tracepoint-update.c
Source file repositories/reference/linux-study-clean/scripts/tracepoint-update.c
File Facts
- System
- Linux kernel
- Corpus path
scripts/tracepoint-update.c- Extension
.c- Size
- 6095 bytes
- Lines
- 267
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/types.hsys/stat.hgetopt.hfcntl.hstdio.hstdlib.hstdbool.hstring.hunistd.herrno.hpthread.helf-parse.h
Detected Declarations
struct elf_tracepointfunction compare_stringsfunction add_stringfunction make_trace_arrayfunction tracepointsfunction find_eventfunction check_tracepointsfunction process_tracepointsfunction main
Annotated Snippet
struct elf_tracepoint {
Elf_Ehdr *ehdr;
const char **array;
int count;
};
#define REALLOC_SIZE (1 << 10)
#define REALLOC_MASK (REALLOC_SIZE - 1)
static int add_string(const char *str, const char ***vals, int *count)
{
const char **array = *vals;
if (!(*count & REALLOC_MASK)) {
int size = (*count) + REALLOC_SIZE;
array = realloc(array, sizeof(char *) * size);
if (!array) {
fprintf(stderr, "Failed memory allocation\n");
free(*vals);
*vals = NULL;
return -1;
}
*vals = array;
}
array[(*count)++] = str;
return 0;
}
/**
* for_each_shdr_str - iterator that reads strings that are in an ELF section.
* @len: "int" to hold the length of the current string
* @ehdr: A pointer to the ehdr of the ELF file
* @sec: The section that has the strings to iterate on
*
* This is a for loop that iterates over all the nul terminated strings
* that are in a given ELF section. The variable "str" will hold
* the current string for each iteration and the passed in @len will
* contain the strlen() of that string.
*/
#define for_each_shdr_str(len, ehdr, sec) \
for (const char *str = (void *)(ehdr) + shdr_offset(sec), \
*end = str + shdr_size(sec); \
len = strlen(str), str < end; \
str += (len) + 1)
static void make_trace_array(struct elf_tracepoint *etrace)
{
Elf_Ehdr *ehdr = etrace->ehdr;
const char **vals = NULL;
int count = 0;
int len;
etrace->array = NULL;
/*
* The __tracepoint_check section is filled with strings of the
* names of tracepoints (in tracepoint_strings). Create an array
* that points to each string and then sort the array.
*/
for_each_shdr_str(len, ehdr, check_data_sec) {
if (!len)
continue;
if (add_string(str, &vals, &count) < 0)
return;
}
/* If CONFIG_TRACEPOINT_VERIFY_USED is not set, there's nothing to do */
if (!count)
return;
qsort(vals, count, sizeof(char *), compare_strings);
etrace->array = vals;
etrace->count = count;
}
static int find_event(const char *str, void *array, size_t size)
{
return bsearch(&str, array, size, sizeof(char *), compare_strings) != NULL;
}
static void check_tracepoints(struct elf_tracepoint *etrace, const char *fname)
{
Elf_Ehdr *ehdr = etrace->ehdr;
int len;
if (!etrace->array)
Annotation
- Immediate include surface: `sys/types.h`, `sys/stat.h`, `getopt.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `stdbool.h`, `string.h`.
- Detected declarations: `struct elf_tracepoint`, `function compare_strings`, `function add_string`, `function make_trace_array`, `function tracepoints`, `function find_event`, `function check_tracepoints`, `function process_tracepoints`, `function main`.
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.