{"id":24772511,"url":"https://github.com/makcymal/dbg-cpp","last_synced_at":"2025-10-10T12:19:39.212Z","repository":{"id":274390007,"uuid":"922105667","full_name":"makcymal/dbg-cpp","owner":"makcymal","description":"The macro dbg() in C++, just like in Rust","archived":false,"fork":false,"pushed_at":"2025-01-28T12:46:00.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T20:44:54.822Z","etag":null,"topics":["cpp","debug","debugging","macro","pretty-print","single-header"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/makcymal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-25T10:32:55.000Z","updated_at":"2025-01-28T12:46:03.000Z","dependencies_parsed_at":"2025-01-27T02:31:03.093Z","dependency_job_id":"78f3e03e-db7c-4748-aba2-08f35ac14997","html_url":"https://github.com/makcymal/dbg-cpp","commit_stats":null,"previous_names":["makcymal/dbg-cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/makcymal/dbg-cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makcymal%2Fdbg-cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makcymal%2Fdbg-cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makcymal%2Fdbg-cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makcymal%2Fdbg-cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/makcymal","download_url":"https://codeload.github.com/makcymal/dbg-cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/makcymal%2Fdbg-cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268322440,"owners_count":24231819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","debug","debugging","macro","pretty-print","single-header"],"created_at":"2025-01-29T04:23:12.550Z","updated_at":"2025-10-10T12:19:39.129Z","avatar_url":"https://github.com/makcymal.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The macro `dbg()` in C++, just like in Rust\n\nThis provides two macros `dbg(...)` and `DERIVE_DEBUG(...)`, an analogue of `dbg!(...)` and `#[derive(Debug)]`\n\n\n## Example\n\nFor example, the following code with nested classes and variables:\n```c++\n#include \"dbg.h\"\n\nclass Foo {\n  class Bar {\n    float pi = 3.14, e = 2.71;\n    std::shared_ptr\u003cfloat\u003e count{std::make_shared\u003cfloat\u003e(9.81)};\n   public:\n    DERIVE_DEBUG(pi * e, count);\n  };\n\n  std::map\u003cstd::string, float\u003e map{{\"light speed\", 2.9e+8},\n                                   {\"electron mass\", 9.1e-31}};\n  std::vector\u003cBar\u003e bars{Bar()};\n public:\n  DERIVE_DEBUG(map, bars);\n};\n\nint main() {\n  std::string msg = \"dbg is fun!\";\n  dbg(msg);\n  std::list\u003cFoo\u003e foo_list{Foo()};\n  dbg(foo_list, (msg.substr(7, 3)));\n}\n```\n\n... gives the following `dbg.log`:\n```\n[main.cc:26 (main) 25.01.25 12:34:56]\nmsg: std::string = \"dbg is fun!\"\n\n[main.cc:28 (main) 25.01.25 12:34:56]\nfoo_list: std::list = {\n  \u003cFoo\u003e\n  [0] = {\n    map: std::map = {\n      \u003cstd::string -\u003e float\u003e\n      [\"electron mass\"] = 9.1e-31\n      [\"light speed\"] = 2.9e+08\n    }\n    bars: std::vector = {\n      \u003cFoo::Bar\u003e\n      [0] = {\n        pi * e: float = 8.5094\n        count: std::shared_ptr = {9.81}\n      }\n    }\n  }\n}\nmsg.substr(7, 3): std::string = \"fun\"\n```\n\n## Macro `dbg(...)`\n\nPrint the debug information in the following form:\n```\n[\u003cfile\u003e:\u003cline\u003e (\u003cfunction\u003e) \u003cdate\u003e \u003ctime\u003e]\n\u003cvariable\u003e: \u003ctype\u003e = \u003cpretty-printed-variable\u003e\n```\nThis is repeated for each nested variable with the nice indentation. Can be called with fields, expressions and method calls, for instance: `dbg(a, b + c, (Method(a, b)))`. In order to correctly split on `[\"a\", \"b + c\", \"Method(a, b)\"]`, not `[\"a\", \"b + c\", \"Method(a\", \"b)\"]`, the method calls should be enclosed in parentheses\n\n\u003e Enclose the expessions containing commas in parentheses\n\n\n## Macro `DERIVE_DEBUG(...)`\n\nGenerate the method within class, that will called to pretty-print it. Can be called with fields, expressions and method calls, for instance: `DERIVE_DEBUG(a, b + c, (Method(a, b)))`.\n\n\u003e Ensure `DERIVE_DEBUG()` is placed in public block\n\nIn order to correctly split on `[\"a\", \"b + c\", \"Method(a, b)\"]`, not `[\"a\", \"b + c\", \"Method(a\", \"b)\"]`, the method calls should be enclosed in parentheses\n\n\u003e Enclose the expessions containing commas in parentheses\n\n\n## Enabling or disable debug\n\nOne can disable debugging without having to remove all `dbg()`'s with `DISABLE_DEBUG`. To enable it back do `ENABLE_DEBUG`. By default it's enabled, of course. Ensure the order of your `DISABLE_DEBUG`'s and `ENABLE_DEBUG`'s is what you think it is\n\n\n## Customization\n\nBy default debug messages are piped into `dbg.log` file (e.g., it's a pain to look for them among test reports, isn't it?).\nAnd by default it's rewritten on each run. To append instead of rewrite define\n`DBG_APPEND_TO_FILE` macro before including this file:\n```c++\n#define DBG_APPEND_TO_FILE\n#include \"dbg.h\"\n```\n\nTo pipe debug messages into `stdout` define `DBG_WRITE_TO_STDOUT`:\n```c++\n#define DBG_WRITE_TO_STDOUT\n#include \"dbg.h\"\n```\n\n\n## Known issues\n\n- On GCC and Clang user-defined class names turn out to be correct, thanks to\ntheir extension `abi::__cxa_demangle`. On MSVC class names can be mangled a bit\n\n- Besides `dbg` and `DERIVE_DEBUG` brings into scope where it was included the symbols `DBG_DEMANGLE_CLASS_NAMES`, `DBG_WRITE_TO_FILE`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakcymal%2Fdbg-cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmakcymal%2Fdbg-cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmakcymal%2Fdbg-cpp/lists"}