Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Hui Zhu <teawater@gmail.com>
To: Keith Seitz <keiths@redhat.com>
Cc: Hui Zhu <hui_zhu@mentor.com>,
	gdb-patches ml <gdb-patches@sourceware.org>
Subject: Re: [PATCH] Fix dprintf work not right if it is pending
Date: Thu, 04 Apr 2013 18:42:00 -0000	[thread overview]
Message-ID: <CANFwon2F1-2b4y+WkcCzhxKU4C0+nCi7D8LzaM9R9rcHxoeUuw@mail.gmail.com> (raw)
In-Reply-To: <515B1DF7.3090705@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 1323 bytes --]

On Wed, Apr 3, 2013 at 2:05 AM, Keith Seitz <keiths@redhat.com> wrote:
> On 03/29/2013 12:42 AM, Hui Zhu wrote:
>
>>>> +  breakpoint_re_set_default (b);
>>>> +
>>>> +  if (b->extra_string != NULL)
>>>> +    update_dprintf_command_list (b);
>>>> +}
>>>> +
>>>
>>>
>>>
>>> This will update the command list every time breakpoints are reset and
>>> could
>>> be limited to only those needing updating. Is there perhaps a reason to
>>> always do this?
>>
>>
>> I think it need, because it need to generate different commands with
>> different status for example:
>>        if (target_can_run_breakpoint_commands ())
>>         printf_line = xstrprintf ("agent-printf %s", dprintf_args);
>>
>
> I'm not understanding this example. How is this likely to change whenever
> breakpoints are reset? Is there perhaps a way to add a test to demonstrate
> this requirement?

If the target that GDB connect to is changed  (for example, we set
dprintf and used it with local host target.  Then we changed to use a
remote target), GDB need set different commands of dprintfs.
The code that I post is from function update_dprintf_command_list.

I updated dprintf-pending.exp for this test.

>
> Otherwise, this patch looks good to me, and recommend that a maintainer give
> this a final review.
>

Thanks for your help.

> Keith

Best,
Hui

[-- Attachment #2: dprintf-pending.txt --]
[-- Type: text/plain, Size: 735 bytes --]

--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -12963,6 +12963,17 @@ bkpt_re_set (struct breakpoint *b)
   breakpoint_re_set_default (b);
 }
 
+/* Dprintf breakpoint_ops methods.  */
+
+static void
+dprintf_re_set (struct breakpoint *b)
+{
+  breakpoint_re_set_default (b);
+
+  if (b->extra_string != NULL)
+    update_dprintf_command_list (b);
+}
+
 static int
 bkpt_insert_location (struct bp_location *bl)
 {
@@ -16001,7 +16012,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;

[-- Attachment #3: dprintf-pending-test.txt --]
[-- Type: text/plain, Size: 6130 bytes --]

--- a/gdb/testsuite/gdb.base/Makefile.in
+++ b/gdb/testsuite/gdb.base/Makefile.in
@@ -10,7 +10,8 @@ EXECUTABLES = a2-run advance all-types a
 	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 a
 	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 \
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dprintf-pending.c
@@ -0,0 +1,31 @@
+/* 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/>.  */
+
+#include <stdio.h>
+
+int k = 0;
+
+extern void pendfunc (int x);
+
+int main()
+{
+  pendfunc (3); /* break main here */
+  pendfunc (4);
+  k = 1;
+  pendfunc (3);
+  return 0;
+}
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dprintf-pending.exp
@@ -0,0 +1,104 @@
+#   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/>.
+
+load_lib gdbserver-support.exp
+
+if {[skip_shlib_tests]} {
+    return 0
+}
+
+set testfile "dprintf-pending"
+set libfile "dprintf-pendshr"
+set srcfile $testfile.c
+set libsrc  $srcdir/$subdir/$libfile.c
+set binfile $objdir/$subdir/$testfile
+set lib_sl  $objdir/$subdir/$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
+}
+
+# Start with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test_multiple "dprintf pendfunc1, \"x=%d\\n\", x" "set pending dprintf" {
+     -re ".*Make dprintf pending.*y or \\\[n\\\]. $" {
+	    gdb_test "y" "Dprintf.*pendfunc1.*pending." "set pending dprintf (without symbols)"
+     }
+}
+
+gdb_test "info break" \
+    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
+\[0-9\]+\[\t \]+dprintf.*keep y.*PENDING.*pendfunc1.*" \
+"single pending dprintf info (without symbols)"
+
+gdb_load ${binfile}
+gdb_load_shlibs $lib_sl
+
+gdb_run_cmd
+
+gdb_test "" ".*x=3.*x=4.*x=3.*" "run to resolved dprintf (without symbols)"
+
+# Restart with a fresh gdb.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_load ${binfile}
+gdb_load_shlibs $lib_sl
+
+#
+# Test setting, querying, and modifying pending breakpoints
+#
+
+gdb_test_multiple "dprintf pendfunc1, \"x=%d\\n\", x" "set pending dprintf" {
+     -re ".*Make dprintf pending.*y or \\\[n\\\]. $" {
+	    gdb_test "y" "Dprintf.*pendfunc1.*pending." "set pending dprintf"
+     }
+}
+
+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"
+
+if { [skip_gdbserver_tests] } {
+    return 0
+}
+
+# Get warning or no output is OK.
+gdb_test "set dprintf-style agent" ".*" "Set dprintf style to agent"
+
+gdbserver_run ""
+
+gdb_test "info break" ".*agent-printf \"x=%d\\\\n\", x" \
+"single pending dprintf info with agent-printf"
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dprintf-pendshr.c
@@ -0,0 +1,28 @@
+/* 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/>.  */
+
+#include <stdio.h>
+
+void pendfunc1 (int x)
+{
+  int y = x + 4;
+}
+
+void pendfunc (int x)
+{
+  pendfunc1 (x);
+}

  reply	other threads:[~2013-04-04 13:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-22  7:39 Hui Zhu
2013-03-22 12:40 ` Yao Qi
2013-03-25  1:00   ` Keith Seitz
2013-03-25  2:14     ` Yao Qi
2013-03-26 14:55     ` Hui Zhu
2013-03-28 17:07       ` Keith Seitz
2013-03-29 15:50         ` Hui Zhu
2013-04-03  3:34           ` Keith Seitz
2013-04-04 18:42             ` Hui Zhu [this message]
2013-04-05 18:30             ` Pedro Alves
2013-04-08  7:20               ` Keith Seitz
2013-04-08 17:57                 ` Pedro Alves
2013-04-08  9:34               ` Hui Zhu
2013-04-08 14:35                 ` Hui Zhu
2013-04-08 18:34                   ` Pedro Alves
2013-04-09 15:28                     ` Hui Zhu
2013-04-09 15:28                       ` Pedro Alves
2013-04-10 15:57                         ` Hui Zhu
2013-04-10 16:12                           ` Hui Zhu
2013-04-11  5:46                             ` Joel Brobecker
2013-04-11 17:03                               ` Pedro Alves
2013-04-12 12:21                                 ` Hui Zhu
2013-03-25  8:25   ` Hui Zhu
2013-03-25  8:28     ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANFwon2F1-2b4y+WkcCzhxKU4C0+nCi7D8LzaM9R9rcHxoeUuw@mail.gmail.com \
    --to=teawater@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hui_zhu@mentor.com \
    --cc=keiths@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox