* Re: crash in gc with upside-down stack
2008-11-13 5:21 ` Linas Vepstas
@ 2008-11-13 19:27 ` Linas Vepstas
0 siblings, 0 replies; 3+ messages in thread
From: Linas Vepstas @ 2008-11-13 19:27 UTC (permalink / raw)
To: bug-guile
Attached below is a debugging patch, and its output,
which shows that the stack bounds are frequently
up-side-down, and are sometimes upside-down
when the GC runs, thus leading to a crash.
In the next email, I'll propose a patch that fixes the
the problem.
The original problem report:
> 2008/11/11 Linas Vepstas <linasvepstas@gmail.com>:
>>
>> My stack below.
>>
>> Program received signal SIGSEGV, Segmentation fault.
>> [Switching to Thread 0xf5333b90 (LWP 20587)]
>> 0xf7711ce3 in scm_mark_locations (x=0xf5333110, n=4294966782) at gc-mark.c:435
>> 435 SCM obj = * (SCM *) &x[m];
>> Current language: auto; currently c
>> (gdb) bt
>> #0 0xf7711ce3 in scm_mark_locations (x=0xf5333110, n=4294966782)
>> at gc-mark.c:435
>> #1 0xf7766a12 in scm_threads_mark_stacks () at threads.c:1375
>> #2 0xf7711d38 in scm_mark_all () at gc-mark.c:82
>> #3 0xf7710d33 in scm_i_gc (what=0xf778602e "cells") at gc.c:598
>
A debugging patch. Yes, its ugly, its intentionally ugly.
More of an eye-catcher that way.
Index: guile-1.8.5/libguile/threads.c
===================================================================
--- guile-1.8.5.orig/libguile/threads.c 2008-11-13 07:58:22.000000000 -0600
+++ guile-1.8.5/libguile/threads.c 2008-11-13 13:14:00.000000000 -0600
@@ -395,6 +395,10 @@ static scm_t_guile_ticket
scm_leave_guile ()
{
scm_i_thread *t = suspend ();
+int sz=t->base - t->top;
+if(0>sz) {
+printf("duuude scm_leav_guile backwards stack %d\n", sz);
+}
scm_i_pthread_mutex_unlock (&t->heap_mutex);
return (scm_t_guile_ticket) t;
}
@@ -694,7 +698,15 @@ scm_i_with_guile_and_parent (void *(*fun
really_entered = scm_i_init_thread_for_guile (&base_item, parent);
res = scm_c_with_continuation_barrier (func, data);
if (really_entered)
- scm_leave_guile ();
+{
+ // scm_leave_guile ();
+scm_i_thread * t = (scm_i_thread *) scm_leave_guile ();
+int sz=t->base - t->top;
+int szb=t->base - &base_item;
+if(0>sz) {
+printf("duuude scm_leav_guile and parent %d %d\n", sz, szb);
+}
+}
return res;
}
@@ -704,6 +716,11 @@ scm_without_guile (void *(*func)(void *)
void *res;
scm_t_guile_ticket t;
t = scm_leave_guile ();
+scm_i_thread * s = (scm_i_thread *) t;
+int sz=s->base - s->top;
+if(0>sz) {
+printf("duuude scm_wo guile %d\n", sz);
+}
res = func (data);
scm_enter_guile (t);
return res;
@@ -1371,8 +1388,15 @@ scm_threads_mark_stacks (void)
#if SCM_STACK_GROWS_UP
scm_mark_locations (t->base, t->top - t->base);
+xxxx
#else
+int sz=t->base - t->top;
+if(0<=sz) {
scm_mark_locations (t->top, t->base - t->top);
+} else {
+printf ("duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude bugg!!\n");
+printf ("duude stack top=%p base=%p sz=%d\n", t->top, t->base,
t->base - t->top);
+}
#endif
scm_mark_locations ((SCM_STACKITEM *) t->regs,
((size_t) sizeof(t->regs)
@@ -1441,6 +1465,11 @@ int
scm_pthread_mutex_lock (scm_i_pthread_mutex_t *mutex)
{
scm_t_guile_ticket t = scm_leave_guile ();
+scm_i_thread * s = (scm_i_thread *) t;
+int sz=s->base - s->top;
+if(0>sz) {
+printf("duuude scm_mutexe %d\n", sz);
+}
int res = scm_i_pthread_mutex_lock (mutex);
scm_enter_guile (t);
return res;
@@ -1463,6 +1492,11 @@ int
scm_pthread_cond_wait (scm_i_pthread_cond_t *cond,
scm_i_pthread_mutex_t *mutex)
{
scm_t_guile_ticket t = scm_leave_guile ();
+scm_i_thread * s = (scm_i_thread *) t;
+int sz=s->base - s->top;
+if(0>sz) {
+printf("duuude scm_conde %d\n", sz);
+}
int res = scm_i_pthread_cond_wait (cond, mutex);
scm_enter_guile (t);
return res;
@@ -1578,7 +1612,12 @@ scm_i_thread_put_to_sleep ()
{
scm_i_thread *t;
- scm_leave_guile ();
+ // scm_leave_guile ();
+ t = (scm_i_thread *) scm_leave_guile ();
+int sz=t->base - t->top;
+if(0>sz) {
+printf("duuude scm_leav_guile backwards was scm_i_thread_put_to_sleep
%d\n", sz);
+}
scm_i_pthread_mutex_lock (&thread_admin_mutex);
/* Signal all threads to go to sleep
@@ -1620,6 +1659,10 @@ void
scm_i_thread_sleep_for_gc ()
{
scm_i_thread *t = suspend ();
+int sz=t->base - t->top;
+if(0>sz) {
+printf("duuude scm_i_thread_sleep_for_gc backwards stack %d\n", sz);
+}
scm_i_pthread_cond_wait (&wake_up_cond, &t->heap_mutex);
resume (t);
}
Here is an example of the output generated:
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude bugg!!
duude stack top=0xf355b9e0 base=0xf355b908 sz=-54
duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude bugg!!
duude stack top=0xf355b9e0 base=0xf355b908 sz=-54
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
etc... lots of the above. Also, here's a typical
thread exit:
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duude thread
going away on f5f09b90
duuude scm_leav_guile backwards stack -518
duuude scm_mutexe -518
duuude scm_leav_guile backwards stack -522
duuude scm_mutexe -522
duuude scm_leav_guile backwards stack -638
duuude scm_leav_guile and parent -638 -660
[Thread 0xf5f09b90 (LWP 25812) exited]
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
Sometimes the gc happens while the thread is going away:
duuude scm_leav_guile and parent -54 -76
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duude thread going away on f5708b90
duuude scm_leav_guile backwards stack -518
duuude scm_mutexe -518
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude bugg!!
duude stack top=0xf2d5a9e0 base=0xf2d5a908 sz=-54
duuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuude bugg!!
duude stack top=0xf5708120 base=0xf5707908 sz=-518
duuude scm_leav_guile backwards stack -522
duuude scm_mutexe -522
duuude scm_leav_guile backwards stack -638
duuude scm_leav_guile and parent -638 -660
[Thread 0xf5708b90 (LWP 25826) exited]
duuude scm_leav_guile backwards stack -54
duuude scm_leav_guile and parent -54 -76
^ permalink raw reply [flat|nested] 3+ messages in thread