Coverage Report

Created: 2026-05-30 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/elfutils/backends/aarch64_initreg_sample.c
Line
Count
Source
1
/* Populate process registers from a register sample.
2
   Copyright (C) 2026 Red Hat Inc.
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
#ifdef HAVE_CONFIG_H
30
# include <config.h>
31
#endif
32
33
#define BACKEND aarch64_
34
#include "libebl_CPU.h"
35
#include "libebl_PERF_FLAGS.h"
36
37
bool
38
aarch64_sample_sp_pc (const Dwarf_Word *regs, uint32_t n_regs,
39
          const int *regs_mapping, size_t n_regs_mapping,
40
          Dwarf_Word *sp, Dwarf_Word *pc)
41
0
{
42
0
  return generic_sample_sp_pc (regs, n_regs, regs_mapping, n_regs_mapping,
43
0
             sp, 31 /* index of sp in dwarf_regs */,
44
0
             pc, 32 /* index of pc in dwarf_regs */);
45
0
}
46
47
bool
48
aarch64_set_initial_registers_sample (const Dwarf_Word *regs, uint32_t n_regs,
49
              const int *regs_mapping, size_t n_regs_mapping,
50
              ebl_tid_registers_t *setfunc,
51
              void *arg)
52
0
{
53
0
#define N_GREGS 33
54
0
  Dwarf_Word dwarf_regs[N_GREGS];
55
0
  bool scratch_present = false;
56
0
  size_t i;
57
0
  for (i = 0; i < N_GREGS; i++)
58
0
    dwarf_regs[i] = 0x0;
59
0
  for (i = 0; i < n_regs; i++)
60
0
    {
61
0
      if (i >= n_regs_mapping)
62
0
  break;
63
0
      if (regs_mapping[i] < 0 || regs_mapping[i] >= N_GREGS)
64
0
  continue;
65
0
      if (regs_mapping[i] < 19)
66
0
  scratch_present = true;
67
0
      dwarf_regs[regs_mapping[i]] = regs[i];
68
0
    }
69
70
  /* X0..X18 only if present.  */
71
0
  if (scratch_present && ! setfunc (0, 19, &dwarf_regs[0], arg))
72
0
    return false;
73
74
  /* X19..X29, X30(LR) plus SP.  */
75
0
  if (! setfunc (19, 32 - 18, &dwarf_regs[19], arg))
76
0
    return false;
77
78
  /* PC.  */
79
0
  if (! setfunc (-1, 1, &dwarf_regs[32], arg))
80
0
    return false;
81
82
  /* TODO: May need to obtain PAC mask since the unwinder needs to
83
     strip it from LR/X30 to handle pointer authentication.  This
84
     requires additional querying of the target process (e.g. a
85
     one-time ptrace operation) in addition to perf_events data.
86
87
     Alternatively, stripping the top 16 bits from the pointer
88
     may work as a desperation heuristic.  */
89
90
  /* Skip ELR, RA_SIGN_STATE  */
91
92
  /* XXX Skip FP registers.  */
93
0
  return true;
94
0
}