aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRudnicki, Piotr <piotr.rudnicki@intel.com>2025-02-12 10:50:37 +0100
committerTom Tromey <tromey@adacore.com>2025-02-24 07:12:04 -0700
commita4f974e939e350cdc34089bd59508296abcb4211 (patch)
tree5ba9b1a7e853cf2963af91ba2caeed01eb864729
parentc619e92beb0784775552abe64d9a886a8cdc7236 (diff)
downloadbinutils-a4f974e939e350cdc34089bd59508296abcb4211.zip
binutils-a4f974e939e350cdc34089bd59508296abcb4211.tar.gz
binutils-a4f974e939e350cdc34089bd59508296abcb4211.tar.bz2
gdb, testsuite, rust: fix for empty array
For the Rust language, to avoid segmentation fault in case of an empty array, do not try to copy any elements, but allocate and return the empty array immediately. With the command before the change, gdb crashes with message: (gdb) set lang rust (gdb) p [1;0] Fatal signal: Segmentation fault After the fix in this commit, gdb shows following message: (gdb) set lang rust (gdb) p [1;0] $1 = [] Update the existing test case gdb.rust/expr.exp to verify the change. Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r--gdb/rust-lang.c2
-rw-r--r--gdb/testsuite/gdb.rust/expr.exp4
2 files changed, 5 insertions, 1 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d4cd880..8bec934 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1455,7 +1455,7 @@ eval_op_rust_array (struct type *expect_type, struct expression *exp,
if (copies < 0)
error (_("Array with negative number of elements"));
- if (noside == EVAL_NORMAL)
+ if (noside == EVAL_NORMAL && copies > 0)
return value_array (0, std::vector<value *> (copies, elt));
else
{
diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.exp
index 97db748a..ca01c5f 100644
--- a/gdb/testsuite/gdb.rust/expr.exp
+++ b/gdb/testsuite/gdb.rust/expr.exp
@@ -115,6 +115,10 @@ gdb_test "print \[1,2 3" "',' or ']' expected"
gdb_test "print \[1 2" "',', ';', or ']' expected"
gdb_test "print \[23\]" " = \\\[23\\\]"
+gdb_test "print \[0;0\]" " = \\\[\\\]"
+gdb_test "print \[1;0\]" " = \\\[\\\]"
+gdb_test "print \[0;1\]" " = \\\[0\\\]"
+
gdb_test "print b\"hi rust\"" " = b\"hi rust\""
# This isn't rusty syntax yet, but that's another bug -- this is just
# testing that byte escapes work properly.