blob: 21ce8e6924e575073f7cd68e7cdbadfd13e36fb6 [file] [log] [blame]
Jorge Lucangeli Obese84e1542014-12-08 17:53:09 -08001# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6
7from autotest_lib.client.bin import utils
8
9
10_ASAN_SYMBOL = "__asan_init"
11
12
13def running_on_asan(binary="debugd"):
14 """Returns whether we're running on ASan.
15
16 @param binary: file to test for ASan symbols.
17 """
18 # -q, --quiet * Only output 'bad' things
19 # -F, --format <arg> * Use specified format for output
20 # -g, --gmatch * Use regex rather than string compare (with -s)
21 # -s, --symbol <arg> * Find a specified symbol
22 scanelf_command = "scanelf -qF'%s#F'"
23 scanelf_command += " -gs %s `which %s`" % (_ASAN_SYMBOL, binary)
24 symbol = utils.system_output(scanelf_command)
25 logging.debug("running_on_asan(): symbol: '%s', _ASAN_SYMBOL: '%s'",
26 symbol, _ASAN_SYMBOL)
27 return symbol != ""