Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169651
b: refs/heads/master
c: f1617b4
h: refs/heads/master
i:
  169649: a04324d
  169647: 4d74a38
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Nov 19, 2009
1 parent 2c57cd1 commit 46ed770
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 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: e30a3d12ddf04add3268bfceb0e57ffe47f254c6
refs/heads/master: f1617b40596cb341ee6602a9d969c5e4cebe9260
5 changes: 5 additions & 0 deletions trunk/tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ perf_header__adds_write(struct perf_header *self, int fd)

buildid_sec = &feat_sec[idx++];

/*
* Read the list of loaded modules with its build_ids
*/
dsos__load_modules();

/* Write build-ids */
buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
if (dsos__write_buildid_table(fd) < 0)
Expand Down
53 changes: 52 additions & 1 deletion trunk/tools/perf/util/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <libelf.h>
#include <gelf.h>
#include <elf.h>
#include <limits.h>
#include <sys/utsname.h>

enum dso_origin {
Expand Down Expand Up @@ -943,6 +944,50 @@ int filename__read_build_id(const char *filename, void *bf, size_t size)
return err;
}

int sysfs__read_build_id(const char *filename, void *build_id, size_t size)
{
int fd, err = -1;

if (size < BUILD_ID_SIZE)
goto out;

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

while (1) {
char bf[BUFSIZ];
GElf_Nhdr nhdr;
int namesz, descsz;

if (read(fd, &nhdr, sizeof(nhdr)) != sizeof(nhdr))
break;

namesz = (nhdr.n_namesz + 3) & -4U;
descsz = (nhdr.n_descsz + 3) & -4U;
if (nhdr.n_type == NT_GNU_BUILD_ID &&
nhdr.n_namesz == sizeof("GNU")) {
if (read(fd, bf, namesz) != namesz)
break;
if (memcmp(bf, "GNU", sizeof("GNU")) == 0) {
if (read(fd, build_id,
BUILD_ID_SIZE) == BUILD_ID_SIZE) {
err = 0;
break;
}
} else if (read(fd, bf, descsz) != descsz)
break;
} else {
int n = namesz + descsz;
if (read(fd, bf, n) != n)
break;
}
}
close(fd);
out:
return err;
}

char dso__symtab_origin(const struct dso *self)
{
static const char origin[] = {
Expand Down Expand Up @@ -1218,7 +1263,7 @@ static struct map *map__new2(u64 start, struct dso *dso)
return self;
}

static int dsos__load_modules(void)
int dsos__load_modules(void)
{
char *line = NULL;
size_t n;
Expand Down Expand Up @@ -1268,6 +1313,12 @@ static int dsos__load_modules(void)
goto out_delete_line;
}

snprintf(name, sizeof(name),
"/sys/module/%s/notes/.note.gnu.build-id", line);
if (sysfs__read_build_id(name, dso->build_id,
sizeof(dso->build_id)) == 0)
dso->has_build_id = true;

dso->origin = DSO__ORIG_KMODULE;
kernel_maps__insert(map);
dsos__add(dso);
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 @@ -78,6 +78,7 @@ void dso__delete(struct dso *self);
struct symbol *dso__find_symbol(struct dso *self, u64 ip);

int dsos__load_kernel(const char *vmlinux, symbol_filter_t filter, int modules);
int dsos__load_modules(void);
struct dso *dsos__findnew(const char *name);
int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
void dsos__fprintf(FILE *fp);
Expand All @@ -89,6 +90,7 @@ char dso__symtab_origin(const struct dso *self);
void dso__set_build_id(struct dso *self, void *build_id);

int filename__read_build_id(const char *filename, void *bf, size_t size);
int sysfs__read_build_id(const char *filename, void *bf, size_t size);
bool dsos__read_build_ids(void);
int build_id__sprintf(u8 *self, int len, char *bf);

Expand Down

0 comments on commit 46ed770

Please sign in to comment.