PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
authorSergio Durigan Junior <sergiodj@redhat.com>
Wed, 15 Feb 2017 20:08:19 +0000 (15:08 -0500)
committerSergio Durigan Junior <sergiodj@redhat.com>
Thu, 16 Feb 2017 00:54:10 +0000 (19:54 -0500)
This is a fix for PR gdb/21164.  The problem started to happen after:

 commit 34c41c681f4a0a0dfe0405c7d2aecf458520557a
 Author:     Doug Evans <xdje42@gmail.com>
 AuthorDate: Mon Dec 19 08:33:46 2016 -0800

    New syntax for mt print symbols,msymbols,psymbols.

This change introduced new syntax for the mentioned commands, and
improved the parsing of arguments by using 'gdb_buildargv'.  However,
it is necessary to check if the argv being built is not NULL, which
can happen if the user doesn't provide any arguments to these
commands.

gdb/ChangeLog:
2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21164
* psymtab.c (maintenance_print_psymbols): Verify if 'argv' is not
NULL before using it.
* symmisc.c (maintenance_print_symbols): Likewise.
(maintenance_print_msymbols): Likewise.

gdb/testsuite/ChangeLog:

gdb/ChangeLog:
2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>

PR gdb/21164
* gdb.base/maint.exp: Add testcases for when the commands do
not have arguments.

gdb/ChangeLog
gdb/psymtab.c
gdb/symmisc.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/maint.exp

index c979d8c78056b68efe896ceb253204e6298579ff..4727433d048582370641ac77e4c685b373c12791 100644 (file)
@@ -1,3 +1,11 @@
+2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR gdb/21164
+       * psymtab.c (maintenance_print_psymbols): Verify if 'argv' is not
+       NULL before using it.
+       * symmisc.c (maintenance_print_symbols): Likewise.
+       (maintenance_print_msymbols): Likewise.
+
 2017-02-14  Tim Wiederhake  <tim.wiederhake@intel.com>
 
        * NEWS: Add record Python bindings entry.
index 1fad8a0750b0abe093d2442c5b8db168b5d83bce..6e42bc5ad58d6f15b8e72fc2b16096deb2e5612b 100644 (file)
@@ -1926,7 +1926,7 @@ maintenance_print_psymbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-pc") == 0)
        {
@@ -1967,7 +1967,7 @@ maintenance_print_psymbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;
 
index 07d571acc40ca0bbadddc9aee71220dcaa09add3..ab50570b9610ca52952ed535ae03b7ad7d683208 100644 (file)
@@ -418,7 +418,7 @@ maintenance_print_symbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-pc") == 0)
        {
@@ -459,7 +459,7 @@ maintenance_print_symbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;
 
@@ -721,7 +721,7 @@ maintenance_print_msymbols (char *args, int from_tty)
   argv = gdb_buildargv (args);
   cleanups = make_cleanup_freeargv (argv);
 
-  for (i = 0; argv[i] != NULL; ++i)
+  for (i = 0; argv != NULL && argv[i] != NULL; ++i)
     {
       if (strcmp (argv[i], "-objfile") == 0)
        {
@@ -747,7 +747,7 @@ maintenance_print_msymbols (char *args, int from_tty)
 
   stdio_file arg_outfile;
 
-  if (argv[outfile_idx] != NULL)
+  if (argv != NULL && argv[outfile_idx] != NULL)
     {
       char *outfile_name;
 
index 0a4f81e60ef6c158a3059c2d009042548038594f..45e38071ba7f37d25266133bb7eba20f0af38434 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-15  Sergio Durigan Junior  <sergiodj@redhat.com>
+
+       PR gdb/21164
+       * gdb.base/maint.exp: Add testcases for when the commands do
+       not have arguments.
+
 2017-02-15  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * gdb.cp/chained-calls.exp: Use p instead of P.
index 2853508d9f6dba55b05ef54cf4f159840e094235..782a21c6949c3fe609bb282981f520e96ed44bc2 100644 (file)
@@ -561,6 +561,13 @@ gdb_expect {
 
 #set timeout $oldtimeout
 
+# Test that the commands work without an argument.  For this test, we
+# don't need an inferior loaded/running.  See PR gdb/21164.
+gdb_exit
+gdb_start
+gdb_test_no_output "maint print symbols"
+gdb_test_no_output "maint print msymbols"
+gdb_test_no_output "maint print psymbols"
 
 gdb_exit
 return 0
This page took 0.038979 seconds and 4 git commands to generate.