1 /* 2 Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 14 15 This program is distributed in the hope that it will be useful, 16 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 GNU General Public License, version 2.0, for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */ 24 /* 25 * helpers.hpp 26 */ 27 28 #ifndef helpers_hpp 29 #define helpers_hpp 30 31 //#include <cstdio> 32 #include <cstdlib> 33 #include <iostream> 34 #include <cstring> 35 36 //using namespace std; 37 using std::cout; 38 using std::endl; 39 using std::flush; 40 41 /************************************************************ 42 * Helper Macros & Functions 43 ************************************************************/ 44 45 // JNI crashes with gcc & operator<<(ostream &, long/int) 46 // so, we use C99's __func__ and also convert to string using sprintf() 47 #define ABORT_ERROR(message) \ 48 do { \ 49 char l[1024]; \ 50 sprintf(l, "%d", __LINE__); \ 51 cout << "!!! error, file: " << (__FILE__) \ 52 << ", function: " << (__func__) \ 53 << ", line: " << l \ 54 << ", msg: " << message << "." << endl; \ 55 exit(-1); \ 56 } while (0) 57 58 // an output stream for debug messages 59 #if DEBUG 60 #define CDBG if (0); else cout 61 #else 62 #define CDBG if (1); else cout 63 #endif 64 65 // some macros for tracing 66 #define ENTER(name) \ 67 CDBG << "--> " << name << endl; 68 69 #define LEAVE(name) \ 70 CDBG << "<-- " << name << endl; 71 72 #define TRACE(name) \ 73 Tracer _tracer_(name); 74 75 // use as: 76 // myfunction() { 77 // TRACE("myfunction()"); 78 // ... 79 // } 80 class Tracer 81 { 82 const char* const name; 83 public: Tracer(const char * name)84 Tracer(const char* name) : name(name) { 85 ENTER(name); 86 } 87 ~Tracer()88 ~Tracer() { 89 LEAVE(name); 90 } 91 }; 92 93 #endif // helpers_hpp 94