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.

Dependency Surface

Detected Declarations

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

Implementation Notes