2013-04-10 Pedro Alves <palves@redhat.com>
authorHui Zhu <teawater@gmail.com>
Wed, 10 Apr 2013 04:35:21 +0000 (04:35 +0000)
committerHui Zhu <teawater@gmail.com>
Wed, 10 Apr 2013 04:35:21 +0000 (04:35 +0000)
    Hui Zhu  <hui@codesourcery.com>

* breakpoint.c (dprintf_re_set): New.
(initialize_breakpoint_ops): Set dprintf_breakpoint_ops re_set
to dprintf_re_set.

2013-04-10  Hui Zhu  <hui@codesourcery.com>

* gdb.base/Makefile.in (EXECUTABLES): Add dprintf-pending.
(MISCELLANEOUS): Add dprintf-pendshr.sl.
* gdb.base/dprintf-pending.c, gdb.base/dprintf-pending.exp: New.

gdb/ChangeLog
gdb/breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/Makefile.in
gdb/testsuite/gdb.base/dprintf-pending.c [new file with mode: 0644]
gdb/testsuite/gdb.base/dprintf-pending.exp [new file with mode: 0644]
gdb/testsuite/gdb.base/dprintf-pendshr.c [new file with mode: 0644]

index c38f8f7..75a0306 100644 (file)
@@ -1,3 +1,10 @@
+2013-04-10  Pedro Alves  <palves@redhat.com>
+           Hui Zhu  <hui@codesourcery.com>
+
+       * breakpoint.c (dprintf_re_set): New.
+       (initialize_breakpoint_ops): Set dprintf_breakpoint_ops re_set
+       to dprintf_re_set.
+
 2013-04-09  Joel Brobecker  <brobecker@adacore.com>
 
        * configure.tgt (gdb_target_obs) <powerpc-*-aix* | rs6000-*-*>:
