Fix valgrind error from gdb.decode_line
authorTom Tromey <tom@tromey.com>
Sat, 21 Dec 2019 16:51:05 +0000 (09:51 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 15 Jan 2020 00:57:52 +0000 (17:57 -0700)
PR symtab/12535 points out that gdb.decode_line("") will cause a
valgrind report.

I think the empty linespec does not really make sense.  So, this patch
changes gdb.decode_line to treat a whitespace-only linespec the same
as a non-existing argument.

gdb/ChangeLog
2020-01-14  Tom Tromey  <tom@tromey.com>

PR symtab/12535:
* python/python.c (gdbpy_decode_line): Treat empty string the same
as no argument.

gdb/testsuite/ChangeLog
2020-01-14  Tom Tromey  <tom@tromey.com>

PR symtab/12535:
* gdb.python/python.exp: Test decode_line with empty string
argument.

Change-Id: I1d95812b4b7a21d69a3e9afd05b9e3141a931897

gdb/ChangeLog
gdb/python/python.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/python.exp

index 213f2d03956e10271c56a5336b7904796d957dcf..d348abbf585f53b618efa9d8ec068d85763559f3 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-14  Tom Tromey  <tom@tromey.com>
+
+       PR symtab/12535:
+       * python/python.c (gdbpy_decode_line): Treat empty string the same
+       as no argument.
+
 2020-01-14  Tom Tromey  <tom@tromey.com>
 
        * Makefile.in (CLIBS): Remove second use of $(LIBIBERTY).
index e0c05f1d0689ee1c4d47045e3bdc43d19083d6e3..d6f7f99c457300cba8e6dbe590ac15b4b2e2b110 100644 (file)
@@ -810,6 +810,15 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
   if (! PyArg_ParseTuple (args, "|s", &arg))
     return NULL;
 
+  /* Treat a string consisting of just whitespace the same as
+     NULL.  */
+  if (arg != NULL)
+    {
+      arg = skip_spaces (arg);
+      if (*arg == '\0')
+       arg = NULL;
+    }
+
   if (arg != NULL)
     location = string_to_event_location_basic (&arg, python_language,
                                               symbol_name_match_type::WILD);
index 4c1e6040d6738bd052fd0d5ab22d1c5a3fe6c25e..fd9ba7ea619bff6b49546bd4df9c0b60693613d2 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-14  Tom Tromey  <tom@tromey.com>
+
+       PR symtab/12535:
+       * gdb.python/python.exp: Test decode_line with empty string
+       argument.
+
 2020-01-14  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
        * gdb.base/skip-inline.exp: Extend test.
index f002497e9d0978f4ff3a3dc8449c60c70a166b86..a50a7b43e2c26c250f3ca914a236f6b712bdd990 100644 (file)
@@ -234,6 +234,10 @@ gdb_test "python print (len(symtab))" "2" "test decode_line current location"
 gdb_test "python print (symtab\[0\])" "None" "test decode_line expression parse"
 gdb_test "python print (len(symtab\[1\]))" "1" "test decode_line current location"
 
+# Test that decode_line with an empty string argument does not crash.
+gdb_py_test_silent_cmd "python symtab2 = gdb.decode_line('')" \
+    "test decode_line with empty string" 1
+
 if { [is_remote host] } {
     set python_c [string_to_regexp "python.c"]
 } else {
This page took 0.033621 seconds and 4 git commands to generate.