Lines Matching full:map

12 #include "map.h"
105 void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso) in map__init() argument
107 map->start = start; in map__init()
108 map->end = end; in map__init()
109 map->pgoff = pgoff; in map__init()
110 map->reloc = 0; in map__init()
111 map->dso = dso__get(dso); in map__init()
112 map->map_ip = map__map_ip; in map__init()
113 map->unmap_ip = map__unmap_ip; in map__init()
114 RB_CLEAR_NODE(&map->rb_node); in map__init()
115 map->erange_warned = false; in map__init()
116 refcount_set(&map->refcnt, 1); in map__init()
119 struct map *map__new(struct machine *machine, u64 start, u64 len, in map__new()
124 struct map *map = malloc(sizeof(*map)); in map__new() local
128 if (map != NULL) { in map__new()
137 map->prot = prot; in map__new()
138 map->flags = flags; in map__new()
143 "/tmp/perf-%d.map", nsinfo__pid(nsi)); in map__new()
171 map__init(map, start, start + len, pgoff, dso); in map__new()
174 map->map_ip = map->unmap_ip = identity__map_ip; in map__new()
208 return map; in map__new()
211 free(map); in map__new()
220 struct map *map__new2(u64 start, struct dso *dso) in map__new2()
222 struct map *map = calloc(1, (sizeof(*map) + in map__new2() local
224 if (map != NULL) { in map__new2()
228 map__init(map, start, 0, 0, dso); in map__new2()
231 return map; in map__new2()
234 bool __map__is_kernel(const struct map *map) in __map__is_kernel() argument
236 if (!map->dso->kernel) in __map__is_kernel()
238 return machine__kernel_map(map__kmaps((struct map *)map)->machine) == map; in __map__is_kernel()
241 bool __map__is_extra_kernel_map(const struct map *map) in __map__is_extra_kernel_map() argument
243 struct kmap *kmap = __map__kmap((struct map *)map); in __map__is_extra_kernel_map()
248 bool __map__is_bpf_prog(const struct map *map) in __map__is_bpf_prog() argument
252 if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO) in __map__is_bpf_prog()
260 name = map->dso->short_name; in __map__is_bpf_prog()
264 bool __map__is_bpf_image(const struct map *map) in __map__is_bpf_image() argument
268 if (map->dso->binary_type == DSO_BINARY_TYPE__BPF_IMAGE) in __map__is_bpf_image()
276 name = map->dso->short_name; in __map__is_bpf_image()
280 bool __map__is_ool(const struct map *map) in __map__is_ool() argument
282 return map->dso && map->dso->binary_type == DSO_BINARY_TYPE__OOL; in __map__is_ool()
285 bool map__has_symbols(const struct map *map) in map__has_symbols() argument
287 return dso__has_symbols(map->dso); in map__has_symbols()
290 static void map__exit(struct map *map) in map__exit() argument
292 BUG_ON(refcount_read(&map->refcnt) != 0); in map__exit()
293 dso__zput(map->dso); in map__exit()
296 void map__delete(struct map *map) in map__delete() argument
298 map__exit(map); in map__delete()
299 free(map); in map__delete()
302 void map__put(struct map *map) in map__put() argument
304 if (map && refcount_dec_and_test(&map->refcnt)) in map__put()
305 map__delete(map); in map__put()
308 void map__fixup_start(struct map *map) in map__fixup_start() argument
310 struct rb_root_cached *symbols = &map->dso->symbols; in map__fixup_start()
314 map->start = sym->start; in map__fixup_start()
318 void map__fixup_end(struct map *map) in map__fixup_end() argument
320 struct rb_root_cached *symbols = &map->dso->symbols; in map__fixup_end()
324 map->end = sym->end; in map__fixup_end()
330 int map__load(struct map *map) in map__load() argument
332 const char *name = map->dso->long_name; in map__load()
335 if (dso__loaded(map->dso)) in map__load()
338 nr = dso__load(map->dso, map); in map__load()
340 if (map->dso->has_build_id) { in map__load()
343 build_id__sprintf(&map->dso->bid, sbuild_id); in map__load()
370 struct symbol *map__find_symbol(struct map *map, u64 addr) in map__find_symbol() argument
372 if (map__load(map) < 0) in map__find_symbol()
375 return dso__find_symbol(map->dso, addr); in map__find_symbol()
378 struct symbol *map__find_symbol_by_name(struct map *map, const char *name) in map__find_symbol_by_name() argument
380 if (map__load(map) < 0) in map__find_symbol_by_name()
383 if (!dso__sorted_by_name(map->dso)) in map__find_symbol_by_name()
384 dso__sort_by_name(map->dso); in map__find_symbol_by_name()
386 return dso__find_symbol_by_name(map->dso, name); in map__find_symbol_by_name()
389 struct map *map__clone(struct map *from) in map__clone()
391 size_t size = sizeof(struct map); in map__clone()
392 struct map *map; in map__clone() local
397 map = memdup(from, size); in map__clone()
398 if (map != NULL) { in map__clone()
399 refcount_set(&map->refcnt, 1); in map__clone()
400 RB_CLEAR_NODE(&map->rb_node); in map__clone()
401 dso__get(map->dso); in map__clone()
404 return map; in map__clone()
407 size_t map__fprintf(struct map *map, FILE *fp) in map__fprintf() argument
410 map->start, map->end, map->pgoff, map->dso->name); in map__fprintf()
413 size_t map__fprintf_dsoname(struct map *map, FILE *fp) in map__fprintf_dsoname() argument
418 if (map && map->dso) { in map__fprintf_dsoname()
419 if (symbol_conf.show_kernel_path && map->dso->long_name) in map__fprintf_dsoname()
420 dsoname = map->dso->long_name; in map__fprintf_dsoname()
422 dsoname = map->dso->name; in map__fprintf_dsoname()
433 char *map__srcline(struct map *map, u64 addr, struct symbol *sym) in map__srcline() argument
435 if (map == NULL) in map__srcline()
437 return get_srcline(map->dso, map__rip_2objdump(map, addr), sym, true, true, addr); in map__srcline()
440 int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, in map__fprintf_srcline() argument
445 if (map && map->dso) { in map__fprintf_srcline()
446 char *srcline = map__srcline(map, addr, NULL); in map__fprintf_srcline()
462 * @map: memory map
466 * map->dso->adjust_symbols==1 for ET_EXEC-like cases except ET_REL which is
471 u64 map__rip_2objdump(struct map *map, u64 rip) in map__rip_2objdump() argument
473 struct kmap *kmap = __map__kmap(map); in map__rip_2objdump()
478 * main kernel map, so just use that instead. in map__rip_2objdump()
481 struct map *kernel_map = machine__kernel_map(kmap->kmaps->machine); in map__rip_2objdump()
484 map = kernel_map; in map__rip_2objdump()
487 if (!map->dso->adjust_symbols) in map__rip_2objdump()
490 if (map->dso->rel) in map__rip_2objdump()
491 return rip - map->pgoff; in map__rip_2objdump()
497 if (map->dso->kernel == DSO_SPACE__USER) in map__rip_2objdump()
498 return rip + map->dso->text_offset; in map__rip_2objdump()
500 return map->unmap_ip(map, rip) - map->reloc; in map__rip_2objdump()
505 * @map: memory map
509 * objdump and converts it to a memory address. Note this assumes that @map
511 * e.g. map__rip_2objdump(map->map_ip(map, map__objdump_2mem(map, ip))) == ip
515 u64 map__objdump_2mem(struct map *map, u64 ip) in map__objdump_2mem() argument
517 if (!map->dso->adjust_symbols) in map__objdump_2mem()
518 return map->unmap_ip(map, ip); in map__objdump_2mem()
520 if (map->dso->rel) in map__objdump_2mem()
521 return map->unmap_ip(map, ip + map->pgoff); in map__objdump_2mem()
527 if (map->dso->kernel == DSO_SPACE__USER) in map__objdump_2mem()
528 return map->unmap_ip(map, ip - map->dso->text_offset); in map__objdump_2mem()
530 return ip + map->reloc; in map__objdump_2mem()
533 bool map__contains_symbol(const struct map *map, const struct symbol *sym) in map__contains_symbol() argument
535 u64 ip = map->unmap_ip(map, sym->start); in map__contains_symbol()
537 return ip >= map->start && ip < map->end; in map__contains_symbol()
540 static struct map *__map__next(struct map *map) in __map__next() argument
542 struct rb_node *next = rb_next(&map->rb_node); in __map__next()
545 return rb_entry(next, struct map, rb_node); in __map__next()
549 struct map *map__next(struct map *map) in map__next() argument
551 return map ? __map__next(map) : NULL; in map__next()
554 struct kmap *__map__kmap(struct map *map) in __map__kmap() argument
556 if (!map->dso || !map->dso->kernel) in __map__kmap()
558 return (struct kmap *)(map + 1); in __map__kmap()
561 struct kmap *map__kmap(struct map *map) in map__kmap() argument
563 struct kmap *kmap = __map__kmap(map); in map__kmap()
566 pr_err("Internal error: map__kmap with a non-kernel map\n"); in map__kmap()
570 struct maps *map__kmaps(struct map *map) in map__kmaps() argument
572 struct kmap *kmap = map__kmap(map); in map__kmaps()
575 pr_err("Internal error: map__kmaps with a non-kernel map\n"); in map__kmaps()
581 u64 map__map_ip(const struct map *map, u64 ip) in map__map_ip() argument
583 return ip - map->start + map->pgoff; in map__map_ip()
586 u64 map__unmap_ip(const struct map *map, u64 ip) in map__unmap_ip() argument
588 return ip + map->start - map->pgoff; in map__unmap_ip()
591 u64 identity__map_ip(const struct map *map __maybe_unused, u64 ip) in identity__map_ip()