Branch data Line data Source code
1 : : /* Populate process registers from a linux perf_events sample.
2 : : Copyright (C) 2026 Matt Turner
3 : : This file is part of elfutils.
4 : :
5 : : This file is free software; you can redistribute it and/or modify
6 : : it under the terms of either
7 : :
8 : : * the GNU Lesser General Public License as published by the Free
9 : : Software Foundation; either version 3 of the License, or (at
10 : : your option) any later version
11 : :
12 : : or
13 : :
14 : : * the GNU General Public License as published by the Free
15 : : Software Foundation; either version 2 of the License, or (at
16 : : your option) any later version
17 : :
18 : : or both in parallel, as here.
19 : :
20 : : elfutils is distributed in the hope that it will be useful, but
21 : : WITHOUT ANY WARRANTY; without even the implied warranty of
22 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 : : General Public License for more details.
24 : :
25 : : You should have received copies of the GNU General Public License and
26 : : the GNU Lesser General Public License along with this program. If
27 : : not, see <http://www.gnu.org/licenses/>. */
28 : :
29 : :
30 : : #ifdef HAVE_CONFIG_H
31 : : # include <config.h>
32 : : #endif
33 : :
34 : : #define BACKEND alpha_
35 : : #include "libebl_CPU.h"
36 : : #include "libebl_PERF_FLAGS.h"
37 : :
38 : : /* The default sample_perf_regs_mapping maps perf register numbers 1:1,
39 : : which gives the DWARF number for $0-$30. PERF_REG_ALPHA_PC is 31,
40 : : which cannot be mistaken for $31 since the kernel does not sample
41 : : the zero register. */
42 : : #define SAMPLE_PC 31
43 : :
44 : : bool
45 : 0 : alpha_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
46 : : const int *regs_mapping, size_t n_regs_mapping,
47 : : Dwarf_Word *sp, Dwarf_Word *pc)
48 : : {
49 : 0 : return generic_sample_sp_pc (regs, n_regs, regs_mapping, n_regs_mapping,
50 : : sp, 30 /* index of sp in dwarf_regs */,
51 : : pc, SAMPLE_PC);
52 : : }
53 : :
54 : : bool
55 : 0 : alpha_set_initial_registers_sample (const Dwarf_Word *regs, uint32_t n_regs,
56 : : const int *regs_mapping, size_t n_regs_mapping,
57 : : ebl_tid_registers_t *setfunc,
58 : : void *arg)
59 : : {
60 : 0 : Dwarf_Word dwarf_regs[32] = { 0 };
61 [ # # # # ]: 0 : for (size_t i = 0; i < n_regs && i < n_regs_mapping; i++)
62 [ # # ]: 0 : if (regs_mapping[i] >= 0 && regs_mapping[i] < 32)
63 : 0 : dwarf_regs[regs_mapping[i]] = regs[i];
64 : :
65 : 0 : Dwarf_Word pc = dwarf_regs[SAMPLE_PC];
66 : 0 : dwarf_regs[31] = 0;
67 : :
68 : : /* The kernel cannot sample the callee-saved $9-$15. Leave them
69 : : unset so that the unwinder does not use a bogus value. */
70 : 0 : return (setfunc (0, 9, &dwarf_regs[0], arg)
71 [ # # ]: 0 : && setfunc (16, 16, &dwarf_regs[16], arg)
72 [ # # # # ]: 0 : && setfunc (-1, 1, &pc, arg));
73 : : }
|