diff mbox

Add a simple test of line numbers in the g++ debug info

Message ID AANLkTikZ5qJo_Ss-fWrSMhplBtpACzeEET5WDEWABERG@mail.gmail.com
State New
Headers show

Commit Message

Jeffrey Yasskin July 19, 2010, 9:28 p.m. UTC
Jason pointed out a simpler way to do this with -dA and
scan-assembler, so here's a new patch that takes that approach. Tested
on Linux and Darwin.

gcc/testsuite/ChangeLog:
2010-07-19  Jeffrey Yasskin  <jyasskin@google.com>

        * lib/scanasm.exp (dg-function-on-line): Test that a function
is defined on the current line.
        * g++.dg/debug/dwarf2/lineno-simple1.C: New. Line number sanity test.
diff mbox

Patch

Index: gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C
===================================================================
--- gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C	(revision 0)
+++ gcc/testsuite/g++.dg/debug/dwarf2/lineno-simple1.C	(revision 0)
@@ -0,0 +1,13 @@ 
+// { dg-do compile }
+// { dg-options "-g -O0 -dA" }
+
+struct C {  // { dg-function-on-line {_ZN1CC[12]Ev} }
+  virtual void
+  foo() {}  // { dg-function-on-line _ZN1C3fooEv }
+};
+static C dummy;
+
+int
+main (void)
+{  // { dg-function-on-line main }
+}
Index: gcc/testsuite/lib/scanasm.exp
===================================================================
--- gcc/testsuite/lib/scanasm.exp	(revision 162315)
+++ gcc/testsuite/lib/scanasm.exp	(working copy)
@@ -291,3 +291,31 @@  proc scan-assembler-dem-not { args } {
 	fail "$testcase scan-assembler-dem-not $pp_pattern"
     }
 }
+
+# Utility for testing that a function is defined on the current line.
+# Call pass if so, otherwise fail.  Invoked directly; the file must
+# have been compiled with -g -dA.
+#
+# Argument 0 is the current line, passed implicitly by dejagnu
+# Argument 1 is the function to check
+# Argument 2 handles expected failures and the like
+proc dg-function-on-line { args } {
+    # Upvar from dg-final:
+    upvar dg-final-code final-code
+
+    set line [lindex $args 0]
+    set symbol [lindex $args 1]
+    set failures [lindex $args 2]
+
+    set pattern [format {%s:[^\t]*(\t.file[^\t]*)?\t# \S*:%d\n} \
+                 $symbol $line]
+
+    # The lack of spaces around $pattern is important, since they'd
+    # become part of the regex scan-assembler tries to match.
+    set cmd "scan-assembler {$pattern}"
+    if { [llength $args] >= 3 } {
+        set cmd "$cmd {$failures}"
+    }
+
+    append final-code "$cmd\n"
+}