| 1 |
""" |
| 2 |
Strip symbols from an executable, but keep them in a .debug file |
| 3 |
""" |
| 4 |
|
| 5 |
import sys |
| 6 |
import os |
| 7 |
import py |
| 8 |
|
| 9 |
def _strip(exe): |
| 10 |
if sys.platform == 'win32': |
| 11 |
pass |
| 12 |
elif sys.platform == 'darwin': |
| 13 |
|
| 14 |
os.system("strip -x " + str(exe)) |
| 15 |
else: |
| 16 |
os.system("strip " + str(exe)) |
| 17 |
|
| 18 |
def _extract_debug_symbols(exe, debug): |
| 19 |
if sys.platform == 'linux2': |
| 20 |
os.system("objcopy --only-keep-debug %s %s" % (exe, debug)) |
| 21 |
os.system("objcopy --add-gnu-debuglink=%s %s" % (debug, exe)) |
| 22 |
perm = debug.stat().mode |
| 23 |
perm &= ~(0o111) |
| 24 |
debug.chmod(perm) |
| 25 |
|
| 26 |
def smartstrip(exe, keep_debug=True): |
| 27 |
exe = py.path.local(exe) |
| 28 |
debug = py.path.local(str(exe) + '.debug') |
| 29 |
if keep_debug: |
| 30 |
_extract_debug_symbols(exe, debug) |
| 31 |
_strip(exe) |
| 32 |
|
| 33 |
|
| 34 |
if __name__ == '__main__': |
| 35 |
smartstrip(sys.argv[1]) |