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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* %CopyrightBegin%
*
* Copyright Ericsson AB 2001-2013. All Rights Reserved.
*
* The contents of this file are subject to the Erlang Public License,
* Version 1.1, (the "License"); you may not use this file except in
* compliance with the License. You should have received a copy of the
* Erlang Public License along with this software. If not, it can be
* retrieved online at http://www.erlang.org/.
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* %CopyrightEnd%
*/
/*
* hipe_debug.c
*
* TODO:
* - detect mode-switch native return addresses (ARCH-specific)
* - map user-code native return addresses to symbolic names
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stddef.h> /* offsetof() */
#include <stdio.h>
#include "sys.h"
#include "erl_vm.h"
#include "global.h"
#include "erl_process.h"
#include "beam_catches.h"
#include "beam_load.h"
#include "hipe_mode_switch.h"
#include "hipe_debug.h"
#include "erl_map.h"
static const char dashes[2*sizeof(long)+5] = {
[0 ... 2*sizeof(long)+3] = '-'
};
static const char dots[2*sizeof(long)+5] = {
[0 ... 2*sizeof(long)+3] = '.'
};
static const char stars[2*sizeof(long)+5] = {
[0 ... 2*sizeof(long)+3] = '*'
};
extern Uint beam_apply[];
static void print_beam_pc(BeamInstr *pc)
{
if (pc == hipe_beam_pc_return) {
printf("return-to-native");
} else if (pc == hipe_beam_pc_throw) {
printf("throw-to-native");
} else if (pc == &beam_apply[1]) {
printf("normal-process-exit");
} else {
BeamInstr *mfa = find_function_from_pc(pc);
if (mfa)
erts_printf("%T:%T/%bpu + 0x%bpx",
mfa[0], mfa[1], mfa[2], pc - &mfa[3]);
else
printf("?");
}
}
static void catch_slot(Eterm *pos, Eterm val)
{
BeamInstr *pc = catch_pc(val);
printf(" | 0x%0*lx | 0x%0*lx | CATCH 0x%0*lx (BEAM ",
2*(int)sizeof(long), (unsigned long)pos,
2*(int)sizeof(long), (unsigned long)val,
2*(int)sizeof(long), (unsigned long)pc);
print_beam_pc(pc);
printf(")\r\n");
}
static void print_beam_cp(Eterm *pos, Eterm val)
{
printf(" |%s|%s| BEAM ACTIVATION RECORD\r\n", dashes, dashes);
printf(" | 0x%0*lx | 0x%0*lx | BEAM PC ",
2*(int)sizeof(long), (unsigned long)pos,
2*(int)sizeof(long), (unsigned long)val);
print_beam_pc(cp_val(val));
printf("\r\n");
}
static void print_catch(Eterm *pos, Eterm val)
{
printf(" |%s|%s| BEAM CATCH FRAME\r\n", dots, dots);
catch_slot(pos, val);
printf(" |%s|%s|\r\n", stars, stars);
}
static void print_stack(Eterm *sp, Eterm *end)
{
printf(" | %*s | %*s |\r\n",
2+2*(int)sizeof(long), "Address",
2+2*(int)sizeof(long), "Contents");
while (sp < end) {
Eterm val = sp[0];
if (is_CP(val))
print_beam_cp(sp, val);
else if (is_catch(val))
print_catch(sp, val);
else {
printf(" | 0x%0*lx | 0x%0*lx | ",
2*(int)sizeof(long), (unsigned long)sp,
2*(int)sizeof(long), (unsigned long)val);
erts_printf("%.30T", val);
printf("\r\n");
}
sp += 1;
}
printf(" |%s|%s|\r\n", dashes, dashes);
}
void hipe_print_estack(Process *p)
{
printf(" | BEAM STACK |\r\n");
print_stack(p->stop, STACK_START(p));
}
static void print_heap(Eterm *pos, Eterm *end)
{
printf("From: 0x%0*lx to 0x%0*lx\n\r",
2*(int)sizeof(long), (unsigned long)pos,
2*(int)sizeof(long), (unsigned long)end);
printf(" | H E A P |\r\n");
printf(" | %*s | %*s |\r\n",
2+2*(int)sizeof(long), "Address",
2+2*(int)sizeof(long), "Contents");
printf(" |%s|%s|\r\n", dashes, dashes);
while (pos < end) {
Eterm val = pos[0];
printf(" | 0x%0*lx | 0x%0*lx | ",
2*(int)sizeof(long), (unsigned long)pos,
2*(int)sizeof(long), (unsigned long)val);
++pos;
if (is_arity_value(val))
printf("Arity(%lu)", arityval(val));
else if (is_thing(val)) {
unsigned int ari = thing_arityval(val);
printf("Thing Arity(%u) Tag(%lu)", ari, thing_subtag(val));
while (ari) {
printf("\r\n | 0x%0*lx | 0x%0*lx | THING",
2*(int)sizeof(long), (unsigned long)pos,
2*(int)sizeof(long), (unsigned long)*pos);
++pos;
--ari;
}
} else
erts_printf("%.30T", val);
printf("\r\n");
}
printf(" |%s|%s|\r\n", dashes, dashes);
}
void hipe_print_heap(Process *p)
{
print_heap(p->heap, p->htop);
}
void hipe_print_pcb(Process *p)
{
printf("P: 0x%0*lx\r\n", 2*(int)sizeof(long), (unsigned long)p);
printf("-----------------------------------------------\r\n");
printf("Offset| Name | Value | *Value |\r\n");
#undef U
#define U(n,x) \
printf(" % 4d | %s | 0x%0*lx | |\r\n", (int)offsetof(Process,x), n, 2*(int)sizeof(long), (unsigned long)p->x)
#undef P
#define P(n,x) \
printf(" % 4d | %s | 0x%0*lx | 0x%0*lx |\r\n", (int)offsetof(Process,x), n, 2*(int)sizeof(long), (unsigned long)p->x, 2*(int)sizeof(long), p->x ? (unsigned long)*(p->x) : -1UL)
U("htop ", htop);
U("hend ", hend);
U("heap ", heap);
U("heap_sz ", heap_sz);
U("stop ", stop);
U("gen_gcs ", gen_gcs);
U("max_gen_gcs", max_gen_gcs);
U("high_water ", high_water);
U("old_hend ", old_hend);
U("old_htop ", old_htop);
U("old_head ", old_heap);
U("min_heap_..", min_heap_size);
U("rcount ", rcount);
U("id ", common.id);
U("reds ", reds);
U("tracer_pr..", common.tracer_proc);
U("trace_fla..", common.trace_flags);
U("group_lea..", group_leader);
U("flags ", flags);
U("fvalue ", fvalue);
U("freason ", freason);
U("fcalls ", fcalls);
/*XXX: ErlTimer tm; */
U("next ", next);
/*XXX: ErlOffHeap off_heap; */
U("reg ", common.u.alive.reg);
U("nlinks ", common.u.alive.links);
/*XXX: ErlMessageQueue msg; */
U("mbuf ", mbuf);
U("mbuf_sz ", mbuf_sz);
U("dictionary ", dictionary);
U("seq..clock ", seq_trace_clock);
U("seq..astcnt", seq_trace_lastcnt);
U("seq..token ", seq_trace_token);
U("intial[0] ", initial[0]);
U("intial[1] ", initial[1]);
U("intial[2] ", initial[2]);
P("current ", current);
P("cp ", cp);
P("i ", i);
U("catches ", catches);
U("arity ", arity);
P("arg_reg ", arg_reg);
U("max_arg_reg", max_arg_reg);
U("def..reg[0]", def_arg_reg[0]);
U("def..reg[1]", def_arg_reg[1]);
U("def..reg[2]", def_arg_reg[2]);
U("def..reg[3]", def_arg_reg[3]);
U("def..reg[4]", def_arg_reg[4]);
U("def..reg[5]", def_arg_reg[5]);
#ifdef HIPE
U("nsp ", hipe.nsp);
U("nstack ", hipe.nstack);
U("nstend ", hipe.nstend);
U("ncallee ", hipe.u.ncallee);
hipe_arch_print_pcb(&p->hipe);
#endif /* HIPE */
#undef U
#undef P
printf("-----------------------------------------------\r\n");
}
|