1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/* Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This is a revised version of gdb/testsuite/gdb.opt/inline-bt.c. */
#include <execinfo.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sframe-stacktrace-api.h"
#define ALWAYS_INLINE __attribute__((always_inline))
#define BT_BUF_SIZE 32
int x, y;
volatile int z = 0;
volatile int result;
/* funclist. */
const char *const flist[] =
{
"main"
};
void bar(void)
{
x += y;
}
inline ALWAYS_INLINE int func1(void)
{
bar ();
return x * y;
}
inline ALWAYS_INLINE int func2(void)
{
void *buffer[BT_BUF_SIZE];
int ok = 0, nptrs, err;
char **strings;
/* Call the unwinder to get an array of return addresses. */
nptrs = sframe_stacktrace (buffer, BT_BUF_SIZE, &err);
if (nptrs == -1)
{
printf ("SFrame error: %s\n", sframe_bt_errmsg (err));
return -1;
}
/* Get these addresses symbolically. */
strings = backtrace_symbols (buffer, nptrs);
if (strings == NULL) {
printf ("Error in backtrace_symbols");
return -1;
}
/* Verify the results. */
if (nptrs == 1 && strstr (strings[0], flist[0]))
ok = 1;
free(strings);
printf ("%s: stacktrace with inlined function\n", ok == 1 ? "PASS" : "FAIL");
return x * func1 ();
}
int main (void)
{
int val;
x = 7;
y = 8;
bar ();
val = func1 ();
result = val;
val = func2 ();
result = val;
return 0;
}
|