Skip to content

Commit ac9e666

Browse files
committed
Introduce: AMReX_ADDRLINES (Default: ON)
This is addign the new CMake option `AMReX_ADDRLINES` and CMake public interface target `AMReX::FLAGS_ADDRLINES`. This option adds *minimal* debug info (`-g1` / `-gline-tables-only`) to executables, which generates more usable backtraces on crashes. In symmetry to GNUmake, we turn this now ON. This is a breaking change. Note that this flag still creates significant binary size overheads, so package managers might decide to turn if off in deployments. Also, if the increased binary sizes lead to significant startup overhead at scale on HPC systems, we might need to reconsider the default (for CMake and GNUmake) in the future.
1 parent 9751217 commit ac9e666

File tree

7 files changed

+41
-3
lines changed

7 files changed

+41
-3
lines changed

Docs/sphinx_documentation/source/BuildingAMReX.rst

+4
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ The list of available options is reported in the :ref:`table <tab:cmakevar>` bel
496496
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
497497
| AMReX_FPE | Build with Floating Point Exceptions checks | NO | YES, NO |
498498
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
499+
| AMReX_ADDRLINES | Build with minimal debug info for line numbers | YES | YES, NO |
500+
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
499501
| AMReX_ASSERTIONS | Build with assertions turned on | NO | YES, NO |
500502
+------------------------------+-------------------------------------------------+-------------------------+-----------------------+
501503
| AMReX_BOUND_CHECK | Enable bound checking in Array4 class | NO | YES, NO |
@@ -618,6 +620,8 @@ In the above snippet, ``<amrex-target-name>`` is any of the targets listed in th
618620
+-----------------------+-------------------------------------------------+
619621
| Flags_FPE | Floating Point Exception flags (interface) |
620622
+-----------------------+-------------------------------------------------+
623+
| FLAGS_ADDRLINES | Minimal debug/line numbers flags (interface) |
624+
+-----------------------+-------------------------------------------------+
621625
.. raw:: latex
622626

623627
\end{center}

Docs/sphinx_documentation/source/Debugging.rst

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ with ``TEST=TRUE`` or ``DEBUG=TRUE`` in GNU make, or with ``-DCMAKE_BUILD_TYPE=D
2929
One can also control the setting for ``FArrayBox`` using the runtime parameter, ``fab.init_snan``.
3030
Note for Macs, M1 and M2 chips using Arm64 architecture are not able to trap division by zero.
3131

32+
By default, even AMReX release mode builds add minimal address to line debub information.
33+
This can be turned off via ``-DAMReX_ADDRLINES=NO``.
34+
3235
One can get more information than the backtrace of the call stack by
3336
instrumenting the code. Here is an example.
3437
You know the line ``Real rho = state(cell,0);`` is causing a segfault. You

Src/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ foreach(D IN LISTS AMReX_SPACEDIM)
8686
$<BUILD_INTERFACE:Flags_FPE>
8787
)
8888
endif ()
89+
90+
if (AMReX_ADDRLINES)
91+
target_link_libraries(amrex_${D}d
92+
PUBLIC
93+
$<BUILD_INTERFACE:Flags_ADDRLINES>
94+
)
95+
endif ()
8996
endforeach()
9097

9198
# General configuration

Tools/CMake/AMReXConfig.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ set(AMReX_HDF5_ZFP_FOUND @AMReX_HDF5_ZFP@)
8888

8989
# Compilation options
9090
set(AMReX_FPE_FOUND @AMReX_FPE@)
91+
set(AMReX_ADDRLINES_FOUND @AMReX_ADDRLINES@)
9192
set(AMReX_PIC_FOUND @AMReX_PIC@)
9293
set(AMReX_ASSERTIONS_FOUND @AMReX_ASSERTIONS@)
9394

Tools/CMake/AMReXFlagsTargets.cmake

+18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# Flags_CXX --> Optional flags for C++ code
66
# Flags_Fortran --> Optional flags for Fortran code
77
# Flags_FPE --> Floating-Point Exception flags for both C++ and Fortran
8+
# FLAGS_ADDRLINES --> Minimal debug flags that only record address to line number
89
#
910
# These INTERFACE targets can be added to the AMReX export set.
1011
#
@@ -61,6 +62,23 @@ else ()
6162
endif ()
6263

6364

65+
#
66+
# Minimal Debug info for address --> line
67+
#
68+
add_library(FLAGS_ADDRLINES INTERFACE)
69+
add_library(AMReX::FLAGS_ADDRLINES ALIAS FLAGS_ADDRLINES)
70+
71+
target_compile_options( FLAGS_ADDRLINES
72+
INTERFACE
73+
$<${_cxx_gnu}:-g1>
74+
$<${_cxx_intel}:>
75+
$<${_cxx_pgi}:>
76+
$<${_cxx_cray}:>
77+
$<${_cxx_clang}:-gline-tables-only>
78+
$<${_cxx_appleclang}:-gline-tables-only>
79+
$<${_cxx_intelllvm}:-gline-tables-only> # -fdebug-info-for-profiling is recommended by Intel VTune
80+
)
81+
6482
#
6583
# C++ flags
6684
#

Tools/CMake/AMReXOptions.cmake

+4-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ print_option( AMReX_IPO )
369369
option(AMReX_FPE "Enable Floating Point Exceptions checks" OFF)
370370
print_option( AMReX_FPE )
371371

372+
option(AMReX_ADDRLINES "Add minimal debug info that only records line numbers" ON)
373+
print_option( AMReX_ADDRLINES )
374+
372375
if ( "${CMAKE_BUILD_TYPE}" MATCHES "Debug" )
373376
option( AMReX_ASSERTIONS "Enable assertions" ON)
374377
else ()
@@ -377,7 +380,7 @@ endif ()
377380

378381
print_option( AMReX_ASSERTIONS )
379382

380-
option(AMReX_BOUND_CHECK "Enable bound checking in Array4 class" OFF)
383+
option(AMReX_BOUND_CHECK "Enable bound checking in Array4 class" OFF)
381384
print_option( AMReX_BOUND_CHECK )
382385

383386
if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")

Tools/CMake/AMReX_Config.cmake

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ function (configure_amrex AMREX_TARGET)
2323
#
2424
# Check that needed options have already been defined
2525
#
26-
if ( ( NOT ( DEFINED AMReX_MPI ) ) OR ( NOT (DEFINED AMReX_OMP) )
27-
OR ( NOT (DEFINED AMReX_PIC) ) OR (NOT (DEFINED AMReX_FPE)))
26+
if ( (NOT (DEFINED AMReX_MPI) ) OR (NOT (DEFINED AMReX_OMP) )
27+
OR (NOT (DEFINED AMReX_PIC) ) OR (NOT (DEFINED AMReX_FPE) )
28+
OR (NOT (DEFINED AMReX_ADDRLINES) )
29+
)
2830
message ( AUTHOR_WARNING "Required options are not defined" )
2931
endif ()
3032

0 commit comments

Comments
 (0)