Example #1
0
static
void lttng_ust_dl_dlopen(void *so_base, const char *so_name, void *ip)
{
	char resolved_path[PATH_MAX];
	struct lttng_ust_elf *elf;
	uint64_t memsz;
	uint8_t *build_id;
	size_t build_id_len;
	char *dbg_file;
	uint32_t crc;
	int has_build_id = 0, has_debug_link = 0;
	int ret;

	if (!realpath(so_name, resolved_path)) {
		ERR("could not resolve path '%s'", so_name);
		return;
	}

	elf = lttng_ust_elf_create(resolved_path);
	if (!elf) {
		ERR("could not acces file %s", resolved_path);
		return;
	}

	ret = lttng_ust_elf_get_memsz(elf, &memsz);
	if (ret) {
		goto end;
	}
	ret = lttng_ust_elf_get_build_id(
		elf, &build_id, &build_id_len, &has_build_id);
	if (ret) {
		goto end;
	}
	ret = lttng_ust_elf_get_debug_link(
		elf, &dbg_file, &crc, &has_debug_link);
	if (ret) {
		goto end;
	}

	tracepoint(lttng_ust_dl, dlopen,
		ip, so_base, resolved_path, memsz);

	if (has_build_id) {
		tracepoint(lttng_ust_dl, build_id,
			ip, so_base, build_id, build_id_len);
		free(build_id);
	}

	if (has_debug_link) {
		tracepoint(lttng_ust_dl, debug_link,
			ip, so_base, dbg_file, crc);
		free(dbg_file);
	}

end:
	lttng_ust_elf_destroy(elf);
	return;
}
static
int get_elf_info(struct bin_info_data *bin_data)
{
	struct lttng_ust_elf *elf;
	int ret = 0, found;

	elf = lttng_ust_elf_create(bin_data->resolved_path);
	if (!elf) {
		ret = -1;
		goto end;
	}

	ret = lttng_ust_elf_get_memsz(elf, &bin_data->memsz);
	if (ret) {
		goto end;
	}

	found = 0;
	ret = lttng_ust_elf_get_build_id(elf, &bin_data->build_id,
					&bin_data->build_id_len,
					&found);
	if (ret) {
		goto end;
	}
	bin_data->has_build_id = !!found;
	found = 0;
	ret = lttng_ust_elf_get_debug_link(elf, &bin_data->dbg_file,
					&bin_data->crc,
					&found);
	if (ret) {
		goto end;
	}
	bin_data->has_debug_link = !!found;

	bin_data->is_pic = lttng_ust_elf_is_pic(elf);

end:
	lttng_ust_elf_destroy(elf);
	return ret;
}