[1/2] gdb/testsuite: Move helper function into lib/dwarf.exp

Message ID c51116f73e7401d3815e4d46490ad7c876841a9a.1585952198.git.andrew.burgess@embecosm.com
State New
Headers show
Series
  • More regression fixing from is-stmt patches
Related show

Commit Message

Andrew Burgess April 3, 2020, 10:21 p.m.
Every time I write a test making use of the DWARF assembler I end up
copying in the function get_func_info.  Duplicating code is bad, so
lets put this function into lib/dwarf.exp and remove all of the
duplicates.

There should be no changes in the testsuite behaviour after this
commit.

gdb/testsuite/ChangeLog:

	* gdb.dwarf2/dw2-inline-many-frames.exp (get_func_info): Delete.
	* gdb.dwarf2/dw2-inline-small-func.exp: Pass options to
	get_func_info.
	(get_func_info): Delete.
	* gdb.dwarf2/dw2-is-stmt-2.exp (get_func_info): Delete.
	* gdb.dwarf2/dw2-is-stmt.exp (get_func_info): Delete.
	* lib/dwarf.exp (get_func_info): New function.
---
 gdb/testsuite/ChangeLog                             | 10 ++++++++++
 gdb/testsuite/gdb.dwarf2/dw2-inline-many-frames.exp | 14 --------------
 gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp  | 16 +---------------
 gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp          | 14 --------------
 gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp            | 14 --------------
 gdb/testsuite/lib/dwarf.exp                         | 16 ++++++++++++++++
 6 files changed, 27 insertions(+), 57 deletions(-)

-- 
2.14.5

Comments

Tom Tromey April 6, 2020, 8:18 p.m. | #1
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:


Andrew> gdb/testsuite/ChangeLog:

Andrew> 	* gdb.dwarf2/dw2-inline-many-frames.exp (get_func_info): Delete.
Andrew> 	* gdb.dwarf2/dw2-inline-small-func.exp: Pass options to
Andrew> 	get_func_info.
Andrew> 	(get_func_info): Delete.
Andrew> 	* gdb.dwarf2/dw2-is-stmt-2.exp (get_func_info): Delete.
Andrew> 	* gdb.dwarf2/dw2-is-stmt.exp (get_func_info): Delete.
Andrew> 	* lib/dwarf.exp (get_func_info): New function.

Thanks for doing this.  I didn't realize this function was copied so
many times, or I would have merged them myself.  Looks good.

Tom
Andrew Burgess April 14, 2020, 11:18 a.m. | #2
* Tom Tromey <tom@tromey.com> [2020-04-06 14:18:28 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

> 

> Andrew> gdb/testsuite/ChangeLog:

> 

> Andrew> 	* gdb.dwarf2/dw2-inline-many-frames.exp (get_func_info): Delete.

> Andrew> 	* gdb.dwarf2/dw2-inline-small-func.exp: Pass options to

> Andrew> 	get_func_info.

> Andrew> 	(get_func_info): Delete.

> Andrew> 	* gdb.dwarf2/dw2-is-stmt-2.exp (get_func_info): Delete.

> Andrew> 	* gdb.dwarf2/dw2-is-stmt.exp (get_func_info): Delete.

> Andrew> 	* lib/dwarf.exp (get_func_info): New function.

> 

> Thanks for doing this.  I didn't realize this function was copied so

> many times, or I would have merged them myself.  Looks good.


Thanks for reviewing this.

I've gone ahead and pushed this patch as it is a nice clean up
independent of the second patch, which is still under discussion.

Thanks,
Andrew

Patch

diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-many-frames.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-many-frames.exp
index 146af8c6ef7..0c2c6612265 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-inline-many-frames.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-many-frames.exp
@@ -40,20 +40,6 @@  if !$gcc_compiled {
 
 standard_testfile dw2-inline-many-frames.c dw2-inline-many-frames.S
 
-# Extract the start, length, and end for function called NAME and
-# create suitable variables in the callers scope.
-proc get_func_info { name } {
-    global srcdir subdir srcfile
-
-    upvar 1 "${name}_start" func_start
-    upvar 1 "${name}_len" func_len
-    upvar 1 "${name}_end" func_end
-
-    lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
-	func_start func_len
-    set func_end "$func_start + $func_len"
-}
-
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     global srcdir subdir srcfile srcfile2
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp b/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
index 777db062b37..4fcc3cfeac9 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-inline-small-func.exp
@@ -42,26 +42,12 @@  if !$gcc_compiled {
 standard_testfile dw2-inline-small-func-lbls.c dw2-inline-small-func.S \
     dw2-inline-small-func.c dw2-inline-small-func.h
 
-# Extract the start, length, and end for function called NAME and
-# create suitable variables in the callers scope.
-proc get_func_info { name } {
-    global srcdir subdir srcfile
-
-    upvar 1 "${name}_start" func_start
-    upvar 1 "${name}_len" func_len
-    upvar 1 "${name}_end" func_end
-
-    lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile] {debug optimize=-O1}] \
-	func_start func_len
-    set func_end "$func_start + $func_len"
-}
-
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     global srcdir subdir srcfile srcfile3 srcfile4
     declare_labels lines_label callee_subprog_label
 
-    get_func_info main
+    get_func_info main {debug optimize=-O1}
 
     cu {} {
 	# It is important that the producer here be 'clang' as, at the
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
index 436c4d01024..2fcad93e957 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt-2.exp
@@ -40,20 +40,6 @@  if !$gcc_compiled {
 
 standard_testfile dw2-is-stmt-2.c dw2-is-stmt-2.S
 
-# Extract the start, length, and end for function called NAME and
-# create suitable variables in the callers scope.
-proc get_func_info { name } {
-    global srcdir subdir srcfile
-
-    upvar 1 "${name}_start" func_start
-    upvar 1 "${name}_len" func_len
-    upvar 1 "${name}_end" func_end
-
-    lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
-	func_start func_len
-    set func_end "$func_start + $func_len"
-}
-
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     global srcdir subdir srcfile
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
index 1bcf5b0c698..e200e91fd77 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-is-stmt.exp
@@ -40,20 +40,6 @@  if !$gcc_compiled {
 
 standard_testfile dw2-is-stmt.c dw2-is-stmt.S
 
-# Extract the start, length, and end for function called NAME and
-# create suitable variables in the callers scope.
-proc get_func_info { name } {
-    global srcdir subdir srcfile
-
-    upvar 1 "${name}_start" func_start
-    upvar 1 "${name}_len" func_len
-    upvar 1 "${name}_end" func_end
-
-    lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
-	func_start func_len
-    set func_end "$func_start + $func_len"
-}
-
 set asm_file [standard_output_file $srcfile2]
 Dwarf::assemble $asm_file {
     global srcdir subdir srcfile
diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp
index 93bde76de35..a7dbe25fd45 100644
--- a/gdb/testsuite/lib/dwarf.exp
+++ b/gdb/testsuite/lib/dwarf.exp
@@ -164,6 +164,22 @@  proc function_range { func src {options {debug}} } {
     return [list "${func}_label - $func_label_offset" $func_length]
 }
 
+# Extract the start, length, and end for function called NAME and
+# create suitable variables in the callers scope.
+proc get_func_info { name {options {debug}} } {
+    global srcdir subdir srcfile
+
+    upvar 1 "${name}_start" func_start
+    upvar 1 "${name}_len" func_len
+    upvar 1 "${name}_end" func_end
+
+    lassign [function_range ${name} \
+		 [list ${srcdir}/${subdir}/$srcfile] \
+		 ${options}]  \
+	func_start func_len
+    set func_end "$func_start + $func_len"
+}
+
 # A DWARF assembler.
 #
 # All the variables in this namespace are private to the