cc_toolchain_debugging.bzl 4.5 KB

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