xref: /illumos-gate/usr/src/test/util-tests/tests/ctf/ctftest-convert-no-dwarf.ksh (revision 344db6f401efe76f7e1d4f4c1a644ae593910219)
1#!/usr/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12# Copyright (c) 2019, Joyent, Inc.
13#
14
15set -e
16
17result=0
18
19progname=$(basename $0)
20
21fail()
22{
23	echo "Failed: $*" 2>&1
24	result=1
25}
26
27fail_no_debug()
28{
29	cmd="$@"
30	set +e
31	out=$($ctf_convert $cmd 2>&1)
32
33	if [[ $? -eq 0 ]]; then
34		fail "$cmd succeeded but should have failed"
35		set -e
36		return;
37	fi
38
39	set -e
40
41	if echo "$out" | grep "is missing debug info" >/dev/null; then
42		return;
43	fi
44
45	if echo "$out" | grep "does not contain DWARF data" >/dev/null; then
46		return;
47	fi
48	fail "$cmd: incorrect output $out"
49}
50
51has_ctf()
52{
53	for f in "$@"; do
54		if ! elfdump -c -N .SUNW_ctf "$f" |
55		    grep '.SUNW_ctf' >/dev/null; then
56			fail "$f lacks CTF section"
57			return
58		fi
59	done
60}
61
62cat <<EOF >file1.c
63#include <stdio.h>
64struct foo { int a; };
65int main(void) { struct foo foo = { 4 }; printf("%d\n", foo.a); }
66EOF
67
68cat <<EOF >file2.c
69#include <stdio.h>
70char myfunc(int a) { printf("%d\n", a); }
71EOF
72
73cat <<EOF >file3.cc
74struct bar { char *tar; };
75void mycxxfunc(char *c) { c[0] = '9'; };
76EOF
77
78cat <<EOF >file4.s
79.globl caller
80.type caller,@function
81caller:
82	movl 4(%ebp), %eax
83	ret
84EOF
85
86echo "$progname: An empty file should fail conversion due to no DWARF"
87echo >emptyfile.c
88
89$ctf_cc -c -o emptyfile.o emptyfile.c
90fail_no_debug emptyfile.o
91$ctf_cc -c -o emptyfile.o emptyfile.c
92$ctf_convert -m emptyfile.o
93
94$ctf_cc $ctf_debugflags -c -o emptyfile.o emptyfile.c
95fail_no_debug emptyfile.o
96$ctf_cc $ctf_debugflags -c -o emptyfile.o emptyfile.c
97$ctf_convert -m emptyfile.o
98
99echo "$progname: A file missing DWARF should fail conversion"
100
101$ctf_cc -c -o file1.o file1.c
102fail_no_debug file1.o
103$ctf_cc -c -o file1.o file1.c
104$ctf_convert -m file1.o
105
106echo "$progname: A binary with DWARF but 0 debug dies should fail conversion"
107
108$ctf_cc -o mybin file1.c
109fail_no_debug mybin
110$ctf_cc -o mybin file1.c
111$ctf_convert -m mybin
112
113echo "$progname: One C file missing DWARF should fail ctfconvert"
114
115$ctf_cc -c -o file1.o file1.c
116$ctf_cc $ctf_debugflags -c -o file2.o file2.c
117ld -r -o files.o file2.o file1.o
118fail_no_debug files.o
119ld -r -o files.o file2.o file1.o
120$ctf_convert -m files.o
121has_ctf files.o
122
123echo "$progname: One .cc file missing DWARF should pass"
124
125$ctf_cc $ctf_debugflags -c -o file1.o file1.c
126$ctf_cc $ctf_debugflags -c -o file2.o file2.c
127$ctf_cxx -c -o file3.o file3.cc
128ld -r -o files.o file1.o file2.o file3.o
129$ctf_convert files.o
130has_ctf files.o
131
132echo "$progname: One .s file missing DWARF should pass"
133$ctf_cc $ctf_debugflags -c -o file1.o file1.c
134$ctf_cc $ctf_debugflags -c -o file2.o file2.c
135$ctf_as -o file4.o file4.s
136$ctf_cc -o mybin file1.o file2.o file4.o
137$ctf_convert mybin
138has_ctf mybin
139
140echo "result is $result"
141exit $result
142