7
#include "beam_catches.h"
8
#include "hipe_bif0.h" /* for hipe_find_sdesc() */
9
7
#include "hipe_stack.h"
10
8
#include "hipe_process.h"
13
#define SLOT_TYPE_VAL 0
14
#define SLOT_TYPE_RA 1
15
#define SLOT_TYPE_ARG 2
16
#define SLOT_TYPE_TRAP 3
18
10
extern void nbif_return(void);
11
extern void nbif_fail(void);
19
12
extern void nbif_stack_trap_ra(void);
22
15
* hipe_print_nstack() is called from hipe_bifs:show_nstack/1.
24
static void print_slot(Process *p, Eterm *sp, unsigned int live,
25
unsigned int type, unsigned long exnra)
17
static void print_slot(Eterm *sp, unsigned int live)
29
case SLOT_TYPE_RA: /* RA */
30
if ((unsigned long) val == (unsigned long)nbif_return) {
31
printf(" | 0x%08lx | 0x%08lx | NATIVE RA", (long)sp, val);
33
printf(", EXNRA 0x%08lx\n\r", exnra);
35
printf(" !! MISSING CATCH !!\n\r");
37
printf(" | MODE | SWITCH |");
40
printf(" | 0x%08lx | 0x%08lx | NATIVE RA", (long)sp, val);
42
printf(", EXNRA 0x%08lx", exnra);
47
printf(" | 0x%08lx | 0x%08lx | ARG ", (long)sp, val);
48
ldisplay(val, COUT, 30);
51
case SLOT_TYPE_TRAP: /* RA */
52
val = (unsigned long)p->hipe.ngra;
53
if ((unsigned long) val == (unsigned long)nbif_return) {
54
printf(" | 0x%08lx | 0x%08lx | TRAP RA", (long)sp, val);
56
printf(", EXNRA 0x%08lx\n\r", exnra);
58
printf(" !! MISSING CATCH !!\n\r");
60
printf(" | MODE | SWITCH |");
63
printf(" | 0x%08lx | 0x%08lx | TRAP RA", (long)sp, val);
65
printf(", EXNRA 0x%08lx", exnra);
71
printf(" | 0x%08lx | 0x%08lx | ", (long)sp, val);
73
ldisplay(val, COUT, 30);
20
printf(" | 0x%0*lx | 0x%0*lx | ",
21
2*(int)sizeof(long), (unsigned long)sp,
22
2*(int)sizeof(long), val);
24
erts_printf("%.30T", val);
85
32
const struct sdesc *sdesc;
87
35
unsigned int arity;
88
36
unsigned int lsize;
92
nstart = p->hipe.nstack;
93
ra = (unsigned long)p->hipe.nra; /* XXX: Temp solution to store RA here */
38
static const char dashes[2*sizeof(long)+5] = {
39
[0 ... 2*sizeof(long)+3] = '-'
96
42
printf(" | NATIVE STACK |\r\n");
97
printf(" |------------|------------|\r\n");
98
printf(" | heap | 0x%08lx |\r\n", (unsigned long)p->heap);
100
printf(" | high_water | 0x%08lx |\r\n", (unsigned long)p->high_water);
102
printf(" | hend | 0x%08lx |\r\n", (unsigned long)p->htop);
104
printf(" | old_heap | 0x%08lx |\r\n", (unsigned long)p->old_heap);
105
printf(" | old_hend | 0x%08lx |\r\n", (unsigned long)p->old_hend);
107
printf(" | nstack | 0x%08lx |\r\n", (unsigned long)p->hipe.nstack);
108
printf(" | nsp | 0x%08lx |\r\n", (unsigned long)p->hipe.nsp);
109
printf(" | nstend | 0x%08lx |\r\n", (unsigned long)p->hipe.nstend);
110
printf(" | nstblacklim| 0x%08lx |\r\n", (unsigned long)p->hipe.nstblacklim);
111
printf(" | nstgraylim | 0x%08lx |\r\n", (unsigned long)p->hipe.nstgraylim);
112
printf(" |------------|------------|\r\n");
113
printf(" | Address | Contents |\r\n");
114
printf(" |------------|------------|\r\n");
116
if( ra == (unsigned long)nbif_stack_trap_ra ) {
117
sdesc = hipe_find_sdesc((unsigned long)p->hipe.ngra);
119
sdesc = hipe_find_sdesc(ra);
122
while( nsp > nstart ) {
43
printf(" |%s|%s|\r\n", dashes, dashes);
44
printf(" | %*s | 0x%0*lx |\r\n",
45
2+2*(int)sizeof(long), "heap",
46
2*(int)sizeof(long), (unsigned long)p->heap);
47
printf(" | %*s | 0x%0*lx |\r\n",
48
2+2*(int)sizeof(long), "high_water",
49
2*(int)sizeof(long), (unsigned long)p->high_water);
50
printf(" | %*s | 0x%0*lx |\r\n",
51
2+2*(int)sizeof(long), "hend",
52
2*(int)sizeof(long), (unsigned long)p->htop);
53
printf(" | %*s | 0x%0*lx |\r\n",
54
2+2*(int)sizeof(long), "old_heap",
55
2*(int)sizeof(long), (unsigned long)p->old_heap);
56
printf(" | %*s | 0x%0*lx |\r\n",
57
2+2*(int)sizeof(long), "old_hend",
58
2*(int)sizeof(long), (unsigned long)p->old_hend);
59
printf(" | %*s | 0x%0*lx |\r\n",
60
2+2*(int)sizeof(long), "nstack",
61
2*(int)sizeof(long), (unsigned long)p->hipe.nstack);
62
printf(" | %*s | 0x%0*lx |\r\n",
63
2+2*(int)sizeof(long), "nsp",
64
2*(int)sizeof(long), (unsigned long)p->hipe.nsp);
65
printf(" | %*s | 0x%0*lx |\r\n",
66
2+2*(int)sizeof(long), "nstend",
67
2*(int)sizeof(long), (unsigned long)p->hipe.nstend);
68
printf(" | %*s| 0x%0*lx |\r\n",
69
2+2*(int)sizeof(long)+1, "nstblacklim",
70
2*(int)sizeof(long), (unsigned long)p->hipe.nstblacklim);
71
printf(" | %*s | 0x%0*lx |\r\n",
72
2+2*(int)sizeof(long), "nstgraylim",
73
2*(int)sizeof(long), (unsigned long)p->hipe.nstgraylim);
74
printf(" |%s|%s|\r\n", dashes, dashes);
75
printf(" | %*s | %*s |\r\n",
76
2+2*(int)sizeof(long), "Address",
77
2+2*(int)sizeof(long), "Contents");
78
printf(" |%s|%s|\r\n", dashes, dashes);
80
ra = (unsigned long)p->hipe.nra;
84
nstart = p->hipe.nstack;
86
if (ra == (unsigned long)&nbif_stack_trap_ra)
87
ra = (unsigned long)p->hipe.ngra;
88
sdesc = hipe_find_sdesc(ra);
90
while (nsp > nstart) {
123
91
arity = sdesc_arity(sdesc);
124
92
lsize = sdesc_fsize(sdesc)- 1;
125
93
printf(" | LOCALS %3i : ARITY %4i | \r\n", lsize, arity);
127
94
for(i = 0; i < lsize; i++)
128
print_slot(p, &nsp[-i], sdesc->livebits[i>>5] & (1<<(i&31)),
95
print_slot(&nsp[-i], sdesc->livebits[i>>5] & (1<<(i&31)));
132
if( ra == (unsigned long)nbif_stack_trap_ra ) {
98
if (ra == (unsigned long)&nbif_stack_trap_ra)
133
99
sdesc = hipe_find_sdesc((unsigned long)p->hipe.ngra);
134
print_slot(p, nsp, 1, SLOT_TYPE_TRAP, sdesc_exnra(sdesc));
136
sdesc = hipe_find_sdesc(ra);
137
print_slot(p, nsp, 1, SLOT_TYPE_RA, sdesc_exnra(sdesc));
101
sdesc = hipe_find_sdesc(ra);
102
printf(" | 0x%0*lx | 0x%0*lx | ",
103
2*(int)sizeof(long), (unsigned long)&nsp[0],
104
2*(int)sizeof(long), ra);
105
if (ra == (unsigned long)&nbif_stack_trap_ra)
106
printf("STACK TRAP, ORIG RA 0x%lx", (unsigned long)p->hipe.ngra);
107
else if (ra == (unsigned long)&nbif_return)
108
printf("MODE SWITCH");
111
if ((exnra = sdesc_exnra(sdesc)) != 0)
112
printf(", EXNRA 0x%lx", exnra);
140
115
for(i = 0; i < arity; ++i)
141
print_slot(p, &nsp[-i], 1, SLOT_TYPE_ARG,0);
116
print_slot(&nsp[-i], 1);
144
118
printf(" |------------|------------|\r\n");
147
/* printf(" |------------|------------|\r\n"); */
151
122
#define MINSTACK 256
152
#define NSKIPFRAMES 32
123
#define NSKIPFRAMES 32
154
125
void hipe_update_stack_trap(Process *p, const struct sdesc *sdesc)
223
182
unsigned long ra;
224
184
unsigned int arity;
225
extern void nbif_fail(void);
227
185
const struct sdesc *sdesc;
229
187
nsp = p->hipe.nsp;
230
188
nstart = p->hipe.nstack;
232
ra = (unsigned long)p->hipe.nra; /* XXX: Temp solution to store RA here */
190
ra = (unsigned long)p->hipe.nra;
234
while( nsp > nstart ) {
235
if( ra == (unsigned long)nbif_stack_trap_ra )
192
while (nsp > nstart) {
193
if (ra == (unsigned long)&nbif_stack_trap_ra)
236
194
ra = (unsigned long)p->hipe.ngra;
237
195
sdesc = hipe_find_sdesc(ra);
238
if( (exnra = sdesc_exnra(sdesc)) != 0 &&
196
if ((exnra = sdesc_exnra(sdesc)) != 0 &&
239
197
(p->catches >= 0 ||
240
exnra == (unsigned long)nbif_fail) ) {
198
exnra == (unsigned long)&nbif_fail)) {
241
199
p->hipe.ncallee = (void(*)(void)) exnra;
242
200
p->hipe.nsp = nsp;
243
201
/* update the gray/white boundary if we threw past it */
244
if( p->hipe.nstgraylim && nsp <= p->hipe.nstgraylim )
202
if (p->hipe.nstgraylim && nsp <= p->hipe.nstgraylim)
245
203
hipe_update_stack_trap(p, sdesc);
249
206
nsp -= sdesc_fsize(sdesc);
252
208
arity = sdesc_arity(sdesc);
253
209
nsp -= arity; /* skip actuals on stack */
255
211
fprintf(stderr, "%s: no native CATCH found!\r\n", __FUNCTION__);
256
hipe_print_nstack(p);