Skip to content

Commit 97c8dc7

Browse files
author
Devang Patel
committed
Add little test harness to measure and compare quality of linenumber information preserved by clang. It produces .lineinfo file, for example
.|int main() { | int Array[100][200], i, j; +| double sum = 0.0; | .| for (i=0; i < 100; i+=2) .| for (j=0; j < 200; j++) .| Array[i][j] = 0; -| test_indvars(Array[0], Array); | x| for (i=0; i < 100; i+=2) x| for (j=0; j < 200; j++) .| sum += Array[i][j]; | .| printf("Checksum = %.0lf\n", sum); | -| return 0; .|} Here, . in first column indicates both clang and base compiler preserves line number information for this line. + in first column indicates only clang preserves line number information for this line. - in first column indicates neigther clang nor base compiler preserves line number information for this line. x in first column indicates clang does not preserve line number information for this line. CC is base compiler and LCC is clang. OPTFLAGS controls the optimization level. llvm-svn: 133276
1 parent 0957597 commit 97c8dc7

File tree

4 files changed

+146
-0
lines changed

4 files changed

+146
-0
lines changed

FindMissingLineNo.py

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import sys
5+
6+
DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".dbg.ml"
7+
OPT_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".dbg.opt.ml"
8+
NATIVE_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".native.dbg.ml"
9+
NATIVE_OPT_DBG_OUTPUT_FILE="Output/" + sys.argv[1] + ".native.dbg.opt.ml"
10+
XFAIL_FILE=sys.argv[2] + "/lineinfo.xfail"
11+
12+
REPORT_FILE="Output/" + sys.argv[1] + ".dbg.missing_lines.report.txt"
13+
14+
def read_inputfile(filename, dict):
15+
f = open(filename, "r")
16+
lines = f.readlines()
17+
for l in range(len(lines)):
18+
columns = lines[l].split()
19+
s = dict.get(columns[0])
20+
if s is None:
21+
s = set()
22+
s.add(columns[1])
23+
dict[columns[0]] = s
24+
f.close()
25+
return
26+
27+
dbg_lines = {}
28+
read_inputfile(DBG_OUTPUT_FILE, dbg_lines)
29+
30+
dbg_opt_lines = {}
31+
read_inputfile(OPT_DBG_OUTPUT_FILE, dbg_opt_lines)
32+
33+
native_dbg_lines = {}
34+
read_inputfile(NATIVE_DBG_OUTPUT_FILE, native_dbg_lines)
35+
36+
native_dbg_opt_lines = {}
37+
read_inputfile(NATIVE_OPT_DBG_OUTPUT_FILE, native_dbg_opt_lines)
38+
39+
xfailed_lines = {}
40+
read_inputfile(XFAIL_FILE, xfailed_lines)
41+
42+
dbg_line_items = dbg_lines.items()
43+
for f in range(len(dbg_line_items)):
44+
fname = dbg_line_items[f][0]
45+
fset = dbg_line_items[f][1]
46+
optset = dbg_opt_lines.get(fname)
47+
nativeoptset = native_dbg_opt_lines.get(fname)
48+
xfailedset = xfailed_lines.get(os.path.basename(fname))
49+
if optset is not None:
50+
src = open(fname, "r")
51+
srclines = src.readlines()
52+
src_output = open("Output/" + sys.argv[1] + ".lineinfo", "w")
53+
for l in range(len(srclines)):
54+
l1 = l + 1
55+
l1s = str(l1)
56+
if l1s in fset:
57+
if l1s in optset:
58+
if nativeoptset is not None and l1s in nativeoptset:
59+
src_output.write(".|")
60+
else:
61+
src_output.write("+|")
62+
else:
63+
if nativeoptset is not None and l1s in nativeoptset:
64+
if xfailedset is not None and l1s in xfailedset:
65+
src_output.write(" |")
66+
else:
67+
src_output.write("x|")
68+
else:
69+
src_output.write("-|")
70+
else:
71+
src_output.write(" |")
72+
src_output.write(srclines[l])
73+
src.close()
74+
src_output.close()

