|
|
@ -1,8 +1,8 @@ |
|
|
|
/**************************************************************************
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* |
|
|
|
* Copyright 2008 VMware, Inc. |
|
|
|
* Copyright 2008 VMware, Inc. |
|
|
|
* All Rights Reserved. |
|
|
|
* All Rights Reserved. |
|
|
|
*
|
|
|
|
* |
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
|
|
* copy of this software and associated documentation files (the |
|
|
|
* copy of this software and associated documentation files (the |
|
|
|
* "Software"), to deal in the Software without restriction, including |
|
|
|
* "Software"), to deal in the Software without restriction, including |
|
|
@ -10,11 +10,11 @@ |
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to |
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to |
|
|
|
* permit persons to whom the Software is furnished to do so, subject to |
|
|
|
* permit persons to whom the Software is furnished to do so, subject to |
|
|
|
* the following conditions: |
|
|
|
* the following conditions: |
|
|
|
*
|
|
|
|
* |
|
|
|
* The above copyright notice and this permission notice (including the |
|
|
|
* The above copyright notice and this permission notice (including the |
|
|
|
* next paragraph) shall be included in all copies or substantial portions |
|
|
|
* next paragraph) shall be included in all copies or substantial portions |
|
|
|
* of the Software. |
|
|
|
* of the Software. |
|
|
|
*
|
|
|
|
* |
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
|
|
@ -22,16 +22,16 @@ |
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
|
|
*
|
|
|
|
* |
|
|
|
**************************************************************************/ |
|
|
|
**************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @file |
|
|
|
* @file |
|
|
|
* Cross-platform debugging helpers. |
|
|
|
* Cross-platform debugging helpers. |
|
|
|
*
|
|
|
|
* |
|
|
|
* For now it just has assert and printf replacements, but it might be extended
|
|
|
|
* For now it just has assert and printf replacements, but it might be extended |
|
|
|
* with stack trace reports and more advanced logging in the near future.
|
|
|
|
* with stack trace reports and more advanced logging in the near future. |
|
|
|
*
|
|
|
|
* |
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com> |
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
@ -62,7 +62,7 @@ extern "C" { |
|
|
|
#define _util_printf_format(fmt, list) PRINTFLIKE(fmt, list) |
|
|
|
#define _util_printf_format(fmt, list) PRINTFLIKE(fmt, list) |
|
|
|
|
|
|
|
|
|
|
|
void _debug_vprintf(const char *format, va_list ap); |
|
|
|
void _debug_vprintf(const char *format, va_list ap); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline void |
|
|
|
static inline void |
|
|
|
_debug_printf(const char *format, ...) |
|
|
|
_debug_printf(const char *format, ...) |
|
|
@ -164,9 +164,9 @@ debug_get_version_option(const char *name, unsigned *major, unsigned *minor); |
|
|
|
#ifdef _MSC_VER |
|
|
|
#ifdef _MSC_VER |
|
|
|
__declspec(noreturn) |
|
|
|
__declspec(noreturn) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
void _debug_assert_fail(const char *expr,
|
|
|
|
void _debug_assert_fail(const char *expr, |
|
|
|
const char *file,
|
|
|
|
const char *file, |
|
|
|
unsigned line,
|
|
|
|
unsigned line, |
|
|
|
const char *function) |
|
|
|
const char *function) |
|
|
|
#if defined(__GNUC__) && !defined(DEBUG) |
|
|
|
#if defined(__GNUC__) && !defined(DEBUG) |
|
|
|
__attribute__((noreturn)) |
|
|
|
__attribute__((noreturn)) |
|
|
@ -174,10 +174,10 @@ void _debug_assert_fail(const char *expr, |
|
|
|
; |
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Assert macro |
|
|
|
* Assert macro |
|
|
|
*
|
|
|
|
* |
|
|
|
* Do not expect that the assert call terminates -- errors must be handled
|
|
|
|
* Do not expect that the assert call terminates -- errors must be handled |
|
|
|
* regardless of assert behavior. |
|
|
|
* regardless of assert behavior. |
|
|
|
* |
|
|
|
* |
|
|
|
* For non debug builds the assert macro will expand to a no-op, so do not |
|
|
|
* For non debug builds the assert macro will expand to a no-op, so do not |
|
|
@ -205,7 +205,7 @@ void _debug_assert_fail(const char *expr, |
|
|
|
_debug_printf("%s\n", __FUNCTION__) |
|
|
|
_debug_printf("%s\n", __FUNCTION__) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define debug_checkpoint() \ |
|
|
|
#define debug_checkpoint() \ |
|
|
|
((void)0)
|
|
|
|
((void)0) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -217,7 +217,7 @@ void _debug_assert_fail(const char *expr, |
|
|
|
_debug_printf("%s:%u:%s\n", __FILE__, __LINE__, __FUNCTION__) |
|
|
|
_debug_printf("%s:%u:%s\n", __FILE__, __LINE__, __FUNCTION__) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define debug_checkpoint_full() \ |
|
|
|
#define debug_checkpoint_full() \ |
|
|
|
((void)0)
|
|
|
|
((void)0) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -229,7 +229,7 @@ void _debug_assert_fail(const char *expr, |
|
|
|
_debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) |
|
|
|
_debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define debug_warning(__msg) \ |
|
|
|
#define debug_warning(__msg) \ |
|
|
|
((void)0)
|
|
|
|
((void)0) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -248,7 +248,7 @@ void _debug_assert_fail(const char *expr, |
|
|
|
} while (0) |
|
|
|
} while (0) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define debug_warn_once(__msg) \ |
|
|
|
#define debug_warn_once(__msg) \ |
|
|
|
((void)0)
|
|
|
|
((void)0) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -257,7 +257,7 @@ void _debug_assert_fail(const char *expr, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
#ifdef DEBUG |
|
|
|
#ifdef DEBUG |
|
|
|
#define debug_error(__msg) \ |
|
|
|
#define debug_error(__msg) \ |
|
|
|
_debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
|
|
|
|
_debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg) |
|
|
|
#else |
|
|
|
#else |
|
|
|
#define debug_error(__msg) \ |
|
|
|
#define debug_error(__msg) \ |
|
|
|
_debug_printf("error: %s\n", __msg) |
|
|
|
_debug_printf("error: %s\n", __msg) |
|
|
@ -282,7 +282,7 @@ struct debug_named_value |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Some C pre-processor magic to simplify creating named values. |
|
|
|
* Some C pre-processor magic to simplify creating named values. |
|
|
|
*
|
|
|
|
* |
|
|
|
* Example: |
|
|
|
* Example: |
|
|
|
* @code |
|
|
|
* @code |
|
|
|
* static const debug_named_value my_names[] = { |
|
|
|
* static const debug_named_value my_names[] = { |
|
|
@ -291,9 +291,9 @@ struct debug_named_value |
|
|
|
* DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z), |
|
|
|
* DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z), |
|
|
|
* DEBUG_NAMED_VALUE_END |
|
|
|
* DEBUG_NAMED_VALUE_END |
|
|
|
* }; |
|
|
|
* }; |
|
|
|
*
|
|
|
|
* |
|
|
|
* ... |
|
|
|
* ... |
|
|
|
* debug_printf("%s = %s\n",
|
|
|
|
* debug_printf("%s = %s\n", |
|
|
|
* name, |
|
|
|
* name, |
|
|
|
* debug_dump_enum(my_names, my_value)); |
|
|
|
* debug_dump_enum(my_names, my_value)); |
|
|
|
* ... |
|
|
|
* ... |
|
|
@ -308,11 +308,11 @@ struct debug_named_value |
|
|
|
* Convert a enum value to a string. |
|
|
|
* Convert a enum value to a string. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const char * |
|
|
|
const char * |
|
|
|
debug_dump_enum(const struct debug_named_value *names,
|
|
|
|
debug_dump_enum(const struct debug_named_value *names, |
|
|
|
unsigned long value); |
|
|
|
unsigned long value); |
|
|
|
|
|
|
|
|
|
|
|
const char * |
|
|
|
const char * |
|
|
|
debug_dump_enum_noprefix(const struct debug_named_value *names,
|
|
|
|
debug_dump_enum_noprefix(const struct debug_named_value *names, |
|
|
|
const char *prefix, |
|
|
|
const char *prefix, |
|
|
|
unsigned long value); |
|
|
|
unsigned long value); |
|
|
|
|
|
|
|
|
|
|
@ -321,7 +321,7 @@ debug_dump_enum_noprefix(const struct debug_named_value *names, |
|
|
|
* Convert binary flags value to a string. |
|
|
|
* Convert binary flags value to a string. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const char * |
|
|
|
const char * |
|
|
|
debug_dump_flags(const struct debug_named_value *names,
|
|
|
|
debug_dump_flags(const struct debug_named_value *names, |
|
|
|
unsigned long value); |
|
|
|
unsigned long value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -364,14 +364,14 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file); |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get option. |
|
|
|
* Get option. |
|
|
|
*
|
|
|
|
* |
|
|
|
* It is an alias for getenv on Linux.
|
|
|
|
* It is an alias for getenv on Linux. |
|
|
|
*
|
|
|
|
* |
|
|
|
* On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line
|
|
|
|
* On Windows it reads C:\gallium.cfg, which is a text file with CR+LF line |
|
|
|
* endings with one option per line as |
|
|
|
* endings with one option per line as |
|
|
|
*
|
|
|
|
* |
|
|
|
* NAME=value |
|
|
|
* NAME=value |
|
|
|
*
|
|
|
|
* |
|
|
|
* This file must be terminated with an extra empty line. |
|
|
|
* This file must be terminated with an extra empty line. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const char * |
|
|
|
const char * |
|
|
@ -384,7 +384,7 @@ long |
|
|
|
debug_get_num_option(const char *name, long dfault); |
|
|
|
debug_get_num_option(const char *name, long dfault); |
|
|
|
|
|
|
|
|
|
|
|
uint64_t |
|
|
|
uint64_t |
|
|
|
debug_get_flags_option(const char *name,
|
|
|
|
debug_get_flags_option(const char *name, |
|
|
|
const struct debug_named_value *flags, |
|
|
|
const struct debug_named_value *flags, |
|
|
|
uint64_t dfault); |
|
|
|
uint64_t dfault); |
|
|
|
|
|
|
|
|
|
|
|