Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix VMDEBUG #13147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions vm_backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ calc_pos(const rb_iseq_t *iseq, const VALUE *pc, int *lineno, int *node_id)
/* use pos-1 because PC points next instruction at the beginning of instruction */
pos--;
}
#if VMDEBUG && defined(HAVE_BUILTIN___BUILTIN_TRAP)
Copy link
Contributor Author

@composerinteralia composerinteralia Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We end up in this branch fairly frequently with pos == 0. I've removed it for now, otherwise this will terminate any program right away.

else {
/* SDR() is not possible; that causes infinite loop. */
rb_print_backtrace(stderr);
__builtin_trap();
}
#endif
if (lineno) *lineno = rb_iseq_line_no(iseq, pos);
#ifdef USE_ISEQ_NODE_ID
if (node_id) *node_id = rb_iseq_node_id(iseq, pos);
Expand Down
5 changes: 0 additions & 5 deletions vm_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
#define VMDEBUG 0
#endif

#if 0
#undef VMDEBUG
#define VMDEBUG 3
#endif

#include "ruby/internal/config.h"

#include <stddef.h>
Expand Down
8 changes: 5 additions & 3 deletions vm_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ vm_stack_dump_each(const rb_execution_context_t *ec, const rb_control_frame_t *c
else {
rb_bug("unsupported frame type: %08lx", VM_FRAME_TYPE(cfp));
}
error:
Copy link
Contributor Author

@composerinteralia composerinteralia Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kprintf macro used above has a goto error. All of this is within a #if VMDEBUG > 2

return;
}
#endif

Expand Down Expand Up @@ -440,7 +442,7 @@ rb_vmdebug_debug_print_pre(const rb_execution_context_t *ec, const rb_control_fr

#if VMDEBUG > 3
kprintf(" (1)");
rb_vmdebug_debug_print_register(errout, ec);
rb_vmdebug_debug_print_register(ec, errout);
#endif
return true;

Expand All @@ -452,12 +454,12 @@ bool
rb_vmdebug_debug_print_post(const rb_execution_context_t *ec, const rb_control_frame_t *cfp, FILE *errout)
{
#if VMDEBUG > 9
if (!rb_vmdebug_stack_dump_raw(ec, cfp, errout)) goto errout;
if (!rb_vmdebug_stack_dump_raw(ec, cfp, errout)) goto error;
#endif

#if VMDEBUG > 3
kprintf(" (2)");
rb_vmdebug_debug_print_register(errout, ec);
rb_vmdebug_debug_print_register(ec, errout);
#endif
/* stack_dump_raw(ec, cfp); */

Expand Down
4 changes: 2 additions & 2 deletions vm_exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ typedef rb_iseq_t *ISEQ;
#if VMDEBUG > 0
#define debugs printf
#define DEBUG_ENTER_INSN(insn) \
rb_vmdebug_debug_print_pre(ec, GET_CFP(), GET_PC());
rb_vmdebug_debug_print_pre(ec, GET_CFP(), GET_PC(), stderr);

#define SC_REGS()

#define DEBUG_END_INSN() \
rb_vmdebug_debug_print_post(ec, GET_CFP() SC_REGS());
rb_vmdebug_debug_print_post(ec, GET_CFP() SC_REGS(), stderr);

#else

Expand Down
2 changes: 1 addition & 1 deletion vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ vm_push_frame(rb_execution_context_t *ec,

ec->cfp = cfp;

if (VMDEBUG == 2) {
if (VMDEBUG == 2 && rb_current_execution_context(false) != NULL) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this I get:

../vm_core.h:1988: Assertion Failed: rb_current_execution_context:!expect_ec || ec != NULL

It happens during vm init, pushing a dummy frame before ruby_current_ec has been set (Init_BareVM -> th_init -> rb_ec_initialize_vm_stack -> vm_push_frame).

SDR();
}
vm_push_frame_debug_counter_inc(ec, cfp, type);
Expand Down
Loading