Previous - Up - Next

8.2   Text Output

Since Simics has its own handling of text output, which allows users to redirect output to several recipients, the standard C library output routines should not be used from within a Simics module. However, by including the simics/api.h header file, some C library function names are redefined as preprocessor macros, which call the Simics versions of these functions instead. E.g., vprintf is redefined as:

    #undef vprintf
    #define vprintf(str, ap) SIM_printf_vararg(str, ap)

This should work just fine for most applications, but if you, for some reason, need to call the actual C library functions, you can either #undef the replacement definition of that function, or insert #define SIM_BC_NO_STDOUT_REDEFINE before including simics/api.h. See the section about SIM_BC_NO_STDOUT_REDEFINE in the Simics Reference Manual for details about these macro definitions.

Whenever Simics is requested to write output using the SIM_write() family of functions (see the Simics Reference Manual description of SIM_write for a list of these), that text is written to stdout, and a call to each previously registered output handler is made. You can register new output handlers using the SIM_add_output_handler() function.

Here is a pseudo-code example of how a module could get Simics to write a copy of all its text output to a log file:

static void
output_handler(void *file, const void *buf, size_t count)
{
    fwrite(buf, 1, count, (FILE *)file);
}

static void
init_local(void)
{
    SIM_add_output_handler(output_handler,
                           (void *)fopen("my-log.txt", "w+"));
}

Previous - Up - Next