2008-02-06 13:27:49 +09:00
|
|
|
/**************************************************************************
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2008 VMware, Inc.
|
2008-02-06 13:27:49 +09:00
|
|
|
* All Rights Reserved.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-02-06 13:27:49 +09:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* 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
|
|
|
|
|
* the following conditions:
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-02-06 13:27:49 +09:00
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
|
* of the Software.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-02-06 13:27:49 +09:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
2008-02-06 13:27:49 +09:00
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-02-06 13:27:49 +09:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file
|
|
|
|
|
* Cross-platform debugging helpers.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* @author Jose Fonseca <jfonseca@vmware.com>
|
2008-02-06 13:27:49 +09:00
|
|
|
*/
|
|
|
|
|
|
2009-02-18 12:05:26 +00:00
|
|
|
#ifndef U_DEBUG_H_
|
|
|
|
|
#define U_DEBUG_H_
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2020-03-25 23:44:59 -04:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <string.h>
|
2020-12-01 10:16:36 -08:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-10-29 11:21:07 -07:00
|
|
|
#include "util/os_misc.h"
|
2022-09-24 15:28:52 +08:00
|
|
|
#include "util/u_atomic.h"
|
2019-08-01 22:36:30 +01:00
|
|
|
#include "util/detect_os.h"
|
2020-03-25 23:44:59 -04:00
|
|
|
#include "util/macros.h"
|
2017-02-22 16:01:24 +00:00
|
|
|
|
2019-08-01 22:36:30 +01:00
|
|
|
#if DETECT_OS_HAIKU
|
2015-11-25 20:43:03 +00:00
|
|
|
/* Haiku provides debug_printf in libroot with OS.h */
|
|
|
|
|
#include <OS.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-31 15:32:36 +08:00
|
|
|
#ifdef __cplusplus
|
2008-02-06 13:27:49 +09:00
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-30 06:10:25 +08:00
|
|
|
enum util_debug_type
|
|
|
|
|
{
|
|
|
|
|
UTIL_DEBUG_TYPE_OUT_OF_MEMORY = 1,
|
|
|
|
|
UTIL_DEBUG_TYPE_ERROR,
|
|
|
|
|
UTIL_DEBUG_TYPE_SHADER_INFO,
|
|
|
|
|
UTIL_DEBUG_TYPE_PERF_INFO,
|
|
|
|
|
UTIL_DEBUG_TYPE_INFO,
|
|
|
|
|
UTIL_DEBUG_TYPE_FALLBACK,
|
|
|
|
|
UTIL_DEBUG_TYPE_CONFORMANCE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Structure that contains a callback for debug messages from the driver back
|
|
|
|
|
* to the gallium frontend.
|
|
|
|
|
*/
|
|
|
|
|
struct util_debug_callback
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* When set to \c true, the callback may be called asynchronously from a
|
|
|
|
|
* driver-created thread.
|
|
|
|
|
*/
|
|
|
|
|
bool async;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Callback for the driver to report debug/performance/etc information back
|
|
|
|
|
* to the gallium frontend.
|
|
|
|
|
*
|
|
|
|
|
* \param data user-supplied data pointer
|
|
|
|
|
* \param id message type identifier, if pointed value is 0, then a
|
|
|
|
|
* new id is assigned
|
|
|
|
|
* \param type UTIL_DEBUG_TYPE_*
|
|
|
|
|
* \param format printf-style format string
|
|
|
|
|
* \param args args for format string
|
|
|
|
|
*/
|
|
|
|
|
void (*debug_message)(void *data,
|
|
|
|
|
unsigned *id,
|
|
|
|
|
enum util_debug_type type,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
va_list args);
|
|
|
|
|
void *data;
|
|
|
|
|
};
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2020-11-21 13:34:18 +01:00
|
|
|
#define _util_printf_format(fmt, list) PRINTFLIKE(fmt, list)
|
2008-05-28 16:12:14 +09:00
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
void _debug_vprintf(const char *format, va_list ap);
|
2022-03-18 13:14:55 +08:00
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline void
|
2008-03-24 20:18:59 +00:00
|
|
|
_debug_printf(const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
_debug_vprintf(format, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-08 16:29:12 +00:00
|
|
|
/**
|
|
|
|
|
* Print debug messages.
|
|
|
|
|
*
|
2009-09-21 17:28:37 +02:00
|
|
|
* The actual channel used to output debug message is platform specific. To
|
|
|
|
|
* avoid misformating or truncation, follow these rules of thumb:
|
2008-03-08 16:29:12 +00:00
|
|
|
* - output whole lines
|
2009-09-21 17:28:37 +02:00
|
|
|
* - avoid outputing large strings (512 bytes is the current maximum length
|
2008-03-08 16:29:12 +00:00
|
|
|
* that is guaranteed to be printed in all platforms)
|
|
|
|
|
*/
|
2019-08-01 22:36:30 +01:00
|
|
|
#if !DETECT_OS_HAIKU
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline void
|
2009-09-21 17:28:37 +02:00
|
|
|
debug_printf(const char *format, ...) _util_printf_format(1,2);
|
|
|
|
|
|
2015-07-20 19:58:43 -04:00
|
|
|
static inline void
|
2008-03-24 20:18:59 +00:00
|
|
|
debug_printf(const char *format, ...)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, format);
|
|
|
|
|
_debug_vprintf(format, ap);
|
|
|
|
|
va_end(ap);
|
2008-03-27 15:27:31 -06:00
|
|
|
#else
|
|
|
|
|
(void) format; /* silence warning */
|
2008-03-24 20:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
2012-01-03 08:10:42 -07:00
|
|
|
#endif
|
2008-03-24 20:18:59 +00:00
|
|
|
|
|
|
|
|
|
2009-04-24 23:45:16 +02:00
|
|
|
/*
|
|
|
|
|
* ... isn't portable so we need to pass arguments in parentheses.
|
|
|
|
|
*
|
|
|
|
|
* usage:
|
2012-02-06 17:56:43 -07:00
|
|
|
* debug_printf_once(("answer: %i\n", 42));
|
2009-04-24 23:45:16 +02:00
|
|
|
*/
|
|
|
|
|
#define debug_printf_once(args) \
|
|
|
|
|
do { \
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool once = true; \
|
2009-04-24 23:45:16 +02:00
|
|
|
if (once) { \
|
2019-08-09 16:14:38 +03:00
|
|
|
once = false; \
|
2009-04-24 23:45:16 +02:00
|
|
|
debug_printf args; \
|
|
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_vprintf(_format, _ap) _debug_vprintf(_format, _ap)
|
|
|
|
|
#else
|
|
|
|
|
#define debug_vprintf(_format, _ap) ((void)0)
|
|
|
|
|
#endif
|
2008-02-07 01:07:49 +09:00
|
|
|
|
2022-03-21 11:43:54 +01:00
|
|
|
#ifdef _WIN32
|
2014-06-03 18:08:34 +01:00
|
|
|
/**
|
2022-03-21 11:43:54 +01:00
|
|
|
* Disable Win32 interactive error message boxes.
|
2014-06-03 18:08:34 +01:00
|
|
|
*
|
|
|
|
|
* Should be called as soon as possible for effectiveness.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2022-03-21 11:43:54 +01:00
|
|
|
debug_disable_win32_error_dialogs(void);
|
|
|
|
|
#endif
|
2014-06-03 18:08:34 +01:00
|
|
|
|
|
|
|
|
|
2008-03-08 16:29:12 +00:00
|
|
|
/**
|
2008-03-24 20:18:59 +00:00
|
|
|
* Hard-coded breakpoint.
|
2008-03-08 16:29:12 +00:00
|
|
|
*/
|
2008-03-24 20:18:59 +00:00
|
|
|
#ifdef DEBUG
|
2010-02-03 12:13:06 +00:00
|
|
|
#define debug_break() os_break()
|
2008-03-24 20:18:59 +00:00
|
|
|
#else /* !DEBUG */
|
|
|
|
|
#define debug_break() ((void)0)
|
|
|
|
|
#endif /* !DEBUG */
|
2008-02-07 01:07:49 +09:00
|
|
|
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2008-03-24 18:49:56 -06:00
|
|
|
long
|
|
|
|
|
debug_get_num_option(const char *name, long dfault);
|
|
|
|
|
|
2020-11-10 09:56:21 +10:00
|
|
|
void
|
|
|
|
|
debug_get_version_option(const char *name, unsigned *major, unsigned *minor);
|
|
|
|
|
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
/**
|
|
|
|
|
* Output the current function name.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_checkpoint() \
|
|
|
|
|
_debug_printf("%s\n", __FUNCTION__)
|
|
|
|
|
#else
|
|
|
|
|
#define debug_checkpoint() \
|
2022-03-18 13:14:55 +08:00
|
|
|
((void)0)
|
2008-03-24 20:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output the full source code position.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_checkpoint_full() \
|
2011-05-16 21:53:06 +02:00
|
|
|
_debug_printf("%s:%u:%s\n", __FILE__, __LINE__, __FUNCTION__)
|
2008-03-24 20:18:59 +00:00
|
|
|
#else
|
|
|
|
|
#define debug_checkpoint_full() \
|
2022-03-18 13:14:55 +08:00
|
|
|
((void)0)
|
2008-03-24 20:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Output a warning message. Muted on release version.
|
|
|
|
|
*/
|
2008-03-18 11:49:02 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_warning(__msg) \
|
2008-03-25 17:47:39 +00:00
|
|
|
_debug_printf("%s:%u:%s: warning: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
|
2008-03-18 11:49:02 +00:00
|
|
|
#else
|
|
|
|
|
#define debug_warning(__msg) \
|
2022-03-18 13:14:55 +08:00
|
|
|
((void)0)
|
2008-03-18 11:49:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2012-01-07 14:16:27 -07:00
|
|
|
/**
|
|
|
|
|
* Emit a warning message, but only once.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_warn_once(__msg) \
|
|
|
|
|
do { \
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool warned = false; \
|
2012-01-07 14:16:27 -07:00
|
|
|
if (!warned) { \
|
|
|
|
|
_debug_printf("%s:%u:%s: one time warning: %s\n", \
|
|
|
|
|
__FILE__, __LINE__, __FUNCTION__, __msg); \
|
2019-08-09 16:14:38 +03:00
|
|
|
warned = true; \
|
2012-01-07 14:16:27 -07:00
|
|
|
} \
|
|
|
|
|
} while (0)
|
|
|
|
|
#else
|
|
|
|
|
#define debug_warn_once(__msg) \
|
2022-03-18 13:14:55 +08:00
|
|
|
((void)0)
|
2012-01-07 14:16:27 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
/**
|
|
|
|
|
* Output an error message. Not muted on release version.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
#define debug_error(__msg) \
|
2022-03-18 13:14:55 +08:00
|
|
|
_debug_printf("%s:%u:%s: error: %s\n", __FILE__, __LINE__, __FUNCTION__, __msg)
|
2008-03-24 20:18:59 +00:00
|
|
|
#else
|
|
|
|
|
#define debug_error(__msg) \
|
2008-03-25 17:47:39 +00:00
|
|
|
_debug_printf("error: %s\n", __msg)
|
2008-03-24 20:18:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
2015-10-30 03:17:35 -04:00
|
|
|
/**
|
|
|
|
|
* Output a debug log message to the debug info callback.
|
|
|
|
|
*/
|
2022-03-31 04:21:45 +08:00
|
|
|
#define util_debug_message(cb, type, fmt, ...) do { \
|
2015-10-30 03:17:35 -04:00
|
|
|
static unsigned id = 0; \
|
2015-12-04 17:44:29 -07:00
|
|
|
if ((cb) && (cb)->debug_message) { \
|
2022-03-31 04:21:45 +08:00
|
|
|
_util_debug_message(cb, &id, \
|
2022-03-31 04:23:56 +08:00
|
|
|
UTIL_DEBUG_TYPE_ ## type, \
|
2015-12-04 17:44:29 -07:00
|
|
|
fmt, ##__VA_ARGS__); \
|
|
|
|
|
} \
|
2015-10-30 03:17:35 -04:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
void
|
2022-03-31 04:21:45 +08:00
|
|
|
_util_debug_message(
|
2022-03-31 04:22:26 +08:00
|
|
|
struct util_debug_callback *cb,
|
2015-10-30 03:17:35 -04:00
|
|
|
unsigned *id,
|
2022-03-31 04:23:16 +08:00
|
|
|
enum util_debug_type type,
|
2015-10-30 03:17:35 -04:00
|
|
|
const char *fmt, ...) _util_printf_format(4, 5);
|
|
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
/**
|
|
|
|
|
* Used by debug_dump_enum and debug_dump_flags to describe symbols.
|
|
|
|
|
*/
|
|
|
|
|
struct debug_named_value
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
2015-07-25 15:55:45 +02:00
|
|
|
uint64_t value;
|
2010-06-01 20:11:02 +02:00
|
|
|
const char *desc;
|
2008-03-19 16:41:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Some C pre-processor magic to simplify creating named values.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-03-19 16:41:07 +00:00
|
|
|
* Example:
|
|
|
|
|
* @code
|
|
|
|
|
* static const debug_named_value my_names[] = {
|
|
|
|
|
* DEBUG_NAMED_VALUE(MY_ENUM_VALUE_X),
|
|
|
|
|
* DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Y),
|
|
|
|
|
* DEBUG_NAMED_VALUE(MY_ENUM_VALUE_Z),
|
|
|
|
|
* DEBUG_NAMED_VALUE_END
|
|
|
|
|
* };
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-03-19 16:41:07 +00:00
|
|
|
* ...
|
2022-03-18 13:14:55 +08:00
|
|
|
* debug_printf("%s = %s\n",
|
2008-03-19 16:41:07 +00:00
|
|
|
* name,
|
|
|
|
|
* debug_dump_enum(my_names, my_value));
|
|
|
|
|
* ...
|
|
|
|
|
* @endcode
|
|
|
|
|
*/
|
2012-11-13 10:23:11 +00:00
|
|
|
#define DEBUG_NAMED_VALUE(__symbol) {#__symbol, (unsigned long)__symbol, NULL}
|
2010-06-01 20:11:02 +02:00
|
|
|
#define DEBUG_NAMED_VALUE_WITH_DESCRIPTION(__symbol, __desc) {#__symbol, (unsigned long)__symbol, __desc}
|
|
|
|
|
#define DEBUG_NAMED_VALUE_END {NULL, 0, NULL}
|
2008-03-19 16:41:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert a enum value to a string.
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2022-03-18 13:14:55 +08:00
|
|
|
debug_dump_enum(const struct debug_named_value *names,
|
2008-03-19 16:41:07 +00:00
|
|
|
unsigned long value);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert binary flags value to a string.
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
2022-03-18 13:14:55 +08:00
|
|
|
debug_dump_flags(const struct debug_named_value *names,
|
2008-03-19 16:41:07 +00:00
|
|
|
unsigned long value);
|
|
|
|
|
|
|
|
|
|
|
2022-11-01 05:59:26 +08:00
|
|
|
struct debug_control {
|
|
|
|
|
const char * string;
|
|
|
|
|
uint64_t flag;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
parse_debug_string(const char *debug,
|
|
|
|
|
const struct debug_control *control);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
parse_enable_string(const char *debug,
|
|
|
|
|
uint64_t default_value,
|
|
|
|
|
const struct debug_control *control);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
comma_separated_list_contains(const char *list, const char *s);
|
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
/**
|
|
|
|
|
* Get option.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2022-08-25 09:28:15 +08:00
|
|
|
* It is an alias for getenv on Unix and Windows.
|
2022-03-18 13:14:55 +08:00
|
|
|
*
|
2008-03-24 22:30:33 +00:00
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
debug_get_option(const char *name, const char *dfault);
|
|
|
|
|
|
2019-08-09 16:14:38 +03:00
|
|
|
bool
|
|
|
|
|
debug_get_bool_option(const char *name, bool dfault);
|
2008-03-24 22:30:33 +00:00
|
|
|
|
|
|
|
|
long
|
2008-06-10 23:22:12 +09:00
|
|
|
debug_get_num_option(const char *name, long dfault);
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2015-07-25 15:55:45 +02:00
|
|
|
uint64_t
|
2022-03-18 13:14:55 +08:00
|
|
|
debug_get_flags_option(const char *name,
|
2008-03-24 22:30:33 +00:00
|
|
|
const struct debug_named_value *flags,
|
2015-07-25 15:55:45 +02:00
|
|
|
uint64_t dfault);
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2015-12-21 16:11:37 -05:00
|
|
|
#define DEBUG_GET_ONCE_OPTION(suffix, name, dfault) \
|
|
|
|
|
static const char * \
|
|
|
|
|
debug_get_option_ ## suffix (void) \
|
|
|
|
|
{ \
|
2022-06-09 14:11:44 -04:00
|
|
|
static bool initialized = false; \
|
2020-11-24 23:35:08 +01:00
|
|
|
static const char * value; \
|
2022-09-24 15:28:52 +08:00
|
|
|
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
|
2020-11-24 23:35:08 +01:00
|
|
|
value = debug_get_option(name, dfault); \
|
2022-09-24 15:28:52 +08:00
|
|
|
p_atomic_set(&initialized, true); \
|
2020-11-24 23:35:08 +01:00
|
|
|
} \
|
|
|
|
|
return value; \
|
2015-12-21 16:11:37 -05:00
|
|
|
}
|
|
|
|
|
|
2020-12-01 10:16:36 -08:00
|
|
|
static inline bool
|
|
|
|
|
__check_suid(void)
|
|
|
|
|
{
|
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
|
if (geteuid() != getuid())
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-22 18:19:39 +01:00
|
|
|
#define DEBUG_GET_ONCE_BOOL_OPTION(sufix, name, dfault) \
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool \
|
2010-04-22 18:19:39 +01:00
|
|
|
debug_get_option_ ## sufix (void) \
|
|
|
|
|
{ \
|
2022-06-09 14:11:44 -04:00
|
|
|
static bool initialized = false; \
|
2020-11-24 23:35:08 +01:00
|
|
|
static bool value; \
|
2022-09-24 15:28:52 +08:00
|
|
|
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
|
2020-11-24 23:35:08 +01:00
|
|
|
value = debug_get_bool_option(name, dfault); \
|
2022-09-24 15:28:52 +08:00
|
|
|
p_atomic_set(&initialized, true); \
|
2020-11-24 23:35:08 +01:00
|
|
|
} \
|
|
|
|
|
return value; \
|
2010-04-22 18:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DEBUG_GET_ONCE_NUM_OPTION(sufix, name, dfault) \
|
|
|
|
|
static long \
|
|
|
|
|
debug_get_option_ ## sufix (void) \
|
|
|
|
|
{ \
|
2022-06-09 14:11:44 -04:00
|
|
|
static bool initialized = false; \
|
2020-11-24 23:35:08 +01:00
|
|
|
static long value; \
|
2022-09-24 15:28:52 +08:00
|
|
|
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
|
2020-11-24 23:35:08 +01:00
|
|
|
value = debug_get_num_option(name, dfault); \
|
2022-09-24 15:28:52 +08:00
|
|
|
p_atomic_set(&initialized, true); \
|
2020-11-24 23:35:08 +01:00
|
|
|
} \
|
|
|
|
|
return value; \
|
2010-04-22 18:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define DEBUG_GET_ONCE_FLAGS_OPTION(sufix, name, flags, dfault) \
|
|
|
|
|
static unsigned long \
|
|
|
|
|
debug_get_option_ ## sufix (void) \
|
|
|
|
|
{ \
|
2022-06-09 14:11:44 -04:00
|
|
|
static bool initialized = false; \
|
2020-11-24 23:35:08 +01:00
|
|
|
static unsigned long value; \
|
2022-09-24 15:28:52 +08:00
|
|
|
if (unlikely(!p_atomic_read_relaxed(&initialized))) { \
|
2020-11-24 23:35:08 +01:00
|
|
|
value = debug_get_flags_option(name, flags, dfault); \
|
2022-09-24 15:28:52 +08:00
|
|
|
p_atomic_set(&initialized, true); \
|
2020-11-24 23:35:08 +01:00
|
|
|
} \
|
|
|
|
|
return value; \
|
2010-04-22 18:19:39 +01:00
|
|
|
}
|
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2022-03-31 15:32:36 +08:00
|
|
|
#ifdef __cplusplus
|
2008-02-06 13:27:49 +09:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-02-18 12:05:26 +00:00
|
|
|
#endif /* U_DEBUG_H_ */
|