aboutsummaryrefslogtreecommitdiffstats
path: root/lib/gwp_asan/scripts/symbolize.sh
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:52:22 +0000
commit3a1720af1d7f43edc5b214cde0be11bfb94d077e (patch)
tree029e0ff2d5e3c0eaf2405fd8e669555fdf5e1297 /lib/gwp_asan/scripts/symbolize.sh
parent8f3cadc28cb2bb9e8f9d69eeaaea1f57f2f7b2ab (diff)
downloadsrc-vendor/compiler-rt.tar.gz
src-vendor/compiler-rt.zip
Vendor import of stripped compiler-rt trunk r375505, the last commitvendor/compiler-rt/compiler-rt-trunk-r375505vendor/compiler-rt
before the upstream Subversion repository was made read-only, and the LLVM project migrated to GitHub: https://llvm.org/svn/llvm-project/compiler-rt/trunk@375505
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=353944 svn path=/vendor/compiler-rt/compiler-rt-r375505/; revision=353945; tag=vendor/compiler-rt/compiler-rt-trunk-r375505
Diffstat (limited to 'lib/gwp_asan/scripts/symbolize.sh')
-rwxr-xr-xlib/gwp_asan/scripts/symbolize.sh55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/gwp_asan/scripts/symbolize.sh b/lib/gwp_asan/scripts/symbolize.sh
new file mode 100755
index 000000000000..fad9620a676e
--- /dev/null
+++ b/lib/gwp_asan/scripts/symbolize.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+# The lines that we're looking to symbolize look like this:
+ #0 ./a.out(_foo+0x3e6) [0x55a52e64c696]
+# ... which come from the backtrace_symbols() symbolisation function used by
+# default in Scudo's implementation of GWP-ASan.
+
+while read -r line; do
+ # Check that this line needs symbolization.
+ should_symbolize="$(echo $line |\
+ grep -E '^[ ]*\#.*\(.*\+0x[0-9a-f]+\) \[0x[0-9a-f]+\]$')"
+
+ if [ -z "$should_symbolize" ]; then
+ echo "$line"
+ continue
+ fi
+
+ # Carve up the input line into sections.
+ binary_name="$(echo $line | grep -oE ' .*\(' | rev | cut -c2- | rev |\
+ cut -c2-)"
+ function_name="$(echo $line | grep -oE '\([^+]*' | cut -c2-)"
+ function_offset="$(echo $line | grep -oE '\(.*\)' | grep -oE '\+.*\)' |\
+ cut -c2- | rev | cut -c2- | rev)"
+ frame_number="$(echo $line | grep -oE '\#[0-9]+ ')"
+
+ if [ -z "$function_name" ]; then
+ # If the offset is binary-relative, just resolve that.
+ symbolized="$(echo $function_offset | addr2line -e $binary_name)"
+ else
+ # Otherwise, the offset is function-relative. Get the address of the
+ # function, and add it to the offset, then symbolize.
+ function_addr="0x$(echo $function_offset |\
+ nm --defined-only $binary_name 2> /dev/null |\
+ grep -E " $function_name$" | cut -d' ' -f1)"
+
+ # Check that we could get the function address from nm.
+ if [ -z "$function_addr" ]; then
+ echo "$line"
+ continue
+ fi
+
+ # Add the function address and offset to get the offset into the binary.
+ binary_offset="$(printf "0x%X" "$((function_addr+function_offset))")"
+ symbolized="$(echo $binary_offset | addr2line -e $binary_name)"
+ fi
+
+ # Check that it symbolized properly. If it didn't, output the old line.
+ echo $symbolized | grep -E ".*\?.*:" > /dev/null
+ if [ "$?" -eq "0" ]; then
+ echo "$line"
+ continue
+ else
+ echo "${frame_number}${symbolized}"
+ fi
+done