Skip to content

Commit 2416846

Browse files
authored
Merge pull request #3225 from boutproject/add-cpptrace
Use `cpptrace` for prettier backtraces from exceptions
2 parents b599e23 + 876fe2c commit 2416846

File tree

158 files changed

+567
-967
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+567
-967
lines changed

.clang-tidy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ CheckOptions:
2020
value: 'MPI_Comm'
2121

2222
- key: misc-include-cleaner.IgnoreHeaders
23-
value: 'adios2/.*;bits/.*'
23+
value: 'adios2/.*;bits/.*;cpptrace/.*'
2424
---
2525

2626
Disabled checks and reasons:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
[submodule "externalpackages/boutdata"]
1414
path = externalpackages/boutdata
1515
url = https://github.com/boutproject/boutdata.git
16+
[submodule "externalpackages/cpptrace"]
17+
path = externalpackages/cpptrace
18+
url = https://github.com/ZedThree/cpptrace.git

CMakeLists.txt

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,6 @@ option(BOUT_ENABLE_SIGFPE "Signalling floating point exceptions" OFF)
574574
message(STATUS "Signalling floating point exceptions: BOUT_USE_SIGFPE=${BOUT_ENABLE_SIGFPE}")
575575
set(BOUT_USE_SIGFPE ${BOUT_ENABLE_SIGFPE})
576576

