tools/perf/util/disasm.c
Source file repositories/reference/linux-study-clean/tools/perf/util/disasm.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/disasm.c- Extension
.c- Size
- 41946 bytes
- Lines
- 1646
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
ctype.helf.herrno.hfcntl.hinttypes.hlibgen.hregex.hstdlib.hunistd.hlinux/string.hlinux/zalloc.hsubcmd/run-command.hannotate.hannotate-data.hbuild-id.hcapstone.hdebug.hdisasm.hdso.hdwarf-regs.henv.hevsel.hlibbfd.hllvm.hmap.hmaps.hnamespaces.hsrcline.hsymbol.hthread.hutil.h
Detected Declarations
function __attribute__function arch__grow_instructionsfunction arch__associate_ins_opsfunction e_machine_and_eflags__cmpfunction arch__key_cmpfunction arch__cmpfunction arch__is_x86function arch__is_powerpcfunction ins_ops__deletefunction ins__raw_scnprintffunction ins__scnprintffunction ins__is_fusedfunction call__parsefunction call__scnprintffunction ins__is_callfunction jump__parsefunction jump__scnprintffunction jump__deletefunction ins__is_jumpfunction comment__symbolfunction lock__parsefunction lock__scnprintffunction lock__deletefunction check_multi_regsfunction mov__parsefunction mov__scnprintffunction dec__parsefunction dec__scnprintffunction nop__scnprintffunction ins__is_nopfunction ins__is_retfunction ins__is_lockfunction ins__key_cmpfunction ins__cmpfunction ins__sortfunction disasm_line__init_insfunction disasm_line__parsefunction disasm_line__parse_powerpcfunction annotation_line__initfunction annotation_line__exitfunction disasm_line_sizefunction disasm_line__freefunction disasm_line__scnprintffunction symbol__parse_objdump_linefunction delete_last_nopfunction symbol__strerror_disassemblefunction dso__disassemble_filenamefunction access
Annotated Snippet
if (!ops->target.addr) {
c = strchr(c, ',');
c = validate_comma(c, ops);
if (c != NULL) {
c++;
ops->target.addr = strtoull(c, NULL, 16);
}
}
} else {
ops->target.addr = strtoull(ops->raw, NULL, 16);
}
target.addr = map__objdump_2mem(map, ops->target.addr);
start = map__unmap_ip(map, sym->start);
end = map__unmap_ip(map, sym->end);
ops->target.outside = target.addr < start || target.addr >= end;
/*
* FIXME: things like this in _cpp_lex_token (gcc's cc1 program):
cpp_named_operator2name@@Base+0xa72
* Point to a place that is after the cpp_named_operator2name
* boundaries, i.e. in the ELF symbol table for cc1
* cpp_named_operator2name is marked as being 32-bytes long, but it in
* fact is much larger than that, so we seem to need a symbols__find()
* routine that looks for >= current->start and < next_symbol->start,
* possibly just for C++ objects?
*
* For now lets just make some progress by marking jumps to outside the
* current function as call like.
*
* Actual navigation will come next, with further understanding of how
* the symbol searching and disassembly should be done.
*/
if (maps__find_ams(thread__maps(ms->thread), &target) == 0 &&
map__rip_2objdump(target.ms.map, map__map_ip(target.ms.map, target.addr)) == ops->target.addr)
ops->target.sym = target.ms.sym;
if (!ops->target.outside) {
ops->target.offset = target.addr - start;
ops->target.offset_avail = true;
} else {
ops->target.offset_avail = false;
}
addr_map_symbol__exit(&target);
return 0;
}
int jump__scnprintf(const struct ins *ins, char *bf, size_t size,
struct ins_operands *ops, int max_ins_name)
{
const char *c;
if (!ops->target.addr || ops->target.offset < 0)
return ins__raw_scnprintf(ins, bf, size, ops, max_ins_name);
if (ops->target.outside && ops->target.sym != NULL)
return scnprintf(bf, size, "%-*s %s", max_ins_name, ins->name, ops->target.sym->name);
c = strchr(ops->raw, ',');
c = validate_comma(c, ops);
if (c != NULL) {
const char *c2 = strchr(c + 1, ',');
c2 = validate_comma(c2, ops);
/* check for 3-op insn */
if (c2 != NULL)
c = c2;
c++;
/* mirror arch objdump's space-after-comma style */
if (*c == ' ')
c++;
}
return scnprintf(bf, size, "%-*s %.*s%" PRIx64, max_ins_name,
ins->name, c ? c - ops->raw : 0, ops->raw,
ops->target.offset);
}
void jump__delete(struct ins_operands *ops __maybe_unused)
{
/*
* The ops->jump.raw_comment and ops->jump.raw_func_start belong to the
* raw string, don't free them.
*/
}
Annotation
- Immediate include surface: `ctype.h`, `elf.h`, `errno.h`, `fcntl.h`, `inttypes.h`, `libgen.h`, `regex.h`, `stdlib.h`.
- Detected declarations: `function __attribute__`, `function arch__grow_instructions`, `function arch__associate_ins_ops`, `function e_machine_and_eflags__cmp`, `function arch__key_cmp`, `function arch__cmp`, `function arch__is_x86`, `function arch__is_powerpc`, `function ins_ops__delete`, `function ins__raw_scnprintf`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.