Commit 4fa0fac0 authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

Add support for lldbinit to macOS.

The build-flag `strip_absolute_paths_from_debug_symbols = 1` produces
deterministic outputs and has better goma caching, but breaks lldb. This CL adds
machinery to help users get functional symbols in lldb while still using that
compile flag.

Bug: 330262
Change-Id: I42f1e6c9c76296d451730ea481d7e1c3c0a69476
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1775227Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691393}
parent e85fa0ec
......@@ -2070,6 +2070,8 @@ buildflag_header("debugging_buildflags") {
header_dir = "base/debug"
enable_gdbinit_warning =
is_debug && (strip_absolute_paths_from_debug_symbols || use_custom_libcxx)
enable_lldbinit_warning =
is_debug && strip_absolute_paths_from_debug_symbols && is_mac
flags = [
"ENABLE_LOCATION_SOURCE=$enable_location_source",
......@@ -2078,6 +2080,7 @@ buildflag_header("debugging_buildflags") {
"UNSAFE_DEVELOPER_BUILD=$is_unsafe_developer_build",
"CAN_UNWIND_WITH_CFI_TABLE=$can_unwind_with_cfi_table",
"ENABLE_GDBINIT_WARNING=$enable_gdbinit_warning",
"ENABLE_LLDBINIT_WARNING=$enable_lldbinit_warning",
]
}
......
......@@ -40,7 +40,8 @@ BASE_EXPORT bool IsDebugUISuppressed();
// If a debugger is present, verifies that it is properly set up, and DCHECK()s
// if misconfigured. Currently only verifies that //tools/gdb/gdbinit has been
// sourced when using gdb on Linux.
// sourced when using gdb on Linux and //tools/lldb/lldbinit.py has been sourced
// when using lldb on macOS.
BASE_EXPORT void VerifyDebugger();
} // namespace debug
......
......@@ -128,7 +128,21 @@ bool BeingDebugged() {
return being_debugged;
}
void VerifyDebugger() {}
void VerifyDebugger() {
#if BUILDFLAG(ENABLE_LLDBINIT_WARNING)
// Quick check before potentially slower GetDebuggerProcess().
if (Environment::Create()->HasVar("CHROMIUM_LLDBINIT_SOURCED"))
return;
DCHECK(false)
<< "Detected lldb without sourcing //tools/lldb/lldbinit.py. lldb may "
"not be able to find debug symbols. Please see debug instructions for "
"using //tools/lldb/lldbinit.py:\n"
"https://chromium.googlesource.com/chromium/src/+/master/docs/"
"lldbinit.md\n"
"To continue anyway, type 'continue' in lldb. To always skip this "
"check, define an environment variable CHROMIUM_LLDBINIT_SOURCED=1";
#endif
}
#elif defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_AIX)
......
# Usage of tools/lldb/lldbinit.py
Usage of Chromium's [lldbinit.py](../tools/lldb/lldbinit.py) is recommended when
debugging with lldb. This is necessary for source-level debugging when
`strip_absolute_paths_from_debug_symbols` is enabled.
To use, add the following to your `~/.lldbinit`
```
# So that lldbinit.py takes precedence.
script sys.path[:0] = ['<.../path/to/chromium/src/tools/lldb>']
script import lldbinit
```
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# The GN arg `strip_absolute_paths_from_debug_symbols = 1` uses relative paths
# for debug symbols. This confuses lldb. We explicitly set the source-map to
# point at the root directory of the chromium checkout.
import os
import lldb
this_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.path.join(os.path.join(this_dir, os.pardir), os.pardir)
lldb.debugger.HandleCommand(
'settings set target.source-map ../.. ' + source_dir)
lldb.debugger.HandleCommand(
'settings set target.env-vars CHROMIUM_LLDBINIT_SOURCED=1')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment