I have another theory about what's causing the hang, can you please try
the attached patch? it replaces popen/read/write with fork/exec, so
that there's no I/O deadlock possible between DT and gdb processes.

On Mon, 2 Sep 2013 15:41:39 +0200
johannes hanika <[email protected]> wrote:

> does your system allow gdb to attach to processes? some disable that by
> default, which might lead to weird behaviour.
> 
> oh, also i'm quite sure we don't restrict ourselves to async-signal-safe
> functions in the sigseg handler (man 7 signal). so i guess every once in a
> million this is quite prone to deadlocking itself. i doubt that's the
> reason for you though if you get it every time.
> 
> -jo
> 
> 
> On Mon, Sep 2, 2013 at 2:58 PM, Richard Levitte <[email protected]> wrote:
> 
> > Hi!
> >
> > When darktable crashes, or bugs out, or whatever you want to call it,
> > it starts gdb with a set of commands.  Trouble is, this simply does
> > nothing.  Or rather, it just freezes.  Processes look like this:
> >
> > : ; ps auxw | grep darktable
> > levitte  13570 28.6 10.7 4171824 877656 pts/7  tl   14:08  10:31 darktable
> > -d memory
> > levitte  16083  0.2  0.9  85248 75384 pts/7    T    14:37   0:01 gdb
> > darktable 13570 -batch -x /usr/share/darktable/gdb_commands
> > levitte  16628  0.0  0.0   5660   808 pts/8    R+   14:45   0:00 grep
> > darktable
> >
> > On the command line where I started darktable, there's this line, I've
> > no clue if it's related or not:
> >
> > warning: Could not load shared library symbols for linux-gate.so.1.
> > Do you need "set solib-search-path" or "set sysroot"?
> >
> > And like many times before, /tmp has a 58 byte file
> > darktable_bt_L0DR2W.txt containing this:
> >
> > ----------
> > this is darktable 1.3+891~g0a180fa reporting a segfault:
> >
> > ----------
> >
> > This isn't terribly helpful, but what worries me most is the stopped
> > gdb process...
> >
> > Is there a way going forward with this?
> >
> > About "-d memory", I was trying to figure out what makes darktable
> > output those "skull" thumbnails on my system.  I run on a Y500 with
> > 8GB RAM and the same amount of swap.  It uses OpenCL, and the graphics
> > card has 2GB RAM.
> >
> > Cheers,
> > Richard
> >
> > --
> > Richard Levitte                         [email protected]
> >                                         http://richard.levitte.org/
> >
> > "Life is a tremendous celebration - and I'm invited!"
> > -- from a friend's blog, translated from Swedish
> >
> >
> > ------------------------------------------------------------------------------
> > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> > Discover the easy way to master current and previous Microsoft technologies
> > and advance your career. Get an incredible 1,500+ hours of step-by-step
> > tutorial videos with LearnDevNow. Subscribe today and save!
> > http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> > _______________________________________________
> > darktable-devel mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/darktable-devel
> >
diff --git a/data/gdb_commands b/data/gdb_commands
index 8ec1488..ef0d14d 100644
--- a/data/gdb_commands
+++ b/data/gdb_commands
@@ -1,2 +1,3 @@
+set logging redirect on
 where
 thread apply all bt full
diff --git a/src/common/darktable.c b/src/common/darktable.c
index 7a5bcb4..110d3ec 100644
--- a/src/common/darktable.c
+++ b/src/common/darktable.c
@@ -130,8 +130,7 @@ static int dprintf(int fd,const char *fmt, ...)
 static
 void _dt_sigsegv_handler(int param)
 {
-  FILE *fd;
-  gchar buf[PIPE_BUF];
+  pid_t pid;
   gchar *name_used;
   int fout;
   gboolean delete_file = FALSE;
@@ -141,23 +140,25 @@ void _dt_sigsegv_handler(int param)
     fout = STDOUT_FILENO; // just print everything to stdout
 
   dprintf(fout, "this is %s reporting a segfault:\n\n", PACKAGE_STRING);
+
+  if(fout != STDOUT_FILENO)
+    close(fout);
+
   dt_loc_get_datadir(datadir, DT_MAX_PATH_LEN);
-  gchar *command = g_strdup_printf("gdb %s %d -batch -x %s/gdb_commands", darktable.progname, (int)getpid(), datadir);
+  gchar *pid_arg = g_strdup_printf("%d", (int)getpid());
+  gchar *comm_arg = g_strdup_printf("%s/gdb_commands", datadir);
+  gchar *log_arg = g_strdup_printf("set logging on %s", name_used);
 
-  if((fd = popen(command, "r")) != NULL)
+  if((pid = fork()) != -1)
   {
-    gboolean read_something = FALSE;
-    while((fgets(buf, PIPE_BUF, fd)) != NULL)
+    if(pid)
     {
-      read_something = TRUE;
-      dprintf(fout, "%s", buf);
+      waitpid(pid, NULL, 0);
+      g_printerr("backtrace written to %s\n", name_used);
     }
-    pclose(fd);
-    if(fout != STDOUT_FILENO)
+    else
     {
-      if(read_something)
-        g_printerr("backtrace written to %s\n", name_used);
-      else
+      if(execlp("gdb", "gdb", darktable.progname, pid_arg, "-batch", "-ex", log_arg, "-x", comm_arg, NULL))
       {
         delete_file = TRUE;
         g_printerr("an error occurred while trying to execute gdb. please check if gdb is installed on your system.\n");
@@ -170,11 +171,11 @@ void _dt_sigsegv_handler(int param)
     g_printerr("an error occurred while trying to execute gdb.\n");
   }
 
-  if(fout != STDOUT_FILENO)
-    close(fout);
   if(delete_file)
     g_unlink(name_used);
-  g_free(command);
+  g_free(pid_arg);
+  g_free(comm_arg);
+  g_free(log_arg);
   g_free(name_used);
 
   /* pass it further to the old handler*/
------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
darktable-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/darktable-devel

Reply via email to