Là một dự án backend, sharkdp/dbg-macro đã đạt 3.2k sao trên GitHub, ngôn ngữ C++. A dbg(…) macro for C++
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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
sharkdp/dbg-macro có 3.2k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/sharkdp/dbg-macro. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
sharkdp/dbg-macro có những chủ đề gì?
GitHub topics của sharkdp/dbg-macro: "cpp", "debugging", "macro", "pretty-printing". TopGit xếp repo vào nhóm Backend.
sharkdp/dbg-macro còn đang phát triển không?
Commit gần nhất trên sharkdp/dbg-macro là 6 tháng trước (theo timestamp GitHub). Repo có 275 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
sharkdp/dbg-macro là gì?
sharkdp/dbg-macro (sharkdp/dbg-macro) là dự án C++ trên GitHub. Theo mô tả gốc: A dbg(…) macro for C++
sharkdp/dbg-macro so với các dự án Backend khác thế nào?
sharkdp/dbg-macro được TopGit xếp vào nhóm Backend, với 3.2k sao GitHub và viết bằng C++. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
sharkdp/dbg-macro viết bằng ngôn ngữ gì?
sharkdp/dbg-macro chủ yếu viết bằng C++. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao sharkdp/dbg-macro được xếp vào nhóm Backend?
TopGit xếp sharkdp/dbg-macro vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "cpp", "debugging", "macro"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
dbg-macro có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về dbg-macro.