Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

eerimoq/dbg-macro

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
71 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buildstatus codecov nala

About

A few macros that prints and returns the value of a given expression for quick and dirty debugging, inspired by Rusts dbg!(…) macro and its C++ variant.

dbg(expr) for primitive data types (int, float, etc.), strings and pointers.

dbgb(expr) to force boolean true/false output.

dbga(expr, length) for array of primitive data types.

dbgh(expr, size) for hexdump output.

dbge(expr) for negative error codes.

dbgbt() for a backtrace.

Just include dbg.h in your project to use it.

Example

tryit

See examples for the files used in this example.

#include "dbg.h"

static int factorial(int n)
{
    if (dbgb(n <= 1)) {
        return dbg(1);
    } else {
        return dbg(n * factorial(n - 1));
    }
}

int main()
{
    char message[] = "hello";
    dbg(message);  // main.c:15: message = "hello"
    dbgh(message, sizeof(message));

    const int a = 2;
    const int b = dbg(3 * a) + 1;  // main.c:19: 3 * a = 6 (0x6)

    int numbers[2] = { b, 13 };
    dbga(numbers, 2);  // main.c:22: numbers = [7, 13] (length: 2)

    dbg(factorial(4));
    dbge(-EINVAL);
    dbgbt();

    return (0);
}

Build and run:

https://github.com/eerimoq/dbg-macro/raw/master/docs/example-build-and-run.png

Compile time configuration

Define NDBG to make the macros a no-op.

Define DBG_NCOLOR for colorless output.

Define DBG_OSTREAM=<my-ostream> for custom output stream (stderr by default).

About

A set of dbg(…) macros for C

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.