1 # Copyright (C) 2018-2024 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 set testname "addr2line"
22 # powerpc64 function symbols are on descriptors rather than code.
23 # MUSL uses the ELFv2 ABI for PowerPC, so the problem does not apply there.
24 if { [istarget powerpc64-*-*] && ![istarget powerpc64-*-musl] } {
29 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } {
30 verbose "Unable to compile test file."
35 #testcase for default option.
36 #Run nm command and input the main symbol address to addr2line.
37 set output [binutils_run $NM "$opts tmpdir/testprog$exe"]
38 if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${dot}main" $output contents] then {
41 set list [regexp -inline -all -- {\S+} $contents]
42 set got [binutils_run $ADDR2LINE "-e tmpdir/testprog$exe [lindex $list 0]"]
43 set want "$srcdir/$subdir/testprog.c:\[0-9\]+"
44 if ![regexp $want $got] then {
45 fail "$testname $got\n"
51 #testcase for -f option.
52 #Run nm command and input the fn function symbol address to addr2line.
53 if ![regexp -line "^(\[0-9a-fA-F\]+)? +\[Tt\] ${dot}fn" $output contents] then {
54 fail "$testname -f option"
56 set list [regexp -inline -all -- {\S+} $contents]
57 set got [binutils_run $ADDR2LINE "-f -e tmpdir/testprog$exe [lindex $list 0]"]
58 set want "fn\n$srcdir/$subdir/testprog.c:\[0-9\]+"
59 if ![regexp $want $got] then {
60 fail "$testname -f option $got\n"
62 pass "$testname -f option"
65 #testcase for -s option.
66 #Using the same fn function address used in -f option.
67 set got [binutils_run $ADDR2LINE "-s -e tmpdir/testprog$exe [lindex $list 0]"]
68 set want "testprog.c:\[0-9\]+"
69 if ![regexp $want $got] then {
70 fail "$testname -s option $got\n"
72 pass "$testname -s option"