Skip to content
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 7 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ build:linux --define=pfm=1
#
# Note: if using GDB, see documentation to get that working:
# https://docs.carbon-lang.dev/docs/project/contribution_tools.html#debugging-with-gdb-instead-of-lldb
build:linux --fission=yes
#
# TODO: Bazel has a bug where it doesn't manage dwo files in the cache correctly.
# build:linux --fission=yes

# Disables `actions.declare_symlink`. Done for cross-environment support.
build --allow_unresolved_symlinks=false
Expand Down
22 changes: 22 additions & 0 deletions .vscode/gdb_launch.json
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}"
}
]
}
36 changes: 36 additions & 0 deletions .vscode/lldb_launch.json
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}\""
]
}
]
}
51 changes: 42 additions & 9 deletions docs/project/contribution_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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`
Copy link
Contributor

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:

Suggested change
2. Symlink `lldb_launch.json` to `launch.json`:
`ln -s lldb_launch.json .vscode/launch.json`
2. Symlink `lldb_launch.json` to `launch.json` in the workspace directory (typically the checkout of the `carbon-lang` repository):
`ln -s lldb_launch.json .vscode/launch.json`

Copy link
Contributor Author

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"?

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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld;lldbg
-DLLVM_ENABLE_PROJECTS=clang;clang-tools-extra;lld;lldb

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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
Expand Down
Loading