Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf disassemble: Extract logic to find file to pass to objdump to a separate function

Disentangling this a bit further, more to come.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-7bjv2xazuyzs0xw01mlwosn5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+38 -28
+38 -28
tools/perf/util/annotate.c
··· 1162 1162 return 0; 1163 1163 } 1164 1164 1165 + static int dso__disassemble_filename(struct dso *dso, char *filename, size_t filename_size) 1166 + { 1167 + char linkname[PATH_MAX]; 1168 + char *build_id_filename; 1169 + 1170 + if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && 1171 + !dso__is_kcore(dso)) 1172 + return SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; 1173 + 1174 + build_id_filename = dso__build_id_filename(dso, NULL, 0); 1175 + if (build_id_filename) { 1176 + __symbol__join_symfs(filename, filename_size, build_id_filename); 1177 + free(build_id_filename); 1178 + } else { 1179 + if (dso->has_build_id) 1180 + return ENOMEM; 1181 + goto fallback; 1182 + } 1183 + 1184 + if (dso__is_kcore(dso) || 1185 + readlink(filename, linkname, sizeof(linkname)) < 0 || 1186 + strstr(linkname, DSO__NAME_KALLSYMS) || 1187 + access(filename, R_OK)) { 1188 + fallback: 1189 + /* 1190 + * If we don't have build-ids or the build-id file isn't in the 1191 + * cache, or is just a kallsyms file, well, lets hope that this 1192 + * DSO is the same as when 'perf record' ran. 1193 + */ 1194 + __symbol__join_symfs(filename, filename_size, dso->long_name); 1195 + } 1196 + 1197 + return 0; 1198 + } 1199 + 1165 1200 int symbol__disassemble(struct symbol *sym, struct map *map, size_t privsize) 1166 1201 { 1167 1202 struct dso *dso = map->dso; 1168 - char *filename; 1169 1203 char command[PATH_MAX * 2]; 1170 1204 FILE *file; 1171 1205 char symfs_filename[PATH_MAX]; ··· 1209 1175 int lineno = 0; 1210 1176 int nline; 1211 1177 pid_t pid; 1212 - int err = SYMBOL_ANNOTATE_ERRNO__NO_VMLINUX; 1178 + int err = dso__disassemble_filename(dso, symfs_filename, sizeof(symfs_filename)); 1213 1179 1214 - if (dso->symtab_type == DSO_BINARY_TYPE__KALLSYMS && 1215 - !dso__is_kcore(dso)) 1216 - goto out; 1217 - 1218 - filename = dso__build_id_filename(dso, NULL, 0); 1219 - if (filename) { 1220 - symbol__join_symfs(symfs_filename, filename); 1221 - free(filename); 1222 - } else { 1223 - if (dso->has_build_id) 1224 - return ENOMEM; 1225 - goto fallback; 1226 - } 1227 - 1228 - if (dso__is_kcore(dso) || 1229 - readlink(symfs_filename, command, sizeof(command)) < 0 || 1230 - strstr(command, DSO__NAME_KALLSYMS) || 1231 - access(symfs_filename, R_OK)) { 1232 - fallback: 1233 - /* 1234 - * If we don't have build-ids or the build-id file isn't in the 1235 - * cache, or is just a kallsyms file, well, lets hope that this 1236 - * DSO is the same as when 'perf record' ran. 1237 - */ 1238 - symbol__join_symfs(symfs_filename, dso->long_name); 1239 - } 1180 + if (err) 1181 + return err; 1240 1182 1241 1183 pr_debug("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n", __func__, 1242 1184 symfs_filename, sym->name, map->unmap_ip(map, sym->start),