return -1;
}
- for (pos = maps__first(maps); pos; pos = map__next(pos)) {
+ maps__for_each_entry(maps, pos) {
struct kmap *kmap;
size_t size;
static size_t maps__fprintf_task(struct maps *maps, int indent, FILE *fp)
{
size_t printed = 0;
- struct rb_node *nd;
-
- for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) {
- struct map *map = rb_entry(nd, struct map, rb_node);
+ struct map *map;
+ maps__for_each_entry(maps, map) {
printed += fprintf(fp, "%*s %" PRIx64 "-%" PRIx64 " %c%c%c%c %08" PRIx64 " %" PRIu64 " %s\n",
indent, "", map->start, map->end,
map->prot & PROT_READ ? 'r' : '-',
header_printed = false;
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
struct map *
/*
* If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
header_printed = false;
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
struct map *pair;
mem_start = vmlinux_map->unmap_ip(vmlinux_map, map->start);
maps = machine__kernel_maps(&kallsyms);
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
if (!map->priv) {
if (!header_printed) {
pr_info("WARN: Maps only in kallsyms:\n");
* In the vmlinux case, pgoff is a virtual address which must now be
* mapped to a vmlinux offset.
*/
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
struct kmap *kmap = __map__kmap(map);
struct map *dest_map;
static void __maps__purge(struct maps *maps)
{
- struct rb_root *root = &maps->entries;
- struct rb_node *next = rb_first(root);
+ struct map *pos, *next;
- while (next) {
- struct map *pos = rb_entry(next, struct map, rb_node);
-
- next = rb_next(&pos->rb_node);
- rb_erase_init(&pos->rb_node, root);
+ maps__for_each_entry_safe(maps, pos, next) {
+ rb_erase_init(&pos->rb_node, &maps->entries);
map__put(pos);
}
}
static void __maps__purge_names(struct maps *maps)
{
- struct rb_root *root = &maps->names;
- struct rb_node *next = rb_first(root);
-
- while (next) {
- struct map *pos = rb_entry(next, struct map, rb_node_name);
+ struct map *pos, *next;
- next = rb_next(&pos->rb_node_name);
- rb_erase_init(&pos->rb_node_name, root);
+ maps__for_each_entry_by_name_safe(maps, pos, next) {
+ rb_erase_init(&pos->rb_node_name, &maps->names);
map__put(pos);
}
}
struct map **mapp)
{
struct symbol *sym;
- struct rb_node *nd;
+ struct map *pos;
down_read(&maps->lock);
- for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) {
- struct map *pos = rb_entry(nd, struct map, rb_node);
-
+ maps__for_each_entry(maps, pos) {
sym = map__find_symbol_by_name(pos, name);
if (sym == NULL)
static size_t maps__fprintf(struct maps *maps, FILE *fp)
{
size_t printed = 0;
- struct rb_node *nd;
+ struct map *pos;
down_read(&maps->lock);
- for (nd = rb_first(&maps->entries); nd; nd = rb_next(nd)) {
- struct map *pos = rb_entry(nd, struct map, rb_node);
+ maps__for_each_entry(maps, pos) {
printed += fprintf(fp, "Map:");
printed += map__fprintf(pos, fp);
if (verbose > 2) {
down_read(&maps->lock);
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
struct map *new = map__clone(map);
if (new == NULL)
goto out_unlock;
return map ? __map__next(map) : NULL;
}
+struct map *maps__first_by_name(struct maps *maps)
+{
+ struct rb_node *first = rb_first(&maps->names);
+
+ if (first)
+ return rb_entry(first, struct map, rb_node_name);
+ return NULL;
+}
+
+static struct map *__map__next_by_name(struct map *map)
+{
+ struct rb_node *next = rb_next(&map->rb_node_name);
+
+ if (next)
+ return rb_entry(next, struct map, rb_node_name);
+ return NULL;
+}
+
+struct map *map__next_by_name(struct map *map)
+{
+ return map ? __map__next_by_name(map) : NULL;
+}
+
struct kmap *__map__kmap(struct map *map)
{
if (!map->dso || !map->dso->kernel)
struct map *maps__find(struct maps *maps, u64 addr);
struct map *maps__first(struct maps *maps);
struct map *map__next(struct map *map);
+
+#define maps__for_each_entry(maps, map) \
+ for (map = maps__first(maps); map; map = map__next(map))
+
+#define maps__for_each_entry_safe(maps, map, next) \
+ for (map = maps__first(maps), next = map__next(map); map; map = next, next = map__next(map))
+
struct symbol *maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp);
+struct map *maps__first_by_name(struct maps *maps);
+struct map *map__next_by_name(struct map *map);
+
+#define maps__for_each_entry_by_name(maps, map) \
+ for (map = maps__first_by_name(maps); map; map = map__next_by_name(map))
+
+#define maps__for_each_entry_by_name_safe(maps, map, next) \
+ for (map = maps__first_by_name(maps), next = map__next_by_name(map); map; map = next, next = map__next_by_name(map))
struct map_groups {
struct maps maps;
return map__get(pos);
}
- for (pos = maps__first(maps); pos; pos = map__next(pos)) {
+ maps__for_each_entry(maps, pos) {
/* short_name is "[module]" */
if (strncmp(pos->dso->short_name + 1, module,
pos->dso->short_name_len - 2) == 0 &&
void map_groups__fixup_end(struct map_groups *mg)
{
struct maps *maps = &mg->maps;
- struct map *next, *curr;
+ struct map *prev = NULL, *curr;
down_write(&maps->lock);
- curr = maps__first(maps);
- if (curr == NULL)
- goto out_unlock;
+ maps__for_each_entry(maps, curr) {
+ if (prev != NULL && !prev->end)
+ prev->end = curr->start;
- for (next = map__next(curr); next; next = map__next(curr)) {
- if (!curr->end)
- curr->end = next->start;
- curr = next;
+ prev = curr;
}
/*
* We still haven't the actual symbols, so guess the
* last map final address.
*/
- if (!curr->end)
+ if (curr && !curr->end)
curr->end = ~0ULL;
-out_unlock:
up_write(&maps->lock);
}
else
event->header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
- for (pos = maps__first(maps); pos; pos = map__next(pos)) {
+ maps__for_each_entry(maps, pos) {
size_t size;
if (!__map__is_kmodule(pos))
down_read(&maps->lock);
- for (map = maps__first(maps); map; map = map__next(map)) {
+ maps__for_each_entry(maps, map) {
err = unwind__prepare_access(thread->mg, map, &initialized);
if (err || initialized)
break;