]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - tools/perf/util/thread.c
perf thread: Generalize function to copy from thread addr space from intel-bts code
[linux.git] / tools / perf / util / thread.c
index c83372329f891a2c17e32784387142bfc7d0d807..50678d318185496c35983dda3270497ee6668e65 100644 (file)
@@ -12,6 +12,8 @@
 #include "debug.h"
 #include "namespaces.h"
 #include "comm.h"
+#include "map.h"
+#include "symbol.h"
 #include "unwind.h"
 
 #include <api/fs/fs.h>
@@ -392,3 +394,25 @@ struct thread *thread__main_thread(struct machine *machine, struct thread *threa
 
        return machine__find_thread(machine, thread->pid_, thread->pid_);
 }
+
+int thread__memcpy(struct thread *thread, struct machine *machine,
+                  void *buf, u64 ip, int len, bool *is64bit)
+{
+       u8 cpumode = PERF_RECORD_MISC_USER;
+       struct addr_location al;
+       long offset;
+
+       if (machine__kernel_ip(machine, ip))
+               cpumode = PERF_RECORD_MISC_KERNEL;
+
+       if (!thread__find_map(thread, cpumode, ip, &al) || !al.map->dso ||
+          al.map->dso->data.status == DSO_DATA_STATUS_ERROR ||
+          map__load(al.map) < 0)
+               return -1;
+
+       offset = al.map->map_ip(al.map, ip);
+       if (is64bit)
+               *is64bit = al.map->dso->is_64_bit;
+
+       return dso__data_read_offset(al.map->dso, machine, offset, buf, len);
+}