Back to index

extremetuxracer  0.5beta
Defines | Enumerations | Functions
debug.h File Reference
#include "etracer.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define check_assertion(condition, desc)
#define code_not_reached()   check_assertion( 0, "supposedly unreachable code reached!" )

Enumerations

enum  debug_mode_t {
  DEBUG_ODE, DEBUG_QUADTREE, DEBUG_CONTROL, DEBUG_SOUND,
  DEBUG_TEXTURE, DEBUG_VIEW, DEBUG_GL_EXT, DEBUG_FONT,
  DEBUG_UI, DEBUG_GAME_LOGIC, DEBUG_SAVE, DEBUG_JOYSTICK,
  DEBUG_GL_INFO, NUM_DEBUG_MODES
}

Functions

void init_debug ()
bool debug_mode_is_active (debug_mode_t mode)
void debug_mode_set_active (debug_mode_t mode, bool active)
void print_debug (debug_mode_t mode, char *fmt,...)
void setup_diagnostic_log ()
 Opens the diagnostic log, writes a header, and activates all debugging modes.

Define Documentation

#define check_assertion (   condition,
  desc 
)
Value:
if ( condition ) {} else { \
        fprintf( stderr, "!!! " PROG_NAME " unexpected error [%s:%d]: %s\n", \
               __FILE__, __LINE__, desc ); \
        abort(); \
    }

Definition at line 58 of file debug.h.

#define code_not_reached ( )    check_assertion( 0, "supposedly unreachable code reached!" )

Definition at line 68 of file debug.h.


Enumeration Type Documentation

Enumerator:
DEBUG_ODE 
DEBUG_QUADTREE 
DEBUG_CONTROL 
DEBUG_SOUND 
DEBUG_TEXTURE 
DEBUG_VIEW 
DEBUG_GL_EXT 
DEBUG_FONT 
DEBUG_UI 
DEBUG_GAME_LOGIC 
DEBUG_SAVE 
DEBUG_JOYSTICK 
DEBUG_GL_INFO 
NUM_DEBUG_MODES 

Definition at line 27 of file debug.h.


Function Documentation

Definition at line 102 of file debug.cpp.

{
    return debug_setting[ mode ];
}

Here is the caller graph for this function:

void debug_mode_set_active ( debug_mode_t  mode,
bool  active 
)

Definition at line 107 of file debug.cpp.

{
    check_assertion( mode >= 0 &&
                   mode < NUM_DEBUG_MODES,
                   "Invalid debug mode" );

    debug_setting[ mode ] = active;
}

Here is the caller graph for this function:

void init_debug ( )

Definition at line 47 of file debug.cpp.

{
    char *debug_str, *tmp_str;
    char *p;
    int i;
    bool new_setting;

    for ( i=0; i<NUM_DEBUG_MODES; i++ ) {
       debug_setting[i] = false;
    }

    debug_str = getparam_debug();
    tmp_str = debug_str;

    while ( (p = strtok( tmp_str, " " )) != NULL ) {
       tmp_str = NULL;

       new_setting = true;

       if ( *p == '-' ) {
           p++;
           new_setting = false;

           if ( *p == '\0' ) {
              print_warning( CONFIGURATION_WARNING, 
                            "solitary `-' in debug parameter -- ignored." );
              continue;
           }
       }

       if ( *p == '\0' ) {
           continue;
       }


       if ( strcmp( p, "all" ) == 0 ) {
           for (i=0; i<NUM_DEBUG_MODES; i++) {
              debug_setting[i] = new_setting;
           }
       } else {
           for ( i=0; i<NUM_DEBUG_MODES; i++ ) {
              if ( strcmp( p, debug_desc[i] ) == 0 ) {
                  debug_setting[i] = new_setting;
                  break;
              }
           }

           if ( i == NUM_DEBUG_MODES ) {
              print_warning( CONFIGURATION_WARNING,
                            "unrecognized debug mode `%s'", p );
           }
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void print_debug ( debug_mode_t  mode,
char *  fmt,
  ... 
)

Definition at line 116 of file debug.cpp.

{
    va_list args;

    check_assertion( 0 <= mode && mode < NUM_DEBUG_MODES,
                   "invalid debugging mode" );

    if ( ! debug_mode_is_active( mode ) ) {
       return;
    }

    va_start( args, fmt );

    fprintf( stderr, PROG_NAME " debug (%s): ", debug_desc[ mode ] );
    vfprintf( stderr, fmt, args );
    fprintf( stderr, "\n" );

    va_end( args );
}

Here is the call graph for this function:

Here is the caller graph for this function:

Opens the diagnostic log, writes a header, and activates all debugging modes.

All subsequent output to stderr will be redirected to the diagnostic log.

Author:
jfpatry

Definition at line 146 of file debug.cpp.

{
    FILE *newfp;
    time_t t;
    char os_buff[BUFF_LEN];
    char time_buff[BUFF_LEN];

    /* Activate a bunch of debugging modes */
    debug_mode_set_active( DEBUG_QUADTREE, true );
    debug_mode_set_active( DEBUG_CONTROL, true );
    debug_mode_set_active( DEBUG_SOUND, true );
    debug_mode_set_active( DEBUG_TEXTURE, true );
    debug_mode_set_active( DEBUG_VIEW, true );
    debug_mode_set_active( DEBUG_GL_EXT, true );
    debug_mode_set_active( DEBUG_FONT, true );
    debug_mode_set_active( DEBUG_UI, true );
    debug_mode_set_active( DEBUG_GAME_LOGIC, true );
    debug_mode_set_active( DEBUG_SAVE, true );
    debug_mode_set_active( DEBUG_JOYSTICK, true );
    debug_mode_set_active( DEBUG_GL_INFO, true );

    /* Redirect stderr to file; taken from SDL_main.c, which is in the 
       public domain */
    newfp = freopen(BUGREPORT_FILE, "w", stderr);
    if ( newfp == NULL ) {  /* This happens on NT */
#if !defined(stderr)
       stderr = fopen(BUGREPORT_FILE, "w");
#else
       newfp = fopen(BUGREPORT_FILE, "w");
       if ( newfp ) {
           *stderr = *newfp;
       }
#endif
    }

    /* Write bug report header */
    fprintf( stderr, "PlanetPenguin Racer Diagnostic Log\n\n" );

    /* Generate time string */
    t = time( NULL );
    sprintf( time_buff, "%s", asctime( gmtime( &t ) ) );
    time_buff[ strlen(time_buff)-1 ] = (char)0; /* remove trailing newline */

    fprintf( stderr, "Generated:       %s GMT\n", time_buff );
    fprintf( stderr, "PPRacer Version:      %s\n", VERSION );
    fprintf( stderr, "OS:              " );

    if ( get_os_version( os_buff, sizeof( os_buff ) ) == 0 ) {
       fprintf( stderr, "%s\n", os_buff );
    } else {
       fprintf( stderr, "Could not determine!\n" );
    }

    fprintf( stderr, "\n" );
}

Here is the call graph for this function:

Here is the caller graph for this function: