libfoedus-core
FOEDUS Core Library
assert_nd.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #include "foedus/assert_nd.hpp"
19 
20 #include <iostream>
21 #include <sstream>
22 #include <string>
23 #include <vector>
24 
26 
27 namespace foedus {
28 std::string print_assert(const char* file, const char* func, int line, const char* description) {
29  std::stringstream str;
30  str << "***************************************************************************" << std::endl;
31  str << "**** Assertion failed! \"" << description
32  << "\" did not hold in " << func << "(): " << file << ":" << line << std::endl;
33  str << "***************************************************************************" << std::endl;
34  return str.str();
35 }
36 
37 std::string print_backtrace() {
38  std::vector<std::string> traces = assorted::get_backtrace(true);
39  std::stringstream str;
40  str << "=== Stack frame (length=" << traces.size() << ")" << std::endl;
41  for (uint16_t i = 0; i < traces.size(); ++i) {
42  str << "- [" << i << "/" << traces.size() << "] " << traces[i] << std::endl;
43  }
44  return str.str();
45 }
46 
51 
52 void print_assert_backtrace(const char* file, const char* func, int line, const char* description) {
53  std::string message = print_assert(file, func, line, description);
54  message += print_backtrace();
55  static_recent_assert_backtrace += message;
56  std::cerr << message;
57 }
58 
59 
62 }
63 
64 } // namespace foedus
std::string get_recent_assert_backtrace()
Retrieves the info left by print_assert_backtrace().
Definition: assert_nd.cpp:60
std::string print_assert(const char *file, const char *func, int line, const char *description)
Helper function to report what assertion failed.
Definition: assert_nd.cpp:28
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
std::vector< std::string > get_backtrace(bool rich=true)
Returns the backtrace information of the current stack.
void print_assert_backtrace(const char *file, const char *func, int line, const char *description)
print_assert() + print_backtrace().
Definition: assert_nd.cpp:52
std::string static_recent_assert_backtrace
Leaves recent crash information in a static global variable so that a signal handler can pick it...
Definition: assert_nd.cpp:50
std::string print_backtrace()
Prints out backtrace.
Definition: assert_nd.cpp:37