Revisión | 819e813755f7bc534362b7b9b2beaa29fbf17663 (tree) |
---|---|
Tiempo | 2013-06-03 15:07:55 |
Autor | Katsuhiko Nishimra <ktns.87@gmai...> |
Commiter | Katsuhiko Nishimra |
Print backtrace of the exception. #31491
git-svn-id: https://svn.sourceforge.jp/svnroot/molds/trunk@1360 1136aad2-a195-0410-b898-f5ea1d11b9d8
@@ -68,8 +68,9 @@ COMPILE(using GNUmake): | ||
68 | 68 | For both case, the compile succeeded if you could fine "MolDS.out" in the "src" directory. |
69 | 69 | Type "$ make clean" when you wanna clean the compilation. |
70 | 70 | 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" | |
73 | 74 | |
74 | 75 | ============================================================================== |
75 | 76 | CARRY OUT MolDS: |
@@ -68,6 +68,7 @@ void MolDS::Run(int argc, char *argv[]){ | ||
68 | 68 | } |
69 | 69 | catch(MolDSException ex){ |
70 | 70 | this->OutputLog(boost::format("%s\n") % ex.what()); |
71 | + ex.PrintBacktrace(); | |
71 | 72 | runsNormally = false; |
72 | 73 | } |
73 | 74 |
@@ -162,6 +163,7 @@ void MolDS::CalculateElectronicStructureOnce(Molecule* molecule, bool* runsNorma | ||
162 | 163 | } |
163 | 164 | catch(MolDSException ex){ |
164 | 165 | this->OutputLog(boost::format("%s\n") % ex.what()); |
166 | + ex.PrintBacktrace(); | |
165 | 167 | *runsNormally = false; |
166 | 168 | } |
167 | 169 | } |
@@ -174,6 +176,7 @@ void MolDS::DoMC(Molecule* molecule, bool* runsNormally) const{ | ||
174 | 176 | } |
175 | 177 | catch(MolDSException ex){ |
176 | 178 | this->OutputLog(boost::format("%s\n") % ex.what()); |
179 | + ex.PrintBacktrace(); | |
177 | 180 | *runsNormally = false; |
178 | 181 | } |
179 | 182 | } |
@@ -186,6 +189,7 @@ void MolDS::DoMD(Molecule* molecule, bool* runsNormally) const{ | ||
186 | 189 | } |
187 | 190 | catch(MolDSException ex){ |
188 | 191 | this->OutputLog(boost::format("%s\n") % ex.what()); |
192 | + ex.PrintBacktrace(); | |
189 | 193 | *runsNormally = false; |
190 | 194 | } |
191 | 195 | } |
@@ -197,6 +201,7 @@ void MolDS::DoRPMD(Molecule* molecule, bool* runsNormally) const{ | ||
197 | 201 | } |
198 | 202 | catch(MolDSException ex){ |
199 | 203 | this->OutputLog(boost::format("%s\n") % ex.what()); |
204 | + ex.PrintBacktrace(); | |
200 | 205 | *runsNormally = false; |
201 | 206 | } |
202 | 207 | } |
@@ -208,6 +213,7 @@ void MolDS::DoNASCO(Molecule* molecule, bool* runsNormally) const{ | ||
208 | 213 | } |
209 | 214 | catch(MolDSException ex){ |
210 | 215 | this->OutputLog(boost::format("%s\n") % ex.what()); |
216 | + ex.PrintBacktrace(); | |
211 | 217 | *runsNormally = false; |
212 | 218 | } |
213 | 219 | } |
@@ -219,6 +225,7 @@ void MolDS::OptimizeGeometry(Molecule* molecule, bool* runsNormally) const{ | ||
219 | 225 | } |
220 | 226 | catch(MolDSException ex){ |
221 | 227 | this->OutputLog(boost::format("%s\n") % ex.what()); |
228 | + ex.PrintBacktrace(); | |
222 | 229 | *runsNormally = false; |
223 | 230 | } |
224 | 231 | } |
@@ -229,6 +236,7 @@ void MolDS::DiagonalizePrincipalAxes(Molecule* molecule, bool* runsNormally) con | ||
229 | 236 | } |
230 | 237 | catch(MolDSException ex){ |
231 | 238 | this->OutputLog(boost::format("%s\n") % ex.what()); |
239 | + ex.PrintBacktrace(); | |
232 | 240 | *runsNormally = false; |
233 | 241 | } |
234 | 242 | } |
@@ -239,6 +247,7 @@ void MolDS::TranslateMolecule(Molecule* molecule, bool* runsNormally) const{ | ||
239 | 247 | } |
240 | 248 | catch(MolDSException ex){ |
241 | 249 | this->OutputLog(boost::format("%s\n") % ex.what()); |
250 | + ex.PrintBacktrace(); | |
242 | 251 | *runsNormally = false; |
243 | 252 | } |
244 | 253 | } |
@@ -249,6 +258,7 @@ void MolDS::RotateMolecule(Molecule* molecule, bool* runsNormally) const{ | ||
249 | 258 | } |
250 | 259 | catch(MolDSException ex){ |
251 | 260 | this->OutputLog(boost::format("%s\n") % ex.what()); |
261 | + ex.PrintBacktrace(); | |
252 | 262 | *runsNormally = false; |
253 | 263 | } |
254 | 264 | } |
@@ -16,20 +16,35 @@ | ||
16 | 16 | // You should have received a copy of the GNU General Public License // |
17 | 17 | // along with MolDS. If not, see <http://www.gnu.org/licenses/>. // |
18 | 18 | //************************************************************************// |
19 | +#include<execinfo.h> | |
19 | 20 | #include<string> |
20 | 21 | #include<stdexcept> |
21 | 22 | #include<boost/format.hpp> |
22 | 23 | #include"MolDSException.h" |
23 | 24 | using namespace std; |
24 | 25 | 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); | |
26 | 28 | } |
27 | 29 | |
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); | |
29 | 32 | } |
30 | -} | |
31 | - | |
32 | - | |
33 | 33 | |
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 | +} | |
34 | 41 | |
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 | +} | |
35 | 50 |
@@ -18,6 +18,7 @@ | ||
18 | 18 | //************************************************************************// |
19 | 19 | #ifndef INCLUDED_MOLDSEXCEPTION |
20 | 20 | #define INCLUDED_MOLDSEXCEPTION |
21 | +#include<boost/shared_array.hpp> | |
21 | 22 | namespace MolDS_base{ |
22 | 23 | class MolDSException : public std::domain_error { |
23 | 24 | public: |
@@ -25,7 +26,12 @@ public: | ||
25 | 26 | #ifdef BOOST_FORMAT_HPP |
26 | 27 | MolDSException(const boost::format& cause); |
27 | 28 | #endif |
29 | + ~MolDSException() throw(){}; | |
30 | + void PrintBacktrace(); | |
28 | 31 | private: |
32 | + void GetBacktrace(int bufsize); | |
33 | + size_t backtraceSize; | |
34 | + boost::shared_array<void*> backtracePtr; | |
29 | 35 | }; |
30 | 36 | } |
31 | 37 | #endif |