Skip to content

Commit

Permalink
debug.c: rgengc debug option
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 19, 2017
1 parent 263a0f7 commit 22c8dcf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
62 changes: 39 additions & 23 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,50 +119,66 @@ extern int ruby_w32_rtc_error;
#include <windows.h>
UINT ruby_w32_codepage[2];
#endif
extern int ruby_rgengc_debug;

static void
set_debug_option(const char *str, int len, void *arg)
{
int ov;
size_t retlen;
unsigned long n;
#define SET_WHEN(name, var, val) do { \
if (len == sizeof(name) - 1 && \
strncmp(str, (name), len) == 0) { \
(var) = (val); \
return; \
} \
} while (0)
#define NAME_MATCH_VALUE(name) \
((size_t)len >= sizeof(name) && \
strncmp(str, (name), sizeof(name)-1) == 0 && \
str[sizeof(name)-1] == '=' && \
(str += sizeof(name), len -= sizeof(name), 1))
#define NAME_MATCH_VALUE(name) \
((size_t)len >= sizeof(name)-1 && \
strncmp(str, (name), sizeof(name)-1) == 0 && \
((len == sizeof(name)-1 && !(len = 0)) || \
(str[sizeof(name)-1] == '=' && \
(str += sizeof(name), len -= sizeof(name), 1))))
#define SET_UINT(val) do { \
n = ruby_scan_digits(str, len, 10, &retlen, &ov); \
if (!ov && retlen) { \
val = (unsigned int)n; \
} \
str += retlen; \
len -= retlen; \
} while (0)
#define SET_UINT_LIST(name, vals, num) do { \
int i; \
for (i = 0; i < (num); ++i) { \
SET_UINT((vals)[i]); \
if (!len || *str != ':') break; \
++str; \
--len; \
} \
if (len > 0) { \
fprintf(stderr, "ignored "name" option: `%.*s'\n", len, str); \
} \
} while (0)
#define SET_WHEN_UINT(name, vals, num, req) \
if (NAME_MATCH_VALUE(name)) SET_UINT_LIST(name, vals, num);

SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr, Qtrue);
SET_WHEN("core", ruby_enable_coredump, 1);
if (NAME_MATCH_VALUE("rgengc")) {
if (!len) ruby_rgengc_debug = 1;
else SET_UINT_LIST("rgengc", &ruby_rgengc_debug, 1);
return;
}
#if defined _WIN32
# if RUBY_MSVCRT_VERSION >= 80
SET_WHEN("rtc_error", ruby_w32_rtc_error, 1);
# endif
#endif
#if defined _WIN32 || defined __CYGWIN__
if (NAME_MATCH_VALUE("codepage")) {
int i;
int ov;
size_t retlen;
unsigned long n;
for (i = 0; i < numberof(ruby_w32_codepage); ++i) {
n = ruby_scan_digits(str, len, 10, &retlen, &ov);
if (!ov && retlen) {
ruby_w32_codepage[i] = (UINT)n;
}
str += retlen;
len -= retlen;
if (!len || *str != ':') break;
++str;
--len;
}
if (len > 0) {
fprintf(stderr, "ignored codepage option: `%.*s'\n", len, str);
}
if (!len) fprintf(stderr, "missing codepage argument");
else SET_UINT_LIST("codepage", ruby_w32_codepage, numberof(ruby_w32_codepage));
return;
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ static ruby_gc_params_t gc_params = {
#ifndef RGENGC_DEBUG
#define RGENGC_DEBUG 0
#endif
#if RGENGC_DEBUG < 0
#undef RGENGC_DEBUG
#define RGENGC_DEBUG ruby_rgengc_debug
#endif
int ruby_rgengc_debug;

/* RGENGC_CHECK_MODE
* 0: disable all assertions
Expand Down

0 comments on commit 22c8dcf

Please sign in to comment.