I tried the backtrace from thorsen consulting, it gave me a trace looking like this:
0: prog [0x8049989]
1: prog(__gxx_personality_v0+0x253) [0x8049427]
2: [0xffffe420]
3: prog(__gxx_personality_v0+0x16b) [0x804933f]
4: prog(__gxx_personality_v0+0x1c0) [0x8049394]
5: /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe0) [0xb6e62050]
6: prog(__gxx_personality_v0+0xfd) [0x80492d1]
It looks the same whether the executable has debuginfo in it or not. 
Some further testing show that the problems I had reading from gdb was not caused by calling Qt functions after a SEGV, it did not work better when calling segv_handler as an ordinary function either. With some more command line options, gdb becomes easier to control from another process:
#include <QApplication>
#include <QProcess>
#include <signal.h>
void segv_handler(int)
{
pro.
setProcessChannelMode(QProcess::MergedChannels);
qDebug("Caught SEGV, trying to get a backtrace from gdb...");
<< "-batch"
<< "-x" << "/home/drhex/src/foto/backtrace" // a file that just contains the word "backtrace"
<< qApp
->arguments
().
at(0) << qPrintable
(QString::number(getpid
())) if (!pro.waitForStarted()) {
qDebug("Could not start gdb");
exit(1);
}
char buf[1024];
int len;
bool doprint = false;
do {
pro.waitForReadyRead();
do {
len = pro.readLine(buf, sizeof(buf));
if (len>0) {
if (s.indexOf("signal handler called") >-1) doprint = true;
s.chop(1); // skip newline
if (doprint) qDebug("%s", qPrintable(s));
}
} while (len>0);
} while(pro.
state() == QProcess::Running);
exit(1);
}
void cause_segv(int x)
{
*(int *)0 = x;
}
int main(int argc, char *argv[])
{
signal(SIGSEGV, segv_handler);
cause_segv(26);
app.exec();
return 0;
}
#include <QApplication>
#include <QProcess>
#include <signal.h>
void segv_handler(int)
{
QProcess pro;
pro.setProcessChannelMode(QProcess::MergedChannels);
qDebug("Caught SEGV, trying to get a backtrace from gdb...");
pro.start("gdb", QStringList()
<< "-batch"
<< "-x" << "/home/drhex/src/foto/backtrace" // a file that just contains the word "backtrace"
<< qApp->arguments().at(0) << qPrintable(QString::number(getpid()))
,QIODevice::ReadOnly);
if (!pro.waitForStarted()) {
qDebug("Could not start gdb");
exit(1);
}
char buf[1024];
int len;
bool doprint = false;
do {
pro.waitForReadyRead();
do {
len = pro.readLine(buf, sizeof(buf));
if (len>0) {
QString s = buf;
if (s.indexOf("signal handler called") >-1) doprint = true;
s.chop(1); // skip newline
if (doprint) qDebug("%s", qPrintable(s));
}
} while (len>0);
} while(pro.state() == QProcess::Running);
exit(1);
}
void cause_segv(int x)
{
*(int *)0 = x;
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
signal(SIGSEGV, segv_handler);
cause_segv(26);
app.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
With the above program, I get the following output:
Caught SEGV, trying to get a backtrace from gdb...
#6 <signal handler called>
#7 0x0804983f in cause_segv (x=26) at prog.cc:42
#8 0x08049894 in main (argc=Cannot access memory at address 0x0
) at prog.cc:52
Line numbers, arguments, function names and file names, just like I wanted
Bookmarks