tools/perf/util/genelf_debug.c
Source file repositories/reference/linux-study-clean/tools/perf/util/genelf_debug.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/genelf_debug.c- Extension
.c- Size
- 14677 bytes
- Lines
- 626
- 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
linux/compiler.hlinux/zalloc.hsys/types.hstdio.hgetopt.hstddef.hlibelf.hstring.hstdlib.hinttypes.hlimits.hfcntl.herr.hdwarf.hgenelf.h../util/jitdump.h
Detected Declarations
struct buffer_extstruct debug_line_headerstruct compilation_unit_headerfunction buffer_ext_dumpfunction buffer_ext_addfunction buffer_ext_initfunction buffer_ext_exitfunction buffer_ext_sizefunction buffer_ext_addrfunction emit_uwordfunction emit_stringfunction emit_unsigned_LEB128function emit_signed_LEB128function emit_extended_opcodefunction emit_opcodefunction emit_opcode_signedfunction emit_opcode_unsignedfunction emit_advance_pcfunction emit_advance_linenofunction emit_lne_end_of_sequencefunction emit_set_filefunction emit_lne_define_filenamefunction emit_lne_set_addressfunction get_special_opcodefunction emit_lineno_infofunction add_debug_linefunction add_debug_abbrevfunction add_compilation_unitfunction jit_process_debug_infofunction jit_add_debug_info
Annotated Snippet
struct buffer_ext {
size_t cur_pos;
size_t max_sz;
void *data;
};
static void
buffer_ext_dump(struct buffer_ext *be, const char *msg)
{
size_t i;
warnx("DUMP for %s", msg);
for (i = 0 ; i < be->cur_pos; i++)
warnx("%4zu 0x%02x", i, (((char *)be->data)[i]) & 0xff);
}
static inline int
buffer_ext_add(struct buffer_ext *be, void *addr, size_t sz)
{
void *tmp;
size_t be_sz = be->max_sz;
retry:
if ((be->cur_pos + sz) < be_sz) {
memcpy(be->data + be->cur_pos, addr, sz);
be->cur_pos += sz;
return 0;
}
if (!be_sz)
be_sz = BUFFER_EXT_DFL_SIZE;
else
be_sz <<= 1;
tmp = realloc(be->data, be_sz);
if (!tmp)
return -1;
be->data = tmp;
be->max_sz = be_sz;
goto retry;
}
static void
buffer_ext_init(struct buffer_ext *be)
{
be->data = NULL;
be->cur_pos = 0;
be->max_sz = 0;
}
static void
buffer_ext_exit(struct buffer_ext *be)
{
zfree(&be->data);
}
static inline size_t
buffer_ext_size(struct buffer_ext *be)
{
return be->cur_pos;
}
static inline void *
buffer_ext_addr(struct buffer_ext *be)
{
return be->data;
}
struct debug_line_header {
// Not counting this field
uword total_length;
// version number (2 currently)
uhalf version;
// relative offset from next field to
// program statement
uword prolog_length;
ubyte minimum_instruction_length;
ubyte default_is_stmt;
// line_base - see DWARF 2 specs
sbyte line_base;
// line_range - see DWARF 2 specs
ubyte line_range;
// number of opcode + 1
ubyte opcode_base;
/* follow the array of opcode args nr: ubytes [nr_opcode_base] */
/* follow the search directories index, zero terminated string
* terminated by an empty string.
*/
/* follow an array of { filename, LEB128, LEB128, LEB128 }, first is
Annotation
- Immediate include surface: `linux/compiler.h`, `linux/zalloc.h`, `sys/types.h`, `stdio.h`, `getopt.h`, `stddef.h`, `libelf.h`, `string.h`.
- Detected declarations: `struct buffer_ext`, `struct debug_line_header`, `struct compilation_unit_header`, `function buffer_ext_dump`, `function buffer_ext_add`, `function buffer_ext_init`, `function buffer_ext_exit`, `function buffer_ext_size`, `function buffer_ext_addr`, `function emit_uword`.
- 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.