Created
December 9, 2013 09:03
-
-
Save authorNari/7869392 to your computer and use it in GitHub Desktop.
GCのタイミングでバックトレース吐く奴。Ruby1.9.3用。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gc.c b/gc.c | |
index 1d3ac79..2b833da 100644 | |
--- a/gc.c | |
+++ b/gc.c | |
@@ -2585,7 +2585,8 @@ garbage_collect(rb_objspace_t *objspace) | |
{ | |
INIT_GC_PROF_PARAMS; | |
- if (GC_NOTIFY) printf("start garbage_collect()\n"); | |
+ fprintf(stderr, "garbage_collect(%d)\n", objspace->count); | |
+ rb_print_backtrace(); | |
if (!heaps) { | |
return FALSE; | |
diff --git a/internal.h b/internal.h | |
index 59c9284..9806bdc 100644 | |
--- a/internal.h | |
+++ b/internal.h | |
@@ -196,6 +196,7 @@ const void **rb_vm_get_insns_address_table(void); | |
/* vm_dump.c */ | |
void rb_vm_bugreport(void); | |
+void rb_print_backtrace(void); | |
/* vm_eval.c */ | |
void Init_vm_eval(void); | |
diff --git a/vm_dump.c b/vm_dump.c | |
index 63a10a5..1a4428b 100644 | |
--- a/vm_dump.c | |
+++ b/vm_dump.c | |
@@ -767,6 +767,34 @@ dump_thread(void *arg) | |
#endif | |
void | |
+rb_print_backtrace(void) | |
+{ | |
+#if HAVE_BACKTRACE | |
+#define MAX_NATIVE_TRACE 1024 | |
+ static void *trace[MAX_NATIVE_TRACE]; | |
+ int n = backtrace(trace, MAX_NATIVE_TRACE); | |
+ char **syms = backtrace_symbols(trace, n); | |
+ | |
+ if (syms) { | |
+#ifdef USE_ELF | |
+ rb_dump_backtrace_with_lines(n, trace, syms); | |
+#else | |
+ int i; | |
+ for (i=0; i<n; i++) { | |
+ fprintf(stderr, "%s\n", syms[i]); | |
+ } | |
+#endif | |
+ free(syms); | |
+ } | |
+#elif defined(_WIN32) | |
+ DWORD tid = GetCurrentThreadId(); | |
+ HANDLE th = (HANDLE)_beginthread(dump_thread, 0, &tid); | |
+ if (th != (HANDLE)-1) | |
+ WaitForSingleObject(th, INFINITE); | |
+#endif | |
+} | |
+ | |
+void | |
rb_vm_bugreport(void) | |
{ | |
rb_vm_t *vm = GET_VM(); | |
@@ -782,38 +810,7 @@ rb_vm_bugreport(void) | |
#if HAVE_BACKTRACE || defined(_WIN32) | |
fprintf(stderr, "-- C level backtrace information " | |
"-------------------------------------------\n"); | |
- | |
- { | |
-#if defined __MACH__ && defined __APPLE__ | |
- fprintf(stderr, "\n"); | |
- fprintf(stderr, " See Crash Report log file under " | |
- "~/Library/Logs/CrashReporter or\n"); | |
- fprintf(stderr, " /Library/Logs/CrashReporter, for " | |
- "the more detail of.\n"); | |
-#elif HAVE_BACKTRACE | |
-#define MAX_NATIVE_TRACE 1024 | |
- static void *trace[MAX_NATIVE_TRACE]; | |
- int n = backtrace(trace, MAX_NATIVE_TRACE); | |
- char **syms = backtrace_symbols(trace, n); | |
- | |
- if (syms) { | |
-#ifdef USE_ELF | |
- rb_dump_backtrace_with_lines(n, trace, syms); | |
-#else | |
- int i; | |
- for (i=0; i<n; i++) { | |
- fprintf(stderr, "%s\n", syms[i]); | |
- } | |
-#endif | |
- free(syms); | |
- } | |
-#elif defined(_WIN32) | |
- DWORD tid = GetCurrentThreadId(); | |
- HANDLE th = (HANDLE)_beginthread(dump_thread, 0, &tid); | |
- if (th != (HANDLE)-1) | |
- WaitForSingleObject(th, INFINITE); | |
-#endif | |
- } | |
+ rb_print_backtrace(); | |
fprintf(stderr, "\n"); | |
#endif /* HAVE_BACKTRACE */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment