public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use gdb_produce_source
@ 2013-11-28  9:07 Yao Qi
  2013-12-06 19:19 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Yao Qi @ 2013-11-28  9:07 UTC (permalink / raw)
  To: gdb-patches

We added a new proc gdb_produce_source recently, and it can be used
more widely in lib/gdb.exp to generate source file.

gdb/testsuite:

2013-11-28  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (support_complex_tests): Use gdb_produce_source.
	(is_elf_target, is_ilp32_target, is_ilp64_target): Likewise.
	(is_64_target, is_amd64_regs_target): Likewise.
	(skip_altivec_tests, skip_vsx_tests, skip_btrace_tests): Likewise.
---
 gdb/testsuite/lib/gdb.exp |  108 ++++++++++++++++++++++++---------------------
 1 files changed, 57 insertions(+), 51 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 2c1cf29..978b753 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1751,13 +1751,15 @@ gdb_caching_proc support_complex_tests {
     set src [standard_temp_file complex[pid].c]
     set exe [standard_temp_file complex[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "_Complex float cf;"
-    puts $f "_Complex double cd;"
-    puts $f "_Complex long double cld;"
-    puts $f "  return 0; }"
-    close $f
+    set list {
+	"int main() {"
+	"_Complex float cf;"
+	"_Complex double cd;"
+	"_Complex long double cld;"
+	"  return 0; }"
+    }
+    gdb_produce_source $src [join $list \n]
+
 
     verbose "compiling testfile $src" 2
     set compile_flags {debug nowarnings quiet}
@@ -1829,9 +1831,8 @@ gdb_caching_proc is_elf_target {
     set src [standard_temp_file is_elf_target[pid].c]
     set obj [standard_temp_file is_elf_target[pid].o]
 
-    set fp_src [open $src "w"]
-    puts $fp_src "int foo () {return 0;}"
-    close $fp_src
+    set list { "int foo () {return 0;}" }
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1880,11 +1881,12 @@ gdb_caching_proc is_ilp32_target {
     set src [standard_temp_file ilp32[pid].c]
     set obj [standard_temp_file ilp32[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int dummy\[sizeof (int) == 4"
-    puts $f "           && sizeof (void *) == 4"
-    puts $f "           && sizeof (long) == 4 ? 1 : -1\];"
-    close $f
+    set list {
+	"int dummy\[sizeof (int) == 4"
+	"           && sizeof (void *) == 4"
+	"           && sizeof (long) == 4 ? 1 : -1\];"
+    }
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1909,11 +1911,12 @@ gdb_caching_proc is_lp64_target {
     set src [standard_temp_file lp64[pid].c]
     set obj [standard_temp_file lp64[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int dummy\[sizeof (int) == 4"
-    puts $f "           && sizeof (void *) == 8"
-    puts $f "           && sizeof (long) == 8 ? 1 : -1\];"
-    close $f
+    set list {
+	"int dummy\[sizeof (int) == 4"
+	"           && sizeof (void *) == 8"
+	"           && sizeof (long) == 8 ? 1 : -1\];"
+    }
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1938,10 +1941,11 @@ gdb_caching_proc is_64_target {
     set src [standard_temp_file is64[pid].c]
     set obj [standard_temp_file is64[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int function(void) { return 3; }"
-    puts $f "int dummy\[sizeof (&function) == 8 ? 1 : -1\];"
-    close $f
+    set list {
+	"int function(void) { return 3; }"
+	"int dummy\[sizeof (&function) == 8 ? 1 : -1\];"
+    }
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1970,12 +1974,12 @@ gdb_caching_proc is_amd64_regs_target {
     set src [standard_temp_file reg64[pid].s]
     set obj [standard_temp_file reg64[pid].o]
 
-    set f [open $src "w"]
+    set list {}
     foreach reg \
-            {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
-	puts $f "\tincq %$reg"
-    }
-    close $f
+	{rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
+	    lappend list "\tincq %$reg"
+	}
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -2046,15 +2050,17 @@ gdb_caching_proc skip_altivec_tests {
     set src [standard_temp_file vmx[pid].c]
     set exe [standard_temp_file vmx[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "#ifdef __MACH__"
-    puts $f "  asm volatile (\"vor v0,v0,v0\");"
-    puts $f "#else"
-    puts $f "  asm volatile (\"vor 0,0,0\");"
-    puts $f "#endif"
-    puts $f "  return 0; }"
-    close $f
+    set list {
+	"int main() {"
+	"#ifdef __MACH__"
+	"  asm volatile (\"vor v0,v0,v0\");"
+	"#else"
+	"  asm volatile (\"vor 0,0,0\");"
+	"#endif"
+	"  return 0; }"
+    }
+    gdb_produce_source $src [join $list \n]
+
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $exe executable $compile_flags]
@@ -2126,16 +2132,17 @@ gdb_caching_proc skip_vsx_tests {
     set src [standard_temp_file vsx[pid].c]
     set exe [standard_temp_file vsx[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "  double a\[2\] = { 1.0, 2.0 };"
-    puts $f "#ifdef __MACH__"
-    puts $f "  asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
-    puts $f "#else"
-    puts $f "  asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
-    puts $f "#endif"
-    puts $f "  return 0; }"
-    close $f
+    set list {
+	"int main() {"
+	"  double a\[2\] = { 1.0, 2.0 };"
+	"#ifdef __MACH__"
+	"  asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
+	"#else"
+	"  asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
+	"#endif"
+	"  return 0; }"
+    }
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $exe executable $compile_flags]
@@ -2192,9 +2199,8 @@ gdb_caching_proc skip_btrace_tests {
     set src [standard_temp_file btrace[pid].c]
     set exe [standard_temp_file btrace[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main(void) { return 0; }"
-    close $f
+    set list {"int main(void) { return 0; }"}
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set compile_flags {debug nowarnings quiet}
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use gdb_produce_source
  2013-11-28  9:07 [PATCH] Use gdb_produce_source Yao Qi
@ 2013-12-06 19:19 ` Tom Tromey
  2013-12-08  7:17   ` Yao Qi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2013-12-06 19:19 UTC (permalink / raw)
  To: Yao Qi; +Cc: gdb-patches

>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:

Yao> 2013-11-28  Yao Qi  <yao@codesourcery.com>
Yao> 	* lib/gdb.exp (support_complex_tests): Use gdb_produce_source.
Yao> 	(is_elf_target, is_ilp32_target, is_ilp64_target): Likewise.
Yao> 	(is_64_target, is_amd64_regs_target): Likewise.
Yao> 	(skip_altivec_tests, skip_vsx_tests, skip_btrace_tests): Likewise.

Ok.

Yao> -    set f [open $src "w"]
Yao> -    puts $f "int main() {"
Yao> -    puts $f "_Complex float cf;"
Yao> -    puts $f "_Complex double cd;"
Yao> -    puts $f "_Complex long double cld;"
Yao> -    puts $f "  return 0; }"
Yao> -    close $f
Yao> +    set list {
Yao> +	"int main() {"
Yao> +	"_Complex float cf;"
Yao> +	"_Complex double cd;"
Yao> +	"_Complex long double cld;"
Yao> +	"  return 0; }"
Yao> +    }
Yao> +    gdb_produce_source $src [join $list \n]

There's a more idiomatic approach, which is to just take advantage of
Tcl's string-based nature.  That is:

gdb_produce_source $src {
  int main() {
    _Complex float cf;
    ...
  }
}

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Use gdb_produce_source
  2013-12-06 19:19 ` Tom Tromey
@ 2013-12-08  7:17   ` Yao Qi
  0 siblings, 0 replies; 3+ messages in thread
From: Yao Qi @ 2013-12-08  7:17 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 12/07/2013 03:19 AM, Tom Tromey wrote:
> There's a more idiomatic approach, which is to just take advantage of
> Tcl's string-based nature.  That is:
> 
> gdb_produce_source $src {
>    int main() {
>      _Complex float cf;
>      ...
>    }
> }

Good point!  I adjust the patch in this way, and pushed.

-- 
Yao (齐尧)

gdb/testsuite:

2013-12-08  Yao Qi  <yao@codesourcery.com>

	* lib/gdb.exp (support_complex_tests): Use gdb_produce_source.
	(is_elf_target, is_ilp32_target, is_ilp64_target): Likewise.
	(is_64_target, is_amd64_regs_target): Likewise.
	(skip_altivec_tests, skip_vsx_tests, skip_btrace_tests): Likewise.
---
 gdb/testsuite/lib/gdb.exp |  105 +++++++++++++++++++++++----------------------
 1 files changed, 54 insertions(+), 51 deletions(-)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index 2c1cf29..d221505 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -1751,13 +1751,14 @@ gdb_caching_proc support_complex_tests {
     set src [standard_temp_file complex[pid].c]
     set exe [standard_temp_file complex[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "_Complex float cf;"
-    puts $f "_Complex double cd;"
-    puts $f "_Complex long double cld;"
-    puts $f "  return 0; }"
-    close $f
+    gdb_produce_source $src {
+	int main() {
+	    _Complex float cf;
+	    _Complex double cd;
+	    _Complex long double cld;
+	    return 0;
+	}
+    }
 
     verbose "compiling testfile $src" 2
     set compile_flags {debug nowarnings quiet}
@@ -1829,9 +1830,9 @@ gdb_caching_proc is_elf_target {
     set src [standard_temp_file is_elf_target[pid].c]
     set obj [standard_temp_file is_elf_target[pid].o]
 
-    set fp_src [open $src "w"]
-    puts $fp_src "int foo () {return 0;}"
-    close $fp_src
+    gdb_produce_source $src {
+	int foo () {return 0;}
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1880,11 +1881,11 @@ gdb_caching_proc is_ilp32_target {
     set src [standard_temp_file ilp32[pid].c]
     set obj [standard_temp_file ilp32[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int dummy\[sizeof (int) == 4"
-    puts $f "           && sizeof (void *) == 4"
-    puts $f "           && sizeof (long) == 4 ? 1 : -1\];"
-    close $f
+    gdb_produce_source $src {
+	int dummy[sizeof (int) == 4
+		  && sizeof (void *) == 4
+		  && sizeof (long) == 4 ? 1 : -1];
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1909,11 +1910,11 @@ gdb_caching_proc is_lp64_target {
     set src [standard_temp_file lp64[pid].c]
     set obj [standard_temp_file lp64[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int dummy\[sizeof (int) == 4"
-    puts $f "           && sizeof (void *) == 8"
-    puts $f "           && sizeof (long) == 8 ? 1 : -1\];"
-    close $f
+    gdb_produce_source $src {
+	int dummy[sizeof (int) == 4
+		  && sizeof (void *) == 8
+		  && sizeof (long) == 8 ? 1 : -1];
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1938,10 +1939,10 @@ gdb_caching_proc is_64_target {
     set src [standard_temp_file is64[pid].c]
     set obj [standard_temp_file is64[pid].o]
 
-    set f [open $src "w"]
-    puts $f "int function(void) { return 3; }"
-    puts $f "int dummy\[sizeof (&function) == 8 ? 1 : -1\];"
-    close $f
+    gdb_produce_source $src {
+	int function(void) { return 3; }
+	int dummy[sizeof (&function) == 8 ? 1 : -1];
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -1970,12 +1971,12 @@ gdb_caching_proc is_amd64_regs_target {
     set src [standard_temp_file reg64[pid].s]
     set obj [standard_temp_file reg64[pid].o]
 
-    set f [open $src "w"]
+    set list {}
     foreach reg \
-            {rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
-	puts $f "\tincq %$reg"
-    }
-    close $f
+	{rax rbx rcx rdx rsi rdi rbp rsp r8 r9 r10 r11 r12 r13 r14 r15} {
+	    lappend list "\tincq %$reg"
+	}
+    gdb_produce_source $src [join $list \n]
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $obj object {quiet}]
@@ -2046,15 +2047,16 @@ gdb_caching_proc skip_altivec_tests {
     set src [standard_temp_file vmx[pid].c]
     set exe [standard_temp_file vmx[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "#ifdef __MACH__"
-    puts $f "  asm volatile (\"vor v0,v0,v0\");"
-    puts $f "#else"
-    puts $f "  asm volatile (\"vor 0,0,0\");"
-    puts $f "#endif"
-    puts $f "  return 0; }"
-    close $f
+    gdb_produce_source $src {
+	int main() {
+	    #ifdef __MACH__
+	    asm volatile ("vor v0,v0,v0");
+	    #else
+	    asm volatile ("vor 0,0,0");
+	    #endif
+	    return 0;
+	}
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $exe executable $compile_flags]
@@ -2126,16 +2128,17 @@ gdb_caching_proc skip_vsx_tests {
     set src [standard_temp_file vsx[pid].c]
     set exe [standard_temp_file vsx[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main() {"
-    puts $f "  double a\[2\] = { 1.0, 2.0 };"
-    puts $f "#ifdef __MACH__"
-    puts $f "  asm volatile (\"lxvd2x v0,v0,%\[addr\]\" : : \[addr\] \"r\" (a));"
-    puts $f "#else"
-    puts $f "  asm volatile (\"lxvd2x 0,0,%\[addr\]\" : : \[addr\] \"r\" (a));"
-    puts $f "#endif"
-    puts $f "  return 0; }"
-    close $f
+    gdb_produce_source $src {
+	int main() {
+	    double a[2] = { 1.0, 2.0 };
+	    #ifdef __MACH__
+	    asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a));
+	    #else
+	    asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a));
+	    #endif
+	    return 0;
+	}
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set lines [gdb_compile $src $exe executable $compile_flags]
@@ -2192,9 +2195,9 @@ gdb_caching_proc skip_btrace_tests {
     set src [standard_temp_file btrace[pid].c]
     set exe [standard_temp_file btrace[pid].x]
 
-    set f [open $src "w"]
-    puts $f "int main(void) { return 0; }"
-    close $f
+    gdb_produce_source $src {
+	int main(void) { return 0; }
+    }
 
     verbose "$me:  compiling testfile $src" 2
     set compile_flags {debug nowarnings quiet}
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-12-08  7:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28  9:07 [PATCH] Use gdb_produce_source Yao Qi
2013-12-06 19:19 ` Tom Tromey
2013-12-08  7:17   ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).