build: Fix source paths for debugging in CMake #34081

pull arejula27 wants to merge 1 commits into bitcoin:master from arejula27:debug-path-cmake-adjust changing 1 files +10 −0
  1. arejula27 commented at 6:20 PM on December 16, 2025: none

    <!-- *** Please remove the following help text before submitting: *** Pull requests without a rationale or clear improvement may be closed immediately. GUI-related pull requests should be opened against https://github.com/bitcoin-core/gui first. See CONTRIBUTING.md -->

    <!-- Please provide clear motivation for your patch and explain how it improves Bitcoin Core user experience or Bitcoin Core developer experience significantly: * Any test improvements or new tests that improve coverage are always welcome. * All other changes should have accompanying unit tests (see `src/test/`) or functional tests (see `test/`). Contributors should note which tests cover modified code. If no tests exist for a region of modified code, new tests should accompany the change. * Bug fixes are most welcome when they come with steps to reproduce or an explanation of the potential issue as well as reasoning for the way the bug was fixed. * Features are welcome, but might be rejected due to design or scope issues. If a feature is based on a lot of dependencies, contributors should first consider building the system outside of Bitcoin Core, if possible. * Refactoring changes are only accepted if they are required for a feature or bug fix or otherwise improve developer experience significantly. For example, most "code style" refactoring changes require a thorough explanation why they are useful, what downsides they have and why they *significantly* improve developer experience or avoid serious programming bugs. Note that code style is often a subjective matter. Unless they are explicitly mentioned to be preferred in the [developer notes](/doc/developer-notes.md), stylistic code changes are usually rejected. -->

    <!-- Bitcoin Core has a thorough review process and even the most trivial change needs to pass a lot of eyes and requires non-zero or even substantial time effort to review. There is a huge lack of active reviewers on the project, so patches often sit for a long time. -->

    With the build workflow change from Autotools to CMake, the debug information became incorrect due to outdated file path remapping (#31204). This issue comes from a workaround that was needed in the previous build system (#21885 problem, which was addressed in #20353 and later again on #22409. ).

    This PR attempts to resolve the problem by correcting the file path remapping for the new out-of-source build.

    I have tested the fix both in the terminal using GDB and in VS Code using LLDB

    After my changes, I tested by running gdb:

    cmake -DCMAKE_BUILD_TYPE=Debug -B build 
    cmake --build build -j "$(($(nproc)/2+1))"
    
    gdb  build/bin/bitcoind
    break init.cpp:1848
    run  -regtest 
          Thread 1 "bitcoind" hit Breakpoint 1, AppInitMain (node=..., tip_info=0x0) at ./init.cpp:1848
           1848        if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
    

    And also with lldb and vscode using the following .vscode/launch.json:

    {
    "version": "0.2.0",
    "configurations": [
    	{
    	"type": "lldb",
    	"request": "launch",
    	"name": "Debug",
    	"program": "${workspaceFolder}/build/bin/bitcoind",
    	"args": [
    		"-regtest"
    	],
    	"cwd": "${workspaceFolder}",
    	}
    ]
    }
    

    Alternatives

    If this PR is not considered, I have two alternative proposals:

    • Update the doc to remove the text indicating the user must debug from the root of the project
    • PR #https://github.com/bitcoin/bitcoin/pull/32205 Update the doc indicating they must use set substitute-path path/to/build/src /path/to/project/root/src
  2. build: Fix source paths for debugging in CMake e3195783ed
  3. DrahtBot added the label Build system on Dec 16, 2025
  4. DrahtBot commented at 6:20 PM on December 16, 2025: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34081.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK pinheadmz, ismaelsadeeq

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34116 (cmake: Fix debugging info by hebasto)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. maflcko commented at 7:41 PM on December 16, 2025: member
  6. arejula27 commented at 7:52 PM on December 16, 2025: none

    re: @maflcko

    See #31204 (comment)

    I didn’t see this, thank you. The issue points exactly to the problem I’m trying to fix. I see that the proposed solution in #32205 addresses the problem by updating the documentation. While that might work, it doesn’t actually fix the underlying issue and requires updating the paths for each build (some users may run cmake -B debug-build1 and cmake -B debug-build2 . My proposal avoids additional user configuration, and it is more dynamic as it uses variables within CMake (PROJECT_BINARY_DIR)

  7. maflcko commented at 7:56 PM on December 16, 2025: member

    How is your patch different from just removing the prefix-map option?

  8. arejula27 commented at 8:01 PM on December 16, 2025: none

    As I understand the problem, the solution is not removing the prefix-map option but changing where it points. This can be done either in .lldbinit, .gdbinit, or in CMake. My proposal simply removes friction for the developer, as it will not require them to put a path in their configuration.

    i propose modifying the cmake: "-fdebug-prefix-map=${PROJECT_BINARY_DIR}/src=${PROJECT_SOURCE_DIR}/src"

    The #32205 proposes suggesting users to modify the debugger config: settings set target.source-map /path/to/bitcoin/build/src /path/to/bitcoin/src

    It will have the same outcome, but mine will be automatically done. Also it is more interoperable as I mentioned i it worked with gdb and lldb, while in the other case I would require to configure both debuggers

  9. maflcko commented at 8:11 PM on December 16, 2025: member

    As I understand the problem, the solution is not removing the prefix-map option but changing where it points.

    Yes, but I am asking why? What would be the observable difference? It just seems odd to have code that doesn't achieve anything.

    At least last time I checked, the two seemed to achieve the same: #31957 (comment)

  10. arejula27 commented at 8:24 PM on December 16, 2025: none

    Just tested what you mean, removed:

    -try_append_cxx_flags("-fdebug-prefix-map=A=B" TARGET core_interface SKIP_LINK
    -  IF_CHECK_PASSED "-fdebug-prefix-map=${PROJECT_SOURCE_DIR}/src=."
    -)
    

    It had the same effect, yes, make more sense removing code that makes an incorrect behaviour than adding more above it. I will try to research if it has any advantages, but in other cas,e the correct approach should be to remove the incorrect mapping

    Edit: @hebasto pointed out that removing it might resurface an issue (https://github.com/bitcoin/bitcoin/issues/30799.) I will try to look into it #31957 (comment)

  11. maflcko commented at 8:42 PM on December 16, 2025: member

    Edit: @hebasto pointed out that removing it might resurface an issue (#30799.) I will try to look into it #31957 (comment)

    This may be a macro, and not the debug info, so may be fine, but I haven't checked this.

  12. arejula27 commented at 11:19 PM on December 17, 2025: none

    I have analysed how the different debug information is stored in the master branch, using my changes and removing the remaps (your proposal ). The observable difference is in how DWARF debug information records source file paths.

    Here are the three scenarios I tested with objdump to extract the info:

    objdump -g ./build/bin/bitcoind | grep -A5 -B5 "src/" 
    

    First case (master branch – remap relative path for old project layout)

    <3674904>   DW_AT_name        : (indirect line string, offset: 0x5f8a): ./wallet/interfaces.cpp
    <3674908>   DW_AT_comp_dir    : (indirect line string, offset: 0x5f4f): /home/arejula27/workspaces/bitcoin/build-master/src/wallet
    <367490c>   DW_AT_ranges      : 0xedf1f
    
    • DW_AT_comp_dir points to a build directory (build-master/src/wallet)
    • This indicates an out-of-tree build (build and src folders are not the same)
    • The debug info records paths relative to the build tree

    Second case (with my changes, remap relative path correctly)

    <3674904>   DW_AT_name        : (indirect line string, offset: 0x5f70): ./wallet/interfaces.cpp
    <3674908>   DW_AT_comp_dir    : (indirect line string, offset: 0x5f42): /home/arejula27/workspaces/bitcoin/src/wallet
    
    • DW_AT_comp_dir points to the source directory (src/wallet)
    • This indicates an in-tree-like behaviour for paths (build and src folders are the same)
    • The debug info records paths relative to the source tree

    Third case (removing the flags entirely, use absolute path)

    <18>   DW_AT_name        : (indirect string, offset: 0x32): /home/arejula27/workspaces/bitcoin/src/bitcoind.cpp
    <1c>   DW_AT_comp_dir    : (indirect string, offset: 0): /home/arejula27/workspaces/bitcoin/build-clean/src
    
    • DW_AT_name contains an absolute path to the source file (src/bitcoind.cpp)
    • DW_AT_comp_dir points to a build directory (build-clean/src)
    • This indicates an out-of-tree build
    • The debug info records the full source path directly, not relative to the build or source tree

    Conclusion

    So replying to:

    What would be the observable difference? It just seems odd to have code that doesn't achieve anything.

    The difference is in storing absolute paths or relative ones. The current branch is just wrong, it points incorrectly. The decision is whether you prefer a relative or an absolute path. I read on some old related issues/pr that relative paths are better for tools like ccache, but I am not an expert on that.

  13. maflcko commented at 8:53 AM on December 19, 2025: member

    Second case (with my changes, remap relative path correctly)

    It is interesting that this is using relative paths. I had the impression that "-fdebug-prefix-map=${PROJECT_BINARY_DIR}/src=${PROJECT_SOURCE_DIR}/src" has absolute paths on both sides of the mapping.

    The difference is in storing absolute paths or relative ones. The current branch is just wrong, it points incorrectly. The decision is whether you prefer a relative or an absolute path. I read on some old related issues/pr that relative paths are better for tools like ccache, but I am not an expert on that.

    I think the ccache behavior is currently broken anyway (https://github.com/bitcoin/bitcoin/pull/30861 was closed), so there is little that can be broken by removing the code.

    Of course, everything will still need to be tested to confirm the fixes and no new breakages.

    You'll have to include in the pull request descriptions, which bugs are fixed. Also, mentioning autogen and configure doesn't really help, when the project here is using cmake.

  14. pinheadmz commented at 8:53 PM on December 22, 2025: member

    concept ACK, this works for source code in src/ when debugging bitcoind but more changes are needed, for example, to debug test_bitcoin.

    This is a much better fix than just updating docs like #32205

    Example that works: bitcoind, set breakpoint at BindListenPort

    master:

    Process 92900 stopped
    * thread [#1](/bitcoin-bitcoin/1/), queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
        frame [#0](/bitcoin-bitcoin/0/): 0x00000001002c9720 bitcoind`CConnman::BindListenPort(this=0x0000000121009a00, addrBind=0x000000016fdfa980, strError=0x000000016fdfa950, permissions=None) at net.cpp:3139:9
    Target 0: (bitcoind) stopped.
    

    PR:

    Process 97697 stopped
    * thread [#1](/bitcoin-bitcoin/1/), queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
        frame [#0](/bitcoin-bitcoin/0/): 0x00000001002c56f0 bitcoind`CConnman::BindListenPort(this=0x000000012b80e000, addrBind=0x000000016fdfab60, strError=0x000000016fdfab30, permissions=None) at net.cpp:3139:9
       3136 
       3137 bool CConnman::BindListenPort(const CService& addrBind, bilingual_str& strError, NetPermissionFlags permissions)
       3138 {
    -> 3139     int nOne = 1;
       3140 
       3141     // Create socket for listening for incoming connections
       3142     struct sockaddr_storage sockaddr;
    Target 0: (bitcoind) stopped.
    

    Example that doesn't work: test_bitcoin, set breakpoint at GetCheckRatio() in addrman_tests

    both master and PR:

    Process 97809 stopped
    * thread [#1](/bitcoin-bitcoin/1/), name = 'b-test', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
        frame [#0](/bitcoin-bitcoin/0/): 0x0000000100169820 test_bitcoin`GetCheckRatio(node_ctx=0x000000016fdfa9b8) at addrman_tests.cpp:32:32
    Target 0: (test_bitcoin) stopped.
    
  15. arejula27 commented at 10:40 AM on December 24, 2025: none

    re: @maflcko

    You'll have to include in the pull request descriptions, which bugs are fixed. Also, mentioning autogen and configure doesn't really help, when the project here is using cmake.

    Thank you for your feedback. This is my first PR, so any advice is welcome. I’ve edited the description to better summarize the change and to point directly to the specific bug being addressed.

  16. arejula27 commented at 10:43 AM on December 24, 2025: none

    re: @pinheadmz

    this works [...] when debugging bitcoind but more changes are needed, for example, to debug test_bitcoin

    Good point, I’ll try to address this as well. Is there any other binary you’d like me to verify? I don’t think the functional tests are related to this PR, but I might be others I am missing.

  17. ismaelsadeeq commented at 11:12 AM on December 24, 2025: member

    Concept ACK

    This works for me out of the box

    Process 98441 stopped
    * thread [#36](/bitcoin-bitcoin/36/), name = 'b-msghand', stop reason = breakpoint 1.1
        frame [#0](/bitcoin-bitcoin/0/): 0x00000001002d8a3c bitcoind`(anonymous namespace)::PeerManagerImpl::ProcessMessage(this=0x00000007e703d400, pfrom=0x0000000103b6b430, msg_type="version", vRecv=0x000000017111eb30, time_received=1766574637095060 µs, interruptMsgProc=0x00000007e703d240) at net_processing.cpp:3431:5
       3428	                                     const std::chrono::microseconds time_received,
       3429	                                     const std::atomic<bool>& interruptMsgProc)
       3430	{
    -> 3431	    AssertLockHeld(g_msgproc_mutex);
       3432	
       3433	    LogDebug(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId());
       3434	
    Target 0: (bitcoind) stopped.
    (lldb) 
    

    I also saw the same behaviour as @pinheadmz for test_bitcoin

    You can see the list of binaries using

     ls build/bin
    bitcoin*        bitcoin-cli*    bitcoin-node*   bitcoin-tx*     bitcoin-util*   bitcoin-wallet* bitcoind*       test_bitcoin*
    
  18. arejula27 commented at 1:03 PM on December 24, 2025: none

    This PR conflicts with #34116, which solves the same issue. After reviewing it i believe #34116 is a better approach. I would keep this one open to receive other opinions, but this PR should be closed if #34116 is preferred by the community

  19. fanquake commented at 2:13 PM on January 2, 2026: member

    After reviewing it i believe #34116 is a better approach.

    Thanks, we'll close this in favour of #34116 for now.

  20. fanquake closed this on Jan 2, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me