This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] Expand LEN parameter of value_*string functions
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Tue, 25 Sep 2012 20:39:40 +0530
- Subject: [PATCH] Expand LEN parameter of value_*string functions
Hi,
The value_string and value_cstring functions take string lengths as
parameters and that ought to be at least ssize_t. Attached patch makes
this change and also adjusts the parameters of functions it calls, i.e.
lookup_array_range_type and lookup_string_range_type. The bounds
parameters of these functions are expanded to LONGEST instead of just
ssize_t to match them with the type of low and high in
type.main_type.fields[i].flds_bnds.bounds. This fix is separated from
the earlier bitpos patch[1].
I have verified that this does not cause any regressions on x86_64. OK
to commit?
Regards,
Siddhesh
[1] http://sourceware.org/ml/gdb-patches/2012-08/msg00144.html
gdb/ChangeLog:
* gdbtypes.c (lookup_array_range_type): Expand parameters
LOW_BOUND and HIGH_BOUND to LONGEST.
(lookup_string_range_type): Likewise.
* gdbtypes.h (lookup_array_range_type): Likewise.
(lookup_string_range_type): Likewise.
* valops.c (value_cstring): Expand parameter LEN to ssize_t.
Expand HIGHBOUND to ssize_t.
(value_string): Likewise.
* value.h (value_cstring): Expand parameter LEN to ssize_t.
(value_string): Likewise.
Index: gdb/gdbtypes.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.c,v
retrieving revision 1.242
diff -u -r1.242 gdbtypes.c
--- gdb/gdbtypes.c 10 Sep 2012 17:12:51 -0000 1.242
+++ gdb/gdbtypes.c 25 Sep 2012 14:33:46 -0000
@@ -964,7 +964,7 @@
struct type *
lookup_array_range_type (struct type *element_type,
- int low_bound, int high_bound)
+ LONGEST low_bound, LONGEST high_bound)
{
struct gdbarch *gdbarch = get_type_arch (element_type);
struct type *index_type = builtin_type (gdbarch)->builtin_int;
@@ -1000,7 +1000,7 @@
struct type *
lookup_string_range_type (struct type *string_char_type,
- int low_bound, int high_bound)
+ LONGEST low_bound, LONGEST high_bound)
{
struct type *result_type;
Index: gdb/gdbtypes.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbtypes.h,v
retrieving revision 1.172
diff -u -r1.172 gdbtypes.h
--- gdb/gdbtypes.h 10 Sep 2012 17:12:51 -0000 1.172
+++ gdb/gdbtypes.h 25 Sep 2012 14:33:47 -0000
@@ -1526,11 +1526,11 @@
extern struct type *create_array_type (struct type *, struct type *,
struct type *);
-extern struct type *lookup_array_range_type (struct type *, int, int);
+extern struct type *lookup_array_range_type (struct type *, LONGEST, LONGEST);
extern struct type *create_string_type (struct type *, struct type *,
struct type *);
-extern struct type *lookup_string_range_type (struct type *, int, int);
+extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);
extern struct type *create_set_type (struct type *, struct type *);
Index: gdb/valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.303
diff -u -r1.303 valops.c
--- gdb/valops.c 25 Sep 2012 12:48:53 -0000 1.303
+++ gdb/valops.c 25 Sep 2012 14:33:48 -0000
@@ -1838,11 +1838,11 @@
}
struct value *
-value_cstring (char *ptr, int len, struct type *char_type)
+value_cstring (char *ptr, ssize_t len, struct type *char_type)
{
struct value *val;
int lowbound = current_language->string_lower_bound;
- int highbound = len / TYPE_LENGTH (char_type);
+ ssize_t highbound = len / TYPE_LENGTH (char_type);
struct type *stringtype
= lookup_array_range_type (char_type, lowbound, highbound + lowbound - 1);
@@ -1861,11 +1861,11 @@
string may contain embedded null bytes. */
struct value *
-value_string (char *ptr, int len, struct type *char_type)
+value_string (char *ptr, ssize_t len, struct type *char_type)
{
struct value *val;
int lowbound = current_language->string_lower_bound;
- int highbound = len / TYPE_LENGTH (char_type);
+ ssize_t highbound = len / TYPE_LENGTH (char_type);
struct type *stringtype
= lookup_string_range_type (char_type, lowbound, highbound + lowbound - 1);
Index: gdb/value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.209
diff -u -r1.209 value.h
--- gdb/value.h 13 Aug 2012 00:54:04 -0000 1.209
+++ gdb/value.h 25 Sep 2012 14:33:48 -0000
@@ -587,9 +587,9 @@
extern void value_free_to_mark (struct value *mark);
-extern struct value *value_cstring (char *ptr, int len,
+extern struct value *value_cstring (char *ptr, ssize_t len,
struct type *char_type);
-extern struct value *value_string (char *ptr, int len,
+extern struct value *value_string (char *ptr, ssize_t len,
struct type *char_type);
extern struct value *value_array (int lowbound, int highbound,