diff --git a/.bazelrc b/.bazelrc index a2b3d462228..52a9653d303 100644 --- a/.bazelrc +++ b/.bazelrc @@ -41,6 +41,7 @@ # asan: Build with the clang address sanitizer # msan: Build with the clang memory sanitizer # ubsan: Build with the clang undefined behavior sanitizer +# dbg: Build with debug info # # # TF version options; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9791777b61c..713d9d10ae2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -254,3 +254,28 @@ There are two ways to test the code in the docstring locally: ``` The `--module` is relative to `tensorflow.python`. + +#### Debug builds + +When [building Tensorflow](https://www.tensorflow.org/install/source), passing +`--config=dbg` to Bazel will build with debugging information and without +optimizations, allowing you to use GDB or other debuggers to debug C++ code. For +example, you can build the pip package with debugging information by running: + +```bash +bazel build --config=dbg //tensorflow/tools/pip_package:build_pip_package +``` + +TensorFlow kernels and TensorFlow's dependencies are still not built with +debugging information with `--config=dbg`, as issues occur on Linux if +there is too much debug info (see [this GitHub +issue](https://github.com/tensorflow/tensorflow/issues/48919) for context). If +you want to debug a kernel, you can compile specific files with `-g` using the +`--per_file_copt` bazel option. For example, if you want to debug the Identity +op, which are in files starting with `identity_op`, you can run + +```bash +bazel build --config=dbg --per_file_copt=+tensorflow/core/kernels/identity_op.*@-g //tensorflow/tools/pip_package:build_pip_package +``` + +Note that the `--config=dbg` option is not officially supported.