Linux Perf
unwind-libunwind.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include "unwind.h"
3 #include "thread.h"
4 #include "session.h"
5 #include "debug.h"
6 #include "env.h"
7 
11 
12 static void unwind__register_ops(struct thread *thread,
13  struct unwind_libunwind_ops *ops)
14 {
15  thread->unwind_libunwind_ops = ops;
16 }
17 
19  bool *initialized)
20 {
21  const char *arch;
22  enum dso_type dso_type;
24  int err;
25 
26  if (thread->addr_space) {
27  pr_debug("unwind: thread map already set, dso=%s\n",
28  map->dso->name);
29  if (initialized)
30  *initialized = true;
31  return 0;
32  }
33 
34  /* env->arch is NULL for live-mode (i.e. perf top) */
35  if (!thread->mg->machine->env || !thread->mg->machine->env->arch)
36  goto out_register;
37 
38  dso_type = dso__type(map->dso, thread->mg->machine);
39  if (dso_type == DSO__TYPE_UNKNOWN)
40  return 0;
41 
42  arch = perf_env__arch(thread->mg->machine->env);
43 
44  if (!strcmp(arch, "x86")) {
45  if (dso_type != DSO__TYPE_64BIT)
47  } else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
48  if (dso_type == DSO__TYPE_64BIT)
50  }
51 
52  if (!ops) {
53  pr_err("unwind: target platform=%s is not supported\n", arch);
54  return 0;
55  }
56 out_register:
57  unwind__register_ops(thread, ops);
58 
59  err = thread->unwind_libunwind_ops->prepare_access(thread);
60  if (initialized)
61  *initialized = err ? false : true;
62  return err;
63 }
64 
66 {
67  if (thread->unwind_libunwind_ops)
68  thread->unwind_libunwind_ops->flush_access(thread);
69 }
70 
72 {
73  if (thread->unwind_libunwind_ops)
74  thread->unwind_libunwind_ops->finish_access(thread);
75 }
76 
78  struct thread *thread,
79  struct perf_sample *data, int max_stack)
80 {
81  if (thread->unwind_libunwind_ops)
82  return thread->unwind_libunwind_ops->get_entries(cb, arg, thread, data, max_stack);
83  return 0;
84 }
struct map_groups * mg
Definition: thread.h:23
enum dso_type dso__type(struct dso *dso, struct machine *machine)
Definition: dso.c:1483
struct unwind_libunwind_ops __weak * arm64_unwind_libunwind_ops
void unwind__finish_access(struct thread *thread)
dictionary data
Definition: stat-cpi.py:4
int int err
Definition: 5sec.c:44
int(* unwind_entry_cb_t)(struct unwind_entry *entry, void *arg)
Definition: unwind.h:19
#define pr_err(fmt,...)
Definition: json.h:21
static void unwind__register_ops(struct thread *thread, struct unwind_libunwind_ops *ops)
char * arch
Definition: env.h:40
Definition: thread.h:18
char name[0]
Definition: dso.h:197
struct unwind_libunwind_ops __weak * local_unwind_libunwind_ops
#define pr_debug(fmt,...)
Definition: json.h:27
int unwind__get_entries(unwind_entry_cb_t cb, void *arg, struct thread *thread, struct perf_sample *data, int max_stack)
struct dso * dso
Definition: map.h:45
dso_type
Definition: dso.h:62
const char * perf_env__arch(struct perf_env *env)
Definition: env.c:164
int unwind__prepare_access(struct thread *thread, struct map *map, bool *initialized)
void unwind__flush_access(struct thread *thread)
Definition: jevents.c:228
struct unwind_libunwind_ops __weak * x86_32_unwind_libunwind_ops
Definition: annotate.c:60
struct machine * machine
Definition: map.h:65
struct perf_env * env
Definition: machine.h:49