Ruby: vm_dump.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

vm_dump.c
Go to the documentation of this file.
1/**********************************************************************
2
3 vm_dump.c -
4
5 $Author$
6
7 Copyright (C) 2004-2007 Koichi Sasada
8
9**********************************************************************/
10
11#include "ruby/internal/config.h"
12
13#ifdef HAVE_UCONTEXT_H
14# include <ucontext.h>
15#endif
16
17#ifdef __APPLE__
18# ifdef HAVE_LIBPROC_H
19# include <libproc.h>
20# endif
21# include <mach/vm_map.h>
22# include <mach/mach_init.h>
23# ifdef __LP64__
24# define vm_region_recurse vm_region_recurse_64
25# endif
26/* that is defined in sys/queue.h, and conflicts with
27 * ccan/list/list.h */
28# undef LIST_HEAD
29#endif
30
31#include "addr2line.h"
32#include "gc.h"
33#include "internal.h"
34#include "internal/variable.h"
35#include "internal/vm.h"
36#include "iseq.h"
37#include "vm_core.h"
38#include "ractor_core.h"
39
40#define MAX_POSBUF 128
41
42#define VM_CFP_CNT(ec, cfp) \
43 ((rb_control_frame_t *)((ec)->vm_stack + (ec)->vm_stack_size) - \
44 (rb_control_frame_t *)(cfp))
45
46const char *rb_method_type_name(rb_method_type_t type);
47 int ruby_on_ci;
48
49static void
50control_frame_dump(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
51{
52 ptrdiff_t pc = -1;
53 ptrdiff_t ep = cfp->ep - ec->vm_stack;
54 char ep_in_heap = ' ';
55 char posbuf[MAX_POSBUF+1];
56 int line = 0;
57 const char *magic, *iseq_name = "-", *selfstr = "-", *biseq_name = "-";
58 VALUE tmp;
59 const rb_iseq_t *iseq = NULL;
60 const rb_callable_method_entry_t *me = rb_vm_frame_method_entry(cfp);
61
62 if (ep < 0 || (size_t)ep > ec->vm_stack_size) {
63 ep = (ptrdiff_t)cfp->ep;
64 ep_in_heap = 'p';
65 }
66
67 switch (VM_FRAME_TYPE(cfp)) {
68 case VM_FRAME_MAGIC_TOP:
69 magic = "TOP";
70 break;
71 case VM_FRAME_MAGIC_METHOD:
72 magic = "METHOD";
73 break;
74 case VM_FRAME_MAGIC_CLASS:
75 magic = "CLASS";
76 break;
77 case VM_FRAME_MAGIC_BLOCK:
78 magic = "BLOCK";
79 break;
80 case VM_FRAME_MAGIC_CFUNC:
81 magic = "CFUNC";
82 break;
83 case VM_FRAME_MAGIC_IFUNC:
84 magic = "IFUNC";
85 break;
86 case VM_FRAME_MAGIC_EVAL:
87 magic = "EVAL";
88 break;
89 case VM_FRAME_MAGIC_RESCUE:
90 magic = "RESCUE";
91 break;
92 case 0:
93 magic = "------";
94 break;
95 default:
96 magic = "(none)";
97 break;
98 }
99
100 if (0) {
101 tmp = rb_inspect(cfp->self);
102 selfstr = StringValueCStr(tmp);
103 }
104 else {
105 selfstr = "";
106 }
107
108 if (cfp->iseq != 0) {
109#define RUBY_VM_IFUNC_P(ptr) IMEMO_TYPE_P(ptr, imemo_ifunc)
110 if (RUBY_VM_IFUNC_P(cfp->iseq)) {
111 iseq_name = "<ifunc>";
112 }
113 else if (SYMBOL_P((VALUE)cfp->iseq)) {
114 tmp = rb_sym2str((VALUE)cfp->iseq);
115 iseq_name = RSTRING_PTR(tmp);
116 snprintf(posbuf, MAX_POSBUF, ":%s", iseq_name);
117 line = -1;
118 }
119 else {
120 iseq = cfp->iseq;
121 pc = cfp->pc - iseq->body->iseq_encoded;
122 iseq_name = RSTRING_PTR(iseq->body->location.label);
123 line = rb_vm_get_sourceline(cfp);
124 if (line) {
125 snprintf(posbuf, MAX_POSBUF, "%s:%d", RSTRING_PTR(rb_iseq_path(iseq)), line);
126 }
127 }
128 }
129 else if (me != NULL) {
130 iseq_name = rb_id2name(me->def->original_id);
131 snprintf(posbuf, MAX_POSBUF, ":%s", iseq_name);
132 line = -1;
133 }
134
135 fprintf(stderr, "c:%04"PRIdPTRDIFF" ",
136 ((rb_control_frame_t *)(ec->vm_stack + ec->vm_stack_size) - cfp));
137 if (pc == -1) {
138 fprintf(stderr, "p:---- ");
139 }
140 else {
141 fprintf(stderr, "p:%04"PRIdPTRDIFF" ", pc);
142 }
143 fprintf(stderr, "s:%04"PRIdPTRDIFF" ", cfp->sp - ec->vm_stack);
144 fprintf(stderr, ep_in_heap == ' ' ? "e:%06"PRIdPTRDIFF" " : "E:%06"PRIxPTRDIFF" ", ep % 10000);
145 fprintf(stderr, "%-6s", magic);
146 if (line) {
147 fprintf(stderr, " %s", posbuf);
148 }
149 if (VM_FRAME_FINISHED_P(cfp)) {
150 fprintf(stderr, " [FINISH]");
151 }
152 if (0) {
153 fprintf(stderr, " \t");
154 fprintf(stderr, "iseq: %-24s ", iseq_name);
155 fprintf(stderr, "self: %-24s ", selfstr);
156 fprintf(stderr, "%-1s ", biseq_name);
157 }
158 fprintf(stderr, "\n");
159
160 // additional information for CI machines
161 if (ruby_on_ci) {
162 char buff[0x100];
163
164 if (me) {
165 if (IMEMO_TYPE_P(me, imemo_ment)) {
166 fprintf(stderr, " me:\n");
167 fprintf(stderr, " called_id: %s, type: %s\n", rb_id2name(me->called_id), rb_method_type_name(me->def->type));
168 fprintf(stderr, " owner class: %s\n", rb_raw_obj_info(buff, 0x100, me->owner));
169 if (me->owner != me->defined_class) {
170 fprintf(stderr, " defined_class: %s\n", rb_raw_obj_info(buff, 0x100, me->defined_class));
171 }
172 }
173 else {
174 fprintf(stderr, " me is corrupted (%s)\n", rb_raw_obj_info(buff, 0x100, (VALUE)me));
175 }
176 }
177
178 fprintf(stderr, " self: %s\n", rb_raw_obj_info(buff, 0x100, cfp->self));
179
180 if (iseq) {
181 if (iseq->body->local_table_size > 0) {
182 fprintf(stderr, " lvars:\n");
183 for (unsigned int i=0; i<iseq->body->local_table_size; i++) {
184 const VALUE *argv = cfp->ep - cfp->iseq->body->local_table_size - VM_ENV_DATA_SIZE + 1;
185 fprintf(stderr, " %s: %s\n",
186 rb_id2name(iseq->body->local_table[i]),
187 rb_raw_obj_info(buff, 0x100, argv[i]));
188 }
189 }
190 }
191 }
192}
193
194void
195 rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
196{
197#if 0
198 VALUE *sp = cfp->sp;
199 const VALUE *ep = cfp->ep;
200 VALUE *p, *st, *t;
201
202 fprintf(stderr, "-- stack frame ------------\n");
203 for (p = st = ec->vm_stack; p < sp; p++) {
204 fprintf(stderr, "%04ld (%p): %08"PRIxVALUE, (long)(p - st), p, *p);
205
206 t = (VALUE *)*p;
207 if (ec->vm_stack <= t && t < sp) {
208 fprintf(stderr, " (= %ld)", (long)((VALUE *)GC_GUARDED_PTR_REF((VALUE)t) - ec->vm_stack));
209 }
210
211 if (p == ep)
212 fprintf(stderr, " <- ep");
213
214 fprintf(stderr, "\n");
215 }
216#endif
217
218 fprintf(stderr, "-- Control frame information "
219 "-----------------------------------------------\n");
220 while ((void *)cfp < (void *)(ec->vm_stack + ec->vm_stack_size)) {
221 control_frame_dump(ec, cfp);
222 cfp++;
223 }
224 fprintf(stderr, "\n");
225}
226
227void
228rb_vmdebug_stack_dump_raw_current(void)
229{
230 const rb_execution_context_t *ec = GET_EC();
231 rb_vmdebug_stack_dump_raw(ec, ec->cfp);
232}
233
234void
235rb_vmdebug_env_dump_raw(const rb_env_t *env, const VALUE *ep)
236{
237 unsigned int i;
238 fprintf(stderr, "-- env --------------------\n");
239
240 while (env) {
241 fprintf(stderr, "--\n");
242 for (i = 0; i < env->env_size; i++) {
243 fprintf(stderr, "%04d: %08"PRIxVALUE" (%p)", i, env->env[i], (void *)&env->env[i]);
244 if (&env->env[i] == ep) fprintf(stderr, " <- ep");
245 fprintf(stderr, "\n");
246 }
247
248 env = rb_vm_env_prev_env(env);
249 }
250 fprintf(stderr, "---------------------------\n");
251}
252
253void
254rb_vmdebug_proc_dump_raw(rb_proc_t *proc)
255{
256 const rb_env_t *env;
257 char *selfstr;
258 VALUE val = rb_inspect(vm_block_self(&proc->block));
259 selfstr = StringValueCStr(val);
260
261 fprintf(stderr, "-- proc -------------------\n");
262 fprintf(stderr, "self: %s\n", selfstr);
263 env = VM_ENV_ENVVAL_PTR(vm_block_ep(&proc->block));
264 rb_vmdebug_env_dump_raw(env, vm_block_ep(&proc->block));
265}
266
267void
268rb_vmdebug_stack_dump_th(VALUE thval)
269{
270 rb_thread_t *target_th = rb_thread_ptr(thval);
271 rb_vmdebug_stack_dump_raw(target_th->ec, target_th->ec->cfp);
272}
273
274#if VMDEBUG > 2
275
276/* copy from vm.c */
277static const VALUE *
278vm_base_ptr(const rb_control_frame_t *cfp)
279{
280 const rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
281 const VALUE *bp = prev_cfp->sp + cfp->iseq->body->local_table_size + VM_ENV_DATA_SIZE;
282
283 if (cfp->iseq->body->type == ISEQ_TYPE_METHOD) {
284 bp += 1;
285 }
286 return bp;
287}
288
289static void
290vm_stack_dump_each(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
291{
292 int i, argc = 0, local_table_size = 0;
293 VALUE rstr;
294 VALUE *sp = cfp->sp;
295 const VALUE *ep = cfp->ep;
296
297 if (VM_FRAME_RUBYFRAME_P(cfp)) {
298 const rb_iseq_t *iseq = cfp->iseq;
299 argc = iseq->body->param.lead_num;
300 local_table_size = iseq->body->local_table_size;
301 }
302
303 /* stack trace header */
304
305 if (VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_METHOD||
306 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_TOP ||
307 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_BLOCK ||
308 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CLASS ||
309 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_CFUNC ||
310 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_IFUNC ||
311 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_EVAL ||
312 VM_FRAME_TYPE(cfp) == VM_FRAME_MAGIC_RESCUE)
313 {
314 const VALUE *ptr = ep - local_table_size;
315
316 control_frame_dump(ec, cfp);
317
318 for (i = 0; i < argc; i++) {
319 rstr = rb_inspect(*ptr);
320 fprintf(stderr, " arg %2d: %8s (%p)\n", i, StringValueCStr(rstr),
321 (void *)ptr++);
322 }
323 for (; i < local_table_size - 1; i++) {
324 rstr = rb_inspect(*ptr);
325 fprintf(stderr, " local %2d: %8s (%p)\n", i, StringValueCStr(rstr),
326 (void *)ptr++);
327 }
328
329 ptr = vm_base_ptr(cfp);
330 for (; ptr < sp; ptr++, i++) {
331 switch (TYPE(*ptr)) {
332 case T_UNDEF:
333 rstr = rb_str_new2("undef");
334 break;
335 case T_IMEMO:
336 rstr = rb_str_new2("imemo"); /* TODO: can put mode detail information */
337 break;
338 default:
339 rstr = rb_inspect(*ptr);
340 break;
341 }
342 fprintf(stderr, " stack %2d: %8s (%"PRIdPTRDIFF")\n", i, StringValueCStr(rstr),
343 (ptr - ec->vm_stack));
344 }
345 }
346 else if (VM_FRAME_FINISHED_P(cfp)) {
347 if (ec->vm_stack + ec->vm_stack_size > (VALUE *)(cfp + 1)) {
348 vm_stack_dump_each(ec, cfp + 1);
349 }
350 else {
351 /* SDR(); */
352 }
353 }
354 else {
355 rb_bug("unsupported frame type: %08lx", VM_FRAME_TYPE(cfp));
356 }
357}
358#endif
359
360void
361rb_vmdebug_debug_print_register(const rb_execution_context_t *ec)
362{
363 rb_control_frame_t *cfp = ec->cfp;
364 ptrdiff_t pc = -1;
365 ptrdiff_t ep = cfp->ep - ec->vm_stack;
366 ptrdiff_t cfpi;
367
368 if (VM_FRAME_RUBYFRAME_P(cfp)) {
369 pc = cfp->pc - cfp->iseq->body->iseq_encoded;
370 }
371
372 if (ep < 0 || (size_t)ep > ec->vm_stack_size) {
373 ep = -1;
374 }
375
376 cfpi = ((rb_control_frame_t *)(ec->vm_stack + ec->vm_stack_size)) - cfp;
377 fprintf(stderr, " [PC] %04"PRIdPTRDIFF", [SP] %04"PRIdPTRDIFF", [EP] %04"PRIdPTRDIFF", [CFP] %04"PRIdPTRDIFF"\n",
378 pc, (cfp->sp - ec->vm_stack), ep, cfpi);
379}
380
381void
382rb_vmdebug_thread_dump_regs(VALUE thval)
383{
384 rb_vmdebug_debug_print_register(rb_thread_ptr(thval)->ec);
385}
386
387void
388 rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc)
389{
390 const rb_iseq_t *iseq = cfp->iseq;
391
392 if (iseq != 0) {
393 ptrdiff_t pc = _pc - iseq->body->iseq_encoded;
394 int i;
395
396 for (i=0; i<(int)VM_CFP_CNT(ec, cfp); i++) {
397 printf(" ");
398 }
399 printf("| ");
400 if(0)printf("[%03ld] ", (long)(cfp->sp - ec->vm_stack));
401
402 /* printf("%3"PRIdPTRDIFF" ", VM_CFP_CNT(ec, cfp)); */
403 if (pc >= 0) {
404 const VALUE *iseq_original = rb_iseq_original_iseq((rb_iseq_t *)iseq);
405
406 rb_iseq_disasm_insn(0, iseq_original, (size_t)pc, iseq, 0);
407 }
408 }
409
410#if VMDEBUG > 3
411 fprintf(stderr, " (1)");
412 rb_vmdebug_debug_print_register(ec);
413#endif
414}
415
416void
417 rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp
418#if OPT_STACK_CACHING
419 , VALUE reg_a, VALUE reg_b
420#endif
421 )
422{
423#if VMDEBUG > 9
424 SDR2(cfp);
425#endif
426
427#if VMDEBUG > 3
428 fprintf(stderr, " (2)");
429 rb_vmdebug_debug_print_register(ec);
430#endif
431 /* stack_dump_raw(ec, cfp); */
432
433#if VMDEBUG > 2
434 /* stack_dump_thobj(ec); */
435 vm_stack_dump_each(ec, ec->cfp);
436
437#if OPT_STACK_CACHING
438 {
439 VALUE rstr;
440 rstr = rb_inspect(reg_a);
441 fprintf(stderr, " sc reg A: %s\n", StringValueCStr(rstr));
442 rstr = rb_inspect(reg_b);
443 fprintf(stderr, " sc reg B: %s\n", StringValueCStr(rstr));
444 }
445#endif
446 printf
447 ("--------------------------------------------------------------\n");
448#endif
449}
450
451 VALUE
452rb_vmdebug_thread_dump_state(VALUE self)
453{
454 rb_thread_t *th = rb_thread_ptr(self);
455 rb_control_frame_t *cfp = th->ec->cfp;
456
457 fprintf(stderr, "Thread state dump:\n");
458 fprintf(stderr, "pc : %p, sp : %p\n", (void *)cfp->pc, (void *)cfp->sp);
459 fprintf(stderr, "cfp: %p, ep : %p\n", (void *)cfp, (void *)cfp->ep);
460
461 return Qnil;
462}
463
464#if defined __APPLE__
465# if __DARWIN_UNIX03
466# define MCTX_SS_REG(reg) __ss.__##reg
467# else
468# define MCTX_SS_REG(reg) ss.reg
469# endif
470#endif
471
472#if defined(HAVE_BACKTRACE)
473# ifdef HAVE_LIBUNWIND
474# undef backtrace
475# define backtrace unw_backtrace
476# elif defined(__APPLE__) && defined(__x86_64__) && defined(HAVE_LIBUNWIND_H)
477# define UNW_LOCAL_ONLY
478# include <libunwind.h>
479# include <sys/mman.h>
480# undef backtrace
481int
482backtrace(void **trace, int size)
483{
484 unw_cursor_t cursor; unw_context_t uc;
485 unw_word_t ip;
486 int n = 0;
487
488 unw_getcontext(&uc);
489 unw_init_local(&cursor, &uc);
490 while (unw_step(&cursor) > 0) {
491 unw_get_reg(&cursor, UNW_REG_IP, &ip);
492 trace[n++] = (void *)ip;
493 {
494 char buf[256];
495 unw_get_proc_name(&cursor, buf, 256, &ip);
496 if (strncmp("_sigtramp", buf, sizeof("_sigtramp")) == 0) {
497 goto darwin_sigtramp;
498 }
499 }
500 }
501 return n;
502darwin_sigtramp:
503 /* darwin's bundled libunwind doesn't support signal trampoline */
504 {
505 ucontext_t *uctx;
506 char vec[1];
507 int r;
508 /* get previous frame information from %rbx at _sigtramp and set values to cursor
509 * http://www.opensource.apple.com/source/Libc/Libc-825.25/i386/sys/_sigtramp.s
510 * http://www.opensource.apple.com/source/libunwind/libunwind-35.1/src/unw_getcontext.s
511 */
512 unw_get_reg(&cursor, UNW_X86_64_RBX, &ip);
513 uctx = (ucontext_t *)ip;
514 unw_set_reg(&cursor, UNW_X86_64_RAX, uctx->uc_mcontext->MCTX_SS_REG(rax));
515 unw_set_reg(&cursor, UNW_X86_64_RBX, uctx->uc_mcontext->MCTX_SS_REG(rbx));
516 unw_set_reg(&cursor, UNW_X86_64_RCX, uctx->uc_mcontext->MCTX_SS_REG(rcx));
517 unw_set_reg(&cursor, UNW_X86_64_RDX, uctx->uc_mcontext->MCTX_SS_REG(rdx));
518 unw_set_reg(&cursor, UNW_X86_64_RDI, uctx->uc_mcontext->MCTX_SS_REG(rdi));
519 unw_set_reg(&cursor, UNW_X86_64_RSI, uctx->uc_mcontext->MCTX_SS_REG(rsi));
520 unw_set_reg(&cursor, UNW_X86_64_RBP, uctx->uc_mcontext->MCTX_SS_REG(rbp));
521 unw_set_reg(&cursor, UNW_X86_64_RSP, 8+(uctx->uc_mcontext->MCTX_SS_REG(rsp)));
522 unw_set_reg(&cursor, UNW_X86_64_R8, uctx->uc_mcontext->MCTX_SS_REG(r8));
523 unw_set_reg(&cursor, UNW_X86_64_R9, uctx->uc_mcontext->MCTX_SS_REG(r9));
524 unw_set_reg(&cursor, UNW_X86_64_R10, uctx->uc_mcontext->MCTX_SS_REG(r10));
525 unw_set_reg(&cursor, UNW_X86_64_R11, uctx->uc_mcontext->MCTX_SS_REG(r11));
526 unw_set_reg(&cursor, UNW_X86_64_R12, uctx->uc_mcontext->MCTX_SS_REG(r12));
527 unw_set_reg(&cursor, UNW_X86_64_R13, uctx->uc_mcontext->MCTX_SS_REG(r13));
528 unw_set_reg(&cursor, UNW_X86_64_R14, uctx->uc_mcontext->MCTX_SS_REG(r14));
529 unw_set_reg(&cursor, UNW_X86_64_R15, uctx->uc_mcontext->MCTX_SS_REG(r15));
530 ip = uctx->uc_mcontext->MCTX_SS_REG(rip);
531
532 /* There are 4 cases for SEGV:
533 * (1) called invalid address
534 * (2) read or write invalid address
535 * (3) received signal
536 *
537 * Detail:
538 * (1) called invalid address
539 * In this case, saved ip is invalid address.
540 * It needs to just save the address for the information,
541 * skip the frame, and restore the frame calling the
542 * invalid address from %rsp.
543 * The problem is how to check whether the ip is valid or not.
544 * This code uses mincore(2) and assume the address's page is
545 * incore/referenced or not reflects the problem.
546 * Note that High Sierra's mincore(2) may return -128.
547 * (2) read or write invalid address
548 * saved ip is valid. just restart backtracing.
549 * (3) received signal in user space
550 * Same as (2).
551 * (4) received signal in kernel
552 * In this case saved ip points just after syscall, but registers are
553 * already overwritten by kernel. To fix register consistency,
554 * skip libc's kernel wrapper.
555 * To detect this case, just previous two bytes of ip is "\x0f\x05",
556 * syscall instruction of x86_64.
557 */
558 r = mincore((const void *)ip, 1, vec);
559 if (r || vec[0] <= 0 || memcmp((const char *)ip-2, "\x0f\x05", 2) == 0) {
560 /* if segv is caused by invalid call or signal received in syscall */
561 /* the frame is invalid; skip */
562 trace[n++] = (void *)ip;
563 ip = *(unw_word_t*)uctx->uc_mcontext->MCTX_SS_REG(rsp);
564 }
565 trace[n++] = (void *)ip;
566 unw_set_reg(&cursor, UNW_REG_IP, ip);
567 }
568 while (unw_step(&cursor) > 0) {
569 unw_get_reg(&cursor, UNW_REG_IP, &ip);
570 trace[n++] = (void *)ip;
571 }
572 return n;
573}
574# elif defined(BROKEN_BACKTRACE)
575# undef HAVE_BACKTRACE
576# define HAVE_BACKTRACE 0
577# endif
578#else
579# define HAVE_BACKTRACE 0
580#endif
581
582#if HAVE_BACKTRACE
583# include <execinfo.h>
584#elif defined(_WIN32)
585# include <imagehlp.h>
586# ifndef SYMOPT_DEBUG
587# define SYMOPT_DEBUG 0x80000000
588# endif
589# ifndef MAX_SYM_NAME
590# define MAX_SYM_NAME 2000
591typedef struct {
592 DWORD64 Offset;
593 WORD Segment;
594 ADDRESS_MODE Mode;
595} ADDRESS64;
596typedef struct {
597 DWORD64 Thread;
598 DWORD ThCallbackStack;
599 DWORD ThCallbackBStore;
600 DWORD NextCallback;
601 DWORD FramePointer;
602 DWORD64 KiCallUserMode;
603 DWORD64 KeUserCallbackDispatcher;
604 DWORD64 SystemRangeStart;
605 DWORD64 KiUserExceptionDispatcher;
606 DWORD64 StackBase;
607 DWORD64 StackLimit;
608 DWORD64 Reserved[5];
609} KDHELP64;
610typedef struct {
611 ADDRESS64 AddrPC;
612 ADDRESS64 AddrReturn;
613 ADDRESS64 AddrFrame;
614 ADDRESS64 AddrStack;
615 ADDRESS64 AddrBStore;
616 void *FuncTableEntry;
617 DWORD64 Params[4];
618 BOOL Far;
619 BOOL Virtual;
620 DWORD64 Reserved[3];
621 KDHELP64 KdHelp;
622} STACKFRAME64;
623typedef struct {
624 ULONG SizeOfStruct;
625 ULONG TypeIndex;
626 ULONG64 Reserved[2];
627 ULONG Index;
628 ULONG Size;
629 ULONG64 ModBase;
630 ULONG Flags;
631 ULONG64 Value;
632 ULONG64 Address;
633 ULONG Register;
634 ULONG Scope;
635 ULONG Tag;
636 ULONG NameLen;
637 ULONG MaxNameLen;
638 char Name[1];
639} SYMBOL_INFO;
640typedef struct {
641 DWORD SizeOfStruct;
642 void *Key;
643 DWORD LineNumber;
644 char *FileName;
645 DWORD64 Address;
646} IMAGEHLP_LINE64;
647typedef void *PREAD_PROCESS_MEMORY_ROUTINE64;
648typedef void *PFUNCTION_TABLE_ACCESS_ROUTINE64;
649typedef void *PGET_MODULE_BASE_ROUTINE64;
650typedef void *PTRANSLATE_ADDRESS_ROUTINE64;
651# endif
652
653static void
654dump_thread(void *arg)
655{
656 HANDLE dbghelp;
657 BOOL (WINAPI *pSymInitialize)(HANDLE, const char *, BOOL);
658 BOOL (WINAPI *pSymCleanup)(HANDLE);
659 BOOL (WINAPI *pStackWalk64)(DWORD, HANDLE, HANDLE, STACKFRAME64 *, void *, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64);
660 DWORD64 (WINAPI *pSymGetModuleBase64)(HANDLE, DWORD64);
661 BOOL (WINAPI *pSymFromAddr)(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFO *);
662 BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE, DWORD64, DWORD *, IMAGEHLP_LINE64 *);
663 HANDLE (WINAPI *pOpenThread)(DWORD, BOOL, DWORD);
664 DWORD tid = *(DWORD *)arg;
665 HANDLE ph;
666 HANDLE th;
667
668 dbghelp = LoadLibrary("dbghelp.dll");
669 if (!dbghelp) return;
670 pSymInitialize = (BOOL (WINAPI *)(HANDLE, const char *, BOOL))GetProcAddress(dbghelp, "SymInitialize");
671 pSymCleanup = (BOOL (WINAPI *)(HANDLE))GetProcAddress(dbghelp, "SymCleanup");
672 pStackWalk64 = (BOOL (WINAPI *)(DWORD, HANDLE, HANDLE, STACKFRAME64 *, void *, PREAD_PROCESS_MEMORY_ROUTINE64, PFUNCTION_TABLE_ACCESS_ROUTINE64, PGET_MODULE_BASE_ROUTINE64, PTRANSLATE_ADDRESS_ROUTINE64))GetProcAddress(dbghelp, "StackWalk64");
673 pSymGetModuleBase64 = (DWORD64 (WINAPI *)(HANDLE, DWORD64))GetProcAddress(dbghelp, "SymGetModuleBase64");
674 pSymFromAddr = (BOOL (WINAPI *)(HANDLE, DWORD64, DWORD64 *, SYMBOL_INFO *))GetProcAddress(dbghelp, "SymFromAddr");
675 pSymGetLineFromAddr64 = (BOOL (WINAPI *)(HANDLE, DWORD64, DWORD *, IMAGEHLP_LINE64 *))GetProcAddress(dbghelp, "SymGetLineFromAddr64");
676 pOpenThread = (HANDLE (WINAPI *)(DWORD, BOOL, DWORD))GetProcAddress(GetModuleHandle("kernel32.dll"), "OpenThread");
677 if (pSymInitialize && pSymCleanup && pStackWalk64 && pSymGetModuleBase64 &&
678 pSymFromAddr && pSymGetLineFromAddr64 && pOpenThread) {
679 SymSetOptions(SYMOPT_UNDNAME | SYMOPT_DEFERRED_LOADS | SYMOPT_DEBUG | SYMOPT_LOAD_LINES);
680 ph = GetCurrentProcess();
681 pSymInitialize(ph, NULL, TRUE);
682 th = pOpenThread(THREAD_SUSPEND_RESUME|THREAD_GET_CONTEXT, FALSE, tid);
683 if (th) {
684 if (SuspendThread(th) != (DWORD)-1) {
685 CONTEXT context;
686 memset(&context, 0, sizeof(context));
687 context.ContextFlags = CONTEXT_FULL;
688 if (GetThreadContext(th, &context)) {
689 char libpath[MAX_PATH];
690 char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME];
691 SYMBOL_INFO *info = (SYMBOL_INFO *)buf;
692 DWORD mac;
693 STACKFRAME64 frame;
694 memset(&frame, 0, sizeof(frame));
695#if defined(_M_AMD64) || defined(__x86_64__)
696 mac = IMAGE_FILE_MACHINE_AMD64;
697 frame.AddrPC.Mode = AddrModeFlat;
698 frame.AddrPC.Offset = context.Rip;
699 frame.AddrFrame.Mode = AddrModeFlat;
700 frame.AddrFrame.Offset = context.Rbp;
701 frame.AddrStack.Mode = AddrModeFlat;
702 frame.AddrStack.Offset = context.Rsp;
703#else /* i386 */
704 mac = IMAGE_FILE_MACHINE_I386;
705 frame.AddrPC.Mode = AddrModeFlat;
706 frame.AddrPC.Offset = context.Eip;
707 frame.AddrFrame.Mode = AddrModeFlat;
708 frame.AddrFrame.Offset = context.Ebp;
709 frame.AddrStack.Mode = AddrModeFlat;
710 frame.AddrStack.Offset = context.Esp;
711#endif
712
713 while (pStackWalk64(mac, ph, th, &frame, &context, NULL,
714 NULL, NULL, NULL)) {
715 DWORD64 addr = frame.AddrPC.Offset;
716 IMAGEHLP_LINE64 line;
717 DWORD64 displacement;
718 DWORD tmp;
719
720 if (addr == frame.AddrReturn.Offset || addr == 0 ||
721 frame.AddrReturn.Offset == 0)
722 break;
723
724 memset(buf, 0, sizeof(buf));
725 info->SizeOfStruct = sizeof(SYMBOL_INFO);
726 info->MaxNameLen = MAX_SYM_NAME;
727 if (pSymFromAddr(ph, addr, &displacement, info)) {
728 if (GetModuleFileName((HANDLE)(uintptr_t)pSymGetModuleBase64(ph, addr), libpath, sizeof(libpath)))
729 fprintf(stderr, "%s", libpath);
730 fprintf(stderr, "(%s+0x%"PRI_64_PREFIX"x)",
731 info->Name, displacement);
732 }
733 fprintf(stderr, " [0x%p]", (void *)(VALUE)addr);
734 memset(&line, 0, sizeof(line));
735 line.SizeOfStruct = sizeof(line);
736 if (pSymGetLineFromAddr64(ph, addr, &tmp, &line))
737 fprintf(stderr, " %s:%lu", line.FileName, line.LineNumber);
738 fprintf(stderr, "\n");
739 }
740 }
741
742 ResumeThread(th);
743 }
744 CloseHandle(th);
745 }
746 pSymCleanup(ph);
747 }
748 FreeLibrary(dbghelp);
749}
750#endif
751
752void
753 rb_print_backtrace(void)
754{
755#if HAVE_BACKTRACE
756#define MAX_NATIVE_TRACE 1024
757 static void *trace[MAX_NATIVE_TRACE];
758 int n = (int)backtrace(trace, MAX_NATIVE_TRACE);
759#if (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) && defined(HAVE_DLADDR) && !defined(__sparc) && !defined(__riscv)
760 rb_dump_backtrace_with_lines(n, trace);
761#else
762 char **syms = backtrace_symbols(trace, n);
763 if (syms) {
764 int i;
765 for (i=0; i<n; i++) {
766 fprintf(stderr, "%s\n", syms[i]);
767 }
768 free(syms);
769 }
770#endif
771#elif defined(_WIN32)
772 DWORD tid = GetCurrentThreadId();
773 HANDLE th = (HANDLE)_beginthread(dump_thread, 0, &tid);
774 if (th != (HANDLE)-1)
775 WaitForSingleObject(th, INFINITE);
776#endif
777}
778
779#ifdef HAVE_LIBPROCSTAT
780#include "missing/procstat_vm.c"
781#endif
782
783#if defined __linux__
784# if defined __x86_64__ || defined __i386__ || defined __aarch64__ || defined __arm__
785# define HAVE_PRINT_MACHINE_REGISTERS 1
786# endif
787#elif defined __APPLE__
788# if defined __x86_64__ || defined __i386__
789# define HAVE_PRINT_MACHINE_REGISTERS 1
790# endif
791#endif
792
793#ifdef HAVE_PRINT_MACHINE_REGISTERS
794static int
795print_machine_register(size_t reg, const char *reg_name, int col_count, int max_col)
796{
797 int ret;
798 char buf[64];
799
800#ifdef __LP64__
801 ret = snprintf(buf, sizeof(buf), " %3.3s: 0x%016" PRIxSIZE, reg_name, reg);
802#else
803 ret = snprintf(buf, sizeof(buf), " %3.3s: 0x%08" PRIxSIZE, reg_name, reg);
804#endif
805 if (col_count + ret > max_col) {
806 fputs("\n", stderr);
807 col_count = 0;
808 }
809 col_count += ret;
810 fputs(buf, stderr);
811 return col_count;
812}
813# ifdef __linux__
814# if defined(__x86_64__) || defined(__i386__)
815# define dump_machine_register(reg) (col_count = print_machine_register(mctx->gregs[REG_##reg], #reg, col_count, 80))
816# elif defined(__aarch64__) || defined(__arm__)
817# define dump_machine_register(reg, regstr) (col_count = print_machine_register(reg, #regstr, col_count, 80))
818# endif
819# elif defined __APPLE__
820# define dump_machine_register(reg) (col_count = print_machine_register(mctx->MCTX_SS_REG(reg), #reg, col_count, 80))
821# endif
822
823static void
824 rb_dump_machine_register(const ucontext_t *ctx)
825{
826 int col_count = 0;
827 if (!ctx) return;
828
829 fprintf(stderr, "-- Machine register context "
830 "------------------------------------------------\n");
831
832# if defined __linux__
833 {
834 const mcontext_t *const mctx = &ctx->uc_mcontext;
835# if defined __x86_64__
836 dump_machine_register(RIP);
837 dump_machine_register(RBP);
838 dump_machine_register(RSP);
839 dump_machine_register(RAX);
840 dump_machine_register(RBX);
841 dump_machine_register(RCX);
842 dump_machine_register(RDX);
843 dump_machine_register(RDI);
844 dump_machine_register(RSI);
845 dump_machine_register(R8);
846 dump_machine_register(R9);
847 dump_machine_register(R10);
848 dump_machine_register(R11);
849 dump_machine_register(R12);
850 dump_machine_register(R13);
851 dump_machine_register(R14);
852 dump_machine_register(R15);
853 dump_machine_register(EFL);
854# elif defined __i386__
855 dump_machine_register(GS);
856 dump_machine_register(FS);
857 dump_machine_register(ES);
858 dump_machine_register(DS);
859 dump_machine_register(EDI);
860 dump_machine_register(ESI);
861 dump_machine_register(EBP);
862 dump_machine_register(ESP);
863 dump_machine_register(EBX);
864 dump_machine_register(EDX);
865 dump_machine_register(ECX);
866 dump_machine_register(EAX);
867 dump_machine_register(TRAPNO);
868 dump_machine_register(ERR);
869 dump_machine_register(EIP);
870 dump_machine_register(CS);
871 dump_machine_register(EFL);
872 dump_machine_register(UESP);
873 dump_machine_register(SS);
874# elif defined __aarch64__
875 dump_machine_register(mctx->regs[0], "x0");
876 dump_machine_register(mctx->regs[1], "x1");
877 dump_machine_register(mctx->regs[2], "x2");
878 dump_machine_register(mctx->regs[3], "x3");
879 dump_machine_register(mctx->regs[4], "x4");
880 dump_machine_register(mctx->regs[5], "x5");
881 dump_machine_register(mctx->regs[6], "x6");
882 dump_machine_register(mctx->regs[7], "x7");
883 dump_machine_register(mctx->regs[18], "x18");
884 dump_machine_register(mctx->regs[19], "x19");
885 dump_machine_register(mctx->regs[20], "x20");
886 dump_machine_register(mctx->regs[21], "x21");
887 dump_machine_register(mctx->regs[22], "x22");
888 dump_machine_register(mctx->regs[23], "x23");
889 dump_machine_register(mctx->regs[24], "x24");
890 dump_machine_register(mctx->regs[25], "x25");
891 dump_machine_register(mctx->regs[26], "x26");
892 dump_machine_register(mctx->regs[27], "x27");
893 dump_machine_register(mctx->regs[28], "x28");
894 dump_machine_register(mctx->regs[29], "x29");
895 dump_machine_register(mctx->sp, "sp");
896 dump_machine_register(mctx->fault_address, "fault_address");
897# elif defined __arm__
898 dump_machine_register(mctx->arm_r0, "r0");
899 dump_machine_register(mctx->arm_r1, "r1");
900 dump_machine_register(mctx->arm_r2, "r2");
901 dump_machine_register(mctx->arm_r3, "r3");
902 dump_machine_register(mctx->arm_r4, "r4");
903 dump_machine_register(mctx->arm_r5, "r5");
904 dump_machine_register(mctx->arm_r6, "r6");
905 dump_machine_register(mctx->arm_r7, "r7");
906 dump_machine_register(mctx->arm_r8, "r8");
907 dump_machine_register(mctx->arm_r9, "r9");
908 dump_machine_register(mctx->arm_r10, "r10");
909 dump_machine_register(mctx->arm_sp, "sp");
910 dump_machine_register(mctx->fault_address, "fault_address");
911# endif
912 }
913# elif defined __APPLE__
914 {
915 const mcontext_t mctx = ctx->uc_mcontext;
916# if defined __x86_64__
917 dump_machine_register(rax);
918 dump_machine_register(rbx);
919 dump_machine_register(rcx);
920 dump_machine_register(rdx);
921 dump_machine_register(rdi);
922 dump_machine_register(rsi);
923 dump_machine_register(rbp);
924 dump_machine_register(rsp);
925 dump_machine_register(r8);
926 dump_machine_register(r9);
927 dump_machine_register(r10);
928 dump_machine_register(r11);
929 dump_machine_register(r12);
930 dump_machine_register(r13);
931 dump_machine_register(r14);
932 dump_machine_register(r15);
933 dump_machine_register(rip);
934 dump_machine_register(rflags);
935# elif defined __i386__
936 dump_machine_register(eax);
937 dump_machine_register(ebx);
938 dump_machine_register(ecx);
939 dump_machine_register(edx);
940 dump_machine_register(edi);
941 dump_machine_register(esi);
942 dump_machine_register(ebp);
943 dump_machine_register(esp);
944 dump_machine_register(ss);
945 dump_machine_register(eflags);
946 dump_machine_register(eip);
947 dump_machine_register(cs);
948 dump_machine_register(ds);
949 dump_machine_register(es);
950 dump_machine_register(fs);
951 dump_machine_register(gs);
952# endif
953 }
954# endif
955 fprintf(stderr, "\n\n");
956}
957#else
958# define rb_dump_machine_register(ctx) ((void)0)
959#endif /* HAVE_PRINT_MACHINE_REGISTERS */
960
961void
962 rb_vm_bugreport(const void *ctx)
963{
964#if RUBY_DEVEL
965 const char *cmd = getenv("RUBY_ON_BUG");
966 if (cmd) {
967 char buf[0x100];
968 snprintf(buf, sizeof(buf), "%s %"PRI_PIDT_PREFIX"d", cmd, getpid());
969 int r = system(buf);
970 if (r == -1) {
971 snprintf(buf, sizeof(buf), "Launching RUBY_ON_BUG command failed.");
972 }
973 }
974#endif
975
976#ifdef __linux__
977# define PROC_MAPS_NAME "/proc/self/maps"
978#endif
979#ifdef PROC_MAPS_NAME
980 enum {other_runtime_info = 1};
981#else
982 enum {other_runtime_info = 0};
983#endif
984 const rb_vm_t *const vm = GET_VM();
985 const rb_execution_context_t *ec = rb_current_execution_context(false);
986
987 if (vm && ec) {
988 SDR();
989 rb_backtrace_print_as_bugreport();
990 fputs("\n", stderr);
991 }
992
993 rb_dump_machine_register(ctx);
994
995#if HAVE_BACKTRACE || defined(_WIN32)
996 fprintf(stderr, "-- C level backtrace information "
997 "-------------------------------------------\n");
998 rb_print_backtrace();
999
1000
1001 fprintf(stderr, "\n");
1002#endif /* HAVE_BACKTRACE */
1003
1004 if (other_runtime_info || vm) {
1005 fprintf(stderr, "-- Other runtime information "
1006 "-----------------------------------------------\n\n");
1007 }
1008 if (vm) {
1009 int i;
1010 VALUE name;
1011 long len;
1012 const int max_name_length = 1024;
1013# define LIMITED_NAME_LENGTH(s) \
1014 (((len = RSTRING_LEN(s)) > max_name_length) ? max_name_length : (int)len)
1015
1016 name = vm->progname;
1017 if (name) {
1018 fprintf(stderr, "* Loaded script: %.*s\n",
1019 LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
1020 fprintf(stderr, "\n");
1021 }
1022 if (vm->loaded_features) {
1023 fprintf(stderr, "* Loaded features:\n\n");
1024 for (i=0; i<RARRAY_LEN(vm->loaded_features); i++) {
1025 name = RARRAY_AREF(vm->loaded_features, i);
1026 if (RB_TYPE_P(name, T_STRING)) {
1027 fprintf(stderr, " %4d %.*s\n", i,
1028 LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
1029 }
1030 else if (RB_TYPE_P(name, T_CLASS) || RB_TYPE_P(name, T_MODULE)) {
1031 const char *const type = RB_TYPE_P(name, T_CLASS) ?
1032 "class" : "module";
1033 name = rb_search_class_path(rb_class_real(name));
1034 if (!RB_TYPE_P(name, T_STRING)) {
1035 fprintf(stderr, " %4d %s:<unnamed>\n", i, type);
1036 continue;
1037 }
1038 fprintf(stderr, " %4d %s:%.*s\n", i, type,
1039 LIMITED_NAME_LENGTH(name), RSTRING_PTR(name));
1040 }
1041 else {
1042 VALUE klass = rb_search_class_path(rb_obj_class(name));
1043 if (!RB_TYPE_P(klass, T_STRING)) {
1044 fprintf(stderr, " %4d #<%p:%p>\n", i,
1045 (void *)CLASS_OF(name), (void *)name);
1046 continue;
1047 }
1048 fprintf(stderr, " %4d #<%.*s:%p>\n", i,
1049 LIMITED_NAME_LENGTH(klass), RSTRING_PTR(klass),
1050 (void *)name);
1051 }
1052 }
1053 }
1054 fprintf(stderr, "\n");
1055 }
1056
1057 {
1058#ifdef PROC_MAPS_NAME
1059 {
1060 FILE *fp = fopen(PROC_MAPS_NAME, "r");
1061 if (fp) {
1062 fprintf(stderr, "* Process memory map:\n\n");
1063
1064 while (!feof(fp)) {
1065 char buff[0x100];
1066 size_t rn = fread(buff, 1, 0x100, fp);
1067 if (fwrite(buff, 1, rn, stderr) != rn)
1068 break;
1069 }
1070
1071 fclose(fp);
1072 fprintf(stderr, "\n\n");
1073 }
1074 }
1075#endif /* __linux__ */
1076#ifdef HAVE_LIBPROCSTAT
1077# define MIB_KERN_PROC_PID_LEN 4
1078 int mib[MIB_KERN_PROC_PID_LEN];
1079 struct kinfo_proc kp;
1080 size_t len = sizeof(struct kinfo_proc);
1081 mib[0] = CTL_KERN;
1082 mib[1] = KERN_PROC;
1083 mib[2] = KERN_PROC_PID;
1084 mib[3] = getpid();
1085 if (sysctl(mib, MIB_KERN_PROC_PID_LEN, &kp, &len, NULL, 0) == -1) {
1086 perror("sysctl");
1087 }
1088 else {
1089 struct procstat *prstat = procstat_open_sysctl();
1090 fprintf(stderr, "* Process memory map:\n\n");
1091 procstat_vm(prstat, &kp);
1092 procstat_close(prstat);
1093 fprintf(stderr, "\n");
1094 }
1095#endif /* __FreeBSD__ */
1096#ifdef __APPLE__
1097 vm_address_t addr = 0;
1098 vm_size_t size = 0;
1099 struct vm_region_submap_info map;
1100 mach_msg_type_number_t count = VM_REGION_SUBMAP_INFO_COUNT;
1101 natural_t depth = 0;
1102
1103 fprintf(stderr, "* Process memory map:\n\n");
1104 while (1) {
1105 if (vm_region_recurse(mach_task_self(), &addr, &size, &depth,
1106 (vm_region_recurse_info_t)&map, &count) != KERN_SUCCESS) {
1107 break;
1108 }
1109
1110 if (map.is_submap) {
1111 // We only look at main addresses
1112 depth++;
1113 }
1114 else {
1115 fprintf(stderr, "%lx-%lx %s%s%s", addr, (addr+size),
1116 ((map.protection & VM_PROT_READ) != 0 ? "r" : "-"),
1117 ((map.protection & VM_PROT_WRITE) != 0 ? "w" : "-"),
1118 ((map.protection & VM_PROT_EXECUTE) != 0 ? "x" : "-"));
1119#ifdef HAVE_LIBPROC_H
1120 char buff[PATH_MAX];
1121 if (proc_regionfilename(getpid(), addr, buff, sizeof(buff)) > 0) {
1122 fprintf(stderr, " %s", buff);
1123 }
1124#endif
1125 fprintf(stderr, "\n");
1126 }
1127
1128 addr += size;
1129 size = 0;
1130 }
1131#endif
1132 }
1133}
1134
1135#ifdef NON_SCALAR_THREAD_ID
1136const char *ruby_fill_thread_id_string(rb_nativethread_id_t thid, rb_thread_id_string_t buf);
1137#endif
1138
1139void
1140rb_vmdebug_stack_dump_all_threads(void)
1141{
1142 rb_thread_t *th = NULL;
1143 rb_ractor_t *r = GET_RACTOR();
1144
1145 // TODO: now it only shows current ractor
1146 list_for_each(&r->threads.set, th, lt_node) {
1147#ifdef NON_SCALAR_THREAD_ID
1148 rb_thread_id_string_t buf;
1149 ruby_fill_thread_id_string(th->thread_id, buf);
1150 fprintf(stderr, "th: %p, native_id: %s\n", th, buf);
1151#else
1152 fprintf(stderr, "th: %p, native_id: %p\n", (void *)th, (void *)(uintptr_t)th->thread_id);
1153#endif
1154 rb_vmdebug_stack_dump_raw(th->ec, th->ec->cfp);
1155 }
1156}
addr2line.h
rb_iseq_original_iseq
VALUE * rb_iseq_original_iseq(const rb_iseq_t *iseq)
Definition: compile.c:863
ptr
struct RIMemo * ptr
Definition: debug.c:88
free
#define free(x)
Definition: dln.c:52
map
size_t map(int syms, int left, int len)
Definition: enough.c:237
len
uint8_t len
Definition: escape.c:17
RSTRING_PTR
#define RSTRING_PTR(string)
Definition: fbuffer.h:19
rb_raw_obj_info
const char * rb_raw_obj_info(char *buff, const int buff_size, VALUE obj)
Definition: gc.c:12229
CLASS_OF
#define CLASS_OF
Definition: globals.h:153
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:768
rb_obj_class
VALUE rb_obj_class(VALUE)
Definition: object.c:245
rb_inspect
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
Definition: object.c:585
rb_class_real
VALUE rb_class_real(VALUE)
Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.
Definition: object.c:235
IMEMO_TYPE_P
#define IMEMO_TYPE_P(v, t)
Definition: imemo.h:178
imemo_ment
@ imemo_ment
Definition: imemo.h:41
config.h
Thin wrapper to ruby/config.h.
rb_str_new2
#define rb_str_new2
Definition: string.h:276
rb_id2name
const char * rb_id2name(ID)
Definition: symbol.c:944
rb_sym2str
VALUE rb_sym2str(VALUE)
Definition: symbol.c:927
gc.h
Internal header for GC.
rb_search_class_path
VALUE rb_search_class_path(VALUE)
Definition: variable.c:191
vm.h
Internal header for RubyVM.
rb_backtrace_print_as_bugreport
void rb_backtrace_print_as_bugreport(void)
Definition: vm_backtrace.c:994
internal.h
bp
#define bp()
Definition: internal.h:105
PRIxSIZE
#define PRIxSIZE
Definition: inttypes.h:128
PRIxVALUE
#define PRIxVALUE
Definition: inttypes.h:75
PRIdPTRDIFF
#define PRIdPTRDIFF
Definition: inttypes.h:105
PRIxPTRDIFF
#define PRIxPTRDIFF
Definition: inttypes.h:109
size
voidpf void uLong size
Definition: ioapi.h:138
int
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
buf
voidpf void * buf
Definition: ioapi.h:138
rb_iseq_path
VALUE rb_iseq_path(const rb_iseq_t *iseq)
Definition: iseq.c:1087
rb_iseq_disasm_insn
int rb_iseq_disasm_insn(VALUE ret, const VALUE *code, size_t pos, const rb_iseq_t *iseq, VALUE child)
Disassemble a instruction Iseq -> Iseq inspect object.
Definition: iseq.c:2078
iseq.h
memcmp
int memcmp(const void *s1, const void *s2, size_t len)
Definition: memcmp.c:7
rb_method_type_t
rb_method_type_t
Definition: method.h:109
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
name
const char * name
Definition: nkf.c:208
count
int count
Definition: nkf.c:5055
TRUE
#define TRUE
Definition: nkf.h:175
FALSE
#define FALSE
Definition: nkf.h:174
procstat_vm.c
procstat_vm
void procstat_vm(struct procstat *procstat, struct kinfo_proc *kipp)
Definition: procstat_vm.c:9
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition: psych_emitter.c:7
ractor_core.h
RARRAY_LEN
#define RARRAY_LEN
Definition: rarray.h:52
NULL
#define NULL
Definition: regenc.h:69
ERR
#define ERR(mesg)
StringValueCStr
#define StringValueCStr(v)
Definition: rstring.h:52
argc
int argc
Definition: ruby.c:240
argv
char ** argv
Definition: ruby.c:241
Qnil
#define Qnil
Definition: special_consts.h:51
__sFILE
Definition: vsnprintf.c:169
Size
Definition: pyobjc-tc.c:15
rb_callable_method_entry_struct
Definition: method.h:62
rb_callable_method_entry_struct::called_id
ID called_id
Definition: method.h:66
rb_callable_method_entry_struct::defined_class
const VALUE defined_class
Definition: method.h:64
rb_callable_method_entry_struct::owner
const VALUE owner
Definition: method.h:67
rb_callable_method_entry_struct::def
struct rb_method_definition_struct *const def
Definition: method.h:65
rb_control_frame_struct
Definition: vm_core.h:769
rb_control_frame_struct::sp
VALUE * sp
Definition: vm_core.h:771
rb_control_frame_struct::ep
const VALUE * ep
Definition: vm_core.h:774
rb_control_frame_struct::self
VALUE self
Definition: vm_core.h:773
rb_control_frame_struct::iseq
const rb_iseq_t * iseq
Definition: vm_core.h:772
rb_control_frame_struct::pc
const VALUE * pc
Definition: vm_core.h:770
rb_env_t
Definition: vm_core.h:1099
rb_execution_context_struct
Definition: vm_core.h:854
rb_execution_context_struct::vm_stack
VALUE * vm_stack
Definition: vm_core.h:856
rb_execution_context_struct::vm_stack_size
size_t vm_stack_size
Definition: vm_core.h:857
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:858
rb_iseq_constant_body::type
enum rb_iseq_constant_body::iseq_type type
rb_iseq_constant_body::local_table_size
unsigned int local_table_size
Definition: vm_core.h:424
rb_iseq_constant_body::lead_num
int lead_num
Definition: vm_core.h:361
rb_iseq_constant_body::iseq_encoded
VALUE * iseq_encoded
Definition: vm_core.h:319
rb_iseq_constant_body::location
rb_iseq_location_t location
Definition: vm_core.h:393
rb_iseq_constant_body::param
struct rb_iseq_constant_body::@188 param
parameter information
rb_iseq_constant_body::local_table
const ID * local_table
Definition: vm_core.h:405
rb_iseq_location_struct::label
VALUE label
Definition: vm_core.h:269
rb_iseq_struct
Definition: vm_core.h:444
rb_iseq_struct::body
struct rb_iseq_constant_body * body
Definition: vm_core.h:448
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:189
rb_proc_t
Definition: vm_core.h:1086
rb_proc_t::block
const struct rb_block block
Definition: vm_core.h:1087
rb_ractor_struct
Definition: ractor_core.h:82
rb_ractor_struct::set
struct list_head set
Definition: ractor_core.h:94
rb_ractor_struct::threads
struct rb_ractor_struct::@141 threads
rb_thread_struct
Definition: vm_core.h:935
rb_thread_struct::ec
rb_execution_context_t * ec
Definition: vm_core.h:941
rb_thread_struct::thread_id
rb_nativethread_id_t thread_id
Definition: vm_core.h:953
rb_vm_struct
Definition: vm_core.h:564
rb_vm_struct::progname
VALUE progname
Definition: vm_core.h:643
rb_vm_struct::loaded_features
VALUE loaded_features
Definition: vm_core.h:620
snprintf
#define snprintf
Definition: subst.h:14
t
#define t
Definition: symbol.c:253
PATH_MAX
#define PATH_MAX
VALUE
unsigned long VALUE
Definition: value.h:38
TYPE
#define TYPE(_)
Definition: value_type.h:105
T_STRING
#define T_STRING
Definition: value_type.h:77
T_IMEMO
#define T_IMEMO
Definition: value_type.h:66
T_MODULE
#define T_MODULE
Definition: value_type.h:69
T_UNDEF
#define T_UNDEF
Definition: value_type.h:81
T_CLASS
#define T_CLASS
Definition: value_type.h:57
SYMBOL_P
#define SYMBOL_P
Definition: value_type.h:87
rb_vm_env_prev_env
const rb_env_t * rb_vm_env_prev_env(const rb_env_t *env)
Definition: vm.c:830
rb_vm_get_sourceline
int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
Definition: vm_backtrace.c:71
vm_core.h
rb_vm_frame_method_entry
const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
Definition: vm_insnhelper.c:667
VM_ENV_DATA_SIZE
#define VM_ENV_DATA_SIZE
Definition: vm_core.h:1206
GC_GUARDED_PTR_REF
#define GC_GUARDED_PTR_REF(p)
Definition: vm_core.h:1164
rb_thread_id_string_t
char rb_thread_id_string_t[sizeof(rb_nativethread_id_t) *2+3]
Definition: vm_core.h:844
SDR2
#define SDR2(cfp)
Definition: vm_core.h:1648
SDR
#define SDR()
Definition: vm_core.h:1647
RUBY_VM_PREVIOUS_CONTROL_FRAME
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1392
VM_FRAME_MAGIC_IFUNC
@ VM_FRAME_MAGIC_IFUNC
Definition: vm_core.h:1183
VM_FRAME_MAGIC_METHOD
@ VM_FRAME_MAGIC_METHOD
Definition: vm_core.h:1178
VM_FRAME_MAGIC_TOP
@ VM_FRAME_MAGIC_TOP
Definition: vm_core.h:1181
VM_FRAME_MAGIC_BLOCK
@ VM_FRAME_MAGIC_BLOCK
Definition: vm_core.h:1179
VM_FRAME_MAGIC_CFUNC
@ VM_FRAME_MAGIC_CFUNC
Definition: vm_core.h:1182
VM_FRAME_MAGIC_EVAL
@ VM_FRAME_MAGIC_EVAL
Definition: vm_core.h:1184
VM_FRAME_MAGIC_CLASS
@ VM_FRAME_MAGIC_CLASS
Definition: vm_core.h:1180
VM_FRAME_MAGIC_RESCUE
@ VM_FRAME_MAGIC_RESCUE
Definition: vm_core.h:1185
rb_vmdebug_stack_dump_all_threads
void rb_vmdebug_stack_dump_all_threads(void)
Definition: vm_dump.c:1140
rb_print_backtrace
void rb_print_backtrace(void)
Definition: vm_dump.c:753
rb_vmdebug_stack_dump_raw_current
void rb_vmdebug_stack_dump_raw_current(void)
Definition: vm_dump.c:228
rb_vmdebug_debug_print_register
void rb_vmdebug_debug_print_register(const rb_execution_context_t *ec)
Definition: vm_dump.c:361
rb_vmdebug_debug_print_pre
void rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, const VALUE *_pc)
Definition: vm_dump.c:388
rb_vmdebug_thread_dump_regs
void rb_vmdebug_thread_dump_regs(VALUE thval)
Definition: vm_dump.c:382
rb_vmdebug_thread_dump_state
VALUE rb_vmdebug_thread_dump_state(VALUE self)
Definition: vm_dump.c:452
rb_dump_machine_register
#define rb_dump_machine_register(ctx)
Definition: vm_dump.c:958
rb_vm_bugreport
void rb_vm_bugreport(const void *ctx)
Definition: vm_dump.c:962
rb_vmdebug_env_dump_raw
void rb_vmdebug_env_dump_raw(const rb_env_t *env, const VALUE *ep)
Definition: vm_dump.c:235
rb_vmdebug_stack_dump_raw
void rb_vmdebug_stack_dump_raw(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
Definition: vm_dump.c:195
rb_method_type_name
const char * rb_method_type_name(rb_method_type_t type)
Definition: gc.c:12177
MAX_POSBUF
#define MAX_POSBUF
Definition: vm_dump.c:40
ruby_on_ci
int ruby_on_ci
Definition: vm_dump.c:47
VM_CFP_CNT
#define VM_CFP_CNT(ec, cfp)
Definition: vm_dump.c:42
RUBY_VM_IFUNC_P
#define RUBY_VM_IFUNC_P(ptr)
rb_vmdebug_stack_dump_th
void rb_vmdebug_stack_dump_th(VALUE thval)
Definition: vm_dump.c:268
rb_vmdebug_proc_dump_raw
void rb_vmdebug_proc_dump_raw(rb_proc_t *proc)
Definition: vm_dump.c:254
rb_vmdebug_debug_print_post
void rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
Definition: vm_dump.c:417
LIMITED_NAME_LENGTH
#define LIMITED_NAME_LENGTH(s)
OPT_STACK_CACHING
#define OPT_STACK_CACHING
Definition: vm_opts.h:58
feof
#define feof(p)
Definition: vsnprintf.c:214
getenv
#define getenv(name)
Definition: win32.c:80
env
#define env
uintptr_t
unsigned int uintptr_t
Definition: win32.h:106
DWORD
IUnknown DWORD
Definition: win32ole.c:33