tools/perf/tests/code-reading.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/code-reading.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/code-reading.c- Extension
.c- Size
- 19457 bytes
- Lines
- 886
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- 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
errno.hlinux/kconfig.hlinux/kernel.hlinux/rbtree.hlinux/types.hlinux/zalloc.hinttypes.hstdlib.hunistd.hstdio.hstring.hsys/param.hsys/utsname.hperf/cpumap.hperf/evlist.hperf/mmap.hdebug.hdso.henv.hparse-events.hevlist.hevsel.hthread_map.hmachine.hmap.hsymbol.hevent.hrecord.hutil/mmap.hutil/string2.hutil/synthetic-events.hutil/util.h
Detected Declarations
struct tested_sectionfunction tested_code_insert_or_existsfunction tested_sections__freefunction read_objdump_chunkfunction disassemble_bytesfunction read_objdump_linefunction read_objdump_outputfunction objdump_versionfunction read_via_objdumpfunction dump_buffunction read_object_codefunction architecturesfunction map__loadfunction process_sample_eventfunction process_eventfunction process_eventsfunction compfunction do_sort_somethingfunction sort_somethingfunction syscall_somethingfunction fs_somethingfunction do_somethingfunction do_test_code_readingfunction evlist__for_each_entryfunction test__code_reading
Annotated Snippet
struct tested_section {
struct rb_node rb_node;
u64 addr;
char *path;
};
static bool tested_code_insert_or_exists(const char *path, u64 addr,
struct rb_root *tested_sections)
{
struct rb_node **node = &tested_sections->rb_node;
struct rb_node *parent = NULL;
struct tested_section *data;
while (*node) {
int cmp;
parent = *node;
data = rb_entry(*node, struct tested_section, rb_node);
cmp = strcmp(path, data->path);
if (!cmp) {
if (addr < data->addr)
cmp = -1;
else if (addr > data->addr)
cmp = 1;
else
return true; /* already tested */
}
if (cmp < 0)
node = &(*node)->rb_left;
else
node = &(*node)->rb_right;
}
data = zalloc(sizeof(*data));
if (!data)
return true;
data->addr = addr;
data->path = strdup(path);
if (!data->path) {
free(data);
return true;
}
rb_link_node(&data->rb_node, parent, node);
rb_insert_color(&data->rb_node, tested_sections);
return false;
}
static void tested_sections__free(struct rb_root *root)
{
while (!RB_EMPTY_ROOT(root)) {
struct rb_node *node = rb_first(root);
struct tested_section *ts = rb_entry(node,
struct tested_section,
rb_node);
rb_erase(node, root);
free(ts->path);
free(ts);
}
}
static size_t read_objdump_chunk(const char **line, unsigned char **buf,
size_t *buf_len)
{
size_t bytes_read = 0;
unsigned char *chunk_start = *buf;
/* Read bytes */
while (*buf_len > 0) {
char c1, c2;
/* Get 2 hex digits */
c1 = *(*line)++;
if (!isxdigit(c1))
break;
c2 = *(*line)++;
if (!isxdigit(c2))
break;
/* Store byte and advance buf */
**buf = (hex(c1) << 4) | hex(c2);
(*buf)++;
(*buf_len)--;
bytes_read++;
/* End of chunk? */
if (isspace(**line))
break;
Annotation
- Immediate include surface: `errno.h`, `linux/kconfig.h`, `linux/kernel.h`, `linux/rbtree.h`, `linux/types.h`, `linux/zalloc.h`, `inttypes.h`, `stdlib.h`.
- Detected declarations: `struct tested_section`, `function tested_code_insert_or_exists`, `function tested_sections__free`, `function read_objdump_chunk`, `function disassemble_bytes`, `function read_objdump_line`, `function read_objdump_output`, `function objdump_version`, `function read_via_objdump`, `function dump_buf`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.