-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for running GDB and LLDB #4710
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "by-gdb", | ||
"request": "launch", | ||
"name": "file_test (gdb)", | ||
"program": "bazel-bin/toolchain/testing/file_test", | ||
"programArgs": "--file_tests=${relativeFile}", | ||
"cwd": "${workspaceFolder}", | ||
"env": { "TEST_TMPDIR": "/tmp" } | ||
}, | ||
{ | ||
"type": "by-gdb", | ||
"request": "launch", | ||
"name": "carbon compile (gdb)", | ||
"program": "bazel-bin/toolchain/install/prefix_root/lib/carbon/carbon-busybox", | ||
"programArgs": "compile --phase=lower --dump-sem-ir --stream-errors ${relativeFile}", | ||
"cwd": "${workspaceFolder}" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb-dap", | ||
"request": "launch", | ||
"name": "file_test (lldb)", | ||
"program": "bazel-bin/toolchain/testing/file_test", | ||
"args": ["--file_tests=${relativeFile}"], | ||
"debuggerRoot": "${workspaceFolder}", | ||
"initCommands": [ | ||
"command script import external/_main~llvm_project~llvm-project/llvm/utils/lldbDataFormatters.py", | ||
"settings set target.source-map \".\" \"${workspaceFolder}\"" | ||
], | ||
"env": { "TEST_TMPDIR": "/tmp" } | ||
}, | ||
{ | ||
"type": "lldb-dap", | ||
"request": "launch", | ||
"name": "carbon compile (lldb)", | ||
"program": "bazel-bin/toolchain/install/prefix_root/lib/carbon/carbon-busybox", | ||
"args": [ | ||
"compile", | ||
"--phase=lower", | ||
"--dump-sem-ir", | ||
"--stream-errors", | ||
"${relativeFile}" | ||
], | ||
"debuggerRoot": "${workspaceFolder}", | ||
"initCommands": [ | ||
"command script import external/_main~llvm_project~llvm-project/llvm/utils/lldbDataFormatters.py", | ||
"settings set target.source-map \".\" \"${workspaceFolder}\"" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,14 +22,15 @@ contributions. | |||||
- [Main tools](#main-tools) | ||||||
- [Running pre-commit](#running-pre-commit) | ||||||
- [Optional tools](#optional-tools) | ||||||
- [Using LLDB with VS Code](#using-lldb-with-vs-code) | ||||||
- [Using GDB with VS Code](#using-gdb-with-vs-code) | ||||||
- [Manually building Clang and LLVM (not recommended)](#manually-building-clang-and-llvm-not-recommended) | ||||||
- [Troubleshooting build issues](#troubleshooting-build-issues) | ||||||
- [`bazel clean`](#bazel-clean) | ||||||
- [Old LLVM versions](#old-llvm-versions) | ||||||
- [Asking for help](#asking-for-help) | ||||||
- [Troubleshooting debug issues](#troubleshooting-debug-issues) | ||||||
- [Debugging with GDB instead of LLDB](#debugging-with-gdb-instead-of-lldb) | ||||||
- [Disabling split debug info](#disabling-split-debug-info) | ||||||
- [Debugging other build modes](#debugging-other-build-modes) | ||||||
- [Debugging on MacOS](#debugging-on-macos) | ||||||
|
||||||
|
@@ -239,6 +240,44 @@ considering if they fit your workflow. | |||||
``` | ||||||
- **NOTE**: This assumes you have `python` 3 installed on your system. | ||||||
|
||||||
#### Using LLDB with VS Code | ||||||
|
||||||
The required setup for LLDB is: | ||||||
|
||||||
1. Install a minimum of LLVM 19 instead of LLVM 16. | ||||||
- The `lldb-dap` tool was added as part of LLVM 19. | ||||||
2. Symlink `lldb_launch.json` to `launch.json`: | ||||||
`ln -s lldb_launch.json .vscode/launch.json` | ||||||
3. Install the | ||||||
[`llvm-vs-code-extensions.lldb-dap` extension](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap). | ||||||
4. In VS Code settings, it may be necessary to set `lldb-dap.executable-path` | ||||||
to the path of `lldb-dap`. | ||||||
|
||||||
A typical debug session looks like: | ||||||
|
||||||
1. `bazel build -c dbg //toolchain/testing:file_test` | ||||||
2. Open a `.carbon` testdata file to debug. This must be the active file in VS | ||||||
Code. | ||||||
3. Go to the "Run and debug" panel in VS Code. | ||||||
4. Select and run the `file_test (lldb)` configuration. | ||||||
|
||||||
#### Using GDB with VS Code | ||||||
|
||||||
The required setup for GDB is: | ||||||
|
||||||
1. Symlink `gdb_launch.json` to `launch.json`: | ||||||
`ln -s gdb_launch.json .vscode/launch.json` | ||||||
2. Install the | ||||||
[`coolchyni.beyond-debug` extension](https://marketplace.visualstudio.com/items?itemName=coolchyni.beyond-debug). | ||||||
|
||||||
A typical debug session looks like: | ||||||
|
||||||
1. `bazel build -c dbg --features=-lldb_flags --features=gdb_flags //toolchain/testing:file_test` | ||||||
2. Open a `.carbon` testdata file to debug. This must be the active file in VS | ||||||
Code. | ||||||
3. Go to the "Run and debug" panel in VS Code. | ||||||
4. Select and run the `file_test (gdb)` configuration. | ||||||
|
||||||
### Manually building Clang and LLVM (not recommended) | ||||||
|
||||||
We primarily test against [apt.llvm.org](https://apt.llvm.org) and Homebrew | ||||||
|
@@ -247,9 +286,10 @@ comfortable with it. The essential CMake options to pass in order for this to | |||||
work reliably include: | ||||||
|
||||||
``` | ||||||
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld | ||||||
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld;lldbg | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
-DLLVM_ENABLE_RUNTIMES=compiler-rt;libcxx;libcxxabi;libunwind | ||||||
-DRUNTIMES_CMAKE_ARGS=-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF;-DCMAKE_POSITION_INDEPENDENT_CODE=ON;-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON;-DLIBCXX_STATICALLY_LINK_ABI_IN_SHARED_LIBRARY=OFF;-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON;-DLIBCXX_USE_COMPILER_RT=ON;-DLIBCXXABI_USE_COMPILER_RT=ON;-DLIBCXXABI_USE_LLVM_UNWINDER=ON | ||||||
-DLLDB_ENABLE_PYTHON=ON | ||||||
``` | ||||||
|
||||||
## Troubleshooting build issues | ||||||
|
@@ -336,13 +376,6 @@ Dwarf Error: DW_FORM_strx1 found in non-DWO CU | |||||
It means that the version of GDB used is too old, and does not support the DWARF | ||||||
v5 format. | ||||||
|
||||||
### Disabling split debug info | ||||||
|
||||||
Our build uses split debug info by default on Linux to improve build and | ||||||
debugger performance and reduce the size impact of debug information which can | ||||||
be extremely large. If you encounter problems, you can disable it by passing | ||||||
`--fission=no` to Bazel. | ||||||
|
||||||
### Debugging other build modes | ||||||
|
||||||
If you have an issue that only reproduces with another build mode, you can still | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make it a bit more explicit what this is doing? Thinking about something like this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about instead writing "In the
.vscode
subdirectory"?