Commit f766819c authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

perf tools: Pass build_id object to filename__read_build_id()



Pass a build_id object to filename__read_build_id function, so it can
populate the size of the build_id object.

Changing filename__read_build_id() code for both ELF/non-ELF code.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20201013192441.1299447-3-jolsa@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 0aba7f03
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ static int add_dso(const char *fpath, const struct stat *sb __maybe_unused,
	if (typeflag == FTW_D || typeflag == FTW_SL)
		return 0;

	if (filename__read_build_id(fpath, bid.data, sizeof(bid.data)) < 0)
	if (filename__read_build_id(fpath, &bid) < 0)
		return 0;

	dso->name = realpath(fpath, NULL);
+12 −13
Original line number Diff line number Diff line
@@ -174,19 +174,19 @@ static int build_id_cache__add_kcore(const char *filename, bool force)
static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)
{
	char sbuild_id[SBUILD_ID_SIZE];
	u8 build_id[BUILD_ID_SIZE];
	struct build_id bid;
	int err;
	struct nscookie nsc;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &build_id, sizeof(build_id));
	err = filename__read_build_id(filename, &bid);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
		return -1;
	}

	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
	build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
	err = build_id_cache__add_s(sbuild_id, filename, nsi,
				    false, false);
	pr_debug("Adding %s %s: %s\n", sbuild_id, filename,
@@ -196,21 +196,21 @@ static int build_id_cache__add_file(const char *filename, struct nsinfo *nsi)

static int build_id_cache__remove_file(const char *filename, struct nsinfo *nsi)
{
	u8 build_id[BUILD_ID_SIZE];
	char sbuild_id[SBUILD_ID_SIZE];
	struct build_id bid;
	struct nscookie nsc;

	int err;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &build_id, sizeof(build_id));
	err = filename__read_build_id(filename, &bid);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
		return -1;
	}

	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
	build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
	err = build_id_cache__remove_s(sbuild_id);
	pr_debug("Removing %s %s: %s\n", sbuild_id, filename,
		 err ? "FAIL" : "Ok");
@@ -274,17 +274,16 @@ static int build_id_cache__purge_all(void)
static bool dso__missing_buildid_cache(struct dso *dso, int parm __maybe_unused)
{
	char filename[PATH_MAX];
	u8 build_id[BUILD_ID_SIZE];
	struct build_id bid;

	if (dso__build_id_filename(dso, filename, sizeof(filename), false) &&
	    filename__read_build_id(filename, build_id,
				    sizeof(build_id)) != sizeof(build_id)) {
	    filename__read_build_id(filename, &bid) == -1) {
		if (errno == ENOENT)
			return false;

		pr_warning("Problems with %s file, consider removing it from the cache\n",
			   filename);
	} else if (memcmp(dso->bid.data, build_id, sizeof(dso->bid.data))) {
	} else if (memcmp(dso->bid.data, bid.data, bid.size)) {
		pr_warning("Problems with %s file, consider removing it from the cache\n",
			   filename);
	}
@@ -300,14 +299,14 @@ static int build_id_cache__fprintf_missing(struct perf_session *session, FILE *f

static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
{
	u8 build_id[BUILD_ID_SIZE];
	char sbuild_id[SBUILD_ID_SIZE];
	struct build_id bid;
	struct nscookie nsc;

	int err;

	nsinfo__mountns_enter(nsi, &nsc);
	err = filename__read_build_id(filename, &build_id, sizeof(build_id));
	err = filename__read_build_id(filename, &bid);
	nsinfo__mountns_exit(&nsc);
	if (err < 0) {
		pr_debug("Couldn't read a build-id in %s\n", filename);
@@ -315,7 +314,7 @@ static int build_id_cache__update_file(const char *filename, struct nsinfo *nsi)
	}
	err = 0;

	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
	build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
	if (build_id_cache__cached(sbuild_id))
		err = build_id_cache__remove_s(sbuild_id);

+1 −3
Original line number Diff line number Diff line
@@ -522,10 +522,8 @@ static int dso__read_build_id(struct dso *dso)
		return 0;

	nsinfo__mountns_enter(dso->nsinfo, &nsc);
	if (filename__read_build_id(dso->long_name, dso->bid.data,
				    sizeof(dso->bid.data)) > 0) {
	if (filename__read_build_id(dso->long_name, &dso->bid) > 0)
		dso->has_build_id = true;
	}
	nsinfo__mountns_exit(&nsc);

	return dso->has_build_id ? 0 : -1;
+5 −5
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ static int run_dir(const char *d)
{
	char filename[PATH_MAX];
	char debugfile[PATH_MAX];
	char build_id[BUILD_ID_SIZE];
	struct build_id bid;
	char debuglink[PATH_MAX];
	char expect_build_id[] = {
		0x5a, 0x0f, 0xd8, 0x82, 0xb5, 0x30, 0x84, 0x22,
@@ -36,10 +36,10 @@ static int run_dir(const char *d)
	int ret;

	scnprintf(filename, PATH_MAX, "%s/pe-file.exe", d);
	ret = filename__read_build_id(filename, build_id, BUILD_ID_SIZE);
	ret = filename__read_build_id(filename, &bid);
	TEST_ASSERT_VAL("Failed to read build_id",
			ret == sizeof(expect_build_id));
	TEST_ASSERT_VAL("Wrong build_id", !memcmp(build_id, expect_build_id,
	TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
						  sizeof(expect_build_id)));

	ret = filename__read_debuglink(filename, debuglink, PATH_MAX);
@@ -48,10 +48,10 @@ static int run_dir(const char *d)
			!strcmp(debuglink, expect_debuglink));

	scnprintf(debugfile, PATH_MAX, "%s/%s", d, debuglink);
	ret = filename__read_build_id(debugfile, build_id, BUILD_ID_SIZE);
	ret = filename__read_build_id(debugfile, &bid);
	TEST_ASSERT_VAL("Failed to read debug file build_id",
			ret == sizeof(expect_build_id));
	TEST_ASSERT_VAL("Wrong build_id", !memcmp(build_id, expect_build_id,
	TEST_ASSERT_VAL("Wrong build_id", !memcmp(bid.data, expect_build_id,
						  sizeof(expect_build_id)));

	dso = dso__new(filename);
+3 −3
Original line number Diff line number Diff line
@@ -28,16 +28,16 @@ static int target_function(void)
static int build_id_cache__add_file(const char *filename)
{
	char sbuild_id[SBUILD_ID_SIZE];
	u8 build_id[BUILD_ID_SIZE];
	struct build_id bid;
	int err;

	err = filename__read_build_id(filename, &build_id, sizeof(build_id));
	err = filename__read_build_id(filename, &bid);
	if (err < 0) {
		pr_debug("Failed to read build id of %s\n", filename);
		return err;
	}

	build_id__sprintf(build_id, sizeof(build_id), sbuild_id);
	build_id__sprintf(bid.data, sizeof(bid.data), sbuild_id);
	err = build_id_cache__add_s(sbuild_id, filename, NULL, false, false);
	if (err < 0)
		pr_debug("Failed to add build id cache of %s\n", filename);
Loading