PrintLineNo.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
dwarfdump Output/$1.dbg.dSYM/ -e --debug-line | grep "^0x" | awk '{if ($3) prev=$3; print basename prev," ",$2}' |sort |uniq > Output/$1.dbg.ml;
4+
dwarfdump Output/$1.dbg.opt.dSYM/ -e --debug-line | grep "^0x" | awk '{if ($3) prev=$3; print basename prev," ",$2}' |sort |uniq > Output/$1.dbg.opt.ml;
5+
dwarfdump Output/$1.native.dbg.dSYM/ -e --debug-line | grep "^0x" | awk '{if ($3) prev=$3; print basename prev," ",$2}' |sort |uniq > Output/$1.native.dbg.ml;
6+
dwarfdump Output/$1.native.dbg.opt.dSYM/ -e --debug-line | grep "^0x" | awk '{if ($3) prev=$3; print basename prev," ",$2}' |sort |uniq > Output/$1.native.dbg.opt.ml;

TEST.lineinfo.Makefile

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
##===- TEST.lineinfo.Makefile -----------------------------*- Makefile -*--===##
2+
#
3+
# This test is used to measure quality of debugging information.
4+
#
5+
##===----------------------------------------------------------------------===##
6+
7+
CURDIR := $(shell cd .; pwd)
8+
PROGDIR := $(PROJ_SRC_ROOT)
9+
RELDIR := $(subst $(PROGDIR),,$(CURDIR))
10+
COLLECTOR := $(PROJ_SRC_ROOT)/CollectDebugInfoUsingLLDB.py
11+
12+
REPORTS_TO_GEN := dbg
13+
REPORTS_SUFFIX := $(addsuffix .report.txt, $(REPORTS_TO_GEN))
14+
15+
Output/%.bp: %.c Output/.dir
16+
$(LCC) $(CPPFLAGS) $(CFLAGS) -g -c -emit-llvm $< -o $@.bc
17+
$(LOPT) -print-breakpoints-for-testing $@.bc -o $@
18+
19+
Output/%.bp: %.cpp Output/.dir
20+
$(LCXX) $(CPPFLAGS) $(CFLAGS) -g -c -emit-llvm $< -o $@.bc
21+
$(LOPT) -print-breakpoints-for-testing $@.bc -o $@
22+
23+
Output/%.bp: %.m Output/.dir
24+
$(LCC) $(CPPFLAGS) $(CFLAGS) -g -c -emit-llvm $< -o $@.bc
25+
$(LOPT) -print-breakpoints-for-testing $@.bc -o $@
26+
27+
Output/%.bp: %.mm Output/.dir
28+
$(LCXX) $(CPPFLAGS) $(CFLAGS) -g -c -emit-llvm $< -o $@.bc
29+
$(LOPT) -print-breakpoints-for-testing $@.bc -o $@
30+
31+
$(PROGRAMS_TO_TEST:%=test.$(TEST).%): \
32+
test.$(TEST).%: Output/%.bp Output/%.dbg Output/%.dbg.opt Output/%.native.dbg Output/%.native.dbg.opt
33+
@-is_skip=0; \
34+
if test "$*" == "reversefile"; then \
35+
is_skip=1; \
36+
fi; \
37+
if test "$*" == "spellcheck"; then \
38+
is_skip=1; \
39+
fi; \
40+
if test "$*" == "sumcol"; then \
41+
is_skip=1; \
42+
fi; \
43+
if test "$*" == "wc"; then \
44+
is_skip=1; \
45+
fi; \
46+
if test "$*" == "wordfreq"; then \
47+
is_skip=1; \
48+
fi; \
49+
if test "$*" == "exptree"; then \
50+
is_skip=1; \
51+
fi; \
52+
if test "$*" == "ray"; then \
53+
is_skip=1; \
54+
fi; \
55+
if test "$*" == "oscar"; then \
56+
is_skip=1; \
57+
fi; \
58+
if test "$*" == "spirit"; then \
59+
is_skip=1; \
60+
fi; \
61+
if test $$is_skip == 0; then \
62+
$(PROJ_SRC_ROOT)/PrintLineNo.sh $*; \
63+
$(PROJ_SRC_ROOT)/FindMissingLineNo.py $* $(PROJ_SRC_ROOT);\
64+
fi
65+

lineinfo.xfail

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sse.shift.c 9

0 commit comments

Comments
 (0)