mesa: update to the latest u_debug.h

This requires u_string.h to be updated as well.  There is no more string
functions prefixed by util_.  pipe_debug_message is removed as well.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Ryan Neph <ryanneph@google.com>
Acked-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 3 years ago
parent 049ee8ff40
commit 9526a95d47
  1. 1
      config.h.meson
  2. 2
      meson.build
  3. 2
      src/gallium/auxiliary/tgsi/tgsi_dump.c
  4. 20
      src/gallium/auxiliary/util/u_debug_describe.c
  5. 232
      src/gallium/auxiliary/util/u_string.h
  6. 3
      src/gallium/meson.build
  7. 1
      src/mesa/meson.build
  8. 298
      src/mesa/util/u_debug.c
  9. 158
      src/mesa/util/u_debug.h
  10. 131
      src/mesa/util/u_string.h

@ -15,6 +15,7 @@
#mesondefine HAVE_FUNC_ATTRIBUTE_UNUSED
#mesondefine HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
#mesondefine HAVE_FUNC_ATTRIBUTE_WEAK
#mesondefine HAVE_STRTOK_R
#mesondefine HAVE_TIMESPEC_GET
#mesondefine HAVE_SYS_UIO_H
#mesondefine HAVE_PTHREAD

@ -143,7 +143,7 @@ foreach a : supported_function_attributes
conf_data.set('HAVE_FUNC_ATTRIBUTE_@0@'.format(a.to_upper()), 1)
endforeach
foreach f : ['timespec_get']
foreach f : ['strtok_r', 'timespec_get']
if cc.has_function(f)
conf_data.set('HAVE_@0@'.format(f.to_upper()), 1)
endif

