Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dump correct breakpad symbols on macOS (#19157)
- Loading branch information
Showing
7 changed files
with
226 additions
and
254 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
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,52 @@ | ||
from __future__ import print_function | ||
|
||
import collections | ||
import os | ||
import subprocess | ||
import sys | ||
import errno | ||
|
||
# The BINARY_INFO tuple describes a binary as dump_syms identifies it. | ||
BINARY_INFO = collections.namedtuple('BINARY_INFO', | ||
['platform', 'arch', 'hash', 'name']) | ||
|
||
def get_module_info(header_info): | ||
# header info is of the form "MODULE $PLATFORM $ARCH $HASH $BINARY" | ||
info_split = header_info.strip().split(' ', 4) | ||
if len(info_split) != 5 or info_split[0] != 'MODULE': | ||
return None | ||
return BINARY_INFO(*info_split[1:]) | ||
|
||
def get_symbol_path(symbol_data): | ||
module_info = get_module_info(symbol_data[:symbol_data.index('\n')]) | ||
if not module_info: | ||
raise Exception("Couldn't get module info for binary '{}'".format(binary)) | ||
return os.path.join(module_info.name, module_info.hash, module_info.name + ".sym") | ||
|
||
def mkdir_p(path): | ||
"""Simulates mkdir -p.""" | ||
try: | ||
os.makedirs(path) | ||
except OSError as e: | ||
if e.errno == errno.EEXIST and os.path.isdir(path): | ||
pass | ||
else: raise | ||
|
||
def main(dump_syms, binary, out_dir, stamp_file, dsym_file=None): | ||
args = [dump_syms] | ||
if dsym_file: | ||
args += ["-g", dsym_file] | ||
args += [binary] | ||
|
||
symbol_data = subprocess.check_output(args) | ||
symbol_path = os.path.join(out_dir, get_symbol_path(symbol_data)) | ||
mkdir_p(os.path.dirname(symbol_path)) | ||
|
||
with open(symbol_path, 'w') as out: | ||
out.write(symbol_data) | ||
|
||
with open(stamp_file, 'w'): | ||
pass | ||
|
||
if __name__ == '__main__': | ||
main(*sys.argv[1:]) |
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,55 @@ | ||
import("//build/toolchain/toolchain.gni") | ||
|
||
# Extracts symbols from a binary into a symbol file using dump_syms. | ||
# | ||
# Args: | ||
# binary: Path to the binary containing symbols to extract, e.g.: | ||
# "$root_out_dir/electron" | ||
# symbol_dir: Desired output directory for symbols, e.g.: | ||
# "$root_out_dir/breakpad_symbols" | ||
|
||
if (host_os == "win") { | ||
_host_executable_suffix = ".exe" | ||
} else { | ||
_host_executable_suffix = "" | ||
} | ||
|
||
template("extract_symbols") { | ||
action(target_name) { | ||
forward_variables_from(invoker, | ||
[ | ||
"deps", | ||
"testonly", | ||
]) | ||
assert(defined(invoker.binary), "Need binary to dump") | ||
assert(defined(invoker.symbol_dir), "Need directory for symbol output") | ||
|
||
dump_syms_label = "//third_party/breakpad:dump_syms($host_toolchain)" | ||
dump_syms_binary = get_label_info(dump_syms_label, "root_out_dir") + | ||
"/dump_syms$_host_executable_suffix" | ||
|
||
script = "//electron/build/dump_syms.py" | ||
inputs = [ | ||
invoker.binary, | ||
dump_syms_binary, | ||
] | ||
stamp_file = "${target_gen_dir}/${target_name}.stamp" | ||
outputs = [ | ||
stamp_file, | ||
] | ||
args = [ | ||
"./" + rebase_path(dump_syms_binary, root_build_dir), | ||
rebase_path(invoker.binary, root_build_dir), | ||
rebase_path(invoker.symbol_dir, root_build_dir), | ||
rebase_path(stamp_file, root_build_dir), | ||
] | ||
if (defined(invoker.dsym_file)) { | ||
args += [ rebase_path(invoker.dsym_file, root_build_dir) ] | ||
} | ||
|
||
if (!defined(deps)) { | ||
deps = [] | ||
} | ||
deps += [ dump_syms_label ] | ||
} | ||
} |
Oops, something went wrong.