aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
authorStan Shebs <shebs@codesourcery.com>2012-05-14 15:38:41 +0000
committerStan Shebs <shebs@codesourcery.com>2012-05-14 15:38:41 +0000
commite7e0cddfb0d4c4823cc7ed48c727e12f0e11a600 (patch)
tree3826eb4389246147dbdd6509abc94cb47f1b9e6c /gdb/testsuite
parent27d799802ad136a2b59220c1822c4a6e592d830b (diff)
downloadgdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.zip
gdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.tar.gz
gdb-e7e0cddfb0d4c4823cc7ed48c727e12f0e11a600.tar.bz2
2012-05-14 Stan Shebs <stan@codesourcery.com>
Add dynamic printf. * breakpoint.h (enum bptype): New type bp_dprintf. (struct breakpoint): New field extra_string. (struct breakpoint_ops): Add arg to create_breakpoints_sal. (create_breakpoint): Add extra_string arg. * breakpoint.c (dprintf_breakpoint_ops): New. (is_breakpoint): Add bp_dprintf. (bpstat_what): Add dprintf case. (bptype_string): Ditto. (print_one_breakpoint_location): Ditto. (init_bp_location): Ditto. (bkpt_print_mention): Ditto. (dprintf_style_enums): New array. (dprintf_style): New global. (dprintf_function): New global. (dprintf_channel): New global. (update_dprintf_command_list): New function. (update_dprintf_commands): New function. (init_breakpoint_sal): Add extra_string argument, handle it. (create_breakpoint_sal): Add extra_string argument. (create_breakpoints_sal): Add extra_string argument, update callers. (find_condition_and_thread): Add extra argument. (create_breakpoint): Add extra_string argument, record it. (dprintf_command): New function. (break_command_1): Add arg to create_breakpoint call. (handle_gnu_v3_exceptions): Ditto. (trace_command): Ditto. (ftrace_command): Ditto. (strace_command): Ditto. (bkpt_print_mention): Add dprintf case. (create_breakpoint_sal_default): Add extra_string argument. (_initialize_breakpoint): Add new commands. * mi/mi-cmd-break.c (mi_cmd_break_insert): Add arg to call. * python/py-breakpoint.c (bppy_init): Ditto. * python/py-finishbreakpoint.c (bpfinishpy_init): Ditto. * gdb.texinfo (Dynamic Printf): New subsection. * gdb.base/dprintf.c: New file. * gdb.base/dprintf.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/dprintf.c44
-rw-r--r--gdb/testsuite/gdb.base/dprintf.exp89
3 files changed, 138 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 00bd6c8..fa10a4d 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2012-05-14 Stan Shebs <stan@codesourcery.com>
+
+ * gdb.base/dprintf.c: New file.
+ * gdb.base/dprintf.exp: New file.
+
2012-05-14 Hui Zhu <hui_zhu@mentor.com>
* gdb.trace/Makefile.in (PROGS): Add disconnected-tracing.
diff --git a/gdb/testsuite/gdb.base/dprintf.c b/gdb/testsuite/gdb.base/dprintf.c
new file mode 100644
index 0000000..283ff58
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dprintf.c
@@ -0,0 +1,44 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright (C) 2012 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>
+
+static int g;
+
+void
+foo (int arg)
+{
+ g += arg;
+ g *= 2; /* set dprintf 1 here */
+ g /= 2.5; /* set breakpoint 1 here */
+}
+
+int
+main (int argc, char *argv[])
+{
+ int loc = 1234;
+
+ /* Ensure these functions are available. */
+ printf ("kickoff\n");
+ fprintf (stderr, "also to stderr\n");
+
+ foo (loc++);
+ foo (loc++);
+ foo (loc++);
+ return g;
+}
+
diff --git a/gdb/testsuite/gdb.base/dprintf.exp b/gdb/testsuite/gdb.base/dprintf.exp
new file mode 100644
index 0000000..76f5fc5
--- /dev/null
+++ b/gdb/testsuite/gdb.base/dprintf.exp
@@ -0,0 +1,89 @@
+# Copyright (C) 2012 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 { [prepare_for_testing dprintf.exp "dprintf" {} {debug}] } {
+ return -1
+}
+
+set srcfile dprintf.c
+
+set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
+set dp_location1 [gdb_get_line_number "set dprintf 1 here"]
+
+gdb_breakpoint "main"
+gdb_run_cmd
+
+gdb_test "dprintf" "Format string required"
+
+gdb_test "dprintf foo" "Format string required"
+
+gdb_test "dprintf 29" "Format string required"
+
+delete_breakpoints
+
+gdb_breakpoint "main"
+
+gdb_test "dprintf foo,\"At foo entry\\n\"" \
+ "Dprintf .*"
+
+gdb_test "dprintf $dp_location1,\"arg=%d, g=%d\\n\", arg, g" \
+ "Dprintf .*"
+
+gdb_test "break $bp_location1" \
+ "Breakpoint .*"
+
+gdb_run_cmd
+
+gdb_test "" "Breakpoint"
+
+gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" "1st dprintf, gdb"
+
+gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, gdb"
+
+# The "call" style depends on having I/O functions available, so test.
+
+if ![target_info exists gdb,noinferiorio] {
+
+ # Now switch styles and rerun; in the absence of redirection the
+ # output should be the same.
+
+ gdb_test_no_output "set dprintf-style call" "Set dprintf style to call"
+
+ gdb_run_cmd
+
+ gdb_test "" "Breakpoint"
+
+ gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" "1st dprintf, call"
+
+ gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" "2nd dprintf, call"
+
+ gdb_test_no_output "set dprintf-function fprintf" "Set dprintf function"
+ gdb_test_no_output "set dprintf-channel stderr" "Set dprintf channel"
+
+ gdb_run_cmd
+
+ gdb_test "" "Breakpoint"
+
+ gdb_test "continue" "At foo entry.*arg=1234, g=1234.*" \
+ "1st dprintf, fprintf"
+
+ gdb_test "continue" "At foo entry.*arg=1235, g=2222.*" \
+ "2nd dprintf, fprintf"
+}
+
+gdb_test "set dprintf-style foobar" "Undefined item: \"foobar\"." \
+ "Set dprintf style to an unrecognized type"
+