From 6bf8db9a07e95820705f7ec119f4038a529182ef Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Fri, 9 Aug 2019 13:57:47 +0900 Subject: add rp() and bp() in internal.h. debug utility macro rp() (rp_m()) and bp() are introduced. * rp(obj) shows obj information w/o any side-effect to STDERR. * rp_m(m, obj) is similar to rp(obj), but show m before. * bp() is alias of ruby_debug_breakpoint(), which is registered as a breakpoint in run.gdb (used by `make gdb` or make gdb-ruby`). --- common.mk | 1 - gc.h | 1 - internal.h | 16 ++++++++++++++++ thread.c | 1 - vm_debug.h | 3 --- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/common.mk b/common.mk index 6b4a0b00f1..d0b1b2996e 100644 --- a/common.mk +++ b/common.mk @@ -3035,7 +3035,6 @@ thread.$(OBJEXT): {$(VPATH)}debug_counter.h thread.$(OBJEXT): {$(VPATH)}defines.h thread.$(OBJEXT): {$(VPATH)}encoding.h thread.$(OBJEXT): {$(VPATH)}eval_intern.h -thread.$(OBJEXT): {$(VPATH)}gc.h thread.$(OBJEXT): {$(VPATH)}hrtime.h thread.$(OBJEXT): {$(VPATH)}id.h thread.$(OBJEXT): {$(VPATH)}intern.h diff --git a/gc.h b/gc.h index 018ad0e625..0e7ffba9f1 100644 --- a/gc.h +++ b/gc.h @@ -100,7 +100,6 @@ int ruby_get_stack_grow_direction(volatile VALUE *addr); const char *rb_obj_info(VALUE obj); const char *rb_raw_obj_info(char *buff, const int buff_size, VALUE obj); -void rb_obj_info_dump(VALUE obj); VALUE rb_gc_disable_no_rest(void); diff --git a/internal.h b/internal.h index c502fe076c..76c10c8bf5 100644 --- a/internal.h +++ b/internal.h @@ -1388,6 +1388,22 @@ rb_ary_entry_internal(VALUE ary, long offset) return ptr[offset]; } +/* MRI debug support */ +void rb_obj_info_dump(VALUE obj); +void ruby_debug_breakpoint(void); + +// show obj data structure without any side-effect +#define rp(obj) rb_obj_info_dump((VALUE)obj); +// same as rp, but add message header +#define rp_m(msg, obj) do { \ + fprintf(stderr, "%s", (msg)); \ + rb_obj_info_dump((VALUE)obj); \ +} while (0) + +// `ruby_debug_breakpoint()` does nothing, +// but breakpoint is set in run.gdb, so `make gdb` can stop here. +#define bp() ruby_debug_breakpoint() + /* bignum.c */ extern const char ruby_digitmap[]; double rb_big_fdiv_double(VALUE x, VALUE y); diff --git a/thread.c b/thread.c index f9fc70f3cf..0f8b512405 100644 --- a/thread.c +++ b/thread.c @@ -66,7 +66,6 @@ #include "ruby/config.h" #include "ruby/io.h" #include "eval_intern.h" -#include "gc.h" #include "timev.h" #include "ruby/thread.h" #include "ruby/thread_native.h" diff --git a/vm_debug.h b/vm_debug.h index 32e060732c..8e0350d147 100644 --- a/vm_debug.h +++ b/vm_debug.h @@ -22,13 +22,10 @@ RUBY_SYMBOL_EXPORT_BEGIN #define dpi(i) ruby_debug_print_id(-1, 0, "", (i)) #define dpn(n) ruby_debug_print_node(-1, 0, "", (n)) -#define bp() ruby_debug_breakpoint() - VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v); ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id); NODE *ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node); int ruby_debug_print_indent(int level, int debug_level, int indent_level); -void ruby_debug_breakpoint(void); void ruby_debug_gc_check_func(void); void ruby_set_debug_option(const char *str); -- cgit v1.2.3