~kdsch/uc

fde177562603378d75a6297e16670438a69e233b — Karl Schultheisz 2 years ago 6f83d29
node: add node_dump function

The full tree view is more useful than printing only the crash sites.
4 files changed, 59 insertions(+), 27 deletions(-)

A .gitignore
M node.c
M node.h
M uc.c
A .gitignore => .gitignore +3 -0
@@ 0,0 1,3 @@
*.o
uc
test/crasher

M node.c => node.c +54 -0
@@ 174,3 174,57 @@ node_crashes(const struct node *root, const struct frame *f,
	node_visit(n, &v);
}

static void
indent(unsigned level)
{
	for (unsigned i = 0; i < level; i++) {
		printf("  ");
	}
}

static void
node_dump_indent(const struct node *n, unsigned level)
{
	indent(level);

	if (!n) {
		printf("(null)\n");
		return;
	}

	switch (n->type) {
	case NODE_ROOT:
		printf("root");
		break;
	case NODE_FRAME:
		printf("%s() 0x%lx 0x%lx", n->frame.symbol, n->frame.ip, n->frame.offset);
		break;
	case NODE_CRASH:
		printf("%s {", strsignal(n->crash.signal));
		for (size_t i = 0; n->crash.argv[i]; i++) {
			if (i) {
				printf(", ");
			}
			printf("\"%s\"", n->crash.argv[i]);
		}
		printf("}");
		break;
	}

	printf("\n");
	if (n->type != NODE_CRASH) {
		for (size_t i = 0; i < n->callers.len; i++) {
			if (i) {
				printf("\n");
			}
			node_dump_indent(n->callers.nodes[i], level + 1);
		}
	}
}

void
node_dump(const struct node *n)
{
	node_dump_indent(n, 0);
}


M node.h => node.h +1 -0
@@ 33,5 33,6 @@ struct node {
struct node *node_new_root(void);
void node_add_trace(struct node *root, const struct trace_iter *t, const struct crash *c);
void node_crashes(const struct node *root, const struct frame *f, struct node_array *crashes);
void node_dump(const struct node *n);

#endif

M uc.c => uc.c +1 -27
@@ 35,32 35,6 @@ main(void)
		tracer_finish(&t);
	}

	for (size_t i = 0; i < root->callers.len; i++) {
		struct node *n = root->callers.nodes[i];
		assert(n->type == NODE_FRAME);
		struct node_array crashes = {0};
		node_crashes(root, &n->frame, &crashes);

		if (i) {
			printf("\n");
		}

		printf("ip=%lx offset=%lx %s\n", n->frame.ip, n->frame.offset,
			n->frame.symbol);

		for (size_t j = 0; j < crashes.len; j++) {
			struct node *m = crashes.nodes[j];
			printf("\t");
			for (size_t k = 0; m->crash.argv[k]; k++) {
				if (k) {
					printf(" ");
				}

				printf("%s", m->crash.argv[k]);
			}
			printf("\n");
		}
	}

	node_dump(root);
	return 0;
}