index 09933f4..f374368 100644 (file)
@@ -13512,6 +13512,35 @@ tracepoint_probe_decode_linespec (struct breakpoint *b, char **s,
 
 static struct breakpoint_ops tracepoint_probe_breakpoint_ops;
 
+/* Dprintf breakpoint_ops methods.  */
+
+static void
+dprintf_re_set (struct breakpoint *b)
+{
+  breakpoint_re_set_default (b);
+
+  /* This breakpoint could have been pending, and be resolved now, and
+     if so, we should now have the extra string.  If we don't, the
+     dprintf was malformed when created, but we couldn't tell because
+     we can't extract the extra string until the location is
+     resolved.  */
+  if (b->loc != NULL && b->extra_string == NULL)
+    error (_("Format string required"));
+
+  /* 1 - connect to target 1, that can run breakpoint commands.
+     2 - create a dprintf, which resolves fine.
+     3 - disconnect from target 1
+     4 - connect to target 2, that can NOT run breakpoint commands.
+
+     After steps #3/#4, you'll want the dprintf command list to
+     be updated, because target 1 and 2 may well return different
+     answers for target_can_run_breakpoint_commands().
+     Given absence of finer grained resetting, we get to do
+     it all the time.  */
+  if (b->extra_string != NULL)
+    update_dprintf_command_list (b);
+}
+
 /* The breakpoint_ops structure to be used on static tracepoints with
    markers (`-m').  */
 
@@ -16011,7 +16040,7 @@ initialize_breakpoint_ops (void)
 
   ops = &dprintf_breakpoint_ops;
   *ops = bkpt_base_breakpoint_ops;
-  ops->re_set = bkpt_re_set;
+  ops->re_set = dprintf_re_set;
   ops->resources_needed = bkpt_resources_needed;
   ops->print_it = bkpt_print_it;
   ops->print_mention = bkpt_print_mention;
index 58d692e..8c801a2 100644 (file)
@@ -1,3 +1,9 @@
+2013-04-10  Hui Zhu  <hui@codesourcery.com>
+
+       * gdb.base/Makefile.in (EXECUTABLES): Add dprintf-pending.
+       (MISCELLANEOUS): Add dprintf-pendshr.sl.
+       * gdb.base/dprintf-pending.c, gdb.base/dprintf-pending.exp: New.
+
 2013-04-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
        * gdb.server/server-kill.exp (tstatus): Permit also ECONNRESET
index ca4c9a0..828ec26 100644 (file)
@@ -10,7 +10,8 @@ EXECUTABLES = a2-run advance all-types annota1 annota1-watch_thread_num \
        call-strs callexit callfuncs callfwmall charset checkpoint \
        chng-syms code_elim1 code_elim2 commands compiler complex \
        condbreak consecutive constvars coremaker cursal cvexpr \
-       dbx-test del disasm-end-cu display dump dup-sect dup-sect.debug \
+       dbx-test del disasm-end-cu display dprintf-pending dump dup-sect \
+       dup-sect.debug \
        dup-sect.stripped ending-run execd-prog expand-psymtabs exprs \
        fileio find finish fixsection float foll-exec foll-fork foll-vfork \
        frame-args freebpcmd fullname funcargs gcore \
@@ -44,7 +45,7 @@ EXECUTABLES = a2-run advance all-types annota1 annota1-watch_thread_num \
        wchar whatis whatis-exp catch-syscall \
        pr10179 gnu_vector
 
-MISCELLANEOUS = coremmap.data ../foobar.baz fixsectshr.sl \
+MISCELLANEOUS = coremmap.data dprintf-pendshr.sl ../foobar.baz fixsectshr.sl \
        pendshr.sl shreloc1.sl shreloc2.sl twice-tmp.c \
        shr1.sl shr2.sl solib_sl.sl solib1.sl solib2.sl \
        unloadshr.sl unloadshr2.sl watchpoint-solib-shr.sl \
diff --git a/gdb/testsuite/gdb.base/dprintf-pending.c b/gdb/testsuite/gdb.base/dprintf-pending.c
new file mode 100644 (file)
index 0000000..954bdf2
--- /dev/null
@@ -0,0 +1,29 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int k = 0;
+
+extern void pendfunc (int x);
+
+int main()
+{
+  pendfunc (3); /* break main here */
+  pendfunc (4);
+  k = 1;
+  pendfunc (3);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/dprintf-pending.exp b/gdb/testsuite/gdb.base/dprintf-pending.exp
new file mode 100644 (file)
index 0000000..87abfce
--- /dev/null
@@ -0,0 +1,100 @@
+#   Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+standard_testfile
+set libfile "dprintf-pendshr"
+set libsrc  $srcdir/$subdir/$libfile.c
+set lib_sl [standard_output_file $libfile.sl]
+
+set lib_opts  debug
+set exec_opts [list debug shlib=$lib_sl]
+
+if { [get_compiler_info] } {
+    return -1
+}
+
+if { [gdb_compile_shlib $libsrc $lib_sl $lib_opts] != ""
+     || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != ""} {
+    untested "Could not compile either $libsrc or $srcdir/$subdir/$srcfile."
+    return -1
+}
+
+with_test_prefix "without format" {
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+
+    gdb_test \
+       "dprintf pendfunc" \
+       "Dprintf.*pendfunc.*pending." \
+       "set pending dprintf" \
+       ".*Make dprintf pending.*y or \\\[n\\\]. $" \
+       "y"
+
+    gdb_test "file ${binfile}" ".*Error in re-setting breakpoint.*" "resolved dprintf fails to be re-set"
+}
+
+with_test_prefix "without symbols" {
+    gdb_exit
+    gdb_start
+    gdb_reinitialize_dir $srcdir/$subdir
+
+    gdb_test \
+       "dprintf pendfunc1, \"x=%d\\n\", x" \
+       "Dprintf.*pendfunc1.*pending." \
+       "set pending dprintf" \
+       ".*Make dprintf pending.*y or \\\[n\\\]. $" \
+       "y"
+
+    gdb_test "info break" \
+        "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
+\[0-9\]+\[\t \]+dprintf.*keep y.*PENDING.*pendfunc1.*" \
+       "single pending dprintf info"
+
+    gdb_load ${binfile}
+    gdb_load_shlibs $lib_sl
+
+    gdb_run_cmd
+
+    gdb_test "" ".*x=3.*x=4.*x=3.*" "run to resolved dprintf"
+}
+
+clean_restart ${binfile}
+gdb_load_shlibs $lib_sl
+
+#
+# Test setting, querying, and modifying pending breakpoints
+#
+
+gdb_test \
+    "dprintf pendfunc1, \"x=%d\\n\", x" \
+    "Dprintf.*pendfunc1.*pending." \
+    "set pending dprintf" \
+    ".*Make dprintf pending.*y or \\\[n\\\]. $" \
+    "y"
+
+gdb_test "info break" \
+    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
+\[0-9\]+\[\t \]+dprintf.*keep y.*PENDING.*pendfunc1.*" \
+"single pending dprintf info"
+
+gdb_run_cmd
+
+gdb_test "" ".*x=3.*x=4.*x=3.*" "run to resolved dprintf"
diff --git a/gdb/testsuite/gdb.base/dprintf-pendshr.c b/gdb/testsuite/gdb.base/dprintf-pendshr.c
new file mode 100644 (file)
index 0000000..88c013b
--- /dev/null
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2013 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+void pendfunc1 (int x)
+{
+  int y = x + 4;
+}
+
+void pendfunc (int x)
+{
+  pendfunc1 (x);
+}