p_debug.c File Reference

Include dependency graph for p_debug.c:

Go to the source code of this file.

Functions

void _debug_vprintf (const char *format, va_list ap)
void _debug_break (void)
static const char * _debug_get_option (const char *name)
const char * debug_get_option (const char *name, const char *dfault)
 Get option.
boolean debug_get_bool_option (const char *name, boolean dfault)
long debug_get_num_option (const char *name, long dfault)
unsigned long debug_get_flags_option (const char *name, const struct debug_named_value *flags, unsigned long dfault)
void _debug_assert_fail (const char *expr, const char *file, unsigned line, const char *function)
const char * debug_dump_enum (const struct debug_named_value *names, unsigned long value)
 Convert a enum value to a string.
const char * debug_dump_flags (const struct debug_named_value *names, unsigned long value)
 Convert binary flags value to a string.
const char * pf_name (enum pipe_format format)
 Builds pipe format name from format token.

Variables

static struct debug_named_value pipe_format_names []


Function Documentation

void _debug_assert_fail ( const char *  expr,
const char *  file,
unsigned  line,
const char *  function 
)

Definition at line 337 of file p_debug.c.

References _debug_printf(), debug_break, debug_get_bool_option(), FALSE, and TRUE.

00341 {
00342    _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file, line, function, expr);
00343 #if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER)
00344    if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE))
00345 #else
00346    if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
00347 #endif
00348       debug_break();
00349    else
00350       _debug_printf("continuing...\n");
00351 }

void _debug_break ( void   ) 

Definition at line 140 of file p_debug.c.

00141 {
00142 #if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
00143    __asm("int3");
00144 #elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
00145    _asm {int 3};
00146 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
00147    EngDebugBreak();
00148 #else
00149    abort();
00150 #endif
00151 }

static const char* _debug_get_option ( const char *  name  )  [static]

Definition at line 192 of file p_debug.c.

00193 {
00194 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
00195    /* EngMapFile creates the file if it does not exists, so it must either be
00196     * disabled on release versions (or put in a less conspicuous place). */
00197 #ifdef DEBUG
00198    const char *result = NULL;
00199    ULONG_PTR iFile = 0;
00200    const void *pMap = NULL;
00201    const char *sol, *eol, *sep;
00202    static char output[1024];
00203    
00204    pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
00205    if(pMap) {
00206       sol = (const char *)pMap;
00207       while(1) {
00208          /* TODO: handle LF line endings */
00209          eol = find(sol, NULL, '\r');
00210          if(!eol || eol == sol)
00211             break;
00212          sep = find(sol, eol, '=');
00213          if(!sep)
00214             break;
00215          if(compare(sol, sep, name)) {
00216             copy(output, sep + 1, eol, sizeof(output));
00217             result = output;
00218             break;
00219          }
00220          sol = eol + 2;
00221       }
00222       EngUnmapFile(iFile);
00223    }
00224    return result;
00225 #else
00226    return NULL;
00227 #endif
00228 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) 
00229    /* TODO: implement */
00230    return NULL;
00231 #else
00232    return getenv(name);
00233 #endif
00234 }

void _debug_vprintf ( const char *  format,
va_list  ap 
)

Definition at line 79 of file p_debug.c.

References util_strchr, and util_vsnprintf.

00080 {
00081 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
00082    /* EngDebugPrint does not handle float point arguments, so we need to use
00083     * our own vsnprintf implementation. It is also very slow, so buffer until
00084     * we find a newline. */
00085    static char buf[512] = {'\0'};
00086    size_t len = strlen(buf);
00087    int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
00088    if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
00089       _EngDebugPrint("%s", buf);
00090       buf[0] = '\0';
00091    }
00092 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
00093    /* EngDebugPrint does not handle float point arguments, so we need to use
00094     * our own vsnprintf implementation. It is also very slow, so buffer until
00095     * we find a newline. */
00096    static char buf[512 + 1] = {'\0'};
00097    size_t len = strlen(buf);
00098    int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
00099    if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
00100       OutputDebugStringA(buf);
00101       buf[0] = '\0';
00102    }
00103 
00104    
00105    if(GetConsoleWindow() && !IsDebuggerPresent()) {
00106       fflush(stdout);
00107       vfprintf(stderr, format, ap);
00108       fflush(stderr);
00109    }
00110    
00111 
00112 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT) 
00113    /* TODO */
00114 #else /* !PIPE_SUBSYSTEM_WINDOWS */
00115 #ifdef DEBUG
00116    vfprintf(stderr, format, ap);
00117 #endif
00118 #endif
00119 }

const char* debug_dump_enum ( const struct debug_named_value names,
unsigned long  value 
)

Convert a enum value to a string.

Definition at line 355 of file p_debug.c.

References debug_named_value::name, util_snprintf, and debug_named_value::value.

00357 {
00358    static char rest[64];
00359    
00360    while(names->name) {
00361       if(names->value == value)
00362          return names->name;
00363       ++names;
00364    }
00365 
00366    util_snprintf(rest, sizeof(rest), "0x%08lx", value);
00367    return rest;
00368 }

