Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169574
b: refs/heads/master
c: 2643ce1
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Nov 4, 2009
1 parent 4f0a009 commit f22c870
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a2e71271535fde493c32803b1f34789f97efcb5e
refs/heads/master: 2643ce11457a99a85c5bed8dd631e35968e6ca5a
51 changes: 34 additions & 17 deletions trunk/tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,27 +825,27 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
return err;
}

#define BUILD_ID_SIZE 128
#define BUILD_ID_SIZE 20

static char *dso__read_build_id(struct dso *self)
int filename__read_build_id(const char *filename, void *bf, size_t size)
{
int i;
int fd, err = -1;
GElf_Ehdr ehdr;
GElf_Shdr shdr;
Elf_Data *build_id_data;
Elf_Scn *sec;
char *build_id = NULL, *bid;
unsigned char *raw;
Elf *elf;
int fd = open(self->long_name, O_RDONLY);

if (size < BUILD_ID_SIZE)
goto out;

fd = open(filename, O_RDONLY);
if (fd < 0)
goto out;

elf = elf_begin(fd, PERF_ELF_C_READ_MMAP, NULL);
if (elf == NULL) {
pr_err("%s: cannot read %s ELF file.\n", __func__,
self->long_name);
pr_err("%s: cannot read %s ELF file.\n", __func__, filename);
goto out_close;
}

Expand All @@ -854,29 +854,46 @@ static char *dso__read_build_id(struct dso *self)
goto out_elf_end;
}

sec = elf_section_by_name(elf, &ehdr, &shdr, ".note.gnu.build-id", NULL);
sec = elf_section_by_name(elf, &ehdr, &shdr,
".note.gnu.build-id", NULL);
if (sec == NULL)
goto out_elf_end;

build_id_data = elf_getdata(sec, NULL);
if (build_id_data == NULL)
goto out_elf_end;
build_id = malloc(BUILD_ID_SIZE);
memcpy(bf, build_id_data->d_buf + 16, BUILD_ID_SIZE);
err = BUILD_ID_SIZE;
out_elf_end:
elf_end(elf);
out_close:
close(fd);
out:
return err;
}

static char *dso__read_build_id(struct dso *self)
{
int i, len;
char *build_id = NULL, *bid;
unsigned char rawbf[BUILD_ID_SIZE], *raw;

len = filename__read_build_id(self->long_name, rawbf, sizeof(rawbf));
if (len < 0)
goto out;

build_id = malloc(len * 2 + 1);
if (build_id == NULL)
goto out_elf_end;
raw = build_id_data->d_buf + 16;
goto out;
bid = build_id;

for (i = 0; i < 20; ++i) {
raw = rawbf;
for (i = 0; i < len; ++i) {
sprintf(bid, "%02x", *raw);
++raw;
bid += 2;
}
pr_debug2("%s(%s): %s\n", __func__, self->long_name, build_id);
out_elf_end:
elf_end(elf);
out_close:
close(fd);
out:
return build_id;
}
Expand Down
2 changes: 2 additions & 0 deletions trunk/tools/perf/util/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ void dsos__fprintf(FILE *fp);
size_t dso__fprintf(struct dso *self, FILE *fp);
char dso__symtab_origin(const struct dso *self);

int filename__read_build_id(const char *filename, void *bf, size_t size);

int load_kernel(symbol_filter_t filter);

void symbol__init(unsigned int priv_size);
Expand Down

0 comments on commit f22c870

Please sign in to comment.