10 #include <uapi/linux/mman.h> 18 #include <linux/string.h> 27 return flags & MAP_HUGETLB ||
28 !strcmp(filename,
"//anon") ||
29 !strncmp(filename,
"/dev/zero",
sizeof(
"/dev/zero") - 1) ||
30 !strncmp(filename,
"/anon_hugepage",
sizeof(
"/anon_hugepage") - 1);
35 return !strncmp(filename,
"[stack", 6) ||
36 !strncmp(filename,
"/SYSV",5) ||
37 !strcmp(filename,
"[heap]");
42 return !strncmp(filename,
"/data/app-lib", 13) ||
43 !strncmp(filename,
"/system/lib", 11);
50 size_t app_abi_length, new_length;
51 size_t lib_length = 0;
53 libname = strrchr(filename,
'/');
55 lib_length = strlen(libname);
57 app_abi = getenv(
"APP_ABI");
61 app_abi_length = strlen(app_abi);
63 if (!strncmp(filename,
"/data/app-lib", 13)) {
69 new_length = 7 + app_abi_length + lib_length;
71 apk_path = getenv(
"APK_PATH");
73 new_length += strlen(apk_path) + 1;
76 snprintf(newfilename, new_length,
77 "%s/libs/%s/%s", apk_path, app_abi, libname);
81 snprintf(newfilename, new_length,
82 "libs/%s/%s", app_abi, libname);
87 if (!strncmp(filename,
"/system/lib/", 11)) {
93 ndk = getenv(
"NDK_ROOT");
94 app = getenv(
"APP_PLATFORM");
99 ndk_length = strlen(ndk);
100 app_length = strlen(app);
102 if (!(ndk_length && app_length && app_abi_length))
105 arch = !strncmp(app_abi,
"arm", 3) ?
"arm" :
106 !strncmp(app_abi,
"mips", 4) ?
"mips" :
107 !strncmp(app_abi,
"x86", 3) ?
"x86" : NULL;
112 new_length = 27 + ndk_length +
113 app_length + lib_length
118 snprintf(newfilename, new_length,
119 "%s/platforms/%s/arch-%s/usr/lib/%s",
120 ndk, app, arch, libname);
139 refcount_set(&map->
refcnt, 1);
143 u64
pgoff, u32 d_maj, u32 d_min, u64
ino,
154 int anon, no_dso, vdso, android;
169 if ((anon || no_dso) && nsi && (prot & PROT_EXEC)) {
170 snprintf(newfilename,
sizeof(newfilename),
171 "/tmp/perf-%d.map", nsi->
pid);
172 filename = newfilename;
177 filename = newfilename;
199 map__init(map, start, start + len, pgoff, dso);
201 if (anon || no_dso) {
209 if (!(prot & PROT_EXEC))
229 struct map *
map = calloc(1, (
sizeof(*map) +
259 return kmap && kmap->
name[0];
269 BUG_ON(!RB_EMPTY_NODE(&map->
rb_node));
281 if (map && refcount_dec_and_test(&map->
refcnt))
288 struct rb_node *nd = rb_first(symbols);
298 struct rb_node *nd = rb_last(symbols);
305 #define DSO__DELETED "(deleted)" 330 }
else if (nr == 0) {
331 #ifdef HAVE_LIBELF_SUPPORT 332 const size_t len = strlen(name);
337 pr_warning(
"%.*s was updated (is prelink enabled?). " 338 "Restart the long running apps that use it!\n",
339 (
int)real_len, name);
341 pr_warning(
"no symbols found in %s, maybe install " 342 "a debug package?\n", name);
372 struct map *
map = memdup(from,
sizeof(*map));
375 refcount_set(&map->
refcnt, 1);
400 return fprintf(fp,
" %" PRIx64
"-%" PRIx64
" %" PRIx64
" %s\n",
406 const char *dsoname =
"[unknown]";
408 if (map && map->
dso) {
415 return fprintf(fp,
"%s", dsoname);
430 if (map && map->
dso) {
433 ret = fprintf(fp,
"%s%s", prefix, srcline);
470 return rip - map->
pgoff;
509 return ip + map->
reloc;
522 refcount_set(&mg->
refcnt, 1);
528 struct rb_node *next = rb_first(root);
534 rb_erase_init(&pos->
rb_node, root);
574 if (mg && refcount_dec_and_test(&mg->
refcnt))
579 u64 addr,
struct map **mapp)
584 if (map != NULL &&
map__load(map) >= 0) {
601 for (nd = rb_first(&maps->
entries); nd; nd = rb_next(nd)) {
632 if (ams->
map == NULL)
639 return ams->
sym ? 0 : -1;
649 for (nd = rb_first(&maps->
entries); nd; nd = rb_next(nd)) {
651 printed += fprintf(fp,
"Map:");
655 printed += fprintf(fp,
"--\n");
677 struct rb_root *
root;
678 struct rb_node *next;
684 next = rb_first(root);
687 struct map *pos = rb_entry(next,
struct map,
rb_node);
697 "(disable tui for more info)\n",
700 fputs(
"overlapping maps:\n", fp);
706 rb_erase_init(&pos->
rb_node, root);
714 if (before == NULL) {
726 if (map->
end < pos->
end) {
792 struct rb_node **p = &maps->
entries.rb_node;
793 struct rb_node *parent = NULL;
794 const u64 ip = map->
start;
799 m = rb_entry(parent,
struct map,
rb_node);
806 rb_link_node(&map->
rb_node, parent, p);
833 struct rb_node **p, *parent = NULL;
844 else if (ip >= m->
end)
858 struct rb_node *first = rb_first(&maps->
entries);
861 return rb_entry(first,
struct map, rb_node);
867 struct rb_node *next = rb_next(&map->
rb_node);
870 return rb_entry(next,
struct map, rb_node);
878 return (
struct kmap *)(map + 1);
886 pr_err(
"Internal error: map__kmap with a non-kernel map\n");
894 if (!kmap || !kmap->
kmaps) {
895 pr_err(
"Internal error: map__kmaps with a non-kernel map\n");
u64(* map_ip)(struct map *, u64)
static void dso__set_loaded(struct dso *dso)
void map__init(struct map *map, u64 start, u64 end, u64 pgoff, struct dso *dso)
static u64 map__unmap_ip(struct map *map, u64 ip)
int map_groups__clone(struct thread *thread, struct map_groups *parent)
static int is_no_dso_memory(const char *filename)
struct kmap * map__kmap(struct map *map)
static u64 map__map_ip(struct map *map, u64 ip)
static void map__exit(struct map *map)
static void __maps__remove(struct maps *maps, struct map *map)
char * get_srcline(struct dso *dso, u64 addr, struct symbol *sym, bool show_sym, bool show_addr, u64 ip)
static int maps__fixup_overlappings(struct maps *maps, struct map *map, FILE *fp)
static u64 identity__map_ip(struct map *map __maybe_unused, u64 ip)
void map_groups__exit(struct map_groups *mg)
void maps__remove(struct maps *maps, struct map *map)
void map__fixup_start(struct map *map)
void map__delete(struct map *map)
static bool replace_android_lib(const char *filename, char *newfilename)
static bool is_entry_trampoline(const char *name)
bool dso__sorted_by_name(const struct dso *dso)
void maps__insert(struct maps *maps, struct map *map)
static void __maps__insert(struct maps *maps, struct map *map)
int up_write(struct rw_semaphore *sem)
void map_groups__delete(struct map_groups *mg)
static bool is_vdso_map(const char *filename)
void map__put(struct map *map)
void dso__put(struct dso *dso)
int map__fprintf_srcline(struct map *map, u64 addr, const char *prefix, FILE *fp)
struct map * map__clone(struct map *from)
struct dso * machine__findnew_dso(struct machine *machine, const char *filename)
char * map__srcline(struct map *map, u64 addr, struct symbol *sym)
int down_read(struct rw_semaphore *sem)
void map_groups__init(struct map_groups *mg, struct machine *machine)
struct map * map__new(struct machine *machine, u64 start, u64 len, u64 pgoff, u32 d_maj, u32 d_min, u64 ino, u64 ino_gen, u32 prot, u32 flags, char *filename, struct thread *thread)
static struct map * machine__kernel_map(struct machine *machine)
bool __map__is_extra_kernel_map(const struct map *map)
struct map * maps__first(struct maps *maps)
struct map_groups * groups
static void maps__init(struct maps *maps)
struct symbol * map__find_symbol_by_name(struct map *map, const char *name)
size_t map__fprintf(struct map *map, FILE *fp)
void dso__sort_by_name(struct dso *dso)
struct map * map__next(struct map *map)
size_t map_groups__fprintf(struct map_groups *mg, FILE *fp)
struct symbol * map_groups__find_symbol_by_name(struct map_groups *mg, const char *name, struct map **mapp)
void free_srcline(char *srcline)
static size_t maps__fprintf(struct maps *maps, FILE *fp)
struct dso * dso__get(struct dso *dso)
struct symbol * map_groups__find_symbol(struct map_groups *mg, u64 addr, struct map **mapp)
enum dso_kernel_type kernel
struct map_groups * kmaps
u64 map__objdump_2mem(struct map *map, u64 ip)
u64 map__rip_2objdump(struct map *map, u64 rip)
struct symbol * map__find_symbol(struct map *map, u64 addr)
bool map__has_symbols(const struct map *map)
int map__overlap(struct map *l, struct map *r)
int unwind__prepare_access(struct thread *thread, struct map *map, bool *initialized)
struct nsinfo * nsinfo__copy(struct nsinfo *nsi)
int dso__load(struct dso *dso, struct map *map)
bool dso__loaded(const struct dso *dso)
struct symbol * dso__find_symbol(struct dso *dso, u64 addr)
static struct map * map__get(struct map *map)
void map__fixup_end(struct map *map)
static struct map * map_groups__find(struct map_groups *mg, u64 addr)
size_t dso__fprintf(struct dso *dso, FILE *fp)
struct nsinfo * nsinfo__get(struct nsinfo *nsi)
struct map_groups * map_groups__new(struct machine *machine)
int init_rwsem(struct rw_semaphore *sem)
size_t map__fprintf_dsoname(struct map *map, FILE *fp)
struct map * maps__find(struct maps *maps, u64 ip)
struct symbol * dso__find_symbol_by_name(struct dso *dso, const char *name)
u8 build_id[BUILD_ID_SIZE]
void map_groups__put(struct map_groups *mg)
struct kmap * __map__kmap(struct map *map)
static int sym(yyscan_t scanner, int type, int config)
bool __map__is_kernel(const struct map *map)
int build_id__sprintf(const u8 *build_id, int len, char *bf)
static void __map_groups__insert(struct map_groups *mg, struct map *map)
static void __maps__purge(struct maps *maps)
static bool dso__has_symbols(const struct dso *dso)
int map_groups__find_ams(struct addr_map_symbol *ams)
struct symbol * maps__find_symbol_by_name(struct maps *maps, const char *name, struct map **mapp)
static void maps__exit(struct maps *maps)
int down_write(struct rw_semaphore *sem)
u64(* unmap_ip)(struct map *, u64)
#define pr_warning(fmt,...)
int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map, FILE *fp)
static int is_anon_memory(const char *filename, u32 flags)
static void map_groups__insert(struct map_groups *mg, struct map *map)
int map__load(struct map *map)
void nsinfo__put(struct nsinfo *nsi)
int up_read(struct rw_semaphore *sem)
bool map_groups__empty(struct map_groups *mg)
struct map_groups * map__kmaps(struct map *map)
static int is_android_lib(const char *filename)
struct dso * machine__findnew_vdso(struct machine *machine, struct thread *thread)
struct map * map__new2(u64 start, struct dso *dso)