This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[patch] New testcase function gdb_core_cmd
- From: Doug Evans <dje at google dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 22 Apr 2013 14:09:42 -0700
- Subject: [patch] New testcase function gdb_core_cmd
Hi.
I need to generate and load a core file for a new testcase.
There is a utility function to generate a core file but none to load it.
And it turns out there's a bit of duplicated code sprinkled about in the
testsuite to do this.
I will check this in in a few days if there are no objections.
[It's beyond the scope of this patch to make *every* invocation of the
"core" command use the new function.]
Tested on amd64-linux.
That doesn't test vsx-regs.exp but the change is mechanical.
2013-04-22 Doug Evans <dje@google.com>
* lib/gdb.exp (gdb_core_cmd): New function.
* gdb.arch/system-gcore.exp: Use it.
* gdb.arch/vsx-regs.exp: Ditto.
* gdb.base/gcore.exp: Ditto.
* gdb.threads/gcore-thread.exp: Ditto.
Index: gdb.arch/system-gcore.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/system-gcore.exp,v
retrieving revision 1.9
diff -u -p -r1.9 system-gcore.exp
--- gdb.arch/system-gcore.exp 14 Mar 2013 13:34:01 -0000 1.9
+++ gdb.arch/system-gcore.exp 22 Apr 2013 20:58:53 -0000
@@ -108,30 +108,10 @@ gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
-send_gdb "core ${objdir}/${subdir}/gcore.test\n"
-gdb_expect {
- -re ".* is not a core dump:.*$gdb_prompt $" {
- fail "re-load generated corefile (bad file format)"
- # No use proceeding from here.
- return;
- }
- -re ".*: No such file or directory.*$gdb_prompt $" {
- fail "re-load generated corefile (file not found)"
- # No use proceeding from here.
- return;
- }
- -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
- fail "re-load generated corefile (incomplete note section)"
- }
- -re "Core was generated by .*$gdb_prompt $" {
- pass "re-load generated corefile"
- }
- -re ".*$gdb_prompt $" {
- fail "re-load generated corefile"
- }
- timeout {
- fail "re-load generated corefile (timeout)"
- }
+set core_reloaded [load_core "core ${objdir}/${subdir}/gcore.test"]
+if { $core_reloaded == -1 } {
+ # No use proceeding from here.
+ return
}
gdb_test_sequence "where" "where in corefile" {
Index: gdb.arch/vsx-regs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.arch/vsx-regs.exp,v
retrieving revision 1.14
diff -u -p -r1.14 vsx-regs.exp
--- gdb.arch/vsx-regs.exp 1 Jan 2013 06:33:24 -0000 1.14
+++ gdb.arch/vsx-regs.exp 22 Apr 2013 20:58:53 -0000
@@ -128,8 +128,8 @@ for {set i 0} {$i < 32} {incr i 1} {
# later when loading the core file (i.e., different register values for different
# vector register banks).
-set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/vsx-core.test" \
- "Save a VSX-enabled corefile"]
+set corefile "${objdir}/${subdir}/vsx-core.test"
+set core_supported [gdb_gcore_cmd "$corefile" "Save a VSX-enabled corefile"]
# Now run the F32~F63/VR0~VR31 tests.
@@ -168,31 +168,10 @@ gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
-gdb_test_multiple "core ${objdir}/${subdir}/vsx-core.test" \
- "re-load generated corefile" \
-{
- -re ".* is not a core dump:.*$gdb_prompt $" {
- fail "re-load generated corefile (bad file format)"
- # No use proceeding from here.
- return;
- }
- -re ".*: No such file or directory.*$gdb_prompt $" {
- fail "re-load generated corefile (file not found)"
- # No use proceeding from here.
- return;
- }
- -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
- fail "re-load generated corefile (incomplete note section)"
- }
- -re "Core was generated by .*$gdb_prompt $" {
- pass "re-load generated corefile"
- }
- -re ".*$gdb_prompt $" {
- fail "re-load generated corefile"
- }
- timeout {
- fail "re-load generated corefile (timeout)"
- }
+set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
+if { $core_loaded == -1 } {
+ # No use proceeding from here.
+ return
}
for {set i 0} {$i < 32} {incr i 1} {
Index: gdb.base/gcore.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/gcore.exp,v
retrieving revision 1.25
diff -u -p -r1.25 gcore.exp
--- gdb.base/gcore.exp 14 Mar 2013 13:34:02 -0000 1.25
+++ gdb.base/gcore.exp 22 Apr 2013 20:58:53 -0000
@@ -85,8 +85,8 @@ set pre_corefile_local_array \
set pre_corefile_extern_array \
[capture_command_output "print extern_array" "$print_prefix"]
-set core_supported [gdb_gcore_cmd "${objdir}/${subdir}/gcore.test" \
- "save a corefile"]
+set corefile "${objdir}/${subdir}/gcore.test"
+set core_supported [gdb_gcore_cmd "$corefile" "save a corefile"]
if {!$core_supported} {
return -1
}
@@ -97,24 +97,10 @@ gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
-gdb_test_multiple "core ${objdir}/${subdir}/gcore.test" \
- "re-load generated corefile" {
- -re ".* is not a core dump:.*$gdb_prompt $" {
- fail "re-load generated corefile (bad file format)"
- # No use proceeding from here.
- return;
- }
- -re ".*: No such file or directory.*$gdb_prompt $" {
- fail "re-load generated corefile (file not found)"
- # No use proceeding from here.
- return;
- }
- -re ".*Couldn't find .* registers in core file.*$gdb_prompt $" {
- fail "re-load generated corefile (incomplete note section)"
- }
- -re "Core was generated by .*$gdb_prompt $" {
- pass "re-load generated corefile"
- }
+set core_loaded [gdb_core_cmd "$corefile" "re-load generated corefile"]
+if { $core_loaded == -1 } {
+ # No use proceeding from here.
+ return
}
gdb_test_sequence "where" "where in corefile" {
Index: gdb.threads/gcore-thread.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.threads/gcore-thread.exp,v
retrieving revision 1.29
diff -u -p -r1.29 gcore-thread.exp
--- gdb.threads/gcore-thread.exp 14 Mar 2013 13:34:05 -0000 1.29
+++ gdb.threads/gcore-thread.exp 22 Apr 2013 20:58:53 -0000
@@ -125,37 +125,10 @@ if {"$core0file" != ""} {
# Now restart gdb and load the corefile.
clean_restart ${testfile}
-proc load_core { corefile } {
- global gdb_prompt
- global libthread_db_seen
-
- gdb_test_multiple "core $corefile" \
- "re-load generated corefile" {
- -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
- exp_continue
- }
- -re " is not a core dump:.*\r\n$gdb_prompt $" {
- fail "re-load generated corefile (bad file format)"
- # No use proceeding from here.
- return 0
- }
- -re ": No such file or directory.*\r\n$gdb_prompt $" {
- fail "re-load generated corefile (file not found)"
- # No use proceeding from here.
- return 0
- }
- -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
- fail "re-load generated corefile (incomplete note section)"
- }
- -re "Core was generated by .*\r\n$gdb_prompt $" {
- pass "re-load generated corefile"
- }
- }
- return 1
-}
-
foreach name { corefile core0file } { with_test_prefix $name {
- if ![load_core [subst $$name]] {
+ set core_loaded [gdb_core_cmd [subst $$name] "re-load generated corefile"]
+ if { $core_loaded == -1 } {
+ # No use proceeding from here.
continue
}
Index: lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.230
diff -u -p -r1.230 gdb.exp
--- lib/gdb.exp 15 Apr 2013 20:37:37 -0000 1.230
+++ lib/gdb.exp 22 Apr 2013 21:04:45 -0000
@@ -3176,6 +3176,49 @@ proc gdb_gcore_cmd {core test} {
return $result
}
+# Load core file CORE. TEST is the name of the test case.
+# This will record a pass/fail for loading the core file.
+# Returns:
+# 1 - core file is successfully loaded
+# 0 - core file loaded but has a non fatal error
+# -1 - core file failed to load
+
+proc gdb_core_cmd { core test } {
+ global gdb_prompt
+
+ gdb_test_multiple "core $core" "re-load generated corefile" {
+ -re "\\\[Thread debugging using \[^ \r\n\]* enabled\\\]\r\n" {
+ exp_continue
+ }
+ -re " is not a core dump:.*\r\n$gdb_prompt $" {
+ fail "re-load generated corefile (bad file format)"
+ return -1
+ }
+ -re ": No such file or directory.*\r\n$gdb_prompt $" {
+ fail "re-load generated corefile (file not found)"
+ return -1
+ }
+ -re "Couldn't find .* registers in core file.*\r\n$gdb_prompt $" {
+ fail "re-load generated corefile (incomplete note section)"
+ return 0
+ }
+ -re "Core was generated by .*\r\n$gdb_prompt $" {
+ pass "re-load generated corefile"
+ return 1
+ }
+ -re ".*$gdb_prompt $" {
+ fail "re-load generated corefile"
+ return -1
+ }
+ timeout {
+ fail "re-load generated corefile (timeout)"
+ return -1
+ }
+ }
+ fail "unsupported output from 'core' command"
+ return -1
+}
+
# Return the filename to download to the target and load on the target
# for this shared library. Normally just LIBNAME, unless shared libraries
# for this target have separate link and load images.