Linux Audio

Check our new training course

Loading...
v6.8
 1// SPDX-License-Identifier: GPL-2.0
 2#include "unwind.h"
 3#include "dso.h"
 4#include "map.h"
 5#include "thread.h"
 6#include "session.h"
 7#include "debug.h"
 8#include "env.h"
 9#include "callchain.h"
10
11struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
12struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
13struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
14
15static void unwind__register_ops(struct maps *maps, struct unwind_libunwind_ops *ops)
 
16{
17	RC_CHK_ACCESS(maps)->unwind_libunwind_ops = ops;
18}
19
20int unwind__prepare_access(struct maps *maps, struct map *map, bool *initialized)
 
21{
22	const char *arch;
23	enum dso_type dso_type;
24	struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
25	struct dso *dso = map__dso(map);
26	struct machine *machine;
27	int err;
28
29	if (!dwarf_callchain_users)
30		return 0;
31
32	if (maps__addr_space(maps)) {
33		pr_debug("unwind: thread map already set, dso=%s\n", dso->name);
34		if (initialized)
35			*initialized = true;
36		return 0;
37	}
38
39	machine = maps__machine(maps);
40	/* env->arch is NULL for live-mode (i.e. perf top) */
41	if (!machine->env || !machine->env->arch)
42		goto out_register;
43
44	dso_type = dso__type(dso, machine);
45	if (dso_type == DSO__TYPE_UNKNOWN)
46		return 0;
47
48	arch = perf_env__arch(machine->env);
49
50	if (!strcmp(arch, "x86")) {
51		if (dso_type != DSO__TYPE_64BIT)
52			ops = x86_32_unwind_libunwind_ops;
53	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
54		if (dso_type == DSO__TYPE_64BIT)
55			ops = arm64_unwind_libunwind_ops;
56	}
57
58	if (!ops) {
59		pr_warning_once("unwind: target platform=%s is not supported\n", arch);
60		return 0;
61	}
62out_register:
63	unwind__register_ops(maps, ops);
64
65	err = maps__unwind_libunwind_ops(maps)->prepare_access(maps);
66	if (initialized)
67		*initialized = err ? false : true;
68	return err;
69}
70
71void unwind__flush_access(struct maps *maps)
72{
73	const struct unwind_libunwind_ops *ops = maps__unwind_libunwind_ops(maps);
74
75	if (ops)
76		ops->flush_access(maps);
77}
78
79void unwind__finish_access(struct maps *maps)
80{
81	const struct unwind_libunwind_ops *ops = maps__unwind_libunwind_ops(maps);
82
83	if (ops)
84		ops->finish_access(maps);
85}
86
87int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
88			 struct thread *thread,
89			 struct perf_sample *data, int max_stack,
90			 bool best_effort)
91{
92	const struct unwind_libunwind_ops *ops = maps__unwind_libunwind_ops(thread__maps(thread));
93
94	if (ops)
95		return ops->get_entries(cb, arg, thread, data, max_stack, best_effort);
96	return 0;
97}
v4.17
 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
 8struct unwind_libunwind_ops __weak *local_unwind_libunwind_ops;
 9struct unwind_libunwind_ops __weak *x86_32_unwind_libunwind_ops;
10struct unwind_libunwind_ops __weak *arm64_unwind_libunwind_ops;
11
12static void unwind__register_ops(struct thread *thread,
13			  struct unwind_libunwind_ops *ops)
14{
15	thread->unwind_libunwind_ops = ops;
16}
17
18int unwind__prepare_access(struct thread *thread, struct map *map,
19			   bool *initialized)
20{
21	const char *arch;
22	enum dso_type dso_type;
23	struct unwind_libunwind_ops *ops = local_unwind_libunwind_ops;
 
 
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)
46			ops = x86_32_unwind_libunwind_ops;
47	} else if (!strcmp(arch, "arm64") || !strcmp(arch, "arm")) {
48		if (dso_type == DSO__TYPE_64BIT)
49			ops = arm64_unwind_libunwind_ops;
50	}
51
52	if (!ops) {
53		pr_err("unwind: target platform=%s is not supported\n", arch);
54		return 0;
55	}
56out_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
65void unwind__flush_access(struct thread *thread)
66{
67	if (thread->unwind_libunwind_ops)
68		thread->unwind_libunwind_ops->flush_access(thread);
 
 
69}
70
71void unwind__finish_access(struct thread *thread)
72{
73	if (thread->unwind_libunwind_ops)
74		thread->unwind_libunwind_ops->finish_access(thread);
 
 
75}
76
77int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
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}