diff options
| -rw-r--r-- | tools/perf/util/intel-bts.c | 20 | ||||
| -rw-r--r-- | tools/perf/util/thread.c | 23 | ||||
| -rw-r--r-- | tools/perf/util/thread.h | 3 |
3 files changed, 28 insertions, 18 deletions
diff --git a/tools/perf/util/intel-bts.c b/tools/perf/util/intel-bts.c index 0c0180c67574..47025bc727e1 100644 --- a/tools/perf/util/intel-bts.c +++ b/tools/perf/util/intel-bts.c | |||
| @@ -328,35 +328,19 @@ static int intel_bts_get_next_insn(struct intel_bts_queue *btsq, u64 ip) | |||
| 328 | { | 328 | { |
| 329 | struct machine *machine = btsq->bts->machine; | 329 | struct machine *machine = btsq->bts->machine; |
| 330 | struct thread *thread; | 330 | struct thread *thread; |
| 331 | struct addr_location al; | ||
| 332 | unsigned char buf[INTEL_PT_INSN_BUF_SZ]; | 331 | unsigned char buf[INTEL_PT_INSN_BUF_SZ]; |
| 333 | ssize_t len; | 332 | ssize_t len; |
| 334 | int x86_64; | 333 | bool x86_64; |
| 335 | uint8_t cpumode; | ||
| 336 | int err = -1; | 334 | int err = -1; |
| 337 | 335 | ||
| 338 | if (machine__kernel_ip(machine, ip)) | ||
| 339 | cpumode = PERF_RECORD_MISC_KERNEL; | ||
| 340 | else | ||
| 341 | cpumode = PERF_RECORD_MISC_USER; | ||
| 342 | |||
| 343 | thread = machine__find_thread(machine, -1, btsq->tid); | 336 | thread = machine__find_thread(machine, -1, btsq->tid); |
| 344 | if (!thread) | 337 | if (!thread) |
| 345 | return -1; | 338 | return -1; |
| 346 | 339 | ||
| 347 | if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso) | 340 | len = thread__memcpy(thread, machine, buf, ip, INTEL_PT_INSN_BUF_SZ, &x86_64); |
| 348 | goto out_put; | ||
| 349 | |||
| 350 | len = dso__data_read_addr(al.map->dso, al.map, machine, ip, buf, | ||
| 351 | INTEL_PT_INSN_BUF_SZ); | ||
| 352 | if (len <= 0) | 341 | if (len <= 0) |
| 353 | goto out_put; | 342 | goto out_put; |
| 354 | 343 | ||
| 355 | /* Load maps to ensure dso->is_64_bit has been updated */ | ||
| 356 | map__load(al.map); | ||
| 357 | |||
| 358 | x86_64 = al.map->dso->is_64_bit; | ||
| 359 | |||
| 360 | if (intel_pt_get_insn(buf, len, x86_64, &btsq->intel_pt_insn)) | 344 | if (intel_pt_get_insn(buf, len, x86_64, &btsq->intel_pt_insn)) |
| 361 | goto out_put; | 345 | goto out_put; |
| 362 | 346 | ||
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 4c179fef442d..50678d318185 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "debug.h" | 12 | #include "debug.h" |
| 13 | #include "namespaces.h" | 13 | #include "namespaces.h" |
| 14 | #include "comm.h" | 14 | #include "comm.h" |
| 15 | #include "map.h" | ||
| 15 | #include "symbol.h" | 16 | #include "symbol.h" |
| 16 | #include "unwind.h" | 17 | #include "unwind.h" |
| 17 | 18 | ||
| @@ -393,3 +394,25 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa | |||
| 393 | 394 | ||
| 394 | return machine__find_thread(machine, thread->pid_, thread->pid_); | 395 | return machine__find_thread(machine, thread->pid_, thread->pid_); |
| 395 | } | 396 | } |
| 397 | |||
| 398 | int thread__memcpy(struct thread *thread, struct machine *machine, | ||
| 399 | void *buf, u64 ip, int len, bool *is64bit) | ||
| 400 | { | ||
| 401 | u8 cpumode = PERF_RECORD_MISC_USER; | ||
| 402 | struct addr_location al; | ||
| 403 | long offset; | ||
| 404 | |||
| 405 | if (machine__kernel_ip(machine, ip)) | ||
| 406 | cpumode = PERF_RECORD_MISC_KERNEL; | ||
| 407 | |||
| 408 | if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso || | ||
| 409 | al.map->dso->data.status == DSO_DATA_STATUS_ERROR || | ||
| 410 | map__load(al.map) < 0) | ||
| 411 | return -1; | ||
| 412 | |||
| 413 | offset = al.map->map_ip(al.map, ip); | ||
| 414 | if (is64bit) | ||
| 415 | *is64bit = al.map->dso->is_64_bit; | ||
| 416 | |||
| 417 | return dso__data_read_offset(al.map->dso, machine, offset, buf, len); | ||
| 418 | } | ||
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index 8276ffeec556..cf8375c017a0 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h | |||
| @@ -113,6 +113,9 @@ struct symbol *thread__find_symbol_fb(struct thread *thread, u8 cpumode, | |||
| 113 | void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, | 113 | void thread__find_cpumode_addr_location(struct thread *thread, u64 addr, |
| 114 | struct addr_location *al); | 114 | struct addr_location *al); |
| 115 | 115 | ||
| 116 | int thread__memcpy(struct thread *thread, struct machine *machine, | ||
| 117 | void *buf, u64 ip, int len, bool *is64bit); | ||
| 118 | |||
| 116 | static inline void *thread__priv(struct thread *thread) | 119 | static inline void *thread__priv(struct thread *thread) |
| 117 | { | 120 | { |
| 118 | return thread->priv; | 121 | return thread->priv; |
