This is the mail archive of the gdb-cvs@sourceware.org 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]

[binutils-gdb] PR gdb/21164: maint print {symbols, msymbols, psymbols} without args crash


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=99e8a4f9f8832da0f37c6f35b11629b01897800d

commit 99e8a4f9f8832da0f37c6f35b11629b01897800d
Author: Sergio Durigan Junior <sergiodj@redhat.com>
Date:   Wed Feb 15 15:08:19 2017 -0500

    PR gdb/21164: maint print {symbols,msymbols,psymbols} without args crash
    
    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.

Diff:
---
 gdb/ChangeLog                    | 8 ++++++++
 gdb/psymtab.c                    | 4 ++--
 gdb/symmisc.c                    | 8 ++++----
 gdb/testsuite/ChangeLog          | 6 ++++++
 gdb/testsuite/gdb.base/maint.exp | 7 +++++++
 5 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index c979d8c..4727433 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 1fad8a0..6e42bc5 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -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;
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 07d571a..ab50570 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -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;
 
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 0a4f81e..45e3807 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -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.
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 2853508..782a21c 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -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


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