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

    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:

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

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

     0{
     1"version": "0.2.0",
     2"configurations": [
     3	{
     4	"type": "lldb",
     5	"request": "launch",
     6	"name": "Debug",
     7	"program": "${workspaceFolder}/build/bin/bitcoind",
     8	"args": [
     9		"-regtest"
    10	],
    11	"cwd": "${workspaceFolder}",
    12	}
    13]
    14}
    

    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

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

    Code Coverage & Benchmarks

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

    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 <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    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.

  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:

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

    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:

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

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

    0<3674904>   DW_AT_name        : (indirect line string, offset: 0x5f8a): ./wallet/interfaces.cpp
    1<3674908>   DW_AT_comp_dir    : (indirect line string, offset: 0x5f4f): /home/arejula27/workspaces/bitcoin/build-master/src/wallet
    2<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)

    0<3674904>   DW_AT_name        : (indirect line string, offset: 0x5f70): ./wallet/interfaces.cpp
    1<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)

    0<18>   DW_AT_name        : (indirect string, offset: 0x32): /home/arejula27/workspaces/bitcoin/src/bitcoind.cpp
    1<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:

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

    PR:

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

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

    both master and PR:

    0Process 97809 stopped
    1* thread [#1](/bitcoin-bitcoin/1/), name = 'b-test', queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    2    frame [#0](/bitcoin-bitcoin/0/): 0x0000000100169820 test_bitcoin`GetCheckRatio(node_ctx=0x000000016fdfa9b8) at addrman_tests.cpp:32:32
    3Target 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

     0Process 98441 stopped
     1* thread [#36](/bitcoin-bitcoin/36/), name = 'b-msghand', stop reason = breakpoint 1.1
     2    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
     3   3428	                                     const std::chrono::microseconds time_received,
     4   3429	                                     const std::atomic<bool>& interruptMsgProc)
     5   3430	{
     6-> 3431	    AssertLockHeld(g_msgproc_mutex);
     7   3432	
     8   3433	    LogDebug(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId());
     9   3434	
    10Target 0: (bitcoind) stopped.
    11(lldb) 
    

    I also saw the same behaviour as @pinheadmz for test_bitcoin

    You can see the list of binaries using

    0 ls build/bin
    1bitcoin*        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-01-07 18:13 UTC

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