rb-debug

## rb-debug rb-debug — debugging support functions |

## Synopsis

    #define             rb_debug                            (...)
    void                rb_debug_init                       (gboolean debug);
    void                rb_debug_init_match                 (const char *match);
    gboolean            rb_debug_matches                    (const char *func,
                                                             const char *file);
    char **             rb_debug_get_args                   (void);
    void                rb_debug_stop_in_debugger           (void);
    typedef             RBProfiler;
    RBProfiler *        rb_profiler_new                     (const char *name);
    void                rb_profiler_dump                    (RBProfiler *profiler);
    void                rb_profiler_reset                   (RBProfiler *profiler);
    void                rb_profiler_free                    (RBProfiler *profiler);
    #define             rb_profile_start                    (msg)
    #define             rb_profile_end                      (msg)

## Description

In addition to a simple debug output system, we have two distinct profiling mechanisms for timing sections of code.

## Details

### rb_debug()

    #define             rb_debug(...)

If the call site function or file name matches the current debug output settings, the message will be formatted and printed to standard error, including a timestamp, the thread ID, the file and function names, and the line number. A newline will be appended, so the format string shouldn't include one.

`...` : | printf-style format string followed by any substitution values

### rb_debug_init ()

    void                rb_debug_init                       (gboolean debug);

Sets up debug output, with either all debug enabled or none.

`debug` : | if TRUE, enable all debug output

### rb_debug_init_match ()

    void                rb_debug_init_match                 (const char *match);

Sets up debug output, enabling debug output from file and function names that contain the specified match string.

Also sets up a GLib log handler that will trigger a debugger break for critical or warning level output if any debug output at all is enabled.

`match` : | string to match functions and filenames against

### rb_debug_matches ()

    gboolean            rb_debug_matches                    (const char *func,
                                                             const char *file);

Checks if `file` or `func` matches the current debug output settings.

`func` : | function to check
`file` : | filename to check
Returns : | `TRUE` if matched

### rb_debug_get_args ()

    char **             rb_debug_get_args                   (void);

Constructs arguments to pass to another process using this debug output code that will produce the same debug output settings.

Returns : | debug output arguments, must be freed with #`g_strfreev()`

### rb_debug_stop_in_debugger ()

    void                rb_debug_stop_in_debugger           (void);

Raises a SIGINT signal to get the attention of the debugger. When not running under the debugger, we don't want to stop, so we ignore the signal for just the moment that we raise it.

### RBProfiler

    typedef struct RBProfiler RBProfiler;

### rb_profiler_new ()

    RBProfiler *        rb_profiler_new                     (const char *name);

Creates a new profiler instance. This can be used to time certain sections of code.

`name` : | profiler name
Returns : | profiler instance

### rb_profiler_dump ()

    void                rb_profiler_dump                    (RBProfiler *profiler);

Produces debug output for the profiler instance, showing the elapsed time.

`profiler` : | profiler instance

### rb_profiler_reset ()

    void                rb_profiler_reset                   (RBProfiler *profiler);

Resets the elapsed time for the profiler

`profiler` : | profiler instance

### rb_profiler_free ()

    void                rb_profiler_free                    (RBProfiler *profiler);

Frees the memory associated with a profiler instance.

`profiler` : | profiler instance to destroy

### rb_profile_start()

    #define             rb_profile_start(msg)

Records a start point for profiling. This profile mechanism operates by issuing file access requests with filenames indicating the profile points. Use 'strace -e access' to gather this information.

`msg` : | profile point message

### rb_profile_end()

    #define             rb_profile_end(msg)

Records an end point for profiling. See `rb_profile_start`.

`msg` : | profile point message