Belle II Software  release-08-01-10
strip_debug.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from SCons.Action import Action
13 
14 # Perform debug info splitting according to the GDB manual's guidelines
15 # https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
16 #
17 # Cannot use scons' chdir feature because it doesn't work in parallel builds
18 # (working directory is a global variable that is shared by all threads)
19 #
20 split_debug_action = Action(
21  'cd ${TARGET.dir} && '
22  'objcopy ${STRIP_EXTRA_ARGUMENTS} --only-keep-debug ${TARGET.file} ${TARGET.file}.debug && '
23  'objcopy --add-gnu-debuglink ${TARGET.file}.debug ${TARGET.file} && '
24  'mv ${TARGET.file}.debug .debug/${TARGET.file}.debug && '
25  'objcopy --strip-debug --strip-unneeded ${STRIP_EXTRA_ARGUMENTS} ${TARGET.file}',
26  "${STRIPCOMSTR}", chdir=False)
27 
28 strip_debug_action = Action(
29  'objcopy --strip-debug --strip-unneeded ${STRIP_EXTRA_ARGUMENTS} ${TARGET}',
30  "${STRIPCOMSTR}", chdir=False)
31 
32 
33 def strip_debug_method(env, target):
34  result = []
35  for t in target:
36  if env['SPLIT_DEBUGINFO']:
37  result.append(t.dir.Dir(".debug").File(t.name+".debug"))
38  env.SideEffect(result[-1], t)
39  env.AddPostAction(t, split_debug_action)
40  env.Clean(t, result[-1])
41  else:
42  env.AddPostAction(t, strip_debug_action)
43  return result
44 
45 
46 def generate(env):
47  env.AddMethod(strip_debug_method, 'StripDebug')
48  env['SPLIT_DEBUGINFO'] = True
49  env['STRIP_EXTRA_ARGUMENTS'] = "-R '.gnu.debuglto_*'"
50 
51 
52 def exists(env):
53  return True