debug.hpp revision 0
0N/A/*
3239N/A * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1472N/A * CA 95054 USA or visit www.sun.com if you need additional information or
1472N/A * have any questions.
0N/A *
0N/A */
0N/A
1879N/A// assertions
1879N/A#ifdef ASSERT
1879N/A// Turn this off by default:
1879N/A//#define USE_REPEATED_ASSERTS
1879N/A#ifdef USE_REPEATED_ASSERTS
1879N/A #define assert(p,msg) \
1879N/A { for (int __i = 0; __i < AssertRepeat; __i++) { \
1879N/A if (!(p)) { \
1879N/A report_assertion_failure(__FILE__, __LINE__, \
1879N/A "assert(" XSTR(p) ",\"" msg "\")");\
1879N/A BREAKPOINT; \
1879N/A } \
1879N/A } \
1879N/A }
1879N/A#else
1879N/A #define assert(p,msg) \
1879N/A if (!(p)) { \
0N/A report_assertion_failure(__FILE__, __LINE__, \
0N/A "assert(" XSTR(p) ",\"" msg "\")");\
0N/A BREAKPOINT; \
0N/A }
0N/A#endif
0N/A
0N/A// This version of assert is for use with checking return status from
0N/A// library calls that return actual error values eg. EINVAL,
0N/A// ENOMEM etc, rather than returning -1 and setting errno.
0N/A// When the status is not what is expected it is very useful to know
0N/A// what status was actually returned, so we pass the status variable as
0N/A// an extra arg and use strerror to convert it to a meaningful string
0N/A// like "Invalid argument", "out of memory" etc
0N/A#define assert_status(p, status, msg) \
0N/A do { \
0N/A if (!(p)) { \
0N/A char buf[128]; \
0N/A snprintf(buf, 127, \
0N/A "assert_status(" XSTR(p) ", error: %s(%d), \"" msg "\")" , \
295N/A strerror((status)), (status)); \
0N/A report_assertion_failure(__FILE__, __LINE__, buf); \
0N/A BREAKPOINT; \
0N/A } \
0N/A } while (0)
0N/A
0N/A// Another version of assert where the message is not a string literal
0N/A// The boolean condition is not printed out because cpp doesn't like it.
0N/A#define assert_msg(p, msg) \
0N/A if (!(p)) { \
0N/A report_assertion_failure(__FILE__, __LINE__, msg); \
0N/A BREAKPOINT; \
0N/A }
0N/A
0N/A// Do not assert this condition if there's already another error reported.
0N/A#define assert_if_no_error(cond,msg) assert((cond) || is_error_reported(), msg)
0N/A#else
0N/A #define assert(p,msg)
0N/A #define assert_status(p,status,msg)
0N/A #define assert_if_no_error(cond,msg)
0N/A #define assert_msg(cond,msg)
0N/A#endif
0N/A
0N/A
0N/A// fatals
0N/A#define fatal(m) { report_fatal(__FILE__, __LINE__, m ); BREAKPOINT; }
0N/A#define fatal1(m,x1) { report_fatal_vararg(__FILE__, __LINE__, m, x1 ); BREAKPOINT; }
0N/A#define fatal2(m,x1,x2) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2 ); BREAKPOINT; }
0N/A#define fatal3(m,x1,x2,x3) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3 ); BREAKPOINT; }
0N/A#define fatal4(m,x1,x2,x3,x4) { report_fatal_vararg(__FILE__, __LINE__, m, x1, x2, x3, x4 ); BREAKPOINT; }
0N/A
0N/A// out of memory
0N/A#define vm_exit_out_of_memory(s,m) { report_vm_out_of_memory(__FILE__, __LINE__, s, m ); BREAKPOINT; }
0N/A#define vm_exit_out_of_memory1(s,m,x1) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1 ); BREAKPOINT; }
0N/A#define vm_exit_out_of_memory2(s,m,x1,x2) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2 ); BREAKPOINT; }
0N/A#define vm_exit_out_of_memory3(s,m,x1,x2,x3) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3 ); BREAKPOINT; }
0N/A#define vm_exit_out_of_memory4(s,m,x1,x2,x3,x4) { report_vm_out_of_memory_vararg(__FILE__, __LINE__, s, m, x1, x2, x3, x4); BREAKPOINT; }
0N/A
0N/A// guarantee is like assert except it's always executed -- use it for
0N/A// cheap tests that catch errors that would otherwise be hard to find
0N/A// guarantee is also used for Verify options.
0N/A#define guarantee(b,msg) { if (!(b)) fatal("guarantee(" XSTR(b) ",\"" msg "\")"); }
0N/A
0N/A#define ShouldNotCallThis() { report_should_not_call (__FILE__, __LINE__); BREAKPOINT; }
0N/A#define ShouldNotReachHere() { report_should_not_reach_here (__FILE__, __LINE__); BREAKPOINT; }
0N/A#define Unimplemented() { report_unimplemented (__FILE__, __LINE__); BREAKPOINT; }
0N/A#define Untested(msg) { report_untested (__FILE__, __LINE__, msg); BREAKPOINT; }
0N/A
0N/A// error reporting helper functions
0N/Avoid report_assertion_failure(const char* file_name, int line_no, const char* message);
0N/Avoid report_fatal_vararg(const char* file_name, int line_no, const char* format, ...);
0N/Avoid report_fatal(const char* file_name, int line_no, const char* message);
0N/Avoid report_vm_out_of_memory_vararg(const char* file_name, int line_no, size_t size, const char* format, ...);
0N/Avoid report_vm_out_of_memory(const char* file_name, int line_no, size_t size, const char* message);
0N/Avoid report_should_not_call(const char* file_name, int line_no);
0N/Avoid report_should_not_reach_here(const char* file_name, int line_no);
0N/Avoid report_unimplemented(const char* file_name, int line_no);
0N/Avoid report_untested(const char* file_name, int line_no, const char* msg);
0N/Avoid warning(const char* format, ...);
0N/A
0N/A// out of memory reporting
0N/Avoid report_java_out_of_memory(const char* message);
0N/A
0N/A// Support for self-destruct
0N/Abool is_error_reported();
0N/Avoid set_error_reported();
0N/A
0N/Avoid pd_ps(frame f);
0N/Avoid pd_obfuscate_location(char *buf, size_t buflen);
0N/A