dbg-macro for Mac
A macro for printf-style debugging fans.
dbg-macro — overview
dbg(…)
A macro for printf-style debugging fans.
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 include include
// You can use "dbg(..)" in expressions: int32_t factorial(int32_t n) { if (dbg(n numbers{b, 13, 42}; dbg(numbers); // [example.cpp:21 (main)] numbers = {7, 13, 42} (std::vector)
dbg("this line is executed"); // [example.cpp:23 (main)] this line is executed
factorial(4);
return 0; } bash git clone https://github.com/sharkdp/dbg-macro sudo ln -s $(readlink -f dbg-macro/dbg.h) /usr/local/include/dbg.h bash yay -S dbg-macro bash vcpkg install dbg-macro cmake cmake_minimum_required(VERSION 3.11) # FetchContent added in cmake 3.11 project(app) # name of executable
set(CMAKE_CXX_STANDARD 17)
dbg-macro include(FetchContent)
FetchContent_Declare(dbg_macro GIT_REPOSITORY https://github.com/sharkdp/dbg-macro) FetchContent_MakeAvailable(dbg_macro)
add_executable(${PROJECT_NAME} main.cpp) # your source files goes here target_link_libraries(${PROJECT_NAME} PRIVATE dbg_macro) # make dbg.h available cpp include
int main() { dbg(42, "hello world", false); return 0; } c++ dbg(42, "hello world", false); c++ dbg("a vector:", (std::vector{2, 3, 4})); c++ const uint32_t secret = 12648430; dbg(dbg::hex(secret)); c++ template void my_function_template() { using MyDependentType = typename std::remove_reference::type&&; dbg(dbg::type()); } c++ dbg(dbg::time());
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:
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:
To run the tests, simply call:
You can find the unit tests in tests/basic.cpp.
Acknowledgement
This project is inspired by Rusts dbg!(…)` macro.
Details
C语言的Dbg(…)宏
How to install dbg-macro
- Open Terminal (press ⌘ + Space and type “Terminal”).
- If Homebrew is not installed yet, run the command below first.
- Run this command:
Latest 10 releases
Last updated 2023-09-26; current version v0.5.1, with the latest 6 releases listed.
| Version | Released | Type | Size | macOS | Windows | Linux |
|---|---|---|---|---|---|---|
| v0.5.1 | 2023-09-26 | Stable | — | — | — | — |
| v0.5.0 | 2023-03-25 | Stable | — | — | — | — |
| v0.4.0 | 2020-05-26 | Stable | — | — | — | — |
| v0.3.0 | 2020-01-05 | Stable | — | — | — | — |
| v0.2.1 | 2019-12-30 | Stable | — | — | — | — |
| v0.2.0 | 2019-12-29 | Stable | — | — | — | — |
Data from GitHub Releases; stable releases first, each group sorted newest first.
Prebuilt bottle platforms
Official Homebrew bottles cover:
- all
⚠️ No prebuilt bottle for Intel Macs; Intel users need brew install --build-from-source to build from source.
Compared with similar apps
Only public metadata is compared, with no subjective recommendation; see the compare pages for field-by-field comparisons.
| App | Version | License | Architecture | 30-day installs |
|---|---|---|---|---|
| dbg-macro | v0.5.1 | MIT | CLI | 1 |
| dasm | v2.20.18 | GPL-2.0-or-later | CLI | 13 |
| tass64 | 1.60.3243 | GPL-2.0-or-later AND LGPL-2.0-or-later AND LGPL-2.1-only AND MIT | CLI | 20 |
| m4 | 1.4.21 | GPL-3.0-or-later | CLI | 297 |
Similar apps: Command-line Tools
dasm
Macro assembler with support for several 8-bit microprocessorstass64
tass64 is a macro assembler for 65xx-series processors, suited to developers who need to write…m4
m4 is a macro processing language that often appears in developers' workflows as a command-line…openssl@4
Cryptography and SSL/TLS Toolkitxz
General-purpose data compression with high compression ratiopkgconf
pkgconf is a program which helps to configure compiler and linker flags for development…Categories: Command-line Tools