diff options
Diffstat (limited to 'tools/perf/util/dso.c')
-rw-r--r-- | tools/perf/util/dso.c | 71 |
1 files changed, 62 insertions, 9 deletions
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 819f10414f08..90d02c661dd4 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c | |||
@@ -216,7 +216,7 @@ static int open_dso(struct dso *dso, struct machine *machine) | |||
216 | { | 216 | { |
217 | int fd = __open_dso(dso, machine); | 217 | int fd = __open_dso(dso, machine); |
218 | 218 | ||
219 | if (fd > 0) { | 219 | if (fd >= 0) { |
220 | dso__list_add(dso); | 220 | dso__list_add(dso); |
221 | /* | 221 | /* |
222 | * Check if we crossed the allowed number | 222 | * Check if we crossed the allowed number |
@@ -331,26 +331,44 @@ int dso__data_fd(struct dso *dso, struct machine *machine) | |||
331 | }; | 331 | }; |
332 | int i = 0; | 332 | int i = 0; |
333 | 333 | ||
334 | if (dso->data.status == DSO_DATA_STATUS_ERROR) | ||
335 | return -1; | ||
336 | |||
334 | if (dso->data.fd >= 0) | 337 | if (dso->data.fd >= 0) |
335 | return dso->data.fd; | 338 | goto out; |
336 | 339 | ||
337 | if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) { | 340 | if (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND) { |
338 | dso->data.fd = open_dso(dso, machine); | 341 | dso->data.fd = open_dso(dso, machine); |
339 | return dso->data.fd; | 342 | goto out; |
340 | } | 343 | } |
341 | 344 | ||
342 | do { | 345 | do { |
343 | int fd; | ||
344 | |||
345 | dso->binary_type = binary_type_data[i++]; | 346 | dso->binary_type = binary_type_data[i++]; |
346 | 347 | ||
347 | fd = open_dso(dso, machine); | 348 | dso->data.fd = open_dso(dso, machine); |
348 | if (fd >= 0) | 349 | if (dso->data.fd >= 0) |
349 | return dso->data.fd = fd; | 350 | goto out; |
350 | 351 | ||
351 | } while (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND); | 352 | } while (dso->binary_type != DSO_BINARY_TYPE__NOT_FOUND); |
353 | out: | ||
354 | if (dso->data.fd >= 0) | ||
355 | dso->data.status = DSO_DATA_STATUS_OK; | ||
356 | else | ||
357 | dso->data.status = DSO_DATA_STATUS_ERROR; | ||
352 | 358 | ||
353 | return -EINVAL; | 359 | return dso->data.fd; |
360 | } | ||
361 | |||
362 | bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by) | ||
363 | { | ||
364 | u32 flag = 1 << by; | ||
365 | |||
366 | if (dso->data.status_seen & flag) | ||
367 | return true; | ||
368 | |||
369 | dso->data.status_seen |= flag; | ||
370 | |||
371 | return false; | ||
354 | } | 372 | } |
355 | 373 | ||
356 | static void | 374 | static void |
@@ -526,6 +544,28 @@ static int data_file_size(struct dso *dso) | |||
526 | return 0; | 544 | return 0; |
527 | } | 545 | } |
528 | 546 | ||
547 | /** | ||
548 | * dso__data_size - Return dso data size | ||
549 | * @dso: dso object | ||
550 | * @machine: machine object | ||
551 | * | ||
552 | * Return: dso data size | ||
553 | */ | ||
554 | off_t dso__data_size(struct dso *dso, struct machine *machine) | ||
555 | { | ||
556 | int fd; | ||
557 | |||
558 | fd = dso__data_fd(dso, machine); | ||
559 | if (fd < 0) | ||
560 | return fd; | ||
561 | |||
562 | if (data_file_size(dso)) | ||
563 | return -1; | ||
564 | |||
565 | /* For now just estimate dso data size is close to file size */ | ||
566 | return dso->data.file_size; | ||
567 | } | ||
568 | |||
529 | static ssize_t data_read_offset(struct dso *dso, u64 offset, | 569 | static ssize_t data_read_offset(struct dso *dso, u64 offset, |
530 | u8 *data, ssize_t size) | 570 | u8 *data, ssize_t size) |
531 | { | 571 | { |
@@ -701,8 +741,10 @@ struct dso *dso__new(const char *name) | |||
701 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; | 741 | dso->symbols[i] = dso->symbol_names[i] = RB_ROOT; |
702 | dso->data.cache = RB_ROOT; | 742 | dso->data.cache = RB_ROOT; |
703 | dso->data.fd = -1; | 743 | dso->data.fd = -1; |
744 | dso->data.status = DSO_DATA_STATUS_UNKNOWN; | ||
704 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; | 745 | dso->symtab_type = DSO_BINARY_TYPE__NOT_FOUND; |
705 | dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND; | 746 | dso->binary_type = DSO_BINARY_TYPE__NOT_FOUND; |
747 | dso->is_64_bit = (sizeof(void *) == 8); | ||
706 | dso->loaded = 0; | 748 | dso->loaded = 0; |
707 | dso->rel = 0; | 749 | dso->rel = 0; |
708 | dso->sorted_by_name = 0; | 750 | dso->sorted_by_name = 0; |
@@ -898,3 +940,14 @@ size_t dso__fprintf(struct dso *dso, enum map_type type, FILE *fp) | |||
898 | 940 | ||
899 | return ret; | 941 | return ret; |
900 | } | 942 | } |
943 | |||
944 | enum dso_type dso__type(struct dso *dso, struct machine *machine) | ||
945 | { | ||
946 | int fd; | ||
947 | |||
948 | fd = dso__data_fd(dso, machine); | ||
949 | if (fd < 0) | ||
950 | return DSO__TYPE_UNKNOWN; | ||
951 | |||
952 | return dso__type_fd(fd); | ||
953 | } | ||