cc_toolchain_debugging.bzl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Definitions of debugging related features used in a `cc_toolchain_config`."""
  5. load(
  6. "@rules_cc//cc:cc_toolchain_config_lib.bzl",
  7. "feature",
  8. "feature_set",
  9. "flag_group",
  10. "flag_set",
  11. )
  12. load(
  13. ":cc_toolchain_actions.bzl",
  14. "all_link_actions",
  15. "codegen_compile_actions",
  16. )
  17. # Handle different levels and forms of debug info emission with individual
  18. # features so that they can be ordered and the defaults can override the
  19. # minimal settings if both are enabled.
  20. minimal_debug_info_flags = feature(
  21. name = "minimal_debug_info_flags",
  22. implies = ["debug_info_compression_flags"],
  23. flag_sets = [flag_set(
  24. actions = codegen_compile_actions,
  25. flag_groups = [flag_group(flags = ["-gmlt"])],
  26. )],
  27. )
  28. debug_info_flags = feature(
  29. name = "debug_info_flags",
  30. implies = ["debug_info_compression_flags"],
  31. flag_sets = [flag_set(
  32. actions = codegen_compile_actions,
  33. flag_groups = [
  34. flag_group(flags = ["-g"]),
  35. flag_group(
  36. expand_if_available = "per_object_debug_info_file",
  37. flags = ["-gsplit-dwarf"],
  38. ),
  39. ],
  40. )],
  41. )
  42. debug_info_compression_flags = feature(
  43. name = "debug_info_compression_flags",
  44. flag_sets = [flag_set(
  45. actions = codegen_compile_actions + all_link_actions,
  46. flag_groups = [flag_group(flags = ["-gz"])],
  47. )],
  48. )
  49. # Define a set of mutually exclusive debugger flags.
  50. debugger_flags = feature(name = "debugger_flags")
  51. lldb_flags = feature(
  52. # Use a convenient name for users to select if needed.
  53. name = "lldb_flags",
  54. # Default enable LLDB-optimized flags whenever debugging.
  55. enabled = True,
  56. requires = [feature_set(features = ["debug_info_flags"])],
  57. provides = ["debugger_flags"],
  58. flag_sets = [flag_set(
  59. actions = codegen_compile_actions,
  60. flag_groups = [flag_group(flags = [
  61. "-glldb",
  62. "-gpubnames",
  63. "-gsimple-template-names",
  64. ])],
  65. )],
  66. )
  67. gdb_flags = feature(
  68. # Use a convenient name for users to select if needed.
  69. name = "gdb_flags",
  70. requires = [feature_set(features = ["debug_info_flags"])],
  71. provides = ["debugger_flags"],
  72. flag_sets = [
  73. flag_set(
  74. actions = codegen_compile_actions,
  75. flag_groups = [flag_group(flags = [
  76. "-ggdb",
  77. "-ggnu-pubnames",
  78. ])],
  79. ),
  80. flag_set(
  81. actions = all_link_actions,
  82. flag_groups = [flag_group(flags = ["-Wl,--gdb-index"])],
  83. ),
  84. ],
  85. )
  86. # This feature can be enabled in conjunction with any optimizations to
  87. # ensure accurate call stacks and backtraces for profilers or errors.
  88. preserve_call_stacks = feature(
  89. name = "preserve_call_stacks",
  90. flag_sets = [flag_set(
  91. actions = codegen_compile_actions,
  92. flag_groups = [flag_group(flags = [
  93. # Ensure good backtraces by preserving frame pointers and
  94. # disabling tail call elimination.
  95. "-fno-omit-frame-pointer",
  96. "-mno-omit-leaf-frame-pointer",
  97. "-fno-optimize-sibling-calls",
  98. ])],
  99. )],
  100. )
  101. # Enable split debug info whenever debug info is requested.
  102. enable_split_debug_info = feature(
  103. name = "per_object_debug_info",
  104. enabled = True,
  105. # This has to be directly conditioned on requesting debug info at
  106. # all, otherwise Bazel will look for an extra output file and not
  107. # find one.
  108. requires = [feature_set(features = ["debug_info_flags"])],
  109. )
  110. # Enable debug info whenever in the `dbg` build mode. We do this separately from
  111. # the `debug_info_flags` feature itself as other things may want to enable that
  112. # feature as well.
  113. enable_debug_info_in_dbg = feature(
  114. name = "enable_debug_info_in_dbg",
  115. enabled = True,
  116. requires = [feature_set(["dbg"])],
  117. implies = ["debug_info_flags"],
  118. )
  119. # Note that the order of features is significant in this list and determines the
  120. # relative order of flags from the features listed.
  121. debugging_features = [
  122. minimal_debug_info_flags,
  123. debug_info_flags,
  124. debug_info_compression_flags,
  125. debugger_flags,
  126. lldb_flags,
  127. gdb_flags,
  128. preserve_call_stacks,
  129. enable_split_debug_info,
  130. enable_debug_info_in_dbg,
  131. ]