const char* debug_dump_flags ( const struct debug_named_value names,
unsigned long  value 
)

Convert binary flags value to a string.

Definition at line 372 of file p_debug.c.

References debug_named_value::name, util_snprintf, util_strncat, and debug_named_value::value.

00374 {
00375    static char output[4096];
00376    static char rest[256];
00377    int first = 1;
00378 
00379    output[0] = '\0';
00380 
00381    while(names->name) {
00382       if((names->value & value) == names->value) {
00383          if (!first)
00384             util_strncat(output, "|", sizeof(output));
00385          else
00386             first = 0;
00387          util_strncat(output, names->name, sizeof(output));
00388          value &= ~names->value;
00389       }
00390       ++names;
00391    }
00392    
00393    if (value) {
00394       if (!first)
00395          util_strncat(output, "|", sizeof(output));
00396       else
00397          first = 0;
00398       
00399       util_snprintf(rest, sizeof(rest), "0x%08lx", value);
00400       util_strncat(output, rest, sizeof(output));
00401    }
00402    
00403    if(first)
00404       return "0";
00405    
00406    return output;
00407 }

boolean debug_get_bool_option ( const char *  name,
boolean  dfault 
)

Definition at line 251 of file p_debug.c.

References _debug_get_option(), debug_printf(), FALSE, TRUE, and util_strcmp.

00252 {
00253    const char *str = _debug_get_option(name);
00254    boolean result;
00255    
00256    if(str == NULL)
00257       result = dfault;
00258    else if(!util_strcmp(str, "n"))
00259       result = FALSE;
00260    else if(!util_strcmp(str, "no"))
00261       result = FALSE;
00262    else if(!util_strcmp(str, "0"))
00263       result = FALSE;
00264    else if(!util_strcmp(str, "f"))
00265       result = FALSE;
00266    else if(!util_strcmp(str, "false"))
00267       result = FALSE;
00268    else
00269       result = TRUE;
00270 
00271    debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? "TRUE" : "FALSE");
00272    
00273    return result;
00274 }

unsigned long debug_get_flags_option ( const char *  name,
const struct debug_named_value flags,
unsigned long  dfault 
)

Definition at line 312 of file p_debug.c.

References _debug_get_option(), debug_printf(), debug_named_value::name, util_strcmp, util_strstr, and debug_named_value::value.

00315 {
00316    unsigned long result;
00317    const char *str;
00318    
00319    str = _debug_get_option(name);
00320    if(!str)
00321       result = dfault;
00322    else {
00323       result = 0;
00324       while( flags->name ) {
00325          if (!util_strcmp(str, "all") || util_strstr(str, flags->name ))
00326             result |= flags->value;
00327          ++flags;
00328       }
00329    }
00330 
00331    debug_printf("%s: %s = 0x%lx\n", __FUNCTION__, name, result);
00332 
00333    return result;
00334 }

long debug_get_num_option ( const char *  name,
long  dfault 
)

Definition at line 278 of file p_debug.c.

References _debug_get_option(), and debug_printf().

00279 {
00280    long result;
00281    const char *str;
00282    
00283    str = _debug_get_option(name);
00284    if(!str)
00285       result = dfault;
00286    else {
00287       long sign;
00288       char c;
00289       c = *str++;
00290       if(c == '-') {
00291          sign = -1;
00292          c = *str++;
00293       } 
00294       else {
00295          sign = 1;
00296       }
00297       result = 0;
00298       while('0' <= c && c <= '9') {
00299          result = result*10 + (c - '0');
00300          c = *str++;
00301       }
00302       result *= sign;
00303    }
00304    
00305    debug_printf("%s: %s = %li\n", __FUNCTION__, name, result);
00306 
00307    return result;
00308 }

const char* debug_get_option ( const char *  name,
const char *  dfault 
)

Get option.

It is an alias for getenv on Linux.

On Windows it reads C:.cfg, which is a text file with CR+LF line endings with one option per line as

NAME=value

This file must be terminated with an extra empty line.

Definition at line 237 of file p_debug.c.

References _debug_get_option(), and debug_printf().

00238 {
00239    const char *result;
00240 
00241    result = _debug_get_option(name);
00242    if(!result)
00243       result = dfault;
00244       
00245    debug_printf("%s: %s = %s\n", __FUNCTION__, name, result ? result : "(null)");
00246    
00247    return result;
00248 }

const char* pf_name ( enum pipe_format  format  ) 

Builds pipe format name from format token.

Definition at line 521 of file p_debug.c.

References debug_dump_enum().

00522 {
00523    return debug_dump_enum(pipe_format_names, format);
00524 }


Variable Documentation

struct debug_named_value pipe_format_names[] [static]

Definition at line 410 of file p_debug.c.


Generated on Tue Sep 29 06:25:27 2009 for Gallium3D by  doxygen 1.5.4