@ -734,7 +734,7 @@ str_dump_ctx_printf(struct dump_ctx *ctx, const char *format, ...)
int written;
va_list ap;
va_start(ap, format);
written = util_vsnprintf(sctx->ptr, sctx->left, format, ap);
written = vsnprintf(sctx->ptr, sctx->left, format, ap);
va_end(ap);
/* Some complicated logic needed to handle the return value of

@ -41,25 +41,25 @@ debug_describe_resource(char* buf, const struct pipe_resource *ptr)
switch(ptr->target)
{
case PIPE_BUFFER:
util_sprintf(buf, "pipe_buffer<%u>", (unsigned)util_format_get_stride(ptr->format, ptr->width0));
sprintf(buf, "pipe_buffer<%u>", (unsigned)util_format_get_stride(ptr->format, ptr->width0));
break;
case PIPE_TEXTURE_1D:
util_sprintf(buf, "pipe_texture1d<%u,%s,%u>", ptr->width0, util_format_short_name(ptr->format), ptr->last_level);
sprintf(buf, "pipe_texture1d<%u,%s,%u>", ptr->width0, util_format_short_name(ptr->format), ptr->last_level);
break;
case PIPE_TEXTURE_2D:
util_sprintf(buf, "pipe_texture2d<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level);
sprintf(buf, "pipe_texture2d<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level);
break;
case PIPE_TEXTURE_RECT:
util_sprintf(buf, "pipe_texture_rect<%u,%u,%s>", ptr->width0, ptr->height0, util_format_short_name(ptr->format));
sprintf(buf, "pipe_texture_rect<%u,%u,%s>", ptr->width0, ptr->height0, util_format_short_name(ptr->format));
break;
case PIPE_TEXTURE_CUBE:
util_sprintf(buf, "pipe_texture_cube<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level);
sprintf(buf, "pipe_texture_cube<%u,%u,%s,%u>", ptr->width0, ptr->height0, util_format_short_name(ptr->format), ptr->last_level);
break;
case PIPE_TEXTURE_3D:
util_sprintf(buf, "pipe_texture3d<%u,%u,%u,%s,%u>", ptr->width0, ptr->height0, ptr->depth0, util_format_short_name(ptr->format), ptr->last_level);
sprintf(buf, "pipe_texture3d<%u,%u,%u,%s,%u>", ptr->width0, ptr->height0, ptr->depth0, util_format_short_name(ptr->format), ptr->last_level);
break;
default:
util_sprintf(buf, "pipe_martian_resource<%u>", ptr->target);
sprintf(buf, "pipe_martian_resource<%u>", ptr->target);
break;
}
}
@ -69,7 +69,7 @@ debug_describe_surface(char* buf, const struct pipe_surface *ptr)
{
char res[128];
debug_describe_resource(res, ptr->texture);
util_sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer);
sprintf(buf, "pipe_surface<%s,%u,%u,%u>", res, ptr->u.tex.level, ptr->u.tex.first_layer, ptr->u.tex.last_layer);
}
void
@ -77,7 +77,7 @@ debug_describe_sampler_view(char* buf, const struct pipe_sampler_view *ptr)
{
char res[128];
debug_describe_resource(res, ptr->texture);
util_sprintf(buf, "pipe_sampler_view<%s,%s>", res, util_format_short_name(ptr->format));
sprintf(buf, "pipe_sampler_view<%s,%s>", res, util_format_short_name(ptr->format));
}
void
@ -86,6 +86,6 @@ debug_describe_so_target(char* buf,
{
char res[128];
debug_describe_resource(res, ptr->buffer);
util_sprintf(buf, "pipe_stream_output_target<%s,%u,%u>", res,
sprintf(buf, "pipe_stream_output_target<%s,%u,%u>", res,
ptr->buffer_offset, ptr->buffer_size);
}

@ -1,232 +0,0 @@
/**************************************************************************
*
* Copyright 2008 VMware, Inc.
* All Rights Reserved.
*
* 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:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* 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.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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.
*
**************************************************************************/
/**
* @file
* Platform independent functions for string manipulation.
*
* @author Jose Fonseca <jfonseca@vmware.com>
*/
#ifndef U_STRING_H_
#define U_STRING_H_
#if !defined(_MSC_VER) && !defined(XF86_LIBC_H)
#include <stdio.h>
#endif
#include <stddef.h>
#include <stdarg.h>
#include "pipe/p_compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _GNU_SOURCE
#define util_strchrnul strchrnul
#else
static inline char *
util_strchrnul(const char *s, char c)
{
for (; *s && *s != c; ++s);
return (char *)s;
}
#endif
#ifdef _MSC_VER
int util_vsnprintf(char *, size_t, const char *, va_list);
int util_snprintf(char *str, size_t size, const char *format, ...);
static inline void
util_vsprintf(char *str, const char *format, va_list ap)
{
util_vsnprintf(str, (size_t)-1, format, ap);
}
static inline void
util_sprintf(char *str, const char *format, ...)
{
va_list ap;
va_start(ap, format);
util_vsnprintf(str, (size_t)-1, format, ap);
va_end(ap);
}
static inline char *
util_strchr(const char *s, char c)
{
char *p = util_strchrnul(s, c);
return *p ? p : NULL;
}
static inline char*
util_strncat(char *dst, const char *src, size_t n)
{
char *p = dst + strlen(dst);
const char *q = src;
size_t i;
for (i = 0; i < n && *q != '\0'; ++i)
*p++ = *q++;
*p = '\0';
return dst;
}
static inline int
util_strcmp(const char *s1, const char *s2)
{
unsigned char u1, u2;
while (1) {
u1 = (unsigned char) *s1++;
u2 = (unsigned char) *s2++;
if (u1 != u2)
return u1 - u2;
if (u1 == '\0')
return 0;
}
return 0;
}
static inline int
util_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned char u1, u2;
while (n-- > 0) {
u1 = (unsigned char) *s1++;
u2 = (unsigned char) *s2++;
if (u1 != u2)
return u1 - u2;
if (u1 == '\0')
return 0;
}
return 0;
}
static inline char *
util_strstr(const char *haystack, const char *needle)
{
const char *p = haystack;
size_t len = strlen(needle);
for (; (p = util_strchr(p, *needle)) != 0; p++) {
if (util_strncmp(p, needle, len) == 0) {
return (char *)p;
}
}
return NULL;
}
static inline void *
util_memmove(void *dest, const void *src, size_t n)
{
char *p = (char *)dest;
const char *q = (const char *)src;
if (dest < src) {
while (n--)
*p++ = *q++;
}
else
{
p += n;
q += n;
while (n--)
*--p = *--q;
}
return dest;
}
#else
#define util_vsnprintf vsnprintf
#define util_snprintf snprintf
#define util_vsprintf vsprintf
#define util_sprintf sprintf
#define util_strchr strchr
#define util_strcmp strcmp
#define util_strncmp strncmp
#define util_strncat strncat
#define util_strstr strstr
#define util_memmove memmove
#endif
/**
* Printable string buffer
*/
struct util_strbuf
{
char *str;
char *ptr;
size_t left;
};
static inline void
util_strbuf_init(struct util_strbuf *sbuf, char *str, size_t size)
{
sbuf->str = str;
sbuf->str[0] = 0;
sbuf->ptr = sbuf->str;
sbuf->left = size;
}
static inline void
util_strbuf_printf(struct util_strbuf *sbuf, const char *format, ...)
{
if(sbuf->left > 1) {
size_t written;
va_list ap;
va_start(ap, format);
written = util_vsnprintf(sbuf->ptr, sbuf->left, format, ap);
va_end(ap);
sbuf->ptr += written;
sbuf->left -= written;
}
}
#ifdef __cplusplus
}
#endif
#endif /* U_STRING_H_ */

