2008-02-06 13:27:49 +09:00
|
|
|
/**************************************************************************
|
2016-02-08 09:29:38 -07: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-12-12 05:09:56 +01:00
|
|
|
* Copyright (c) 2008 VMware, Inc.
|
2008-02-06 13:27:49 +09:00
|
|
|
* All Rights Reserved.
|
2016-02-08 09:29:38 -07: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:
|
2016-02-08 09:29:38 -07: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.
|
2016-02-08 09:29:38 -07: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.
|
2016-02-08 09:29:38 -07:00
|
|
|
*
|
2008-02-06 13:27:49 +09:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
2022-08-31 01:26:04 +08:00
|
|
|
#include "util/u_atomic.h"
|
2016-02-08 09:29:38 -07:00
|
|
|
#include "util/u_debug.h"
|
|
|
|
|
#include "util/u_string.h"
|
|
|
|
|
#include "util/u_math.h"
|
2025-02-11 11:31:01 +01:00
|
|
|
#include "c11/threads.h"
|
2015-08-28 09:57:04 +10:00
|
|
|
#include <inttypes.h>
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2011-11-09 07:02:27 +00:00
|
|
|
#include <stdio.h>
|
2010-06-01 20:11:02 +02:00
|
|
|
#include <limits.h> /* CHAR_BIT */
|
2011-01-26 11:46:39 +01:00
|
|
|
#include <ctype.h> /* isalnum */
|
2008-02-06 13:27:49 +09:00
|
|
|
|
2014-06-03 18:08:34 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
void
|
|
|
|
|
_debug_vprintf(const char *format, va_list ap)
|
2008-02-06 13:27:49 +09:00
|
|
|
{
|
2012-05-22 09:32:50 -06:00
|
|
|
static char buf[4096] = {'\0'};
|
2022-11-06 05:19:31 +08:00
|
|
|
#if DETECT_OS_WINDOWS
|
2010-02-03 12:13:06 +00:00
|
|
|
/* We buffer until we find a newline. */
|
2008-06-23 16:24:58 -06:00
|
|
|
size_t len = strlen(buf);
|
2018-11-20 12:02:36 +00:00
|
|
|
int ret = vsnprintf(buf + len, sizeof(buf) - len, format, ap);
|
2018-11-20 11:51:35 +00:00
|
|
|
if (ret > (int)(sizeof(buf) - len - 1) || strchr(buf + len, '\n')) {
|
2011-01-13 11:45:40 +00:00
|
|
|
os_log_message(buf);
|
2008-06-23 16:24:58 -06:00
|
|
|
buf[0] = '\0';
|
|
|
|
|
}
|
2011-01-13 11:44:16 +00:00
|
|
|
#else
|
2018-11-20 12:02:36 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), format, ap);
|
2012-05-22 09:32:50 -06:00
|
|
|
os_log_message(buf);
|
2011-01-13 11:44:16 +00:00
|
|
|
#endif
|
2008-02-07 01:07:49 +09:00
|
|
|
}
|
|
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2015-10-30 03:17:35 -04:00
|
|
|
void
|
2022-03-31 04:22:26 +08:00
|
|
|
_util_debug_message(struct util_debug_callback *cb,
|
2016-02-08 09:29:38 -07:00
|
|
|
unsigned *id,
|
2022-03-31 04:23:16 +08:00
|
|
|
enum util_debug_type type,
|
2016-02-08 09:29:38 -07:00
|
|
|
const char *fmt, ...)
|
2015-10-30 03:17:35 -04:00
|
|
|
{
|
2023-04-19 09:20:36 -04:00
|
|
|
if (!cb || !cb->debug_message)
|
|
|
|
|
return;
|
2015-10-30 03:17:35 -04:00
|
|
|
va_list args;
|
|
|
|
|
va_start(args, fmt);
|
2023-04-19 09:20:36 -04:00
|
|
|
cb->debug_message(cb->data, id, type, fmt, args);
|
2015-10-30 03:17:35 -04:00
|
|
|
va_end(args);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
void
|
2022-03-21 11:43:54 +01:00
|
|
|
debug_disable_win32_error_dialogs(void)
|
2014-06-03 18:08:34 +01:00
|
|
|
{
|
|
|
|
|
/* When Windows' error message boxes are disabled for this process (as is
|
|
|
|
|
* typically the case when running tests in an automated fashion) we disable
|
|
|
|
|
* CRT message boxes too.
|
|
|
|
|
*/
|
|
|
|
|
UINT uMode = SetErrorMode(0);
|
|
|
|
|
SetErrorMode(uMode);
|
2023-01-11 10:43:59 -05:00
|
|
|
#ifndef _GAMING_XBOX
|
2014-06-03 18:08:34 +01:00
|
|
|
if (uMode & SEM_FAILCRITICALERRORS) {
|
|
|
|
|
/* Disable assertion failure message box.
|
|
|
|
|
* http://msdn.microsoft.com/en-us/library/sas1dkb2.aspx
|
|
|
|
|
*/
|
|
|
|
|
_set_error_mode(_OUT_TO_STDERR);
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
/* Disable abort message box.
|
|
|
|
|
* http://msdn.microsoft.com/en-us/library/e631wekh.aspx
|
|
|
|
|
*/
|
|
|
|
|
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2023-01-11 10:43:59 -05:00
|
|
|
#endif /* _GAMING_XBOX */
|
2014-06-03 18:08:34 +01:00
|
|
|
}
|
2022-03-21 11:43:54 +01:00
|
|
|
#endif /* _WIN32 */
|
2014-06-03 18:08:34 +01:00
|
|
|
|
2022-11-06 04:32:05 +08:00
|
|
|
bool
|
|
|
|
|
debug_parse_bool_option(const char *str, bool dfault)
|
2022-08-31 01:26:04 +08:00
|
|
|
{
|
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
|
|
if (str == NULL)
|
|
|
|
|
result = dfault;
|
|
|
|
|
else if (!strcmp(str, "0"))
|
|
|
|
|
result = false;
|
|
|
|
|
else if (!strcasecmp(str, "n"))
|
|
|
|
|
result = false;
|
|
|
|
|
else if (!strcasecmp(str, "no"))
|
|
|
|
|
result = false;
|
|
|
|
|
else if (!strcasecmp(str, "f"))
|
|
|
|
|
result = false;
|
|
|
|
|
else if (!strcasecmp(str, "false"))
|
|
|
|
|
result = false;
|
|
|
|
|
else if (!strcmp(str, "1"))
|
|
|
|
|
result = true;
|
|
|
|
|
else if (!strcasecmp(str, "y"))
|
|
|
|
|
result = true;
|
|
|
|
|
else if (!strcasecmp(str, "yes"))
|
|
|
|
|
result = true;
|
|
|
|
|
else if (!strcasecmp(str, "t"))
|
|
|
|
|
result = true;
|
|
|
|
|
else if (!strcasecmp(str, "true"))
|
|
|
|
|
result = true;
|
|
|
|
|
else
|
|
|
|
|
result = dfault;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool
|
2010-04-22 18:20:06 +01:00
|
|
|
debug_get_option_should_print(void)
|
|
|
|
|
{
|
2022-06-09 14:11:44 -04:00
|
|
|
static bool initialized = false;
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool value = false;
|
2010-04-22 18:20:06 +01:00
|
|
|
|
2022-08-31 01:26:04 +08:00
|
|
|
if (unlikely(!p_atomic_read_relaxed(&initialized))) {
|
2022-11-06 04:32:05 +08:00
|
|
|
bool parsed_value = debug_parse_bool_option(os_get_option("GALLIUM_PRINT_OPTIONS"), false);
|
|
|
|
|
p_atomic_set(&value, parsed_value);
|
2022-08-31 01:26:04 +08:00
|
|
|
p_atomic_set(&initialized, true);
|
|
|
|
|
}
|
2010-04-22 18:20:06 +01:00
|
|
|
|
2022-08-31 01:26:04 +08:00
|
|
|
/* We do not print value of GALLIUM_PRINT_OPTIONS intentionally. */
|
2010-04-22 18:20:06 +01:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2008-07-17 11:26:53 +09:00
|
|
|
const char *
|
|
|
|
|
debug_get_option(const char *name, const char *dfault)
|
|
|
|
|
{
|
|
|
|
|
const char *result;
|
2008-05-29 19:24:53 +09:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
result = os_get_option(name);
|
2015-12-04 17:12:30 +11:00
|
|
|
if (!result)
|
2008-07-17 11:26:53 +09:00
|
|
|
result = dfault;
|
2010-04-22 18:20:06 +01:00
|
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
2022-11-10 16:31:11 +08:00
|
|
|
debug_printf("%s: %s = %s\n", __func__, name,
|
2016-02-08 09:29:38 -07:00
|
|
|
result ? result : "(null)");
|
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2022-11-06 04:26:38 +08:00
|
|
|
const char *
|
|
|
|
|
debug_get_option_cached(const char *name, const char *dfault)
|
|
|
|
|
{
|
|
|
|
|
const char *result;
|
|
|
|
|
|
|
|
|
|
result = os_get_option_cached(name);
|
|
|
|
|
if (!result)
|
|
|
|
|
result = dfault;
|
|
|
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
|
|
|
|
debug_printf("%s: %s = %s\n", __FUNCTION__, name,
|
|
|
|
|
result ? result : "(null)");
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-01 05:59:26 +08:00
|
|
|
/**
|
|
|
|
|
* Reads an environment variable and interprets its value as a boolean.
|
|
|
|
|
* Recognizes 0/n/no/f/false case insensitive as false.
|
|
|
|
|
* Recognizes 1/y/yes/t/true case insensitive as true.
|
|
|
|
|
* Other values result in the default value.
|
|
|
|
|
*/
|
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
|
|
|
{
|
2022-11-06 04:32:05 +08:00
|
|
|
bool result = debug_parse_bool_option(os_get_option(name), dfault);
|
2010-04-22 18:20:06 +01:00
|
|
|
if (debug_get_option_should_print())
|
2022-11-10 16:31:11 +08:00
|
|
|
debug_printf("%s: %s = %s\n", __func__, name,
|
2016-02-08 09:29:38 -07:00
|
|
|
result ? "TRUE" : "FALSE");
|
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-02 14:46:16 +08:00
|
|
|
int64_t
|
2022-11-06 04:32:05 +08:00
|
|
|
debug_parse_num_option(const char *str, int64_t dfault)
|
2008-03-24 22:30:33 +00:00
|
|
|
{
|
2022-11-02 14:46:16 +08:00
|
|
|
int64_t result;
|
2016-09-14 20:37:11 +02:00
|
|
|
if (!str) {
|
2008-06-10 23:22:12 +09:00
|
|
|
result = dfault;
|
2016-09-14 20:37:11 +02:00
|
|
|
} else {
|
|
|
|
|
char *endptr;
|
|
|
|
|
|
2022-11-02 14:46:16 +08:00
|
|
|
result = strtoll(str, &endptr, 0);
|
2016-09-14 20:37:11 +02:00
|
|
|
if (str == endptr) {
|
|
|
|
|
/* Restore the default value when no digits were found. */
|
|
|
|
|
result = dfault;
|
2008-06-10 23:22:12 +09:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-06 04:32:05 +08:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
|
debug_get_num_option(const char *name, int64_t dfault)
|
|
|
|
|
{
|
|
|
|
|
int64_t result = debug_parse_num_option(os_get_option(name), dfault);
|
2010-04-22 18:20:06 +01:00
|
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
2022-11-02 14:46:16 +08:00
|
|
|
debug_printf("%s: %s = %"PRId64"\n", __func__, name, result);
|
2008-06-10 23:22:12 +09:00
|
|
|
|
|
|
|
|
return result;
|
2008-03-24 22:30:33 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-10 09:56:21 +10:00
|
|
|
void
|
|
|
|
|
debug_get_version_option(const char *name, unsigned *major, unsigned *minor)
|
|
|
|
|
{
|
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
|
|
str = os_get_option(name);
|
|
|
|
|
if (str) {
|
|
|
|
|
unsigned v_maj, v_min;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
n = sscanf(str, "%u.%u", &v_maj, &v_min);
|
|
|
|
|
if (n != 2) {
|
|
|
|
|
debug_printf("Illegal version specified for %s : %s\n", name, str);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*major = v_maj;
|
|
|
|
|
*minor = v_min;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
2022-11-10 16:31:11 +08:00
|
|
|
debug_printf("%s: %s = %u.%u\n", __func__, name, *major, *minor);
|
2020-11-10 09:56:21 +10:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2019-08-09 16:14:38 +03:00
|
|
|
static bool
|
2016-02-08 09:29:38 -07:00
|
|
|
str_has_option(const char *str, const char *name)
|
2011-01-24 23:41:51 +01:00
|
|
|
{
|
2011-01-26 11:46:39 +01:00
|
|
|
/* Empty string. */
|
|
|
|
|
if (!*str) {
|
2019-08-09 16:14:38 +03:00
|
|
|
return false;
|
2011-01-26 11:46:39 +01:00
|
|
|
}
|
2011-01-24 23:41:51 +01:00
|
|
|
|
|
|
|
|
/* OPTION=all */
|
2018-11-20 11:49:52 +00:00
|
|
|
if (!strcmp(str, "all")) {
|
2019-08-09 16:14:38 +03:00
|
|
|
return true;
|
2011-01-24 23:41:51 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
/* Find 'name' in 'str' surrounded by non-alphanumeric characters. */
|
|
|
|
|
{
|
|
|
|
|
const char *start = str;
|
|
|
|
|
unsigned name_len = strlen(name);
|
2011-01-24 23:41:51 +01:00
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
/* 'start' is the beginning of the currently-parsed word,
|
|
|
|
|
* we increment 'str' each iteration.
|
|
|
|
|
* if we find either the end of string or a non-alphanumeric character,
|
|
|
|
|
* we compare 'start' up to 'str-1' with 'name'. */
|
2011-01-24 23:41:51 +01:00
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
while (1) {
|
2012-06-27 11:15:53 +01:00
|
|
|
if (!*str || !(isalnum(*str) || *str == '_')) {
|
2011-01-26 11:46:39 +01:00
|
|
|
if (str-start == name_len &&
|
|
|
|
|
!memcmp(start, name, name_len)) {
|
2019-08-09 16:14:38 +03:00
|
|
|
return true;
|
2011-01-26 11:46:39 +01:00
|
|
|
}
|
2011-01-24 23:41:51 +01:00
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
if (!*str) {
|
2019-08-09 16:14:38 +03:00
|
|
|
return false;
|
2011-01-26 11:46:39 +01:00
|
|
|
}
|
2011-01-24 23:41:51 +01:00
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
start = str+1;
|
|
|
|
|
}
|
2011-01-24 23:41:51 +01:00
|
|
|
|
2011-01-26 11:46:39 +01:00
|
|
|
str++;
|
2011-01-24 23:41:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-09 16:14:38 +03:00
|
|
|
return false;
|
2011-01-24 23:41:51 +01:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2015-07-25 15:55:45 +02:00
|
|
|
uint64_t
|
2022-11-06 04:32:05 +08:00
|
|
|
debug_parse_flags_option(const char *name,
|
|
|
|
|
const char *str,
|
|
|
|
|
const struct debug_named_value *flags,
|
|
|
|
|
uint64_t dfault)
|
2008-03-24 22:30:33 +00:00
|
|
|
{
|
2015-07-25 15:55:45 +02:00
|
|
|
uint64_t result;
|
2010-06-01 20:11:02 +02:00
|
|
|
const struct debug_named_value *orig = flags;
|
2013-01-22 17:45:25 -07:00
|
|
|
unsigned namealign = 0;
|
2016-02-08 09:29:38 -07:00
|
|
|
|
|
|
|
|
if (!str)
|
2008-03-24 22:30:33 +00:00
|
|
|
result = dfault;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "help")) {
|
2008-09-23 10:09:36 -06:00
|
|
|
result = dfault;
|
2022-11-10 16:31:11 +08:00
|
|
|
_debug_printf("%s: help for %s:\n", __func__, name);
|
2010-06-01 20:11:02 +02:00
|
|
|
for (; flags->name; ++flags)
|
2010-06-03 07:52:46 -06:00
|
|
|
namealign = MAX2(namealign, strlen(flags->name));
|
2010-06-01 20:11:02 +02:00
|
|
|
for (flags = orig; flags->name; ++flags)
|
2015-10-15 13:30:24 -04:00
|
|
|
_debug_printf("| %*s [0x%0*"PRIx64"]%s%s\n", namealign, flags->name,
|
2015-07-25 15:55:45 +02:00
|
|
|
(int)sizeof(uint64_t)*CHAR_BIT/4, flags->value,
|
2010-06-01 20:11:02 +02:00
|
|
|
flags->desc ? " " : "", flags->desc ? flags->desc : "");
|
2008-09-23 10:09:36 -06:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
else {
|
|
|
|
|
result = 0;
|
2016-02-08 09:29:38 -07:00
|
|
|
while (flags->name) {
|
2022-11-02 17:58:36 +08:00
|
|
|
if (str_has_option(str, flags->name))
|
|
|
|
|
result |= flags->value;
|
|
|
|
|
++flags;
|
2008-03-24 22:30:33 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-06 04:32:05 +08:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
debug_get_flags_option(const char *name,
|
|
|
|
|
const struct debug_named_value *flags,
|
|
|
|
|
uint64_t dfault)
|
|
|
|
|
{
|
|
|
|
|
const char *str = os_get_option(name);
|
|
|
|
|
uint64_t result = debug_parse_flags_option(name, str, flags, dfault);
|
|
|
|
|
|
2010-04-22 18:20:06 +01:00
|
|
|
if (debug_get_option_should_print()) {
|
|
|
|
|
if (str) {
|
2016-02-08 09:29:38 -07:00
|
|
|
debug_printf("%s: %s = 0x%"PRIx64" (%s)\n",
|
2022-11-10 16:31:11 +08:00
|
|
|
__func__, name, result, str);
|
2010-04-22 18:20:06 +01:00
|
|
|
} else {
|
2022-11-10 16:31:11 +08:00
|
|
|
debug_printf("%s: %s = 0x%"PRIx64"\n", __func__, name, result);
|
2010-04-22 18:20:06 +01:00
|
|
|
}
|
2008-09-23 10:09:36 -06:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
const char *
|
2016-02-08 09:29:38 -07:00
|
|
|
debug_dump_enum(const struct debug_named_value *names,
|
2022-11-02 14:46:16 +08:00
|
|
|
uint64_t value)
|
2008-03-19 16:41:07 +00:00
|
|
|
{
|
2008-08-07 19:25:28 +01:00
|
|
|
static char rest[64];
|
2016-02-08 09:29:38 -07:00
|
|
|
|
|
|
|
|
while (names->name) {
|
|
|
|
|
if (names->value == value)
|
2022-11-02 17:58:36 +08:00
|
|
|
return names->name;
|
2008-03-19 16:41:07 +00:00
|
|
|
++names;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-02 14:46:16 +08:00
|
|
|
snprintf(rest, sizeof(rest), "0x%08"PRIx64, value);
|
2008-03-19 16:41:07 +00:00
|
|
|
return rest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char *
|
2022-11-02 14:46:16 +08:00
|
|
|
debug_dump_flags(const struct debug_named_value *names, uint64_t value)
|
2008-03-19 16:41:07 +00:00
|
|
|
{
|
2025-02-11 11:31:01 +01:00
|
|
|
static thread_local char output[4096];
|
|
|
|
|
static thread_local char rest[256];
|
2008-03-19 16:41:07 +00:00
|
|
|
int first = 1;
|
|
|
|
|
|
|
|
|
|
output[0] = '\0';
|
|
|
|
|
|
2016-02-08 09:29:38 -07:00
|
|
|
while (names->name) {
|
|
|
|
|
if ((names->value & value) == names->value) {
|
2022-11-02 17:58:36 +08:00
|
|
|
if (!first)
|
|
|
|
|
strncat(output, "|", sizeof(output) - strlen(output) - 1);
|
|
|
|
|
else
|
|
|
|
|
first = 0;
|
|
|
|
|
strncat(output, names->name, sizeof(output) - strlen(output) - 1);
|
|
|
|
|
output[sizeof(output) - 1] = '\0';
|
|
|
|
|
value &= ~names->value;
|
2008-03-19 16:41:07 +00:00
|
|
|
}
|
|
|
|
|
++names;
|
|
|
|
|
}
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
if (value) {
|
|
|
|
|
if (!first)
|
2022-11-02 17:58:36 +08:00
|
|
|
strncat(output, "|", sizeof(output) - strlen(output) - 1);
|
2008-03-19 16:41:07 +00:00
|
|
|
else
|
2022-11-02 17:58:36 +08:00
|
|
|
first = 0;
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2022-11-02 14:46:16 +08:00
|
|
|
snprintf(rest, sizeof(rest), "0x%08"PRIx64, value);
|
2018-11-20 11:47:06 +00:00
|
|
|
strncat(output, rest, sizeof(output) - strlen(output) - 1);
|
2009-12-23 15:19:45 -08:00
|
|
|
output[sizeof(output) - 1] = '\0';
|
2008-03-19 16:41:07 +00:00
|
|
|
}
|
2016-02-08 09:29:38 -07:00
|
|
|
|
|
|
|
|
if (first)
|
2008-03-19 16:41:07 +00:00
|
|
|
return "0";
|
2016-02-08 09:29:38 -07:00
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
return output;
|
|
|
|
|
}
|
2008-03-20 13:10:32 +00:00
|
|
|
|
|
|
|
|
|
2022-11-01 05:59:26 +08:00
|
|
|
uint64_t
|
|
|
|
|
parse_debug_string(const char *debug,
|
|
|
|
|
const struct debug_control *control)
|
|
|
|
|
{
|
|
|
|
|
uint64_t flag = 0;
|
|
|
|
|
|
|
|
|
|
if (debug != NULL) {
|
|
|
|
|
for (; control->string != NULL; control++) {
|
2024-03-07 19:54:22 +01:00
|
|
|
const char *s = debug;
|
|
|
|
|
unsigned n;
|
2022-11-01 05:59:26 +08:00
|
|
|
|
2025-01-14 13:57:47 +00:00
|
|
|
for (; n = strcspn(s, ", \n"), *s; s += MAX2(1, n)) {
|
2024-03-07 19:54:22 +01:00
|
|
|
if (!n)
|
|
|
|
|
continue;
|
2022-11-01 05:59:26 +08:00
|
|
|
|
2024-03-07 19:54:22 +01:00
|
|
|
if (!strncmp("all", s, n) ||
|
|
|
|
|
(strlen(control->string) == n &&
|
|
|
|
|
!strncmp(control->string, s, n)))
|
|
|
|
|
flag |= control->flag;
|
2022-11-01 05:59:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
|
parse_enable_string(const char *debug,
|
|
|
|
|
uint64_t default_value,
|
|
|
|
|
const struct debug_control *control)
|
|
|
|
|
{
|
|
|
|
|
uint64_t flag = default_value;
|
|
|
|
|
|
|
|
|
|
if (debug != NULL) {
|
2024-06-28 11:17:43 +03:00
|
|
|
const char *s = debug;
|
|
|
|
|
unsigned n;
|
|
|
|
|
|
2025-01-14 13:57:47 +00:00
|
|
|
for (; n = strcspn(s, ", \n"), *s; s += MAX2(1, n)) {
|
2024-06-28 11:17:43 +03:00
|
|
|
bool enable;
|
|
|
|
|
if (s[0] == '+') {
|
|
|
|
|
enable = true;
|
|
|
|
|
s++; n--;
|
|
|
|
|
} else if (s[0] == '-') {
|
|
|
|
|
enable = false;
|
|
|
|
|
s++; n--;
|
2022-11-01 05:59:26 +08:00
|
|
|
} else {
|
2024-06-28 11:17:43 +03:00
|
|
|
enable = true;
|
|
|
|
|
}
|
|
|
|
|
if (!strncmp(s, "all", 3)) {
|
|
|
|
|
if (enable)
|
|
|
|
|
flag = ~0ull;
|
|
|
|
|
else
|
|
|
|
|
flag = 0;
|
|
|
|
|
} else {
|
|
|
|
|
for (const struct debug_control *c = control; c->string != NULL; c++) {
|
|
|
|
|
if (strlen(c->string) == n &&
|
|
|
|
|
!strncmp(c->string, s, n)) {
|
2022-11-01 05:59:26 +08:00
|
|
|
if (enable)
|
2024-06-28 11:17:43 +03:00
|
|
|
flag |= c->flag;
|
2022-11-01 05:59:26 +08:00
|
|
|
else
|
2024-06-28 11:17:43 +03:00
|
|
|
flag &= ~c->flag;
|
2022-11-01 05:59:26 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
comma_separated_list_contains(const char *list, const char *s)
|
|
|
|
|
{
|
|
|
|
|
assert(list);
|
|
|
|
|
const size_t len = strlen(s);
|
|
|
|
|
|
|
|
|
|
for (unsigned n; n = strcspn(list, ","), *list; list += MAX2(1, n)) {
|
|
|
|
|
if (n == len && !strncmp(list, s, n))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-02-11 11:31:44 +01:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dump_debug_control_string(char *output,
|
|
|
|
|
size_t max_size,
|
|
|
|
|
const struct debug_control *control,
|
|
|
|
|
uint64_t flags)
|
|
|
|
|
{
|
|
|
|
|
size_t pos = 0;
|
|
|
|
|
int ret;
|
|
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
|
|
for (const struct debug_control *c = control; c->string != NULL; c++) {
|
|
|
|
|
if (!(flags & c->flag))
|
|
|
|
|
continue;
|
|
|
|
|
ret = snprintf(output + pos, max_size - pos,
|
|
|
|
|
first ? "%s" : "|%s", c->string);
|
|
|
|
|
if (ret < 0 || ret >= max_size - pos) {
|
|
|
|
|
output[max_size-3] = output[max_size-2] = '.';
|
|
|
|
|
output[max_size-1] = '\0';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos += ret;
|
|
|
|
|
first = false;
|
|
|
|
|
flags &= ~(c->flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags) {
|
|
|
|
|
ret = snprintf(output + pos, max_size - pos,
|
|
|
|
|
first ? "0x%" PRIx64 : "|0x%" PRIx64, flags);
|
|
|
|
|
if (ret < 0 || ret >= max_size - pos) {
|
|
|
|
|
output[max_size-3] = output[max_size-2] = '.';
|
|
|
|
|
output[max_size-1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|