Branch data Line data Source code
1 : : /* Get previous frame state for an existing frame state.
2 : : Copyright (C) 2016 The Qt Company Ltd.
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 : : #define FP_REG 29
35 : : #define LR_REG 30
36 : : #define SP_REG 31
37 : : #define FP_OFFSET 0
38 : : #define LR_OFFSET 8
39 : : #define SP_OFFSET 16
40 : :
41 : : #include "libebl_CPU.h"
42 : :
43 : : /* There was no CFI. Maybe we happen to have a frame pointer and can unwind from that? */
44 : :
45 : : bool
46 : 26 : EBLHOOK(unwind) (Ebl *ebl __attribute__ ((unused)), Dwarf_Addr pc __attribute__ ((unused)),
47 : : ebl_tid_registers_t *setfunc, ebl_tid_registers_get_t *getfunc,
48 : : ebl_pid_memory_read_t *readfunc, void *arg,
49 : : bool *signal_framep __attribute__ ((unused)))
50 : : {
51 : 26 : Dwarf_Word fp, lr, sp;
52 : :
53 [ - + ]: 26 : if (!getfunc(LR_REG, 1, &lr, arg))
54 : : return false;
55 : :
56 [ + + - + ]: 26 : if (lr == 0 || !setfunc(-1, 1, &lr, arg))
57 : 4 : return false;
58 : :
59 [ - + ]: 22 : if (!getfunc(FP_REG, 1, &fp, arg))
60 : 0 : fp = 0;
61 : :
62 [ - + ]: 22 : if (!getfunc(SP_REG, 1, &sp, arg))
63 : 0 : sp = 0;
64 : :
65 : 22 : Dwarf_Word newLr, newFp, newSp;
66 : :
67 [ + + ]: 22 : if (!readfunc(fp + LR_OFFSET, &newLr, arg))
68 : 6 : newLr = 0;
69 : :
70 [ + + ]: 22 : if (!readfunc(fp + FP_OFFSET, &newFp, arg))
71 : 6 : newFp = 0;
72 : :
73 : 22 : newSp = fp + SP_OFFSET;
74 : :
75 : : // These are not fatal if they don't work. They will just prevent unwinding at the next frame.
76 : 22 : setfunc(LR_REG, 1, &newLr, arg);
77 : 22 : setfunc(FP_REG, 1, &newFp, arg);
78 : 22 : setfunc(SP_REG, 1, &newSp, arg);
79 : :
80 : : // If the fp is invalid, we might still have a valid lr.
81 : : // But if the fp is valid, then the stack should be moving in the right direction.
82 [ + + + + ]: 40 : return fp == 0 || newSp > sp;
83 : : }
|