{"id":29907987,"url":"https://github.com/codedownio/ghc-debug","last_synced_at":"2025-10-15T22:19:12.153Z","repository":{"id":306357196,"uuid":"1025907879","full_name":"codedownio/ghc-debug","owner":"codedownio","description":"Forked from https://gitlab.haskell.org/ghc/ghc-debug","archived":false,"fork":false,"pushed_at":"2025-07-25T02:32:33.000Z","size":929,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-09T05:20:02.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codedownio.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,"zenodo":null}},"created_at":"2025-07-25T02:30:24.000Z","updated_at":"2025-07-25T02:32:37.000Z","dependencies_parsed_at":"2025-07-25T07:51:00.151Z","dependency_job_id":null,"html_url":"https://github.com/codedownio/ghc-debug","commit_stats":null,"previous_names":["codedownio/ghc-debug"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codedownio/ghc-debug","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedownio%2Fghc-debug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedownio%2Fghc-debug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedownio%2Fghc-debug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedownio%2Fghc-debug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codedownio","download_url":"https://codeload.github.com/codedownio/ghc-debug/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codedownio%2Fghc-debug/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279121642,"owners_count":26108286,"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-10-15T02:00:07.814Z","response_time":56,"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":[],"created_at":"2025-08-01T23:17:28.853Z","updated_at":"2025-10-15T22:19:12.135Z","avatar_url":"https://github.com/codedownio.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[Documentation Site](http://ghc.gitlab.haskell.org/ghc-debug)\n\n\n`ghc-debug` is a set of libraries which allow you to inspect the heap of\na running Haskell program from an external debugger.\n\nFor example, you could use this library to\n* Implement a memory profiler, written in Haskell - [GHC.Debug.Profile](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Profile.hs)\n* Precisely analyse other heap properties such as retainers - [GHC.Debug.Retainers](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Retainers.hs)\n* Work out any other question you want about the heap by writing your own\ncustom analysis. The possibilities are endless!\n\n# Getting Started\n\nThere are two parts to using `ghc-debug`. Firstly the application you want to\ninspect has to be instrumented using the `withGhcDebug` function from\n`GHC.Debug.Stub`. This just wraps the normal main function of your executable,\nwhen it is executed it will create a socket by which a debugger can connect\nand issue requests to. The location of the socket can be controlled by setting\nthe `GHC_DEBUG_SOCKET` variable when the executable is run.\n\n```\nimport GHC.Debug.Stub\n\nmain = withGhcDebug normalMain\n```\n\nNote: To enable source information you should also compile your application and\ndependencies with `-finfo-table-map` and optionally `-fdistinct-constructor-tables`.\n\n## A simple debugger\n\nThe most productive way to use `ghc-debug` is to write your own heap analysis\nscripts. Fortunately, this is also quite simple. Here is a simple, complete, debugger\nwhich connects to the `/tmp/ghc-debug` socket, requests the GC roots and then\ndecodes the first one up to depth 10 before printing the result to the user.\n\n```\nimport GHC.Debug.Client\n\nmain = withDebuggeeConnect \"/tmp/ghc-debug\" p1\n\np1 :: Debuggee -\u003e IO ()\np1 e = do\n  pause e\n  g \u003c- run e $ do\n        precacheBlocks\n        (r:_) \u003c- gcRoots\n        buildHeapGraph (Just 10) r\n  putStrLn (ppHeapGraph (const \"\") g)\n```\n\nThe API for writing debuggers is described in the `GHC.Debug.Client` module.\n\nThere are many more examples in the `test/Test.hs` file.\n\n## Snapshotting\n\nA convenient way to use `ghc-debug` is to take a *snapshot* of the heap and then\nperform further analysis on the snapshot rather than connecting to a running\nprocess. Snapshotting utilities are in the `GHC.Debug.Snapshot` module. A\nsnapshot can be created using the `makeSnapshot` program, it will pause\nthe process and then save a snapshot to the `/tmp/ghc-debug-snapshot` file.\n\n```\nimport GHC.Debug.Client\nimport GHC.Debug.Snapshot\n\nmain = withDebuggeeConnect \"/tmp/ghc-debug\" (\\d -\u003e makeSnapshot d \"/tmp/ghc-debug-snapshot\")\n```\n\nA snapshot can be then used for further analysis. For example, we can run `p1` on\nthe snapshot by using `snapshotRun` instead of `withDebuggeeConnect`. The same\nprograms can be used with snapshots but requests such as pausing and resuming are\njust ignored.\n\n```\nimport GHC.Debug.Client\n\nmain = snapshotRun \"/tmp/ghc-debug-snapshot\" p1\n```\n\n\n## High-Level Analysis\n\nThere are also some more high-level analysis tools already packaged with the\nlibrary. Mostly as an idea about what sort of thing you could program yourself.\n\n* [Profiling](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Profile.hs) - Profiling modes in the spirit of `-hT`.\n* [Object Equivalence](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/ObjectEquiv.hs) - Detect equivalent heap objects which could be shared.\n* [Count](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Count.hs) - Simple heap statistics, total number of objects, total size and maximum object size.\n* [Fragmentation](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Fragmentation.hs) - Functions for analysis memory fragmentation including block and mblock utilisation histograms.\n* [Retainers](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Retainers.hs) - Finding paths through the heap to work out why objects are being retained.\n* [Type Points From](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/TypePointsFrom.hs) - Collapse a heap graph so that nodes are info tables and edges are references between info tables. This allows you to implement the [Cork](https://www.cs.utexas.edu/users/speedway/DaCapo/papers/cork-popl-2007.pdf) leak analysis.\n\nThese analysis modes are implemented in terms of the more low-level traversal\nfunctions.\n\n* [Sequential Traversal](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/Trace.hs) - Traversal with low memory overhead, accounting for cycles.\n* [Parallel Traversal](https://gitlab.haskell.org/ghc/ghc-debug/-/blob/master/client/src/GHC/Debug/ParTrace.hs) - Experimental Parallel Traversal with low memory overhead.\n\n# Other Resources\n\n* [An introduction to ghc-debug: precise memory analysis for Haskell programs](https://www.youtube.com/watch?v=9zuAsGk9xoM)\n\n\n# How does it work?\n\nWe call the process we want to debug the debuggee and the process which does\nthe debugging the debugger.\nWhilst the debuggee is\nrunning it calls the C function `start` which creates a unix domain socket (which is set from `GHC_DEBUG_SOCKET`). The debugger starts and connects to the socket.\n\nOnce the debugger is connected it can send requests to the debuggee to control\nand inspect the RTS.\n\n# How do I use it?\n\nYou can build the libraries directly from hackage.\n\n### Automated Testing\n\nThere are `hspec` tests, that can be run with `cabal`:\n\n```\ncabal new-test all\n```\n\n### Unexpected Build Failures\n\nIf you encounter dependencies failing to build but there's a patch for\nthe library in head.hackage then you may need to delete `~/.cabal/packages/head.hackage.org`\nso that the fresh patch is visible. This is probably a bug in cabal!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedownio%2Fghc-debug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodedownio%2Fghc-debug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodedownio%2Fghc-debug/lists"}