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 an OS X debugging workaround. #5334

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions drake/doc/bazel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ Cheat sheet for operating on specific portions of the project::
prerequisite libraries are also compiled and linked in ``dbg`` mode.
- For the definitions of the "``--config``" options see ``drake-distro/tools/bazel.rc``.

Debugging on OS X
-----------------

On OS X, DWARF debug symbols are emitted to a ``.dSYM`` file. The Bazel
``cc_binary`` and ``cc_test`` rules do not natively generate or expose this
file, so we have implemented a workaround in Drake, ``--config=apple_debug``.
This config turns off sandboxing, which allows a ``genrule`` to access the
``.o`` files and process them into a ``.dSYM``. Use as follows::

bazel build --config=apple_debug drake/path/to/my:binary_or_test_dsym
lldb ./bazel_bin/drake/path/to/my/binary_or_test

For more information, see https://github.com/bazelbuild/bazel/issues/2537.

Updating BUILD files
====================

Expand Down
9 changes: 9 additions & 0 deletions tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,12 @@ config_setting(
"cpu": "k8",
},
)

config_setting(
name = "apple_debug",
values = {
"compilation_mode": "dbg",
"cpu": "darwin",
},
)

11 changes: 11 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ build --deleted_packages=externals/snopt,externals/snopt/cppsrc,externals/snopt/
test:cpplint --build_tests_only
test:cpplint --test_tag_filters=cpplint

### Debug symbols on OS X. ###
# See https://github.com/bazelbuild/bazel/issues/2537
build:apple_debug --spawn_strategy=standalone
build:apple_debug --genrule_strategy=standalone
build:apple_debug --compilation_mode=dbg

# We don't actually use APPLE_DEBUG in code. It's just here to invalidate any
# sandboxed .o files that might be in cache if a developer tried to build
# with --compilation_mode=dbg instead of --config=apple_debug.
build:apple_debug --copt="-DAPPLE_DEBUG"

### Kcov coverage build. ###
build:kcov --copt -g
test:kcov --spawn_strategy=standalone
Expand Down
34 changes: 34 additions & 0 deletions tools/drake.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ def _platform_copts(rule_copts):
"//conditions:default": rule_copts,
})

def _dsym_command(name):
"""Returns the command to produce .dSYM on OS X, or a no-op on Linux."""
return select({
"//tools:apple_debug":
"dsymutil -f $(location :" + name + ") -o $@ 2> /dev/null",
"//conditions:default": "touch $@",
})

def drake_cc_library(
name,
hdrs=None,
Expand Down Expand Up @@ -59,6 +67,7 @@ def drake_cc_binary(
deps=None,
copts=[],
linkstatic=1,
testonly=0,
**kwargs):
"""Creates a rule to declare a C++ binary.
Expand All @@ -71,9 +80,22 @@ def drake_cc_binary(
srcs=srcs,
deps=deps,
copts=_platform_copts(copts),
testonly=testonly,
linkstatic=linkstatic,
**kwargs)

# Also generate the OS X debug symbol file for this binary.
native.genrule(
name=name + "_dsym",
srcs=[":" + name],
outs=[name + ".dSYM"],
output_to_bindir=1,
testonly=testonly,
tags=["dsym"],
visibility=["//visibility:private"],
cmd=_dsym_command(name),
)

def drake_cc_test(
name,
size=None,
Expand Down Expand Up @@ -106,6 +128,18 @@ def drake_cc_test(
copts=_platform_copts(copts),
**kwargs)

# Also generate the OS X debug symbol file for this test.
native.genrule(
name=name + "_dsym",
srcs=[":" + name],
outs=[name + ".dSYM"],
output_to_bindir=1,
testonly=1,
tags=["dsym"],
visibility=["//visibility:private"],
cmd=_dsym_command(name),
)

def drake_cc_googletest(
name,
deps=None,
Expand Down