Indexed by TopGit from live GitHub metadata: sharkdp/dbg-macro has 3.2k stars, written primarily in C++. A dbg(…) macro for C++
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Debuggers are great. But sometimes you just don't have the time or patience to set
up everything correctly and just want a quick way to inspect some values at runtime.
This projects provides a single header file with a dbg(…)
macro that can be used in all circumstances where you would typically write
printf("…", …) or std::cout << …. But it comes with a few extras.
Examples
#include <dbg.h>
#include <cstdint>
#include <vector>
// You can use "dbg(..)" in expressions:
int32_t factorial(int32_t n) {
if (dbg(n <= 1)) {
return dbg(1);
} else {
return dbg(n * factorial(n - 1));
}
}
int32_t main() {
std::string message = "hello";
dbg(message); // [example.cpp:15 (main)] message = "hello" (std::string)
const int32_t a = 2;
const int32_t b = dbg(3 * a) + 1; // [example.cpp:18 (main)] 3 * a = 6 (int32_t)
std::vector<int32_t> numbers{b, 13, 42};
dbg(numbers); // [example.cpp:21 (main)] numbers = {7, 13, 42} (std::vector<int32_t>)
dbg("this line is executed"); // [example.cpp:23 (main)] this line is executed
factorial(4);
return 0;
}
The code above produces this output (try it yourself):
Features
Easy to read, colorized output (colors auto-disable when the output is not an interactive terminal)
Prints file name, line number, function name and the original expression
Adds type information for the printed-out value
Specialized pretty-printers for containers, pointers, string literals, enums, std::optional, etc.
Can be used inside expressions (passing through the original value)
The dbg.h header issues a compiler warning when included (so you don't forget to remove it).
Compatible and tested with C++11, C++14 and C++17.
Installation
To make this practical, the dbg.h header should be readily available from all kinds of different
places and in all kinds of environments. The quick & dirty way is to actually copy the header file
to /usr/local/include or to clone the repository and symlink dbg.h to /usr/local/include/dbg.h.
dbg(…) already prints the type for each value in parenthesis (see screenshot above). But
sometimes you just want to print a type (maybe because you don't have a value for that type).
In this case, you can use the dbg::type<T>() helper to pretty-print a given type T.
For example:
If you want to modify the type name that is printed by dbg(…), you can add a custom
get_type_name overload:
// Customization point for type information
namespace dbg {
std::string get_type_name(type_tag<bool>) {
return "truth value";
}
}
Development
If you want to contribute to dbg-macro, here is how you can build the tests and demos:
Make sure that the submodule(s) are up to date:
git submodule update --init
Then, use the typical cmake workflow. Usage of -DCMAKE_CXX_STANDARD=17 is optional,
but recommended in order to have the largest set of features enabled:
mkdir build
cd build
cmake .. -DCMAKE_CXX_STANDARD=17
make
The most recent commit recorded on sharkdp/dbg-macro was 6 months ago, based on the GitHub push timestamp. The repository has 275 forks — one of the better signals of community interest.
How does sharkdp/dbg-macro compare to other Backend projects?
sharkdp/dbg-macro is tracked by TopGit in the Backend category, with 3.2k GitHub stars and written in C++. Browse the Backend topic page on TopGit to compare it against similar projects by stars and activity.
How many stars does sharkdp/dbg-macro have?
sharkdp/dbg-macro has 3.2k GitHub stars — refresh the page for the live number, or check github.com/sharkdp/dbg-macro. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What is sharkdp/dbg-macro?
sharkdp/dbg-macro (sharkdp/dbg-macro) is a C++ project on GitHub. From the project's own README: A dbg(…) macro for C++
What language is sharkdp/dbg-macro written in?
sharkdp/dbg-macro is written primarily in C++. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is sharkdp/dbg-macro associated with?
GitHub's repository topics for sharkdp/dbg-macro: "cpp", "debugging", "macro", "pretty-printing". TopGit's editorial category is Backend.
Why is sharkdp/dbg-macro categorized under Backend?
TopGit places sharkdp/dbg-macro in the Backend category based on its GitHub topics and description (tagged: "cpp", "debugging", "macro"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Still deciding about dbg-macro?
One click hands the question to an AI along with this page — see what it says about dbg-macro.