• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión819e813755f7bc534362b7b9b2beaa29fbf17663 (tree)
Tiempo2013-06-03 15:07:55
AutorKatsuhiko Nishimra <ktns.87@gmai...>
CommiterKatsuhiko Nishimra

Log Message

Print backtrace of the exception. #31491

git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1360 1136aad2-a195-0410-b898-f5ea1d11b9d8

Cambiar Resumen

Diferencia incremental

--- a/doc/README.txt
+++ b/doc/README.txt
@@ -68,8 +68,9 @@ COMPILE(using GNUmake):
6868 For both case, the compile succeeded if you could fine "MolDS.out" in the "src" directory.
6969 Type "$ make clean" when you wanna clean the compilation.
7070 If you want to compile MolDS in debug-mode,
71- -g and -DMOLDS_DBG should be added to CFLAGS, that is, hit the following command:
72- $make CFLAGS="-O0 -g -DMOLDS_DBG"
71+ -g, -rdynamic(for function names in backtrace) and -DMOLDS_DBG should be added to CFLAGS,
72+ that is, hit the following command:
73+ $make CFLAGS="-O0 -g -rdynamic -DMOLDS_DBG"
7374
7475 ==============================================================================
7576 CARRY OUT MolDS:
--- a/src/base/MolDS.cpp
+++ b/src/base/MolDS.cpp
@@ -68,6 +68,7 @@ void MolDS::Run(int argc, char *argv[]){
6868 }
6969 catch(MolDSException ex){
7070 this->OutputLog(boost::format("%s\n") % ex.what());
71+ ex.PrintBacktrace();
7172 runsNormally = false;
7273 }
7374
@@ -162,6 +163,7 @@ void MolDS::CalculateElectronicStructureOnce(Molecule* molecule, bool* runsNorma
162163 }
163164 catch(MolDSException ex){
164165 this->OutputLog(boost::format("%s\n") % ex.what());
166+ ex.PrintBacktrace();
165167 *runsNormally = false;
166168 }
167169 }
@@ -174,6 +176,7 @@ void MolDS::DoMC(Molecule* molecule, bool* runsNormally) const{
174176 }
175177 catch(MolDSException ex){
176178 this->OutputLog(boost::format("%s\n") % ex.what());
179+ ex.PrintBacktrace();
177180 *runsNormally = false;
178181 }
179182 }
@@ -186,6 +189,7 @@ void MolDS::DoMD(Molecule* molecule, bool* runsNormally) const{
186189 }
187190 catch(MolDSException ex){
188191 this->OutputLog(boost::format("%s\n") % ex.what());
192+ ex.PrintBacktrace();
189193 *runsNormally = false;
190194 }
191195 }
@@ -197,6 +201,7 @@ void MolDS::DoRPMD(Molecule* molecule, bool* runsNormally) const{
197201 }
198202 catch(MolDSException ex){
199203 this->OutputLog(boost::format("%s\n") % ex.what());
204+ ex.PrintBacktrace();
200205 *runsNormally = false;
201206 }
202207 }
@@ -208,6 +213,7 @@ void MolDS::DoNASCO(Molecule* molecule, bool* runsNormally) const{
208213 }
209214 catch(MolDSException ex){
210215 this->OutputLog(boost::format("%s\n") % ex.what());
216+ ex.PrintBacktrace();
211217 *runsNormally = false;
212218 }
213219 }
@@ -219,6 +225,7 @@ void MolDS::OptimizeGeometry(Molecule* molecule, bool* runsNormally) const{
219225 }
220226 catch(MolDSException ex){
221227 this->OutputLog(boost::format("%s\n") % ex.what());
228+ ex.PrintBacktrace();
222229 *runsNormally = false;
223230 }
224231 }
@@ -229,6 +236,7 @@ void MolDS::DiagonalizePrincipalAxes(Molecule* molecule, bool* runsNormally) con
229236 }
230237 catch(MolDSException ex){
231238 this->OutputLog(boost::format("%s\n") % ex.what());
239+ ex.PrintBacktrace();
232240 *runsNormally = false;
233241 }
234242 }
@@ -239,6 +247,7 @@ void MolDS::TranslateMolecule(Molecule* molecule, bool* runsNormally) const{
239247 }
240248 catch(MolDSException ex){
241249 this->OutputLog(boost::format("%s\n") % ex.what());
250+ ex.PrintBacktrace();
242251 *runsNormally = false;
243252 }
244253 }
@@ -249,6 +258,7 @@ void MolDS::RotateMolecule(Molecule* molecule, bool* runsNormally) const{
249258 }
250259 catch(MolDSException ex){
251260 this->OutputLog(boost::format("%s\n") % ex.what());
261+ ex.PrintBacktrace();
252262 *runsNormally = false;
253263 }
254264 }
--- a/src/base/MolDSException.cpp
+++ b/src/base/MolDSException.cpp
@@ -16,20 +16,35 @@
1616 // You should have received a copy of the GNU General Public License //
1717 // along with MolDS. If not, see <http://www.gnu.org/licenses/>. //
1818 //************************************************************************//
19+#include<execinfo.h>
1920 #include<string>
2021 #include<stdexcept>
2122 #include<boost/format.hpp>
2223 #include"MolDSException.h"
2324 using namespace std;
2425 namespace MolDS_base{
25-MolDSException::MolDSException(string cause) : domain_error(cause){
26+MolDSException::MolDSException(string cause) : domain_error(cause), backtraceSize(0){
27+ this->GetBacktrace(80);
2628 }
2729
28-MolDSException::MolDSException(const boost::format& cause) : domain_error(cause.str()){
30+MolDSException::MolDSException(const boost::format& cause) : domain_error(cause.str()), backtraceSize(0){
31+ this->GetBacktrace(80);
2932 }
30-}
31-
32-
3333
34+void MolDSException::GetBacktrace(int bufsize){
35+ backtracePtr.reset(new void*[bufsize]);
36+ this->backtraceSize = backtrace(this->backtracePtr.get(), bufsize);
37+ if(this->backtraceSize==bufsize){
38+ GetBacktrace(bufsize*2);
39+ }
40+}
3441
42+void MolDSException::PrintBacktrace(){
43+ if(this->backtraceSize <= 0){
44+ return;
45+ }
46+ cout<<"backtrace:" << endl;
47+ backtrace_symbols_fd(this->backtracePtr.get(), this->backtraceSize, 1);
48+}
49+}
3550
--- a/src/base/MolDSException.h
+++ b/src/base/MolDSException.h
@@ -18,6 +18,7 @@
1818 //************************************************************************//
1919 #ifndef INCLUDED_MOLDSEXCEPTION
2020 #define INCLUDED_MOLDSEXCEPTION
21+#include<boost/shared_array.hpp>
2122 namespace MolDS_base{
2223 class MolDSException : public std::domain_error {
2324 public:
@@ -25,7 +26,12 @@ public:
2526 #ifdef BOOST_FORMAT_HPP
2627 MolDSException(const boost::format& cause);
2728 #endif
29+ ~MolDSException() throw(){};
30+ void PrintBacktrace();
2831 private:
32+ void GetBacktrace(int bufsize);
33+ size_t backtraceSize;
34+ boost::shared_array<void*> backtracePtr;
2935 };
3036 }
3137 #endif