577-
option(BOUT_ENABLE_BACKTRACE "Enable backtrace" ON)
578-
if (BOUT_ENABLE_BACKTRACE)
579-
find_program(ADDR2LINE_FOUND addr2line)
580-
if (NOT ADDR2LINE_FOUND)
581-
message(FATAL_ERROR "addr2line not found. Disable backtrace by setting BOUT_ENABLE_BACKTRACE=Off")
582-
endif()
583-
target_link_libraries(bout++ PUBLIC ${CMAKE_DL_LIBS})
584-
set(CONFIG_LDFLAGS "${CONFIG_LDFLAGS} -l${CMAKE_DL_LIBS}")
585-
endif()
586-
message(STATUS "Enable backtrace: BOUT_USE_BACKTRACE=${BOUT_ENABLE_BACKTRACE}")
587-
set(BOUT_USE_BACKTRACE ${BOUT_ENABLE_BACKTRACE})
588-
589577
option(BOUT_ENABLE_METRIC_3D "Enable 3D metric support" OFF)
590578
if(BOUT_ENABLE_METRIC_3D)
591579
set(BOUT_METRIC_TYPE "3D")
@@ -830,6 +818,9 @@ endif()
830818
if (NOT BOUT_USE_SYSTEM_FMT)
831819
set(FMT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
832820
endif()
821+
if (NOT BOUT_USE_SYSTEM_CPPTRACE)
822+
set(CPPTRACE_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
823+
endif()
833824
set(BOUT_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
834825
# We don't need the build include path any more
835826
string(REPLACE "-I${CMAKE_CURRENT_BINARY_DIR}/include" "" CONFIG_CFLAGS "${CONFIG_CFLAGS}")
@@ -958,7 +949,6 @@ message("
958949
Output coloring : ${BOUT_USE_COLOR}
959950
Field name tracking : ${BOUT_USE_TRACK}
960951
Floating point exceptions: ${BOUT_USE_SIGFPE}
961-
Backtrace enabled : ${BOUT_USE_BACKTRACE}
962952
RAJA enabled : ${BOUT_HAS_RAJA}
963953
Umpire enabled : ${BOUT_HAS_UMPIRE}
964954
Caliper enabled : ${BOUT_HAS_CALIPER}

bin/bout-add-mod-path

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ def create_mod(modulepath, name, top, build):
104104
else:
105105
prereq = ""
106106
with open(filename, "w") as f:
107-
f.write(
108-
f"""#%Module 1.0
107+
f.write(f"""#%Module 1.0
109108
#
110109
# BOUT++ module for use with 'environment-modules' package
111110
# Created by bout-add-mod-path v0.9
@@ -119,17 +118,14 @@ setenv BOUT_TOP {top}
119118
prepend-path PATH {top}/bin
120119
prepend-path PYTHONPATH {top}/tools/pylib
121120
prepend-path IDL_PATH +{top}/tools/idllib:'<IDL_DEFAULT>'
122-
"""
123-
)
121+
""")
124122
if build != top:
125-
f.write(
126-
f"""#%Module 1.0
123+
f.write(f"""#%Module 1.0
127124
setenv BOUT_BUILD {build}
128125
prepend-path PATH {build}/bin
129126
prepend-path LD_LIBRARY_PATH {build}/lib
130127
prepend-path PYTHONPATH {build}/tools/pylib
131-
"""
132-
)
128+
""")
133129
print(f"created `{filename}`")
134130

135131

bin/bout-pylib-cmd-to-bin

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ def createwrapper(mod, func_name, func, name):
126126
out += end
127127
f.write(out)
128128

129-
fprint(
130-
"""#!/usr/bin/env python3
129+
fprint("""#!/usr/bin/env python3
131130
# PYTHON_ARGCOMPLETE_OK
132131
133132
import argparse
@@ -136,8 +135,7 @@ try:
136135
except ImportError:
137136
argcomplete=None
138137
139-
"""
140-
)
138+
""")
141139
doc = True
142140
para = False
143141
ret = False
@@ -183,19 +181,16 @@ except ImportError:
183181
arg_help[curarg].append(esc(blas))
184182
# Print functions that are needed
185183
if "str_to_slice" in arg_type.values():
186-
fprint(
187-
"""
184+
fprint("""
188185
def str_to_slice(sstr):
189186
args=[]
190187
for s in sstr.split(','):
191188
args.append(int(s))
192189
print(args)
193190
return slice(*args)
194-
"""
195-
)
191+
""")
196192
if "str_to_bool" in arg_type.values():
197-
fprint(
198-
"""
193+
fprint("""
199194
def str_to_bool(sstr):
200195
low=sstr.lower()
201196
# no or false
@@ -206,8 +201,7 @@ def str_to_bool(sstr):
206201
return True
207202
else:
208203
raise ArgumentTypeError("Cannot parse %s to bool type"%sstr)
209-
"""
210-
)
204+
""")
211205
# Create the parser
212206
fprint("parser = argparse.ArgumentParser(%s)" % (esc(docs)))
213207
spec = inspect.signature(func)
@@ -247,24 +241,19 @@ def str_to_bool(sstr):
247241
pre = "\n "
248242
fprint(")")
249243

250-
fprint(
251-
"""
244+
fprint("""
252245
if argcomplete:
253246
argcomplete.autocomplete(parser)
254247
255-
# late import for faster auto-complete"""
256-
)
248+
# late import for faster auto-complete""")
257249
fprint("from %s import %s" % (mod, func_name))
258-
fprint(
259-
"""
250+
fprint("""
260251
args = parser.parse_args()
261252
262253
# Call the function %s, using command line arguments
263254
%s(**args.__dict__)
264255
265-
"""
266-
% (func_name, func_name)
267-
)
256+
""" % (func_name, func_name))
268257
# alternative, but I think 0o755 is easier to read
269258
# import stat
270259
# os.chmod(filename,stat.S_IRWXU|stat.S_IRGRP|stat.S_IXGRP|stat.S_IROTH|stat.S_IXOTH)

bin/bout-v5-factory-upgrader.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import difflib
66
import re
77

8-
98
# Dictionary of factory methods that may need updating
109
factories = {
1110
"Interpolation": {
@@ -62,9 +61,7 @@ def find_factory_calls(factory, source):
6261
\s*=\s*
6362
{factory_name}::
6463
.*{create_method}.*
65-
""".format(
66-
**factory
67-
),
64+
""".format(**factory),
6865
source,
6966
re.VERBOSE,
7067
)
@@ -75,9 +72,7 @@ def find_type_pointers(factory, source):
7572
r"""
7673
\b{type_name}\s*\*\s* # Type name and pointer
7774
([\w_]+)\s*; # Variable name
78-
""".format(
79-
**factory
80-
),
75+
""".format(**factory),
8176
source,
8277
re.VERBOSE,
8378
)
@@ -107,9 +102,7 @@ def fix_declarations(factory, variables, source):
107102
(.*?)(class\s*)? # optional "class" keyword
108103
\b({type_name})\s*\*\s* # Type-pointer
109104
({variable_name})\s*; # Variable
110-
""".format(
111-
type_name=factory["type_name"], variable_name=variable
112-
),
105+
""".format(type_name=factory["type_name"], variable_name=variable),
113106
r"\1std::unique_ptr<\3> \4{nullptr};",
114107
source,
115108
flags=re.VERBOSE,
@@ -123,9 +116,7 @@ def fix_declarations(factory, variables, source):
123116
({variable_name})\s* # Variable
124117
=\s* # Assignment from factory
125118
({factory_name}::.*{create_method}.*);
126-
""".format(
127-
variable_name=variable, **factory
128-
),
119+
""".format(variable_name=variable, **factory),
129120
r"\1auto \4 = \5;",
130121
source,
131122
flags=re.VERBOSE,
@@ -139,9 +130,7 @@ def fix_declarations(factory, variables, source):
139130
({variable_name})\s* # Variable
140131
=\s* # Assignment
141132
(0|nullptr|NULL);
142-
""".format(
143-
variable_name=variable, **factory
144-
),
133+
""".format(variable_name=variable, **factory),
145134
r"\1std::unique_ptr<\2> \3{nullptr};",
146135
source,
147136
flags=re.VERBOSE,

bin/bout-v5-format-upgrader.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import difflib
66
import re
77

8-
98
format_replacements = {
109
"c": "c",
1110
"d": "d",

bin/bout-v5-header-upgrader.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from typing import List
1010
from subprocess import run
1111

12-
1312
header_shim_sentinel = "// BOUT++ header shim"
1413

1514
header_warning = f"""\
@@ -122,8 +121,7 @@ def create_patch(filename, original, modified):
122121
if __name__ == "__main__":
123122
parser = argparse.ArgumentParser(
124123
formatter_class=argparse.RawDescriptionHelpFormatter,
125-
description=textwrap.dedent(
126-
"""\
124+
description=textwrap.dedent("""\
127125
Fix deprecated header locations for BOUT++ v4 -> v5
128126
129127
All BOUT++ headers are now under ``include/bout`` and
@@ -142,8 +140,7 @@ def create_patch(filename, original, modified):
142140
If you have staged changes, this tool will not work, so to
143141
avoid committing undesired or unrelated changes.
144142
145-
"""
146-
),
143+
"""),
147144
)
148145

149146
parser.add_argument(

bin/bout-v5-input-file-upgrader.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False):
271271
if __name__ == "__main__":
272272
parser = argparse.ArgumentParser(
273273
formatter_class=argparse.RawDescriptionHelpFormatter,
274-
description=textwrap.dedent(
275-
"""\
274+
description=textwrap.dedent("""\
276275
Fix input files for BOUT++ v5+
277276
278277
Please note that this will only fix input options in sections with
@@ -300,8 +299,7 @@ def possibly_apply_patch(patch, options_file, quiet=False, force=False):
300299
301300
Files that change in this way will have the "canonicalisation" patch
302301
presented first. If you choose not to apply this patch, the "upgrade
303-
fixer" patch will still include it."""
304-
),
302+
fixer" patch will still include it."""),
305303
)
306304

307305
parser.add_argument("files", action="store", nargs="+", help="Input files")

bin/bout-v5-macro-upgrader.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ def create_patch(filename, original, modified):
342342
if __name__ == "__main__":
343343
parser = argparse.ArgumentParser(
344344
formatter_class=argparse.RawDescriptionHelpFormatter,
345-
description=textwrap.dedent(
346-
"""\
345+
description=textwrap.dedent("""\
347346
Fix macro defines for BOUT++ v4 -> v5
348347
349348
Please note that this is only slightly better than dumb text replacement. It
@@ -359,8 +358,7 @@ def create_patch(filename, original, modified):
359358
still replace them in strings or comments.
360359
361360
Please check the diff output carefully!
362-
"""
363-
),
361+
"""),
364362
)
365363

366364
parser.add_argument("files", action="store", nargs="+", help="Input files")

0 commit comments

Comments
 (0)