2008-02-06 04:27:49 +00:00
|
|
|
/**************************************************************************
|
2016-02-08 16:29:38 +00: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 04:09:56 +00:00
|
|
|
* Copyright (c) 2008 VMware, Inc.
|
2008-02-06 04:27:49 +00:00
|
|
|
* All Rights Reserved.
|
2016-02-08 16:29:38 +00:00
|
|
|
*
|
2008-02-06 04:27:49 +00: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 16:29:38 +00:00
|
|
|
*
|
2008-02-06 04:27:49 +00: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 16:29:38 +00:00
|
|
|
*
|
2008-02-06 04:27:49 +00: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 04:27:49 +00: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 16:29:38 +00:00
|
|
|
*
|
2008-02-06 04:27:49 +00:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
#include "util/u_debug.h"
|
|
|
|
#include "util/u_string.h"
|
|
|
|
#include "util/u_math.h"
|
2015-08-28 00:57:04 +01:00
|
|
|
#include <inttypes.h>
|
2008-02-06 04:27:49 +00:00
|
|
|
|
2011-11-09 07:02:27 +00:00
|
|
|
#include <stdio.h>
|
2010-06-01 19:11:02 +01:00
|
|
|
#include <limits.h> /* CHAR_BIT */
|
2011-01-26 10:46:39 +00:00
|
|
|
#include <ctype.h> /* isalnum */
|
2008-02-06 04:27:49 +00:00
|
|
|
|
2014-06-03 18:08:34 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
void
|
|
|
|
_debug_vprintf(const char *format, va_list ap)
|
2008-02-06 04:27:49 +00:00
|
|
|
{
|
2012-05-22 16:32:50 +01:00
|
|
|
static char buf[4096] = {'\0'};
|
2019-08-01 22:36:30 +01:00
|
|
|
#if DETECT_OS_WINDOWS || defined(EMBEDDED_DEVICE)
|
2010-02-03 12:13:06 +00:00
|
|
|
/* We buffer until we find a newline. */
|
2008-06-23 23:24:58 +01: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 23:24:58 +01: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 16:32:50 +01:00
|
|
|
os_log_message(buf);
|
2011-01-13 11:44:16 +00:00
|
|
|
#endif
|
2008-02-06 16:07:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2015-10-30 07:17:35 +00:00
|
|
|
void
|
2022-03-30 21:22:26 +01:00
|
|
|
_util_debug_message(struct util_debug_callback *cb,
|
2016-02-08 16:29:38 +00:00
|
|
|
unsigned *id,
|
2022-03-30 21:23:16 +01:00
|
|
|
enum util_debug_type type,
|
2016-02-08 16:29:38 +00:00
|
|
|
const char *fmt, ...)
|
2015-10-30 07:17:35 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
if (cb && cb->debug_message)
|
|
|
|
cb->debug_message(cb->data, id, type, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2008-02-06 16:07:49 +00:00
|
|
|
|
2022-03-21 10:43:54 +00:00
|
|
|
#ifdef _WIN32
|
2014-06-03 18:08:34 +01:00
|
|
|
void
|
2022-03-21 10:43:54 +00: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);
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 10:43:54 +00:00
|
|
|
#endif /* _WIN32 */
|
2014-06-03 18:08:34 +01:00
|
|
|
|
|
|
|
|
2008-03-24 20:18:59 +00:00
|
|
|
#ifdef DEBUG
|
2016-02-08 16:29:38 +00:00
|
|
|
void
|
|
|
|
debug_print_blob(const char *name, const void *blob, unsigned size)
|
2008-03-20 13:10:32 +00:00
|
|
|
{
|
|
|
|
const unsigned *ublob = (const unsigned *)blob;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
debug_printf("%s (%d dwords%s)\n", name, size/4,
|
|
|
|
size%4 ? "... plus a few bytes" : "");
|
|
|
|
|
|
|
|
for (i = 0; i < size/4; i++) {
|
|
|
|
debug_printf("%d:\t%08x\n", i, ublob[i]);
|
|
|
|
}
|
|
|
|
}
|
2008-03-24 20:18:59 +00:00
|
|
|
#endif
|
2008-03-20 13:10:32 +00:00
|
|
|
|
|
|
|
|
2019-08-09 14:14:38 +01:00
|
|
|
static bool
|
2010-04-22 18:20:06 +01:00
|
|
|
debug_get_option_should_print(void)
|
|
|
|
{
|
2022-06-09 19:11:44 +01:00
|
|
|
static bool initialized = false;
|
2019-08-09 14:14:38 +01:00
|
|
|
static bool value = false;
|
2010-04-22 18:20:06 +01:00
|
|
|
|
2022-06-09 19:11:44 +01:00
|
|
|
if (initialized)
|
2010-04-22 18:20:06 +01:00
|
|
|
return value;
|
|
|
|
|
|
|
|
/* Oh hey this will call into this function,
|
|
|
|
* but its cool since we set first to false
|
|
|
|
*/
|
2022-06-09 19:11:44 +01:00
|
|
|
initialized = true;
|
2019-08-09 14:14:38 +01:00
|
|
|
value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", false);
|
2010-04-22 18:20:06 +01:00
|
|
|
/* XXX should we print this option? Currently it wont */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2008-07-17 03:26:53 +01:00
|
|
|
const char *
|
|
|
|
debug_get_option(const char *name, const char *dfault)
|
|
|
|
{
|
|
|
|
const char *result;
|
2008-05-29 11:24:53 +01:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
result = os_get_option(name);
|
2015-12-04 06:12:30 +00:00
|
|
|
if (!result)
|
2008-07-17 03:26:53 +01:00
|
|
|
result = dfault;
|
2010-04-22 18:20:06 +01:00
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_printf("%s: %s = %s\n", __FUNCTION__, name,
|
|
|
|
result ? result : "(null)");
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2019-08-09 14:14:38 +01:00
|
|
|
bool
|
|
|
|
debug_get_bool_option(const char *name, bool dfault)
|
2008-03-24 22:30:33 +00:00
|
|
|
{
|
2010-02-03 12:13:06 +00:00
|
|
|
const char *str = os_get_option(name);
|
2019-08-09 14:14:38 +01:00
|
|
|
bool result;
|
2016-02-08 16:29:38 +00:00
|
|
|
|
|
|
|
if (str == NULL)
|
2008-03-24 22:30:33 +00:00
|
|
|
result = dfault;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "n"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "no"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "0"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "f"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "F"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "false"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2018-11-20 11:49:52 +00:00
|
|
|
else if (!strcmp(str, "FALSE"))
|
2019-08-09 14:14:38 +01:00
|
|
|
result = false;
|
2008-03-24 22:30:33 +00:00
|
|
|
else
|
2019-08-09 14:14:38 +01:00
|
|
|
result = true;
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2010-04-22 18:20:06 +01:00
|
|
|
if (debug_get_option_should_print())
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_printf("%s: %s = %s\n", __FUNCTION__, name,
|
|
|
|
result ? "TRUE" : "FALSE");
|
|
|
|
|
2008-03-24 22:30:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long
|
|
|
|
debug_get_num_option(const char *name, long dfault)
|
|
|
|
{
|
2008-06-10 15:22:12 +01:00
|
|
|
long result;
|
|
|
|
const char *str;
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
str = os_get_option(name);
|
2016-09-14 19:37:11 +01:00
|
|
|
if (!str) {
|
2008-06-10 15:22:12 +01:00
|
|
|
result = dfault;
|
2016-09-14 19:37:11 +01:00
|
|
|
} else {
|
|
|
|
char *endptr;
|
|
|
|
|
|
|
|
result = strtol(str, &endptr, 0);
|
|
|
|
if (str == endptr) {
|
|
|
|
/* Restore the default value when no digits were found. */
|
|
|
|
result = dfault;
|
2008-06-10 15:22:12 +01:00
|
|
|
}
|
|
|
|
}
|
2010-04-22 18:20:06 +01:00
|
|
|
|
|
|
|
if (debug_get_option_should_print())
|
|
|
|
debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
|
2008-06-10 15:22:12 +01:00
|
|
|
|
|
|
|
return result;
|
2008-03-24 22:30:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 23:56:21 +00: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())
|
|
|
|
debug_printf("%s: %s = %u.%u\n", __FUNCTION__, name, *major, *minor);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2019-08-09 14:14:38 +01:00
|
|
|
static bool
|
2016-02-08 16:29:38 +00:00
|
|
|
str_has_option(const char *str, const char *name)
|
2011-01-24 22:41:51 +00:00
|
|
|
{
|
2011-01-26 10:46:39 +00:00
|
|
|
/* Empty string. */
|
|
|
|
if (!*str) {
|
2019-08-09 14:14:38 +01:00
|
|
|
return false;
|
2011-01-26 10:46:39 +00:00
|
|
|
}
|
2011-01-24 22:41:51 +00:00
|
|
|
|
|
|
|
/* OPTION=all */
|
2018-11-20 11:49:52 +00:00
|
|
|
if (!strcmp(str, "all")) {
|
2019-08-09 14:14:38 +01:00
|
|
|
return true;
|
2011-01-24 22:41:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-26 10:46:39 +00:00
|
|
|
/* Find 'name' in 'str' surrounded by non-alphanumeric characters. */
|
|
|
|
{
|
|
|
|
const char *start = str;
|
|
|
|
unsigned name_len = strlen(name);
|
2011-01-24 22:41:51 +00:00
|
|
|
|
2011-01-26 10:46:39 +00: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 22:41:51 +00:00
|
|
|
|
2011-01-26 10:46:39 +00:00
|
|
|
while (1) {
|
2012-06-27 11:15:53 +01:00
|
|
|
if (!*str || !(isalnum(*str) || *str == '_')) {
|
2011-01-26 10:46:39 +00:00
|
|
|
if (str-start == name_len &&
|
|
|
|
!memcmp(start, name, name_len)) {
|
2019-08-09 14:14:38 +01:00
|
|
|
return true;
|
2011-01-26 10:46:39 +00:00
|
|
|
}
|
2011-01-24 22:41:51 +00:00
|
|
|
|
2011-01-26 10:46:39 +00:00
|
|
|
if (!*str) {
|
2019-08-09 14:14:38 +01:00
|
|
|
return false;
|
2011-01-26 10:46:39 +00:00
|
|
|
}
|
2011-01-24 22:41:51 +00:00
|
|
|
|
2011-01-26 10:46:39 +00:00
|
|
|
start = str+1;
|
|
|
|
}
|
2011-01-24 22:41:51 +00:00
|
|
|
|
2011-01-26 10:46:39 +00:00
|
|
|
str++;
|
2011-01-24 22:41:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 14:14:38 +01:00
|
|
|
return false;
|
2011-01-24 22:41:51 +00:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2015-07-25 14:55:45 +01:00
|
|
|
uint64_t
|
2016-02-08 16:29:38 +00: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 14:55:45 +01:00
|
|
|
uint64_t dfault)
|
2008-03-24 22:30:33 +00:00
|
|
|
{
|
2015-07-25 14:55:45 +01:00
|
|
|
uint64_t result;
|
2008-03-24 22:30:33 +00:00
|
|
|
const char *str;
|
2010-06-01 19:11:02 +01:00
|
|
|
const struct debug_named_value *orig = flags;
|
2013-01-23 00:45:25 +00:00
|
|
|
unsigned namealign = 0;
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2010-02-03 12:13:06 +00:00
|
|
|
str = os_get_option(name);
|
2016-02-08 16:29:38 +00: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 17:09:36 +01:00
|
|
|
result = dfault;
|
2010-07-06 23:01:27 +01:00
|
|
|
_debug_printf("%s: help for %s:\n", __FUNCTION__, name);
|
2010-06-01 19:11:02 +01:00
|
|
|
for (; flags->name; ++flags)
|
2010-06-03 14:52:46 +01:00
|
|
|
namealign = MAX2(namealign, strlen(flags->name));
|
2010-06-01 19:11:02 +01:00
|
|
|
for (flags = orig; flags->name; ++flags)
|
2015-10-15 18:30:24 +01:00
|
|
|
_debug_printf("| %*s [0x%0*"PRIx64"]%s%s\n", namealign, flags->name,
|
2015-07-25 14:55:45 +01:00
|
|
|
(int)sizeof(uint64_t)*CHAR_BIT/4, flags->value,
|
2010-06-01 19:11:02 +01:00
|
|
|
flags->desc ? " " : "", flags->desc ? flags->desc : "");
|
2008-09-23 17:09:36 +01:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
else {
|
|
|
|
result = 0;
|
2016-02-08 16:29:38 +00:00
|
|
|
while (flags->name) {
|
2011-01-24 22:41:51 +00:00
|
|
|
if (str_has_option(str, flags->name))
|
2008-03-24 22:30:33 +00:00
|
|
|
result |= flags->value;
|
|
|
|
++flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-22 18:20:06 +01:00
|
|
|
if (debug_get_option_should_print()) {
|
|
|
|
if (str) {
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_printf("%s: %s = 0x%"PRIx64" (%s)\n",
|
|
|
|
__FUNCTION__, name, result, str);
|
2010-04-22 18:20:06 +01:00
|
|
|
} else {
|
2015-10-15 18:30:24 +01:00
|
|
|
debug_printf("%s: %s = 0x%"PRIx64"\n", __FUNCTION__, name, result);
|
2010-04-22 18:20:06 +01:00
|
|
|
}
|
2008-09-23 17:09:36 +01:00
|
|
|
}
|
2008-03-24 22:30:33 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
const char *
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_dump_enum(const struct debug_named_value *names,
|
2008-03-19 16:41:07 +00:00
|
|
|
unsigned long value)
|
|
|
|
{
|
2008-08-07 19:25:28 +01:00
|
|
|
static char rest[64];
|
2016-02-08 16:29:38 +00:00
|
|
|
|
|
|
|
while (names->name) {
|
|
|
|
if (names->value == value)
|
2008-03-19 16:41:07 +00:00
|
|
|
return names->name;
|
|
|
|
++names;
|
|
|
|
}
|
|
|
|
|
2018-11-20 11:59:28 +00:00
|
|
|
snprintf(rest, sizeof(rest), "0x%08lx", value);
|
2008-03-19 16:41:07 +00:00
|
|
|
return rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-17 18:45:20 +00:00
|
|
|
const char *
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_dump_enum_noprefix(const struct debug_named_value *names,
|
2009-01-17 18:45:20 +00:00
|
|
|
const char *prefix,
|
|
|
|
unsigned long value)
|
|
|
|
{
|
|
|
|
static char rest[64];
|
2016-02-08 16:29:38 +00:00
|
|
|
|
|
|
|
while (names->name) {
|
|
|
|
if (names->value == value) {
|
2009-01-17 18:45:20 +00:00
|
|
|
const char *name = names->name;
|
|
|
|
while (*name == *prefix) {
|
|
|
|
name++;
|
|
|
|
prefix++;
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
++names;
|
|
|
|
}
|
|
|
|
|
2018-11-20 11:59:28 +00:00
|
|
|
snprintf(rest, sizeof(rest), "0x%08lx", value);
|
2009-01-17 18:45:20 +00:00
|
|
|
return rest;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
const char *
|
2016-02-08 16:29:38 +00:00
|
|
|
debug_dump_flags(const struct debug_named_value *names, unsigned long value)
|
2008-03-19 16:41:07 +00:00
|
|
|
{
|
|
|
|
static char output[4096];
|
|
|
|
static char rest[256];
|
|
|
|
int first = 1;
|
|
|
|
|
|
|
|
output[0] = '\0';
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
while (names->name) {
|
|
|
|
if ((names->value & value) == names->value) {
|
2008-03-19 16:41:07 +00:00
|
|
|
if (!first)
|
2018-11-20 11:47:06 +00:00
|
|
|
strncat(output, "|", sizeof(output) - strlen(output) - 1);
|
2008-03-19 16:41:07 +00:00
|
|
|
else
|
|
|
|
first = 0;
|
2018-11-20 11:47:06 +00:00
|
|
|
strncat(output, names->name, sizeof(output) - strlen(output) - 1);
|
2009-12-23 23:19:45 +00:00
|
|
|
output[sizeof(output) - 1] = '\0';
|
2008-03-19 16:41:07 +00:00
|
|
|
value &= ~names->value;
|
|
|
|
}
|
|
|
|
++names;
|
|
|
|
}
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
if (value) {
|
|
|
|
if (!first)
|
2018-11-20 11:47:06 +00:00
|
|
|
strncat(output, "|", sizeof(output) - strlen(output) - 1);
|
2008-03-19 16:41:07 +00:00
|
|
|
else
|
|
|
|
first = 0;
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2018-11-20 11:59:28 +00:00
|
|
|
snprintf(rest, sizeof(rest), "0x%08lx", value);
|
2018-11-20 11:47:06 +00:00
|
|
|
strncat(output, rest, sizeof(output) - strlen(output) - 1);
|
2009-12-23 23:19:45 +00:00
|
|
|
output[sizeof(output) - 1] = '\0';
|
2008-03-19 16:41:07 +00:00
|
|
|
}
|
2016-02-08 16:29:38 +00:00
|
|
|
|
|
|
|
if (first)
|
2008-03-19 16:41:07 +00:00
|
|
|
return "0";
|
2016-02-08 16:29:38 +00:00
|
|
|
|
2008-03-19 16:41:07 +00:00
|
|
|
return output;
|
|
|
|
}
|
2008-03-20 13:10:32 +00:00
|
|
|
|
|
|
|
|
2009-10-25 00:02:16 +01:00
|
|
|
|
2011-01-23 20:28:44 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
int fl_indent = 0;
|
|
|
|
const char* fl_function[1024];
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
int
|
2017-11-16 15:09:58 +00:00
|
|
|
debug_funclog_enter(const char* f, UNUSED const int line,
|
|
|
|
UNUSED const char* file)
|
2011-01-23 20:28:44 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < fl_indent; i++)
|
|
|
|
debug_printf(" ");
|
|
|
|
debug_printf("%s\n", f);
|
|
|
|
|
|
|
|
assert(fl_indent < 1023);
|
|
|
|
fl_function[fl_indent++] = f;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
void
|
2017-11-16 15:09:58 +00:00
|
|
|
debug_funclog_exit(const char* f, UNUSED const int line,
|
|
|
|
UNUSED const char* file)
|
2011-01-23 20:28:44 +00:00
|
|
|
{
|
|
|
|
--fl_indent;
|
|
|
|
assert(fl_indent >= 0);
|
|
|
|
assert(fl_function[fl_indent] == f);
|
|
|
|
}
|
|
|
|
|
2016-02-08 16:29:38 +00:00
|
|
|
void
|
2017-11-16 15:09:58 +00:00
|
|
|
debug_funclog_enter_exit(const char* f, UNUSED const int line,
|
|
|
|
UNUSED const char* file)
|
2011-01-23 20:28:44 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < fl_indent; i++)
|
|
|
|
debug_printf(" ");
|
|
|
|
debug_printf("%s\n", f);
|
|
|
|
}
|
|
|
|
#endif
|