1#!/bin/bash
2
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.
6
7set -eu
8
9if [[ "$#" -ne 1 ]]; then
10  echo "usage: $0 <version>" >&2
11  echo "(BUILT_PRODUCTS_DIR and FULL_PRODUCT_NAME must be set)" >& 2
12  exit 1
13fi
14
15VERSION="$1"
16DUMP_SYMS_TOOL="${BUILT_PRODUCTS_DIR}/dump_syms"
17SOURCE_BUNDLE="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}"
18
19# Filename of bundle, minus the file extension.
20STEM="$(basename "${SOURCE_BUNDLE%.*}")"
21DWARF_PATH="${SOURCE_BUNDLE}.dSYM/Contents/Resources/DWARF/${STEM}"
22
23ARCHS=$(file "${DWARF_PATH}" | sed -Ene 's/^.*(i386|x86_64)$/\1/p')
24if [[ -z "${ARCHS}" ]]; then
25  echo "$0: expected something dumpable in ${DWARF_PATH}" >& 2
26  exit 1
27fi
28
29for ARCH in ${ARCHS}; do
30  # Use -c to avoid dumping CFI, because the Breakpad stackwalk is incompatible
31  # with CFI produced by clang.
32  # http://code.google.com/p/google-breakpad/issues/detail?id=443
33  "${DUMP_SYMS_TOOL}" -a "${ARCH}" -c "${DWARF_PATH}" > \
34      "${SOURCE_BUNDLE}-${VERSION}-${ARCH}.breakpad"
35done
36