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