Skip to content

Commit

Permalink
Add an OS X debugging workaround.
Browse files Browse the repository at this point in the history
  • Loading branch information
David German authored and david-german-tri committed Feb 27, 2017
1 parent d94ab70 commit 6ee3590
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
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",
},
)

6 changes: 6 additions & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ 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

### 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

0 comments on commit 6ee3590

Please sign in to comment.