summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2015-02-16 10:11:52 +0100
committerPeter Wu <peter@lekensteyn.nl>2015-02-16 10:11:52 +0100
commit6c3a8cc2a5d0fdfce02b2fc37f80687991a443b0 (patch)
treecd52fff2076335e8f12772549fd06ad72c845bae
parent66facb91e09da997187b9ee43027c68c18bc2e66 (diff)
downloadscripts-6c3a8cc2a5d0fdfce02b2fc37f80687991a443b0.tar.gz
asan-help: pretty print ASAN_OPTIONS
ASAN_OPTIONS=help=1 is not supported by GCC 4.9, but I want to know its supported features anyway. Manually copy the names from gcc-4.9-20150204 and print the help text with names highlighted.
-rwxr-xr-xasan-help104
1 files changed, 104 insertions, 0 deletions
diff --git a/asan-help b/asan-help
new file mode 100755
index 0000000..9032018
--- /dev/null
+++ b/asan-help
@@ -0,0 +1,104 @@
+#!/bin/bash
+# Displays supported ASAN options
+
+# gcc 4.9.2 does not support ASAN_OPTIONS=help=1
+# It was merged to gcc at 2014-05-22
+# https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7d752f28b590bbad13c877c2aa7f5f8de2cdff10
+: ${CC:=clang}
+gcc_ver=$("$CC" --version | awk 'NR==1 && $1=="gcc" { print $3 }')
+if [[ $gcc_ver == 4.9.* ]]; then
+ CC=clang
+fi
+
+# Colors for keywords
+CON=$(tput bold; tput setaf 3)
+COFF=$(tput sgr0)
+
+gcc_4_9_sanitizer_common="
+allocator_may_return_null
+detect_leaks
+external_symbolizer_path
+fast_unwind_on_fatal
+fast_unwind_on_malloc
+handle_ioctl
+leak_check_at_exit
+log_path
+malloc_context_size
+print_summary
+strip_path_prefix
+symbolize
+verbosity
+"
+
+gcc_4_9_asan_opts="
+$gcc_4_9_sanitizer_common
+abort_on_error
+alloc_dealloc_mismatch
+allow_reexec
+allow_user_poisoning
+allow_user_segv_handler
+atexit
+check_initialization_order
+check_malloc_usable_size
+coverage
+debug
+detect_stack_use_after_return
+disable_core
+exitcode
+handle_segv
+mac_ignore_invalid_free
+malloc_fill_byte
+max_malloc_fill_size
+poison_heap
+poison_partial
+print_full_thread_history
+print_legend
+print_stats
+quarantine_size
+redzone
+replace_intrin
+replace_str
+report_globals
+sleep_before_dying
+strict_init_order
+strict_memcmp
+uar_stack_size_log
+unmap_shadow_on_exit
+use_sigaltstack
+"
+
+tmp=$(mktemp)
+trap 'rm "$tmp"' EXIT
+echo 'int main(void){ return 0; }' | $CC -fsanitize=address -x c - -o "$tmp"
+
+ASAN_OPTIONS=help=1 "$tmp" 2>&1 |
+gawk -vgcc_4_9_asan_opts="$gcc_4_9_asan_opts" -vgcc_ver="$gcc_ver" '
+BEGIN {
+ n = split(gcc_4_9_asan_opts, gcc49_opts_);
+ split("", gcc49_opts);
+ for (i = 1; i <= n; i++) {
+ gcc49_opts[gcc49_opts_[i]] = 1;
+ }
+
+ split("", desc);
+}
+/^\t[^\t]/ {
+ name = $1;
+}
+/^\t\t- / {
+ desc[name] = $0;
+}
+END {
+ asorti(desc, desc_indices);
+ for (i in desc_indices) {
+ word = desc_indices[i];
+ suffix = "";
+ if (!gcc49_opts[word]) {
+ suffix = " [!gcc49]";
+ }
+ print "\t" word suffix;
+ print desc[word];
+ }
+}
+' | sed -r "s/^(\\t)([a-z0-9_]+)/\\1${CON}\\2${COFF}/"
+