This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 3/3] Add regression test for PR gdb/19858 (JIT code registration on attach)
- From: Pedro Alves <palves at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Yichao Yu <yyc1992 at gmail dot com>
- Date: Wed, 23 Mar 2016 13:29:52 +0000
- Subject: [PATCH 3/3] Add regression test for PR gdb/19858 (JIT code registration on attach)
- Authentication-results: sourceware.org; auth=none
- References: <1458739792-9864-1-git-send-email-palves at redhat dot com>
This test would fail without the previous gdb/jit.c fix:
(gdb) attach 23031
Attaching to program: .../build/gdb/testsuite/outputs/gdb.base/jit/jit-main, process 23031
[...]
207 WAIT_FOR_GDB; i = 0; /* gdb break here 1 */
(gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: attach
set var wait_for_gdb = 0
(gdb) PASS: gdb.base/jit.exp: attach: one_jit_test-2: set var wait_for_gdb = 0
info function ^jit_function
All functions matching regular expression "^jit_function":
(gdb) FAIL: gdb.base/jit.exp: attach: one_jit_test-2: info function ^jit_function
gdb/testsuite/ChangeLog:
2016-03-23 Pedro Alves <palves@redhat.com>
PR gdb/19858
* gdb.base/jit-main.c: Include unistd.h.
(ATTACH): Define to 0 if not already defined.
(wait_for_gdb, mypid): New globals.
(WAIT_FOR_GDB): New macro.
(MAIN): Set an alarm. Store the process's pid. Wait for GDB at
some breakpoint locations.
* gdb.base/jit.exp (clean_reattach, continue_to_test_location):
New procedures.
(one_jit_test): Add REATTACH parameter, and handle it. Use
continue_to_test_location.
(top level): Test attach, and adjusts calls to one_jit_test.
---
gdb/testsuite/gdb.base/jit-main.c | 21 ++++++++++--
gdb/testsuite/gdb.base/jit.exp | 69 ++++++++++++++++++++++++++++++++++-----
2 files changed, 80 insertions(+), 10 deletions(-)
diff --git a/gdb/testsuite/gdb.base/jit-main.c b/gdb/testsuite/gdb.base/jit-main.c
index 2f0707c..63dd1a1 100644
--- a/gdb/testsuite/gdb.base/jit-main.c
+++ b/gdb/testsuite/gdb.base/jit-main.c
@@ -27,6 +27,7 @@
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <unistd.h>
/* ElfW is coming from linux. On other platforms it does not exist.
Let us define it here. */
@@ -116,10 +117,22 @@ update_locations (const void *const addr, int idx)
}
}
+/* Defined by the .exp file if testing attach. */
+#ifndef ATTACH
+#define ATTACH 0
+#endif
+
#ifndef MAIN
#define MAIN main
#endif
+/* Used to spin waiting for GDB. */
+volatile int wait_for_gdb = ATTACH;
+#define WAIT_FOR_GDB while (wait_for_gdb)
+
+/* The current process's PID. GDB retrieves this. */
+int mypid;
+
int
MAIN (int argc, char *argv[])
{
@@ -127,6 +140,10 @@ MAIN (int argc, char *argv[])
const char *libname = NULL;
int count = 0;
+ alarm (300);
+
+ mypid = getpid ();
+
count = count; /* gdb break here 0 */
if (argc < 2)
@@ -190,7 +207,7 @@ MAIN (int argc, char *argv[])
__jit_debug_register_code ();
}
- i = 0; /* gdb break here 1 */
+ WAIT_FOR_GDB; i = 0; /* gdb break here 1 */
/* Now unregister them all in reverse order. */
while (__jit_debug_descriptor.relevant_entry != NULL)
@@ -215,5 +232,5 @@ MAIN (int argc, char *argv[])
free (entry);
}
}
- return 0; /* gdb break here 2 */
+ WAIT_FOR_GDB; return 0; /* gdb break here 2 */
}
diff --git a/gdb/testsuite/gdb.base/jit.exp b/gdb/testsuite/gdb.base/jit.exp
index 3e12301..d1cb41a 100644
--- a/gdb/testsuite/gdb.base/jit.exp
+++ b/gdb/testsuite/gdb.base/jit.exp
@@ -66,7 +66,47 @@ proc compile_jit_test {testname binsuffix options} {
return 0
}
-proc one_jit_test {count match_str} {
+# Detach, restart GDB, and re-attach to the program.
+
+proc clean_reattach {} {
+ global decimal gdb_prompt srcfile testfile
+
+ # Get PID of test program.
+ set testpid -1
+ set test "get inferior process ID"
+ gdb_test_multiple "p mypid" $test {
+ -re ".* = ($decimal).*$gdb_prompt $" {
+ set testpid $expect_out(1,string)
+ pass $test
+ }
+ }
+
+ gdb_test_no_output "set var wait_for_gdb = 1"
+ gdb_test "detach" ".*"
+
+ clean_restart $testfile
+
+ set test "attach"
+ gdb_test_multiple "attach $testpid" "$test" {
+ -re "Attaching to program.*.*main.*at .*$srcfile:.*$gdb_prompt $" {
+ pass "$test"
+ }
+ }
+
+ gdb_test_no_output "set var wait_for_gdb = 0"
+}
+
+# Continue to LOCATION in the program. If REATTACH, detach and
+# re-attach to the program from scratch.
+proc continue_to_test_location {location reattach} {
+ gdb_breakpoint [gdb_get_line_number $location]
+ gdb_continue_to_breakpoint $location
+ if {$reattach} {
+ clean_reattach
+ }
+}
+
+proc one_jit_test {count match_str reattach} {
with_test_prefix "one_jit_test-$count" {
global verbose testfile solib_binfile_target solib_binfile_test_msg
@@ -91,8 +131,7 @@ proc one_jit_test {count match_str} {
gdb_test_no_output "set var libname = \"$solib_binfile_target\"" "set var libname = \"$solib_binfile_test_msg\""
gdb_test_no_output "set var count = $count"
- gdb_breakpoint [gdb_get_line_number "break here 1"]
- gdb_continue_to_breakpoint "break here 1"
+ continue_to_test_location "break here 1" $reattach
gdb_test "info function ^jit_function" "$match_str"
@@ -102,8 +141,8 @@ proc one_jit_test {count match_str} {
gdb_test "maintenance info break"
}
- gdb_breakpoint [gdb_get_line_number "break here 2"]
- gdb_continue_to_breakpoint "break here 2"
+ continue_to_test_location "break here 2" $reattach
+
# All jit librares must have been unregistered
gdb_test "info function jit_function" \
"All functions matching regular expression \"jit_function\":"
@@ -113,8 +152,22 @@ proc one_jit_test {count match_str} {
if {[compile_jit_test jit.exp "" {}] < 0} {
return
}
-one_jit_test 1 "${hex} jit_function_0000"
-one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001"
+one_jit_test 1 "${hex} jit_function_0000" 0
+one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 0
+
+# Test attaching to an inferior with some JIT libraries already
+# registered. We reuse the normal test, and detach/reattach at
+# specific interesting points.
+if {[can_spawn_for_attach]} {
+ if {[compile_jit_test "jit.exp attach tests" \
+ "-attach" {additional_flags=-DATTACH=1}] < 0} {
+ return
+ }
+
+ with_test_prefix attach {
+ one_jit_test 2 "${hex} jit_function_0000\[\r\n\]+${hex} jit_function_0001" 1
+ }
+}
with_test_prefix PIE {
if {[compile_jit_test "jit.exp PIE tests" \
@@ -122,5 +175,5 @@ with_test_prefix PIE {
return
}
- one_jit_test 1 "${hex} jit_function_0000"
+ one_jit_test 1 "${hex} jit_function_0000" 0
}
--
2.5.5