Skip to content

Commit

Permalink
Disabling backtrace() function on Windows system. Mingw doesn't support
Browse files Browse the repository at this point in the history
this at the moment.
  • Loading branch information
rkhaotix committed Oct 13, 2012
1 parent 64bead4 commit 42b5477
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 74 deletions.
39 changes: 22 additions & 17 deletions crashhandler/src/crashhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,36 @@ const char CrashHandler::CHR_DELIMITADOR=static_cast<char>(3);
//***********************************************************
CrashHandler::CrashHandler(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f)
{
ifstream entrada;
QString buf;
char lin[1024];

setupUi(this);
connect(cancelar_btn, SIGNAL(clicked(void)), this, SLOT(close(void)));
connect(criar_btn, SIGNAL(clicked(void)), this, SLOT(gerarRelatorio(void)));
connect(acoes_txt, SIGNAL(textChanged(void)), this, SLOT(habilitarGeracao(void)));

//Abre o arquivo o qual armazena a stack trace do ultimo travamento
entrada.open(AtributosGlobais::DIR_TEMPORARIO +
AtributosGlobais::SEP_DIRETORIO +
AtributosGlobais::ARQ_CRASH_HANDLER);
#ifndef Q_OS_WIN
ifstream entrada;
QString buf;
char lin[1024];

//Le cada linha do arquivo e concatena ao buffer
while(entrada.is_open() && !entrada.eof())
{
entrada.getline(lin, sizeof(lin), '\n');
buf += QString("%1\n").arg(lin);
}
//Abre o arquivo o qual armazena a stack trace do ultimo travamento
entrada.open(AtributosGlobais::DIR_TEMPORARIO +
AtributosGlobais::SEP_DIRETORIO +
AtributosGlobais::ARQ_CRASH_HANDLER);

entrada.close();
//Le cada linha do arquivo e concatena ao buffer
while(entrada.is_open() && !entrada.eof())
{
entrada.getline(lin, sizeof(lin), '\n');
buf += QString("%1\n").arg(lin);
}

entrada.close();

//Exibe o buffer no widget de stack trace
stack_txt->setPlainText(buf);
//Exibe o buffer no widget de stack trace
stack_txt->setPlainText(buf);
#else
//Para sistemas Windows, exibe uma mensagem dizendo a indisponibilidade da stacktrace
stack_txt->setPlainText(trUtf8("** Stack trace unavailable on Windows system **");
#endif

//Cria um destacador de sintaxe para o modelo
dest_modelo_txt=new DestaqueSintaxe(modelo_txt, false);
Expand Down
6 changes: 0 additions & 6 deletions crashhandler/ui/crashhandler.ui
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>We apologize for what happened! It is clear that a nasty bug caused it. Please fill out the form below describing your actions before pgModeler quit unexpectedly. This will help on bug extermination and improve the software.</string>
</property>
Expand Down
3 changes: 3 additions & 0 deletions libpgmodeler_ui/src/modelowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,9 @@ void ModeloWidget::exibirFormObjeto(TipoObjetoBase tipo_obj, ObjetoBase *objeto,
try
{
unsigned tipo_rel=0;
#warning "Crash handler teste"
Tabela *tab=NULL;
tab->definirNome("");

/* Caso o tipo_obj seja maior que o ultimo código de tipo de objeto, indica
que se trata de um tipo específico de relacionamento (1-1, 1-n, n-n, gen, dep).
Expand Down
22 changes: 5 additions & 17 deletions libpgmodeler_ui/ui/formsobre.ui
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>18</pointsize>
<weight>75</weight>
<bold>true</bold>
Expand Down Expand Up @@ -185,11 +184,8 @@
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>true</italic>
<bold>false</bold>
</font>
</property>
<property name="text">
Expand Down Expand Up @@ -219,7 +215,6 @@
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>12</pointsize>
<weight>75</weight>
<italic>true</italic>
Expand All @@ -233,6 +228,11 @@
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;http://pgmodeler.com.br&quot;&gt;&lt;span style=&quot; font-size:11pt; font-style:italic; text-decoration: underline; color:#0057ae;&quot;&gt;http://pgmodeler.com.br&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
Expand Down Expand Up @@ -282,12 +282,6 @@
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Copyright 2006-2012 - Raphael Araújo e Silva &lt;rkhaotix@gmail.com&gt;

Expand Down Expand Up @@ -345,12 +339,6 @@ Special thanks to friends of the software development team of the Legislative As
<height>0</height>
</size>
</property>
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
Expand Down
71 changes: 37 additions & 34 deletions main/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
#include "formprincipal.h"
#include "aplicacao.h"
#include "execinfo.h"
#include <QTranslator>

#ifndef Q_OS_WIN
#include "execinfo.h"
#endif

void executarCrashHandler(int)
{
ofstream saida;
QString cmd, lin;
void *pilha[20];
size_t tam_pilha, i;
char **simbolos=NULL;

//Obtém os simbolos da stack trace (até 20 itens)
tam_pilha = backtrace(pilha, 20);
simbolos = backtrace_symbols(pilha, tam_pilha);

//Cria o arquivo que armazenará a stack trace
saida.open(AtributosGlobais::DIR_TEMPORARIO +
AtributosGlobais::SEP_DIRETORIO +
AtributosGlobais::ARQ_CRASH_HANDLER);

//Caso o arquivo esteja aberto
if(saida.is_open())
{
lin=QString("** pgModeler crashed after receive signal: %1 **\n\n").arg("SIGSEGV");
saida.write(lin.toStdString().c_str(), lin.size());

//Grava cada linha da stack trace no arquivo
for(i=0; i < tam_pilha; i++)
{
lin=QString(simbolos[i]) + QString("\n");
saida.write(lin.toStdString().c_str(), lin.size());
}
//Desaloca a stack trace
free(simbolos);
saida.close();
}

/** A função backtrace não é existe até o momento no MingW (Windows) desta forma
o trecho que gera a stacktrace do programa só é ativado em Linux/Unix **/
#ifdef Q_OS_WIN
cmd="crashhandler.exe";
#else
ofstream saida;
QString cmd, lin;
void *pilha[20];
size_t tam_pilha, i;
char **simbolos=NULL;

//Obtém os simbolos da stack trace (até 20 itens)
tam_pilha = backtrace(pilha, 20);
simbolos = backtrace_symbols(pilha, tam_pilha);

//Cria o arquivo que armazenará a stack trace
saida.open(AtributosGlobais::DIR_TEMPORARIO +
AtributosGlobais::SEP_DIRETORIO +
AtributosGlobais::ARQ_CRASH_HANDLER);

//Caso o arquivo esteja aberto
if(saida.is_open())
{
lin=QString("** pgModeler crashed after receive signal: %1 **\n\n").arg("SIGSEGV");
saida.write(lin.toStdString().c_str(), lin.size());

//Grava cada linha da stack trace no arquivo
for(i=0; i < tam_pilha; i++)
{
lin=QString(simbolos[i]) + QString("\n");
saida.write(lin.toStdString().c_str(), lin.size());
}
//Desaloca a stack trace
free(simbolos);
saida.close();
}
cmd="crashhandler";
#endif

Expand All @@ -50,7 +54,6 @@ void executarCrashHandler(int)
}



int main(int argc, char **argv)
{
try
Expand Down

0 comments on commit 42b5477

Please sign in to comment.