tools/perf/util/print_insn.c
Source file repositories/reference/linux-study-clean/tools/perf/util/print_insn.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/util/print_insn.c- Extension
.c- Size
- 1794 bytes
- Lines
- 68
- 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
inttypes.hstring.hstdbool.hcapstone.hdebug.hsample.hsymbol.hmachine.hthread.hprint_insn.hdump-insn.hmap.hdso.h
Detected Declarations
function Authorfunction is64bitipfunction fprintf_insn_asmfunction sample__fprintf_insn_asm
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Instruction binary disassembler based on capstone.
*
* Author(s): Changbin Du <changbin.du@huawei.com>
*/
#include <inttypes.h>
#include <string.h>
#include <stdbool.h>
#include "capstone.h"
#include "debug.h"
#include "sample.h"
#include "symbol.h"
#include "machine.h"
#include "thread.h"
#include "print_insn.h"
#include "dump-insn.h"
#include "map.h"
#include "dso.h"
size_t sample__fprintf_insn_raw(struct perf_sample *sample, FILE *fp)
{
int printed = 0;
for (int i = 0; i < sample->insn_len; i++) {
printed += fprintf(fp, "%02x", (unsigned char)sample->insn[i]);
if (sample->insn_len - i > 1)
printed += fprintf(fp, " ");
}
return printed;
}
static bool is64bitip(struct machine *machine, struct addr_location *al)
{
const struct dso *dso = al->map ? map__dso(al->map) : NULL;
if (dso)
return dso__is_64_bit(dso);
return machine__is(machine, "x86_64") ||
machine__normalized_is(machine, "arm64") ||
machine__normalized_is(machine, "s390");
}
ssize_t fprintf_insn_asm(struct machine *machine, struct thread *thread, u8 cpumode,
bool is64bit, const uint8_t *code, size_t code_size,
uint64_t ip, int *lenp, int print_opts, FILE *fp)
{
return capstone__fprintf_insn_asm(machine, thread, cpumode, is64bit, code, code_size,
ip, lenp, print_opts, fp);
}
size_t sample__fprintf_insn_asm(struct perf_sample *sample, struct thread *thread,
struct machine *machine, FILE *fp,
struct addr_location *al)
{
bool is64bit = is64bitip(machine, al);
ssize_t printed;
printed = fprintf_insn_asm(machine, thread, sample->cpumode, is64bit,
(uint8_t *)sample->insn, sample->insn_len,
sample->ip, NULL, 0, fp);
if (printed < 0)
return sample__fprintf_insn_raw(sample, fp);
return printed;
}
Annotation
- Immediate include surface: `inttypes.h`, `string.h`, `stdbool.h`, `capstone.h`, `debug.h`, `sample.h`, `symbol.h`, `machine.h`.
- Detected declarations: `function Author`, `function is64bitip`, `function fprintf_insn_asm`, `function sample__fprintf_insn_asm`.
- 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.