This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix -trace-save crash when argument is missing

-trace-save doesn't check whether an argument is passed, leading to a
segfault if you pass nothing.

I added a small test, which only tests the error conditions of


	* mi/mi-main.c (mi_cmd_trace_save): Check if argument is present
	before using it.


	* gdb.trace/mi-trace-save.exp: New file.
 gdb/mi/mi-main.c                          |  4 +++
 gdb/testsuite/gdb.trace/mi-trace-save.exp | 41 +++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100644 gdb/testsuite/gdb.trace/mi-trace-save.exp

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 7cd9706..479d3a4 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -2699,6 +2699,10 @@ mi_cmd_trace_save (char *command, char **argv, int argc)
+  if (oind >= argc)
+    error (_("Argument required (file in which to save trace data)"));
   filename = argv[oind];
   if (generate_ctf)
diff --git a/gdb/testsuite/gdb.trace/mi-trace-save.exp b/gdb/testsuite/gdb.trace/mi-trace-save.exp
new file mode 100644
index 0000000..52ad9f1
--- /dev/null
+++ b/gdb/testsuite/gdb.trace/mi-trace-save.exp
@@ -0,0 +1,41 @@
+# Copyright 2016 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
+# 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 <>.
+# The -trace-save command is already tested in other files (e.g.
+# mi-trace-frame-collected.exp), so this file currently only tests the error
+# cases of -trace-save.
+load_lib mi-support.exp
+# Test without the required "filename" argument.
+proc test_trace_save_missing_arg { } {
+    set err_re [string_to_regexp "^error,msg=\"Argument required (file in which to save trace data)\""]
+    mi_gdb_test "-trace-save" "$err_re" "-trace-save with missing argument"
+# Test with an unrecognized option.
+proc test_trace_save_wrong_opt { } {
+    set err_re [string_to_regexp "^error,msg=\"-trace-save: Unknown option ``hey''\""]
+    mi_gdb_test "-trace-save -hey" "$err_re" "-trace-save with wrong option"

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]