Fix add-symbol-file usage and errors
authorTom Tromey <tom@tromey.com>
Sun, 6 Aug 2017 17:07:28 +0000 (11:07 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 29 Nov 2017 16:21:43 +0000 (09:21 -0700)
This patch updates add-symbol-file help and error text.

It changes add-symbol-file to throw an exception if "-s" is seen but
not all of the arguments are given.  Previously this was silently
ignored.

It changes the unrecognized argument message to more clearly state
what went wrong.

Finally, it updates the usage line in the help text to follow GNU
style regarding "metasyntactic variables"; a change I believe should
be made to all gdb help messages.

gdb/ChangeLog
2017-11-29  Tom Tromey  <tom@tromey.com>

* symfile.c (add_symbol_file_command): Error if some arguments to
-s are missing.  Change unrecognized-argument error message.
(_initialize_symfile): Fix usage text for add-symbol-file.

gdb/testsuite/ChangeLog
2017-11-29  Tom Tromey  <tom@tromey.com>

* gdb.base/relocate.exp: Update invalid argument test.
Add new tests for invalid arguments.

gdb/ChangeLog
gdb/symfile.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/relocate.exp

index ebb969998c4221e79999262c45f2fbc04ddffffd..f3a2175dc924acdcea9216d2286e93f03071a513 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-29  Tom Tromey  <tom@tromey.com>
+
+       * symfile.c (add_symbol_file_command): Error if some arguments to
+       -s are missing.  Change unrecognized-argument error message.
+       (_initialize_symfile): Fix usage text for add-symbol-file.
+
 2017-11-27  Tom Tromey  <tom@tromey.com>
 
        * Makefile.in (REMOTE_OBS): Remove.
index feb50f8b79df889750e1dacd73592a35536cb202..c19cdd20eb5808f9dc7ee421524112ad9bcef290 100644 (file)
@@ -2244,8 +2244,7 @@ add_symbol_file_command (const char *args, int from_tty)
              expecting_sec_addr = 1;
            }
          else
-           error (_("USAGE: add-symbol-file <filename> <textaddress>"
-                    " [-readnow] [-s <secname> <addr>]*"));
+           error (_("Unrecognized argument \"%s\""), arg);
        }
     }
 
@@ -2257,6 +2256,11 @@ add_symbol_file_command (const char *args, int from_tty)
     error (_("The address where %s has been loaded is missing"),
           filename.get ());
 
+  if (expecting_sec_name)
+    error (_("Missing section name after \"-s\""));
+  else if (expecting_sec_addr)
+    error (_("Missing section address after \"-s\""));
+
   /* Print the prompt for the query below.  And save the arguments into
      a sect_addr_info structure to be passed around to other
      functions.  We have to split this up into separate print
@@ -3882,11 +3886,11 @@ to execute."), &cmdlist);
 
   c = add_cmd ("add-symbol-file", class_files, add_symbol_file_command, _("\
 Load symbols from FILE, assuming FILE has been dynamically loaded.\n\
-Usage: add-symbol-file FILE ADDR [-s <SECT> <SECT_ADDR> -s <SECT> <SECT_ADDR>\
- ...]\nADDR is the starting address of the file's text.\n\
-The optional arguments are section-name section-address pairs and\n\
+Usage: add-symbol-file FILE ADDR [-readnow | -s SECT-NAME SECT-ADDR]...\n\
+ADDR is the starting address of the file's text.\n\
+Each '-s' argument provides a section name and address, and\n\
 should be specified if the data and bss segments are not contiguous\n\
-with the text.  SECT is a section name to be loaded at SECT_ADDR."),
+with the text.  SECT-NAME is a section name to be loaded at SECT-ADDR."),
               &cmdlist);
   set_cmd_completer (c, filename_completer);
 
index 87b917e0c55430a1490943b330b435804e132820..4fba24bedc8258bb0c776c9f3c785277e193f98b 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-29  Tom Tromey  <tom@tromey.com>
+
+       * gdb.base/relocate.exp: Update invalid argument test.
+       Add new tests for invalid arguments.
+
 2017-11-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * gdb.cp/psymtab-parameter.cc (func): Change return type back to long.
index 5639cc88473f04d9d4023208112de12ac72308d4..6eef15fb20e3aa2c43dc6b3e5662053dc2ae9508 100644 (file)
@@ -31,11 +31,19 @@ gdb_reinitialize_dir $srcdir/$subdir
 
 #Check that invalid options are rejected.
 foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
+    set word [lindex $x [expr [llength $x]-1]]
     gdb_test "add-symbol-file ${binfile} 0 $x" \
-       "USAGE: add-symbol-file <filename> <textaddress>.*-readnow.*-s <secname> <addr>.*" \
-       "add-symbol-file: unknown option $x"
+       "Unrecognized argument \"$word\"" \
+       "add-symbol-file: unknown option $word"
 }
 
+gdb_test "add-symbol-file ${binfile} 0 -s" \
+    "Missing section name after .-s." \
+    "add-symbol-file bare -s"
+gdb_test "add-symbol-file ${binfile} 0 -s .whatever" \
+    "Missing section address after .-s." \
+    "add-symbol-file missing address"
+
 # Load the object file.
 gdb_test "add-symbol-file ${binfile} 0" \
        "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
This page took 0.045105 seconds and 4 git commands to generate.