-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: generate debug symbols on Linux (#18676)
- Loading branch information
Showing
9 changed files
with
190 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
from __future__ import print_function | ||
import argparse | ||
import os | ||
import sys | ||
|
||
from lib.config import LINUX_BINARIES, PLATFORM | ||
from lib.util import execute, get_objcopy_path, get_out_dir | ||
|
||
def add_debug_link_into_binaries(directory, target_cpu, debug_dir): | ||
for binary in LINUX_BINARIES: | ||
binary_path = os.path.join(directory, binary) | ||
if os.path.isfile(binary_path): | ||
add_debug_link_into_binary(binary_path, target_cpu, debug_dir) | ||
|
||
def add_debug_link_into_binary(binary_path, target_cpu, debug_dir): | ||
try: | ||
objcopy = get_objcopy_path(target_cpu) | ||
except: | ||
if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or | ||
target_cpu == 'arm64'): | ||
# Skip because no objcopy binary on the given target. | ||
return | ||
raise | ||
debug_name = get_debug_name(binary_path) | ||
# Make sure the path to the binary is not relative because of cwd param. | ||
real_binary_path = os.path.realpath(binary_path) | ||
cmd = [objcopy, '--add-gnu-debuglink=' + debug_name, real_binary_path] | ||
execute(cmd, cwd=debug_dir) | ||
|
||
def get_debug_name(binary_path): | ||
return os.path.basename(binary_path) + '.debug' | ||
|
||
def main(): | ||
args = parse_args() | ||
if args.file: | ||
add_debug_link_into_binary(args.file, args.target_cpu, args.debug_dir) | ||
else: | ||
add_debug_link_into_binaries(args.directory, args.target_cpu, | ||
args.debug_dir) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Add debug link to binaries') | ||
parser.add_argument('-d', '--directory', | ||
help='Path to the dir that contains files to add links', | ||
default=get_out_dir(), | ||
required=False) | ||
parser.add_argument('-f', '--file', | ||
help='Path to a specific file to add debug link', | ||
required=False) | ||
parser.add_argument('-s', '--debug-dir', | ||
help='Path to the dir that contain the debugs', | ||
default=None, | ||
required=True) | ||
parser.add_argument('-v', '--verbose', | ||
action='store_true', | ||
help='Prints the output of the subprocesses') | ||
parser.add_argument('--target-cpu', | ||
default='', | ||
required=False, | ||
help='Target cpu of binaries to add debug link') | ||
|
||
return parser.parse_args() | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env python | ||
from __future__ import print_function | ||
import argparse | ||
import os | ||
import sys | ||
|
||
from lib.config import LINUX_BINARIES, PLATFORM | ||
from lib.util import execute, get_objcopy_path, get_out_dir, safe_mkdir | ||
|
||
# It has to be done before stripping the binaries. | ||
def copy_debug_from_binaries(directory, out_dir, target_cpu, compress): | ||
for binary in LINUX_BINARIES: | ||
binary_path = os.path.join(directory, binary) | ||
if os.path.isfile(binary_path): | ||
copy_debug_from_binary(binary_path, out_dir, target_cpu, compress) | ||
|
||
def copy_debug_from_binary(binary_path, out_dir, target_cpu, compress): | ||
try: | ||
objcopy = get_objcopy_path(target_cpu) | ||
except: | ||
if PLATFORM == 'linux' and (target_cpu == 'x86' or target_cpu == 'arm' or | ||
target_cpu == 'arm64'): | ||
# Skip because no objcopy binary on the given target. | ||
return | ||
raise | ||
debug_name = get_debug_name(binary_path) | ||
cmd = [objcopy, '--only-keep-debug'] | ||
if compress: | ||
cmd.extend(['--compress-debug-sections']) | ||
cmd.extend([binary_path, os.path.join(out_dir, debug_name)]) | ||
execute(cmd) | ||
return debug_name | ||
|
||
def get_debug_name(binary_path): | ||
return os.path.basename(binary_path) + '.debug' | ||
|
||
def main(): | ||
args = parse_args() | ||
safe_mkdir(args.out_dir) | ||
if args.file: | ||
copy_debug_from_binary(args.file, args.out_dir, args.target_cpu, | ||
args.compress) | ||
else: | ||
copy_debug_from_binaries(args.directory, args.out_dir, args.target_cpu, | ||
args.compress) | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser(description='Copy debug from binaries') | ||
parser.add_argument('-d', '--directory', | ||
help='Path to the dir that contains files to copy', | ||
default=get_out_dir(), | ||
required=False) | ||
parser.add_argument('-f', '--file', | ||
help='Path to a specific file to copy debug symbols', | ||
required=False) | ||
parser.add_argument('-o', '--out-dir', | ||
help='Path to the dir that will contain the debugs', | ||
default=None, | ||
required=True) | ||
parser.add_argument('-v', '--verbose', | ||
action='store_true', | ||
help='Prints the output of the subprocesses') | ||
parser.add_argument('--target-cpu', | ||
default='', | ||
required=False, | ||
help='Target cpu of binaries to copy debug symbols') | ||
parser.add_argument('--compress', | ||
action='store_true', | ||
required=False, | ||
help='Compress the debug symbols') | ||
|
||
return parser.parse_args() | ||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters