]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - tools/perf/util/map.c
8 static inline int is_anon_memory(const char *filename
)
10 return strcmp(filename
, "//anon") == 0;
13 static int strcommon(const char *pathname
, char *cwd
, int cwdlen
)
17 while (n
< cwdlen
&& pathname
[n
] == cwd
[n
])
23 void map__init(struct map
*self
, u64 start
, u64 end
, u64 pgoff
,
30 self
->map_ip
= map__map_ip
;
31 self
->unmap_ip
= map__unmap_ip
;
32 RB_CLEAR_NODE(&self
->rb_node
);
35 struct map
*map__new(struct mmap_event
*event
, char *cwd
, int cwdlen
)
37 struct map
*self
= malloc(sizeof(*self
));
40 const char *filename
= event
->filename
;
41 char newfilename
[PATH_MAX
];
46 int n
= strcommon(filename
, cwd
, cwdlen
);
49 snprintf(newfilename
, sizeof(newfilename
),
51 filename
= newfilename
;
55 anon
= is_anon_memory(filename
);
58 snprintf(newfilename
, sizeof(newfilename
), "/tmp/perf-%d.map", event
->pid
);
59 filename
= newfilename
;
62 dso
= dsos__findnew(filename
);
66 map__init(self
, event
->start
, event
->start
+ event
->len
,
69 if (self
->dso
== vdso
|| anon
)
70 self
->map_ip
= self
->unmap_ip
= identity__map_ip
;
78 void map__delete(struct map
*self
)
83 void map__fixup_start(struct map
*self
, struct rb_root
*symbols
)
85 struct rb_node
*nd
= rb_first(symbols
);
87 struct symbol
*sym
= rb_entry(nd
, struct symbol
, rb_node
);
88 self
->start
= sym
->start
;
92 void map__fixup_end(struct map
*self
, struct rb_root
*symbols
)
94 struct rb_node
*nd
= rb_last(symbols
);
96 struct symbol
*sym
= rb_entry(nd
, struct symbol
, rb_node
);
101 #define DSO__DELETED "(deleted)"
103 struct symbol
*map__find_function(struct map
*self
, u64 ip
,
104 symbol_filter_t filter
)
106 if (!self
->dso
->loaded
) {
107 int nr
= dso__load(self
->dso
, self
, filter
);
110 if (self
->dso
->has_build_id
) {
111 char sbuild_id
[BUILD_ID_SIZE
* 2 + 1];
113 build_id__sprintf(self
->dso
->build_id
,
114 sizeof(self
->dso
->build_id
),
116 pr_warning("%s with build id %s not found",
117 self
->dso
->long_name
, sbuild_id
);
119 pr_warning("Failed to open %s",
120 self
->dso
->long_name
);
121 pr_warning(", continuing without symbols\n");
123 } else if (nr
== 0) {
124 const char *name
= self
->dso
->long_name
;
125 const size_t len
= strlen(name
);
126 const size_t real_len
= len
- sizeof(DSO__DELETED
);
128 if (len
> sizeof(DSO__DELETED
) &&
129 strcmp(name
+ real_len
+ 1, DSO__DELETED
) == 0) {
130 pr_warning("%.*s was updated, restart the long running apps that use it!\n",
131 (int)real_len
, name
);
133 pr_warning("no symbols found in %s, maybe install a debug package?\n", name
);
139 return self
->dso
->find_function(self
->dso
, ip
);
142 struct map
*map__clone(struct map
*self
)
144 struct map
*map
= malloc(sizeof(*self
));
149 memcpy(map
, self
, sizeof(*self
));
154 int map__overlap(struct map
*l
, struct map
*r
)
156 if (l
->start
> r
->start
) {
162 if (l
->end
> r
->start
)
168 size_t map__fprintf(struct map
*self
, FILE *fp
)
170 return fprintf(fp
, " %Lx-%Lx %Lx %s\n",
171 self
->start
, self
->end
, self
->pgoff
, self
->dso
->name
);