Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany
Accepted Solution

How to hunt down a segfault?

I spent some fruitless hours yesterday hunting down a segfault.

As far as i have understood this it is similar to a nullpointerexception in java.

I have narrowed it down to a few lines of code - when i comment them out the segfault is gone - but i have no clue why it occurs there, as i check every pointer i use for being null.

 

When i use the debugger, it points to a setter with QString, with the message

"QString::smileysurprised:perator=() at 0x..."

 

Not sure if the code is helpful, but i just take the chance:

objectValue is a QString, setFormula is a simple setter

qDebug() << "enabledformula value: " << objectValue;								
DataServiceFormula* dsFormula = buttonInput->getEnabledFormula(); qDebug() << "after retrieving formula"; if (!dsFormula) { qDebug() << "formula is null"; dsFormula = new DataServiceFormula(); } qDebug() << "setting formula"; QString formulaString = objectValue.toLower().trimmed(); qDebug() << "to " << formulaString; dsFormula->setFormula(formulaString); qDebug() << "set formula successful";

 And the debugger creates this output:

Debug: enabledformula value:  "C1" 
Debug: after retrieving formula 
Debug: setting formula 
Debug: to  "c1" 

 After that comes the SIGSEGV

 

Any general ideas how i could find out why it occurs?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to hunt down a segfault?

To try to answer this we need to know declaration and definition of

dsFormula->setFormula()

and dsFormula class itself. I does not look like it is some standard class.

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to hunt down a segfault?

it is a very simple bean class.

 

header:

/*
 * DataServiceFormula.hpp
 *
 *  Created on: 06.09.2012
 *      Author: sha
 */

#ifndef DATASERVICEFORMULA_HPP_
#define DATASERVICEFORMULA_HPP_

#include "DataServiceCondition.hpp"
#include <QHash>
#include <QString>
#include <qobject.h>

class DataServiceFormula: public QObject {
	Q_OBJECT

private:
	QString formula;
	QHash<QString, DataServiceCondition*> conditions;
	QString errorText;

public:
	enum DataServiceFormulaType {
		DataServiceFormulaTypeMandatory = 1,
		DataServiceFormulaTypeReadonly = 2,
		DataServiceFormulaTypeVisible = 3,
		DataServiceFormulaTypeEnabled = 4,
		DataServiceFormulaTypeValidation = 5
	};
	QHash<QString, DataServiceCondition*> getConditions() const;
	void setConditions(QHash<QString, DataServiceCondition*> conditions);
	QString getFormula() const;
	void setFormula(QString formula);
	QString getErrorText() const;
	void setErrorText(QString errorText);
};

#endif /* DATASERVICEFORMULA_HPP_ */

 cpp:

/*
 * DataServiceFormula.cpp
 *
 *  Created on: 06.09.2012
 *      Author: sha
 */
#include "DataServiceFormula.hpp"
#include <QHash>
#include <QString>

QHash<QString, DataServiceCondition*> DataServiceFormula::getConditions() const {
	return conditions;
}

void DataServiceFormula::setConditions(QHash<QString, DataServiceCondition*> conditions) {
	this->conditions = conditions;
}

QString DataServiceFormula::getFormula() const {
	return formula;
}

QString DataServiceFormula::getErrorText() const {
	return errorText;
}

void DataServiceFormula::setErrorText(QString errorText) {
	this->errorText = errorText;
}

void DataServiceFormula::setFormula(QString formula) {
	this->formula = formula;
}

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
borceg
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: How to hunt down a segfault?

First thing that comes to my mind is variable shadowin issue, but maybe I'm wrong

 

void DataServiceFormula::setFormula(QString fParam) {
	this->formula = fParam;
}
Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to hunt down a segfault?

the this-> accessor takes care of that, i use it in a lot of other classes.
i guess the whole getter/setter thing is a java obsession anyhow, but as long as it works...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to hunt down a segfault?

so far everything looks correct. (by the way you can completely remove this-> in your clas member functions).

Now we need to see how DataServiceFormula object is constructed/created.

DataServiceFormula* dsFormula = buttonInput->getEnabledFormula();

can you post buttonInput->getEnabledFormula() implementation and related stuff please?

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to hunt down a segfault?

on the first iteration the value of "getEnabledFormula()" is NULL, in this case i create a new object and set it.
Seems i had removed the call from the code snippet above, below the new call i set it on the buttonInput.

There is no other call in the code, except for serialization/deserialization in the cache, but this is never executed as the code crashes before.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to hunt down a segfault?

where is this 'below'? -)

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to hunt down a segfault?

Here is the part again. It is called in a loop where i iterate attributes from the webservice.

objectValue is a QString, populated from the soap response.

 

qDebug() << "enabledformula value: " << objectValue;
if (!buttonInput){									
qDebug() << "buttonInput is null"; }
DataServiceFormula* dsFormula = buttonInput->getEnabledFormula(); qDebug() << "after retrieving formula"; if (!dsFormula) {
qDebug() << "creating new formula";
dsFormula = new DataServiceFormula();
buttonInput->setEnabledFormula(dsFormula); } qDebug() << "setting formula"; QString formulaString = objectValue.toLower().trimmed(); qDebug() << "to " << formulaString; dsFormula->setFormula(formulaString); qDebug() << "set formula successful";

 And the console output when i run it:

Debug: enabledformula value:  "C1" 
Debug: after retrieving formula 
Debug: setting formula 
Debug: to  "c1" 

Process 80048308 (bb10) terminated SIGSEGV code=1 fltno=11 ip=78e8f182(/base/usr/lib/qt4/lib/libQtCore.so.4.8.4@_ZN7QStringaSERKS_+0x19) mapaddr=0008f182. ref=6f63636d

 

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to hunt down a segfault?

hope somebody else will be able to help you. Good luck with hunting.

Please use plain text.