Docs: Explain how to do Debug builds without optimizations on

This change updates the (advanced) build docs to explain how to do a
Debug build with the CXX `-O0` option set — which tells the compiler to
build with no optimizations at all.

Otherwise, Debug builds use the `-Og` option — which, when trying to
check frame variables in a debugger can result in an error of this form:

> error: Couldn't look up symbols: __ZN2AK6Detail10StringBaseD2Ev
> Hint: The expression tried to call a function that is not present in
> the target, perhaps because it was optimized out by
> the compiler.
This commit is contained in:
sideshowbarker 2024-12-08 17:16:04 +09:00 committed by Andrew Kaster
parent e49fe384d1
commit afca902ea9
Notes: github-actions[bot] 2024-12-12 00:32:51 +00:00

View file

@ -96,3 +96,59 @@ export CCACHE_COMPILERCHECK="%compiler% -v"
By default, ccache will include the plugins themselves in file hashes. So if a plugin changes, the hash of every file
will change, and you will be stuck with an uncached build. This setting will prevent ccache from using plugins in the
file hashes.
## Debugging without any optimizations
Its possible that when trying to inspect certain frame variables in your debugger, youll get an error similar to the following:
> error: Couldn't look up symbols: __ZN2AK6Detail10StringBaseD2Ev
> Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.
If you do run into such an error, the rest of this section explains how to deal with it.
> [!WARNING]
> You probably only want to make the build-file change described below while youre in the middle of examining the state of a particular build in your debugger — and then youll want to revert it after youre done debugging. You otherwise probably dont want to have the build-file change in place while youre running WPT tests or in-tree tests and checking the results.
1. At your command-line prompt in your shell environment, copy and paste the following:
```diff
$ patch -p1 <<EOF
diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake
index 7fec47ac843..45c3af87493 100644
--- a/Meta/CMake/lagom_compile_options.cmake
+++ b/Meta/CMake/lagom_compile_options.cmake
@@ -29,7 +29,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (NOT MSVC)
add_cxx_compile_options(-ggdb3)
endif()
- add_cxx_compile_options(-Og)
+ add_cxx_compile_options(-O0)
else()
add_cxx_compile_options(-O2)
if (NOT MSVC)
EOF
```
…or else copy and paste that patch, and apply it in whatever way you normally use for applying patches.
That will patch the build config in such a way as to disable all compiler optimizations and make all debug symbols always available.
2. At your command-line prompt in your shell environment, run the following command:
```
git update-index --skip-worktree Meta/CMake/lagom_compile_options.cmake
```
That will cause git to ignore the change you made to that build file. Otherwise, if you dont run that command, git will consider that build file to have been modified, and you might then end up inadvertently committing the changes to that build file as part of some actual code change youre making to the sources that youre in the process of debugging.
3. Run a build again with the `Debug` preset, and then go back into your debugger. Youll now be able to inspect any frame variable that you werent able to previously.
After youve finished debugging your code changes with that build, you can revert the above changes by doing this:
1. At your command-line prompt in your shell environment, run the following:
```
git update-index --no-skip-worktree Meta/CMake/lagom_compile_options.cmake \
&& git checkout Meta/CMake/lagom_compile_options.cmake
```
That will restore your git environment to the state it was in before you patched the build file.