Skip to content

Commit

Permalink
* debug.c (ruby_set_debug_option): separated from main.c.
Browse files Browse the repository at this point in the history
* gc.c (ruby_gc_stress), signal.c (ruby_enable_coredump): prefixed.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12665 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jun 29, 2007
1 parent e648fc4 commit eae8a91
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 29 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Fri Jun 29 16:57:22 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>

* debug.c (ruby_set_debug_option): separated from main.c.

* gc.c (ruby_gc_stress), signal.c (ruby_enable_coredump): prefixed.

Fri Jun 29 16:39:06 2007 Koichi Sasada <ko1@atdot.net>

* proc.c (proc_new): fix to return a proc object
Expand Down
41 changes: 36 additions & 5 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "ruby/ruby.h"
#include "debug.h"
#include "yarvcore.h"

void
ruby_debug_print_indent(int level, int debug_level, int indent_level)
Expand All @@ -26,7 +27,7 @@ ruby_debug_print_indent(int level, int debug_level, int indent_level)
}

VALUE
ruby_debug_print_value(int level, int debug_level, char *header, VALUE obj)
ruby_debug_print_value(int level, int debug_level, const char *header, VALUE obj)
{
if (level < debug_level) {
VALUE str;
Expand All @@ -45,7 +46,7 @@ ruby_debug_print_v(VALUE v)
}

ID
ruby_debug_print_id(int level, int debug_level, char *header, ID id)
ruby_debug_print_id(int level, int debug_level, const char *header, ID id)
{
if (level < debug_level) {
fprintf(stderr, "DBG> %s: %s\n", header, rb_id2name(id));
Expand All @@ -55,17 +56,47 @@ ruby_debug_print_id(int level, int debug_level, char *header, ID id)
}

NODE *
ruby_debug_print_node(int level, int debug_level, char *header, NODE *node)
ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node)
{
if (level < debug_level) {
fprintf(stderr, "DBG> %s: %s (%d)\n", header,
fprintf(stderr, "DBG> %s: %s (%lu)\n", header,
ruby_node_name(nd_type(node)), nd_line(node));
}
return node;
return (NODE *)node;
}

void
ruby_debug_breakpoint(void)
{
/* */
}

#ifdef RUBY_DEBUG_ENV
#include <ctype.h>

void
ruby_set_debug_option(const char *str)
{
const char *end;
int len;

if (!str) return;
for (; *str; str = end) {
while (ISSPACE(*str) || *str == ',') str++;
if (!*str) break;
end = str;
while (*end && !ISSPACE(*end) && *end != ',') end++;
len = end - str;
#define SET_WHEN(name, var) \
if (len == sizeof(name) - 1 && \
strncmp(str, name, len) == 0) { \
extern int ruby_##var; \
ruby_##var = 1; \
continue; \
}
SET_WHEN("gc_stress", gc_stress);
SET_WHEN("core", enable_coredump);
fprintf(stderr, "unexpected debug option: %.*s\n", len, str);
}
}
#endif
12 changes: 6 additions & 6 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ VALUE *rb_gc_stack_start = 0;
VALUE *rb_gc_register_stack_start = 0;
#endif

int gc_stress = 0;
int ruby_gc_stress = 0;


#ifdef DJGPP
Expand Down Expand Up @@ -201,7 +201,7 @@ rb_memerror(void)
static VALUE
gc_stress_get(VALUE self)
{
return gc_stress ? Qtrue : Qfalse;
return ruby_gc_stress ? Qtrue : Qfalse;
}

/*
Expand All @@ -220,7 +220,7 @@ static VALUE
gc_stress_set(VALUE self, VALUE bool)
{
rb_secure(2);
gc_stress = RTEST(bool);
ruby_gc_stress = RTEST(bool);
return bool;
}

Expand All @@ -235,7 +235,7 @@ ruby_xmalloc(size_t size)
if (size == 0) size = 1;
malloc_increase += size;

if (gc_stress || malloc_increase > malloc_limit) {
if (ruby_gc_stress || malloc_increase > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
Expand Down Expand Up @@ -283,7 +283,7 @@ ruby_xrealloc(void *ptr, size_t size)
if (!ptr) return ruby_xmalloc(size);
if (size == 0) size = 1;
malloc_increase += size;
if (gc_stress) garbage_collect();
if (ruby_gc_stress) garbage_collect();
RUBY_CRITICAL(mem = realloc(ptr, size));
if (!mem) {
if (garbage_collect()) {
Expand Down Expand Up @@ -466,7 +466,7 @@ rb_newobj_from_heap(void)
{
VALUE obj;

if (gc_stress || !freelist) {
if (ruby_gc_stress || !freelist) {
if(!garbage_collect()) {
rb_memerror();
}
Expand Down
16 changes: 2 additions & 14 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,8 @@ int
main(int argc, char **argv, char **envp)
{
#ifdef RUBY_DEBUG_ENV
RUBY_EXTERN int gc_stress;
RUBY_EXTERN int enable_coredump;
char *str;
str = getenv("RUBY_DEBUG");
if (str) {
for (str = strtok(str, ","); str; str = strtok(NULL, ",")) {
if (strcmp(str, "gc_stress") == 0)
gc_stress = 1;
else if (strcmp(str, "core") == 0)
enable_coredump = 1;
else
fprintf(stderr, "unexpected debug option: %s\n", str);
}
}
extern void ruby_set_debug_option(const char *);
ruby_set_debug_option(getenv("RUBY_DEBUG"));
#endif
#ifdef _WIN32
NtInitialize(&argc, &argv);
Expand Down
8 changes: 4 additions & 4 deletions signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ sigsegv(int sig)
exit(1);
}
else {
extern int gc_stress;
extern int ruby_gc_stress;
segv_received = 1;
gc_stress = 0;
ruby_gc_stress = 0;
rb_bug("Segmentation fault");
}
}
Expand Down Expand Up @@ -994,7 +994,7 @@ init_sigchld(int sig)
}

#ifdef RUBY_DEBUG_ENV
int enable_coredump = 0;
int ruby_enable_coredump = 0;
#endif

/*
Expand Down Expand Up @@ -1070,7 +1070,7 @@ Init_signal(void)
#endif

#ifdef RUBY_DEBUG_ENV
if (!enable_coredump)
if (!ruby_enable_coredump)
#endif
{
#ifdef SIGBUS
Expand Down

0 comments on commit eae8a91

Please sign in to comment.