@ -35,7 +35,6 @@ sources_libgallium = [
'auxiliary/util/u_math.h',
'auxiliary/util/rgtc.h',
'auxiliary/util/u_format.c',
'auxiliary/util/u_debug.h',
'auxiliary/util/u_inlines.h',
'auxiliary/util/u_texture.c',
'auxiliary/util/u_pointer.h',
@ -45,7 +44,6 @@ sources_libgallium = [
'auxiliary/util/u_texture.h',
'auxiliary/util/u_hash_table.h',
'auxiliary/util/u_box.h',
'auxiliary/util/u_debug.c',
'auxiliary/util/u_cpu_detect.c',
'auxiliary/util/u_pack_color.h',
'auxiliary/util/u_double_list.h',
@ -54,7 +52,6 @@ sources_libgallium = [
'auxiliary/util/u_cpu_detect.h',
'auxiliary/util/u_bitmask.h',
'auxiliary/util/u_format_s3tc.h',
'auxiliary/util/u_string.h',
'auxiliary/util/u_surface.c',
'auxiliary/util/u_math.c',
'auxiliary/util/u_half.h',

@ -6,6 +6,7 @@ inc_mesa = include_directories('.', 'compat', 'pipe', 'util')
files_mesa = files(
'util/os_file.c',
'util/os_misc.c',
'util/u_debug.c',
)
deps_mesa = [

@ -27,19 +27,13 @@
**************************************************************************/
/* (virglrenderer) removed includes for p_format.h and p_state.h */
#include "pipe/p_compiler.h"
#include "pipe/p_config.h"
#include "pipe/p_compiler.h"
#include "util/u_debug.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_string.h"
#include "util/u_math.h"
#include "util/u_prim.h"
#include "util/u_surface.h"
#include <inttypes.h>
#include <stdio.h>
#include <limits.h> /* CHAR_BIT */
@ -51,24 +45,28 @@
#endif
void _debug_vprintf(const char *format, va_list ap)
void
_debug_vprintf(const char *format, va_list ap)
{
static char buf[4096] = {'\0'};
#if defined(PIPE_OS_WINDOWS) || defined(PIPE_SUBSYSTEM_EMBEDDED)
#if DETECT_OS_WINDOWS || defined(EMBEDDED_DEVICE)
/* We buffer until we find a newline. */
size_t len = strlen(buf);
int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
int ret = vsnprintf(buf + len, sizeof(buf) - len, format, ap);
if (ret > (int)(sizeof(buf) - len - 1) || strchr(buf + len, '\n')) {
os_log_message(buf);
buf[0] = '\0';
}
#else
util_vsnprintf(buf, sizeof(buf), format, ap);
vsnprintf(buf, sizeof(buf), format, ap);
os_log_message(buf);
#endif
}
/* (virglrenderer) removed _pipe_debug_message */
void
debug_disable_error_message_boxes(void)
{
@ -96,9 +94,8 @@ debug_disable_error_message_boxes(void)
#ifdef DEBUG
void debug_print_blob( const char *name,
const void *blob,
unsigned size )
void
debug_print_blob(const char *name, const void *blob, unsigned size)
{
const unsigned *ublob = (const unsigned *)blob;
unsigned i;
@ -113,11 +110,11 @@ void debug_print_blob( const char *name,
#endif
static boolean
static bool
debug_get_option_should_print(void)
{
static boolean first = TRUE;
static boolean value = FALSE;
static bool first = true;
static bool value = false;
if (!first)
return value;
@ -125,54 +122,58 @@ debug_get_option_should_print(void)
/* Oh hey this will call into this function,
* but its cool since we set first to false
*/
first = FALSE;
value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", FALSE);
first = false;
value = debug_get_bool_option("GALLIUM_PRINT_OPTIONS", false);
/* XXX should we print this option? Currently it wont */
return value;
}
const char *
debug_get_option(const char *name, const char *dfault)
{
const char *result;
result = os_get_option(name);
if(!result)
if (!result)
result = dfault;
if (debug_get_option_should_print())
debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
debug_printf("%s: %s = %s\n", __FUNCTION__, name,
result ? result : "(null)");
return result;
}
boolean
debug_get_bool_option(const char *name, boolean dfault)
bool
debug_get_bool_option(const char *name, bool dfault)
{
const char *str = os_get_option(name);
boolean result;
bool result;
if(str == NULL)
if (str == NULL)
result = dfault;
else if(!util_strcmp(str, "n"))
result = FALSE;
else if(!util_strcmp(str, "no"))
result = FALSE;
else if(!util_strcmp(str, "0"))
result = FALSE;
else if(!util_strcmp(str, "f"))
result = FALSE;
else if(!util_strcmp(str, "F"))
result = FALSE;
else if(!util_strcmp(str, "false"))
result = FALSE;
else if(!util_strcmp(str, "FALSE"))
result = FALSE;
else if (!strcmp(str, "n"))
result = false;
else if (!strcmp(str, "no"))
result = false;
else if (!strcmp(str, "0"))
result = false;
else if (!strcmp(str, "f"))
result = false;
else if (!strcmp(str, "F"))
result = false;
else if (!strcmp(str, "false"))
result = false;
else if (!strcmp(str, "FALSE"))
result = false;
else
result = TRUE;
result = true;
if (debug_get_option_should_print())
debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
debug_printf("%s: %s = %s\n", __FUNCTION__, name,
result ? "TRUE" : "FALSE");
return result;
}
@ -185,25 +186,16 @@ debug_get_num_option(const char *name, long dfault)
const char *str;
str = os_get_option(name);
if(!str)
if (!str) {
result = dfault;
} else {
char *endptr;
result = strtol(str, &endptr, 0);
if (str == endptr) {
/* Restore the default value when no digits were found. */
result = dfault;
else {
long sign;
char c;
c = *str++;
if(c == '-') {
sign = -1;
c = *str++;
}
else {
sign = 1;
}
result = 0;
while('0' <= c && c <= '9') {
result = result*10 + (c - '0');
c = *str++;
}
result *= sign;
}
if (debug_get_option_should_print())
@ -212,16 +204,42 @@ debug_get_num_option(const char *name, long dfault)
return result;
}
static boolean str_has_option(const char *str, const char *name)
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;
}
static bool
str_has_option(const char *str, const char *name)
{
/* Empty string. */
if (!*str) {
return FALSE;
return false;
}
/* OPTION=all */
if (!util_strcmp(str, "all")) {
return TRUE;
if (!strcmp(str, "all")) {
return true;
}
/* Find 'name' in 'str' surrounded by non-alphanumeric characters. */
@ -238,11 +256,11 @@ static boolean str_has_option(const char *str, const char *name)
if (!*str || !(isalnum(*str) || *str == '_')) {
if (str-start == name_len &&
!memcmp(start, name, name_len)) {
return TRUE;
return true;
}
if (!*str) {
return FALSE;
return false;
}
start = str+1;
@ -252,35 +270,36 @@ static boolean str_has_option(const char *str, const char *name)
}
}
return FALSE;
return false;
}
unsigned long
uint64_t
debug_get_flags_option(const char *name,
const struct debug_named_value *flags,
unsigned long dfault)
uint64_t dfault)
{
unsigned long result;
uint64_t result;
const char *str;
const struct debug_named_value *orig = flags;
unsigned namealign = 0;
str = os_get_option(name);
if(!str)
if (!str)
result = dfault;
else if (!util_strcmp(str, "help")) {
else if (!strcmp(str, "help")) {
result = dfault;
_debug_printf("%s: help for %s:\n", __FUNCTION__, name);
for (; flags->name; ++flags)
namealign = MAX2(namealign, strlen(flags->name));
for (flags = orig; flags->name; ++flags)
_debug_printf("| %*s [0x%0*lx]%s%s\n", namealign, flags->name,
(int)sizeof(unsigned long)*CHAR_BIT/4, flags->value,
_debug_printf("| %*s [0x%0*"PRIx64"]%s%s\n", namealign, flags->name,
(int)sizeof(uint64_t)*CHAR_BIT/4, flags->value,
flags->desc ? " " : "", flags->desc ? flags->desc : "");
}
else {
result = 0;
while( flags->name ) {
while (flags->name) {
if (str_has_option(str, flags->name))
result |= flags->value;
++flags;
@ -289,9 +308,10 @@ debug_get_flags_option(const char *name,
if (debug_get_option_should_print()) {
if (str) {
debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__, name, result, str);
debug_printf("%s: %s = 0x%"PRIx64" (%s)\n",
__FUNCTION__, name, result, str);
} else {
debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
debug_printf("%s: %s = 0x%"PRIx64"\n", __FUNCTION__, name, result);
}
}
@ -299,12 +319,12 @@ debug_get_flags_option(const char *name,
}
void _debug_assert_fail(const char *expr,
const char *file,
unsigned line,
void
_debug_assert_fail(const char *expr, const char *file, unsigned line,
const char *function)
{
_debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
_debug_printf("%s:%u:%s: Assertion `%s' failed.\n",
file, line, function, expr);
os_abort();
}
@ -315,13 +335,13 @@ debug_dump_enum(const struct debug_named_value *names,
{
static char rest[64];
while(names->name) {
if(names->value == value)
while (names->name) {
if (names->value == value)
return names->name;
++names;
}
util_snprintf(rest, sizeof(rest), "0x%08lx", value);
snprintf(rest, sizeof(rest), "0x%08lx", value);
return rest;
}
@ -333,8 +353,8 @@ debug_dump_enum_noprefix(const struct debug_named_value *names,
{
static char rest[64];
while(names->name) {
if(names->value == value) {
while (names->name) {
if (names->value == value) {
const char *name = names->name;
while (*name == *prefix) {
name++;
@ -345,16 +365,13 @@ debug_dump_enum_noprefix(const struct debug_named_value *names,
++names;
}
util_snprintf(rest, sizeof(rest), "0x%08lx", value);
snprintf(rest, sizeof(rest), "0x%08lx", value);
return rest;
}
const char *
debug_dump_flags(const struct debug_named_value *names,
unsigned long value)
debug_dump_flags(const struct debug_named_value *names, unsigned long value)
{
static char output[4096];
static char rest[256];
@ -362,13 +379,13 @@ debug_dump_flags(const struct debug_named_value *names,
output[0] = '\0';
while(names->name) {
if((names->value & value) == names->value) {
while (names->name) {
if ((names->value & value) == names->value) {
if (!first)
util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
strncat(output, "|", sizeof(output) - strlen(output) - 1);
else
first = 0;
util_strncat(output, names->name, sizeof(output) - strlen(output) - 1);
strncat(output, names->name, sizeof(output) - strlen(output) - 1);
output[sizeof(output) - 1] = '\0';
value &= ~names->value;
}
@ -377,58 +394,22 @@ debug_dump_flags(const struct debug_named_value *names,
if (value) {
if (!first)
util_strncat(output, "|", sizeof(output) - strlen(output) - 1);
strncat(output, "|", sizeof(output) - strlen(output) - 1);
else
first = 0;
util_snprintf(rest, sizeof(rest), "0x%08lx", value);
util_strncat(output, rest, sizeof(output) - strlen(output) - 1);
snprintf(rest, sizeof(rest), "0x%08lx", value);
strncat(output, rest, sizeof(output) - strlen(output) - 1);
output[sizeof(output) - 1] = '\0';
}
if(first)
if (first)
return "0";
return output;
}
#ifdef DEBUG
void debug_print_format(const char *msg, unsigned fmt )
{
debug_printf("%s: %s\n", msg, util_format_name(fmt));
}
#endif
static const struct debug_named_value pipe_prim_names[] = {
#ifdef DEBUG
DEBUG_NAMED_VALUE(PIPE_PRIM_POINTS),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINES),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_LOOP),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP),
DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES),
DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP),
DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_FAN),
DEBUG_NAMED_VALUE(PIPE_PRIM_QUADS),
DEBUG_NAMED_VALUE(PIPE_PRIM_QUAD_STRIP),
DEBUG_NAMED_VALUE(PIPE_PRIM_POLYGON),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINES_ADJACENCY),
DEBUG_NAMED_VALUE(PIPE_PRIM_LINE_STRIP_ADJACENCY),
DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLES_ADJACENCY),
DEBUG_NAMED_VALUE(PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY),
#endif
DEBUG_NAMED_VALUE_END
};
const char *u_prim_name( unsigned prim )
{
return debug_dump_enum(pipe_prim_names, prim);
}
#ifdef DEBUG
int fl_indent = 0;
@ -469,48 +450,3 @@ debug_funclog_enter_exit(const char* f, UNUSED const int line,
debug_printf("%s\n", f);
}
#endif
#ifdef DEBUG
/**
* Print PIPE_TRANSFER_x flags with a message.
*/
void
debug_print_transfer_flags(const char *msg, unsigned usage)
{
#define FLAG(x) { x, #x }
static const struct {
unsigned bit;
const char *name;
} flags[] = {
FLAG(PIPE_TRANSFER_READ),
FLAG(PIPE_TRANSFER_WRITE),
FLAG(PIPE_TRANSFER_MAP_DIRECTLY),
FLAG(PIPE_TRANSFER_DISCARD_RANGE),
FLAG(PIPE_TRANSFER_DONTBLOCK),
FLAG(PIPE_TRANSFER_UNSYNCHRONIZED),
FLAG(PIPE_TRANSFER_FLUSH_EXPLICIT),
FLAG(PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE)
};
unsigned i;
debug_printf("%s ", msg);
for (i = 0; i < ARRAY_SIZE(flags); i++) {
if (usage & flags[i].bit) {
debug_printf("%s", flags[i].name);
usage &= ~flags[i].bit;
if (usage) {
debug_printf(" | ");
}
}
}
debug_printf("\n");
#undef FLAG
}
#endif

@ -38,23 +38,28 @@
#ifndef U_DEBUG_H_
#define U_DEBUG_H_
#include <stdarg.h>
#include <string.h>
#if !defined(_WIN32)
#include <sys/types.h>
#include <unistd.h>
#endif
#include "util/os_misc.h"
#include "util/detect_os.h"
#include "util/macros.h"
#include "pipe/p_compiler.h"
#include "pipe/p_format.h"
#if DETECT_OS_HAIKU
/* Haiku provides debug_printf in libroot with OS.h */
#include <OS.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__GNUC__)
#define _util_printf_format(fmt, list) __attribute__ ((format (printf, fmt, list)))
#else
#define _util_printf_format(fmt, list)
#endif
#define _util_printf_format(fmt, list) PRINTFLIKE(fmt, list)
void _debug_vprintf(const char *format, va_list ap);
@ -78,7 +83,7 @@ _debug_printf(const char *format, ...)
* - avoid outputing large strings (512 bytes is the current maximum length
* that is guaranteed to be printed in all platforms)
*/
#if !defined(PIPE_OS_HAIKU)
#if !DETECT_OS_HAIKU
static inline void
debug_printf(const char *format, ...) _util_printf_format(1,2);
@ -94,9 +99,6 @@ debug_printf(const char *format, ...)
(void) format; /* silence warning */
#endif
}
#else /* is Haiku */
/* Haiku provides debug_printf in libroot with OS.h */
#include <OS.h>
#endif
@ -108,9 +110,9 @@ debug_printf(const char *format, ...)
*/
#define debug_printf_once(args) \
do { \
static boolean once = TRUE; \
static bool once = true; \
if (once) { \
once = FALSE; \
once = false; \
debug_printf args; \
} \
} while (0)
@ -129,13 +131,8 @@ debug_printf(const char *format, ...)
* messages.
*/
void debug_print_blob( const char *name, const void *blob, unsigned size );
/* Print a message along with a prettified format string
*/
void debug_print_format(const char *msg, unsigned fmt );
#else
#define debug_print_blob(_name, _blob, _size) ((void)0)
#define debug_print_format(_msg, _fmt) ((void)0)
#endif
@ -158,6 +155,12 @@ debug_disable_error_message_boxes(void);
#endif /* !DEBUG */
long
debug_get_num_option(const char *name, long dfault);
void
debug_get_version_option(const char *name, unsigned *major, unsigned *minor);
#ifdef _MSC_VER
__declspec(noreturn)
#endif
@ -180,7 +183,7 @@ void _debug_assert_fail(const char *expr,
* For non debug builds the assert macro will expand to a no-op, so do not
* call functions with side effects in the assert expression.
*/
#ifdef DEBUG
#ifndef NDEBUG
#define debug_assert(expr) ((expr) ? (void)0 : _debug_assert_fail(#expr, __FILE__, __LINE__, __FUNCTION__))
#else
#define debug_assert(expr) (void)(0 && (expr))
@ -236,11 +239,11 @@ void _debug_assert_fail(const char *expr,
#ifdef DEBUG
#define debug_warn_once(__msg) \
do { \
static bool warned = FALSE; \
static bool warned = false; \
if (!warned) { \
_debug_printf("%s:%u:%s: one time warning: %s\n", \
__FILE__, __LINE__, __FUNCTION__, __msg); \
warned = TRUE; \
warned = true; \
} \
} while (0)
#else
@ -260,6 +263,11 @@ void _debug_assert_fail(const char *expr,
_debug_printf("error: %s\n", __msg)
#endif
/**
* Output a debug log message to the debug info callback.
* (virglrenderer) Removed.
*/
/**
* Used by debug_dump_enum and debug_dump_flags to describe symbols.
@ -267,7 +275,7 @@ void _debug_assert_fail(const char *expr,
struct debug_named_value
{
const char *name;
unsigned long value;
uint64_t value;
const char *desc;
};
@ -369,25 +377,71 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file);
const char *
debug_get_option(const char *name, const char *dfault);
boolean
debug_get_bool_option(const char *name, boolean dfault);
bool
debug_get_bool_option(const char *name, bool dfault);
long
debug_get_num_option(const char *name, long dfault);
unsigned long
uint64_t
debug_get_flags_option(const char *name,
const struct debug_named_value *flags,
unsigned long dfault);
uint64_t dfault);
#define DEBUG_GET_ONCE_OPTION(suffix, name, dfault) \
static const char * \
debug_get_option_ ## suffix (void) \
{ \
static bool first = true; \
static const char * value; \
if (first) { \
first = false; \
value = debug_get_option(name, dfault); \
} \
return value; \
}
static inline bool
__check_suid(void)
{
#if !defined(_WIN32)
if (geteuid() != getuid())
return true;
#endif
return false;
}
/**
* Define a getter for a debug option which specifies a 'FILE *'
* to open, with additional checks for suid executables. Note
* that if the return is not NULL, the caller owns the 'FILE *'
* reference.
*/
#define DEBUG_GET_ONCE_FILE_OPTION(suffix, name, dfault, mode) \
static FILE * \
debug_get_option_ ## suffix (void) \
{ \
static bool first = true; \
static const char * value; \
if (__check_suid()) \
return NULL; \
if (first) { \
first = false; \
value = debug_get_option(name, dfault); \
} \
if (!value) \
return NULL; \
return fopen(value, mode); \
}
#define DEBUG_GET_ONCE_BOOL_OPTION(sufix, name, dfault) \
static boolean \
static bool \
debug_get_option_ ## sufix (void) \
{ \
static boolean first = TRUE; \
static boolean value; \
static bool first = true; \
static bool value; \
if (first) { \
first = FALSE; \
first = false; \
value = debug_get_bool_option(name, dfault); \
} \
return value; \
@ -397,10 +451,10 @@ debug_get_option_ ## sufix (void) \
static long \
debug_get_option_ ## sufix (void) \
{ \
static boolean first = TRUE; \
static bool first = true; \
static long value; \
if (first) { \
first = FALSE; \
first = false; \
value = debug_get_num_option(name, dfault); \
} \
return value; \
@ -410,50 +464,16 @@ debug_get_option_ ## sufix (void) \
static unsigned long \
debug_get_option_ ## sufix (void) \
{ \
static boolean first = TRUE; \
static bool first = true; \
static unsigned long value; \
if (first) { \
first = FALSE; \
first = false; \
value = debug_get_flags_option(name, flags, dfault); \
} \
return value; \
}
unsigned long
debug_memory_begin(void);
void
debug_memory_end(unsigned long beginning);
#ifdef DEBUG
struct pipe_context;
struct pipe_surface;
struct pipe_transfer;
struct pipe_resource;
void debug_dump_image(const char *prefix,
enum pipe_format format, unsigned cpp,
unsigned width, unsigned height,
unsigned stride,
const void *data);
void debug_dump_surface(struct pipe_context *pipe,
const char *prefix,
struct pipe_surface *surface);
void debug_dump_texture(struct pipe_context *pipe,
const char *prefix,
struct pipe_resource *texture);
#else
#define debug_dump_image(prefix, format, cpp, width, height, stride, data) ((void)0)
#define debug_dump_surface(pipe, prefix, surface) ((void)0)
#endif
void
debug_print_transfer_flags(const char *msg, unsigned usage);
#ifdef __cplusplus
}
#endif

@ -0,0 +1,131 @@
/**************************************************************************
*
* Copyright 2008 VMware, Inc.
* All Rights Reserved.
*
* 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:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* 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.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* 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.
*
**************************************************************************/
/**
* @file
* Platform independent functions for string manipulation.
*
* @author Jose Fonseca <jfonseca@vmware.com>
*/
#ifndef U_STRING_H_
#define U_STRING_H_
#if !defined(XF86_LIBC_H)
#include <stdio.h>
#endif
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include "util/macros.h" // PRINTFLIKE
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(_GNU_SOURCE) || defined(__APPLE__)
#define strchrnul util_strchrnul
static inline char *
util_strchrnul(const char *s, char c)
{
for (; *s && *s != c; ++s);
return (char *)s;
}
#endif
#ifdef _WIN32
#define sprintf util_sprintf
static inline void
PRINTFLIKE(2, 3)
util_sprintf(char *str, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vsnprintf(str, INT_MAX, format, ap);
va_end(ap);
}
#define vasprintf util_vasprintf
static inline int
util_vasprintf(char **ret, const char *format, va_list ap)
{
va_list ap_copy;
/* Compute length of output string first */
va_copy(ap_copy, ap);
int r = vsnprintf(NULL, 0, format, ap_copy);
va_end(ap_copy);
if (r < 0)
return -1;
*ret = (char *) malloc(r + 1);
if (!*ret)
return -1;
/* Print to buffer */
return vsnprintf(*ret, r + 1, format, ap);
}
#define asprintf util_asprintf
static inline int
util_asprintf(char **str, const char *fmt, ...)
{
int ret;
va_list args;
va_start(args, fmt);
ret = vasprintf(str, fmt, args);
va_end(args);
return ret;
}
#ifndef strcasecmp
#define strcasecmp stricmp
#endif
#define strdup _strdup
#if defined(_WIN32) && !defined(HAVE_STRTOK_R)
#define strtok_r strtok_s
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif /* U_STRING_H_ */
Loading…
Cancel
Save