3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 # This script expects the following environment variables to be set. Xcode
10 # CONFIGURATION - Release or Debug; this script only operates when Release.
11 # SRCROOT - /path/to/chrome/src/chrome
12 # BUILT_PRODUTS_DIR - /path/to/chrome/src/xcodebuild/Release
14 # The script also takes a single argument defining the branding type.
16 # To test this script without running an entire build:
18 # cd /path/to/chrome/src/chrome
19 # CONFIGURATION=Release \
21 # BUILT_PRODUCTS_DIR=$(pwd)/../xcodebuild/Release \
22 # tools/build/mac/dump_app_syms Chromium
24 # Make sure we got the header to write into passed to us
26 echo "error: missing branding as an argument" >&2
32 # Skip out if we're aren't in Release mode, no need for dump_syms on debug runs.
33 if [ "${CONFIGURATION}" != "Release" ] ; then
40 BRAND_SCRIPT="${TOP}/build/branding_value.sh"
41 SRC_APP_NAME=$("${BRAND_SCRIPT}" "${BUILD_BRANDING}" PRODUCT_FULLNAME)
42 . "${TOP}/chrome/VERSION"
44 BREAKPAD_DUMP_SYMS="${BUILT_PRODUCTS_DIR}/dump_syms"
45 FULL_VERSION="${MAJOR}.${MINOR}.${BUILD}.${PATCH}"
47 DSYM_TAR_PATH="${BUILT_PRODUCTS_DIR}/${SRC_APP_NAME}.dSYM.tar.bz2"
49 # Starting with an already-dumped symbol file at ${original_sym_path},
50 # transforms the MODULE line (which must be the first line) from referring to
51 # ${original_stem} to refer to ${variant_stem}. The transformed symbol file
52 # is written to a symbol file at the same location that a symbol file would
53 # be written to if ${variant_name} were in the SRC_NAMES array below.
55 # If the transformed symbol file already appears more recent than
56 # ${original_sym_path}, it is left alone.
57 redump_syms_variant() {
58 local original_sym_path="${1}"
59 local original_stem="${2}"
60 local variant_stem="${3}"
61 local variant_name="${4}"
64 local variant_sym_name="${variant_name}-${FULL_VERSION}-${arch}.breakpad"
65 local variant_sym_path="${BUILT_PRODUCTS_DIR}/${variant_sym_name}"
67 if [[ "${original_sym_path}" -nt "${variant_sym_path}" ]]; then
69 1s/^(MODULE [^ ]+ [^ ]+ [0-9a-fA-F]{33}) ${original_stem}\$/\1 ${variant_stem}/"
70 sed -E -e "${pattern}" < "${original_sym_path}" > "${variant_sym_path}"
76 # Everything in SRC_NAMES is required. It's an error for any of these files
80 "${SRC_APP_NAME} Framework.framework"
81 "${SRC_APP_NAME} Helper.app"
83 "crash_report_sender.app"
86 "libplugin_carbon_interpose.dylib"
87 "ppGoogleNaClPluginChrome.plugin"
88 "remoting_host_plugin.plugin"
91 # PDF.plugin is optional. Only include it if present.
92 if [[ -e "${BUILT_PRODUCTS_DIR}/PDF.plugin" ]]; then
93 SRC_NAMES[${#SRC_NAMES[@]}]="PDF.plugin"
96 # libpeerconnection.so is optional. Only include it if present.
97 if [[ -e "${BUILT_PRODUCTS_DIR}/libpeerconnection.so" ]]; then
98 SRC_NAMES[${#SRC_NAMES[@]}]="libpeerconnection.so"
101 for SRC_NAME in "${SRC_NAMES[@]}"; do
102 # SRC_STEM is the name of the file within the DWARF directory of the .dSYM
103 # bundle, which comes from the on-disk name of an executable or dylib within
104 # its enclosing .app, .framework or .plugin bundle. This is the bundle name
105 # without .app, .framework or .plugin appended. For non-bundled types, the
106 # stem is just the name of the singular file on disk.
107 SRC_STEM=$(echo "${SRC_NAME}" | sed -Ee 's/\.(app|framework|plugin)$//')
108 DSYM_NAME="${SRC_NAME}.dSYM"
109 DSYM_PATH="${BUILT_PRODUCTS_DIR}/${DSYM_NAME}"
110 DWARF_PATH="${DSYM_PATH}/Contents/Resources/DWARF/${SRC_STEM}"
112 ARCHS=$(file "${DWARF_PATH}" | sed -Ene 's/^.*(i386|x86_64)$/\1/p')
113 if [[ -z "${ARCHS}" ]]; then
114 echo "${0}: expected something dumpable in ${DWARF_PATH}" >& 2
118 for ARCH in ${ARCHS}; do
119 BPAD_SYM_NAME="${SRC_NAME}-${FULL_VERSION}-${ARCH}.breakpad"
120 BPAD_SYM_PATH="${BUILT_PRODUCTS_DIR}/${BPAD_SYM_NAME}"
122 # Only run dump_syms if the file has changed since the last dump. Use -c
123 # to avoid dumping CFI, because the Breakpad stackwalk is incompatible
124 # with CFI produced by clang.
125 # http://code.google.com/p/google-breakpad/issues/detail?id=443
126 if [ "${DWARF_PATH}" -nt "${BPAD_SYM_PATH}" ] ; then
127 "${BREAKPAD_DUMP_SYMS}" -a "${ARCH}" -c "${DWARF_PATH}" > \
131 # Some executables will show up with variant names. The Breakpad symbol
132 # server looks up modules based on a combination of the module name and
133 # identifier (UUID). Produce symbol files for these variant names so that
134 # the Breakpad symbol server will have something to return for stacks that
135 # travel through these modules.
136 case "${SRC_NAME}" in
137 "${SRC_APP_NAME}.app")
138 # Google Chrome Canary is produced during packaging.
139 redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
140 "${SRC_STEM} Canary" "${SRC_STEM} Canary.app" \
144 "${SRC_APP_NAME} Helper.app")
145 # Google Chrome Helper EH and Google Chrome Helper NP are produced by
146 # build/mac/make_more_helpers.sh.
147 redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
148 "${SRC_STEM} EH" "${SRC_STEM} EH.app" "${ARCH}"
149 redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
150 "${SRC_STEM} NP" "${SRC_STEM} NP.app" "${ARCH}"
155 # Remove the .dSYM archive if the file has changed since the archive was
156 # last generated. This will cause a new .dSYM archive to be created.
157 if [ "${DWARF_PATH}" -nt "${DSYM_TAR_PATH}" ] ; then
158 rm -f "${DSYM_TAR_PATH}"
161 # Push the .dSYM bundle onto the DSYMS array so that it will be included in
162 # the .dSYM archive if a new one is needed
163 DSYMS[${#DSYMS[@]}]="${DSYM_NAME}"
166 # Create the archive of .dSYM bundles.
167 if [ ! -e "${DSYM_TAR_PATH}" ] ; then
168 # Change directory so that absolute paths aren't included in the archive.
169 (cd "${BUILT_PRODUCTS_DIR}" &&
170 tar -jcf "${DSYM_TAR_PATH}" "${DSYMS[@]}")