[PATCH 2/2] gdb: change functions returning value contents to use gdb::array_view

Simon Marchi simon.marchi@polymtl.ca
Wed Oct 27 13:43:38 GMT 2021



On 2021-10-27 08:53, Luis Machado wrote:
> Hi,
> 
> This seems to break 32-bit builds, at least with older compilers:
> 
> gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
> 
> -- 
> 
> ../../../repos/binutils-gdb/gdb/value.c: In function ‘gdb::array_view<unsigned char> value_contents_raw(value*)’:
> 
> ../../../repos/binutils-gdb/gdb/value.c:1158:78: error: narrowing conversion of ‘length’ from ‘ULONGEST {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]
>    return {value->contents.get () + value->embedded_offset * unit_size, length};
> 
> 
>        ^
> 
> ../../../repos/binutils-gdb/gdb/value.c: In function ‘gdb::array_view<unsigned char> value_contents_all_raw(value*)’:
> ../../../repos/binutils-gdb/gdb/value.c:1167:41: error: narrowing conversion of ‘length’ from ‘ULONGEST {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]
>    return {value->contents.get (), length};
> 
> 
>                                          ^
> 
> ../../../repos/binutils-gdb/gdb/value.c: In function ‘gdb::array_view<const unsigned char> value_contents_for_printing(value*)’:
> 
> ../../../repos/binutils-gdb/gdb/value.c:1252:41: error: narrowing conversion of ‘length’ from ‘ULONGEST {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]
>    return {value->contents.get (), length};
> 
> 
>                                          ^
> ../../../repos/binutils-gdb/gdb/value.c: In function ‘gdb::array_view<const unsigned char> value_contents_for_printing_const(const value*)’:
> ../../../repos/binutils-gdb/gdb/value.c:1261:41: error: narrowing conversion of ‘length’ from ‘ULONGEST {aka long long unsigned int}’ to ‘size_t {aka unsigned int}’ inside { } [-Werror=narrowing]
>    return {value->contents.get (), length};

Oh, sorry about that.  Fixed with the patch below (already pushed).

>From 5612b5d21e41796c9d6fb024c4bbf70719153373 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@efficios.com>
Date: Wed, 27 Oct 2021 09:38:51 -0400
Subject: [PATCH] gdb: fix value.c build on 32-bits

When building on ARM (32-bits), we errors like this:

    /home/smarchi/src/binutils-gdb/gdb/value.c: In function 'gdb::array_view<const unsigned char> value_contents_for_printing(value*)':
    /home/smarchi/src/binutils-gdb/gdb/value.c:1252:35: error: narrowing conversion of 'length' from 'ULONGEST' {aka 'long long unsigned int'} to 'size_t' {aka 'unsigned int'} [-Werror=narrowing]
     1252 |   return {value->contents.get (), length};
          |                                   ^~~~~~

Fix that by using gdb::make_array_view, which does the appropriate
conversion.

Change-Id: I7d6f2e75d7440d248b8fb18f8272ee92954b404d
---
 gdb/value.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gdb/value.c b/gdb/value.c
index 42ce80416f14..a0ce3a796d0c 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1155,7 +1155,8 @@ value_contents_raw (struct value *value)
   allocate_value_contents (value);
 
   ULONGEST length = TYPE_LENGTH (value_type (value));
-  return {value->contents.get () + value->embedded_offset * unit_size, length};
+  return gdb::make_array_view
+    (value->contents.get () + value->embedded_offset * unit_size, length);
 }
 
 gdb::array_view<gdb_byte>
@@ -1164,7 +1165,7 @@ value_contents_all_raw (struct value *value)
   allocate_value_contents (value);
 
   ULONGEST length = TYPE_LENGTH (value_type (value));
-  return {value->contents.get (), length};
+  return gdb::make_array_view (value->contents.get (), length);
 }
 
 struct type *
@@ -1249,7 +1250,7 @@ value_contents_for_printing (struct value *value)
     value_fetch_lazy (value);
 
   ULONGEST length = TYPE_LENGTH (value_type (value));
-  return {value->contents.get (), length};
+  return gdb::make_array_view (value->contents.get (), length);
 }
 
 gdb::array_view<const gdb_byte>
@@ -1258,7 +1259,7 @@ value_contents_for_printing_const (const struct value *value)
   gdb_assert (!value->lazy);
 
   ULONGEST length = TYPE_LENGTH (value_type (value));
-  return {value->contents.get (), length};
+  return gdb::make_array_view (value->contents.get (), length);
 }
 
 gdb::array_view<const gdb_byte>
-- 
2.33.1



More information about the Gdb-patches mailing list