[rfc][23/37] Eliminate builtin_type_ macros: Platform-neutral types for internal variables

uweigand
2008-08-31T17:52:28Z

[-- Attachment #1: diff-type-internal --]
[-- Type: text/plain, Size: 10531 bytes --]

Hello,

the values stored in internal variables (like $_, $bpnum,
$_exitcode etc.) currently use architecture-specific types
like builtin_type_int. However, in many cases this doesn't
really make sense, as it is not quite clear which architecture
should be used ...

The patch below converts all internal variables to always use
platform-neutral types to store values. For integral values,
builtin_type_int32 is used. For characters, builtin_type_true_char.

One problem is the $_ variable, which holds a pointer value. To
allow using a platform-neutral type for this, I'm introducing a
new platform-neutral pointer type builtin_type_void_ptr. The
lenght of this type is chosen so that it can hold every CORE_ADDR
value.

Bye,
Ulrich

ChangeLog:

* gdbtypes.h (builtin_type_void_ptr): New declaration.
* gdbtypes.c (builtin_type_void_ptr): New variable.
(_initialize_gdbtypes): Initialize it.

* breakpoint.c (set_breakpoint_count): Use platform-neutral
types for internal variable values.
* findcmd.c (find_command): Likewise.
* infrun.c (handle_inferior_event): Likewise.
* printcmd.c (set_next_address): Likewise.
* source.c (forward_search_command, reverse_search_command): Likewise.
* tracepoint.c (set_tracepoint_count, set_traceframe_num,
set_tracepoint_num, set_traceframe_context): Likewise.

Index: gdb-head/gdb/breakpoint.c
===================================================================
--- gdb-head.orig/gdb/breakpoint.c
+++ gdb-head/gdb/breakpoint.c
@@ -401,7 +401,7 @@ set_breakpoint_count (int num)
{
breakpoint_count = num;
set_internalvar (lookup_internalvar ("bpnum"),
- value_from_longest (builtin_type_int, (LONGEST) num));
+ value_from_longest (builtin_type_int32, (LONGEST) num));
}

/* Used in run_command to zero the hit count when a new run starts. */
Index: gdb-head/gdb/findcmd.c
===================================================================
--- gdb-head.orig/gdb/findcmd.c
+++ gdb-head/gdb/findcmd.c
@@ -292,12 +292,12 @@ find_command (char *args, int from_tty)
/* Record and print the results. */

set_internalvar (lookup_internalvar ("numfound"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) found_count));
if (found_count > 0)
{
set_internalvar (lookup_internalvar ("_"),
- value_from_pointer (builtin_type_void_data_ptr,
+ value_from_pointer (builtin_type_void_ptr,
last_found_addr));
}

Index: gdb-head/gdb/infrun.c
===================================================================
--- gdb-head.orig/gdb/infrun.c
+++ gdb-head/gdb/infrun.c
@@ -2017,7 +2017,7 @@ handle_inferior_event (struct execution_
/* Record the exit code in the convenience variable $_exitcode, so
that the user can inspect this again later. */
set_internalvar (lookup_internalvar ("_exitcode"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) ecs->ws.value.integer));
gdb_flush (gdb_stdout);
target_mourn_inferior ();
Index: gdb-head/gdb/printcmd.c
===================================================================
--- gdb-head.orig/gdb/printcmd.c
+++ gdb-head/gdb/printcmd.c
@@ -509,7 +509,7 @@ set_next_address (CORE_ADDR addr)

/* Make address available to the user as $_. */
set_internalvar (lookup_internalvar ("_"),
- value_from_pointer (builtin_type_void_data_ptr, addr));
+ value_from_pointer (builtin_type_void_ptr, addr));
}

/* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
Index: gdb-head/gdb/source.c
===================================================================
--- gdb-head.orig/gdb/source.c
+++ gdb-head/gdb/source.c
@@ -1614,7 +1614,7 @@ forward_search_command (char *regex, int
fclose (stream);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar (lookup_internalvar ("_"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) line));
current_source_line = max (line - lines_to_list / 2, 1);
return;
@@ -1696,7 +1696,7 @@ reverse_search_command (char *regex, int
fclose (stream);
print_source_lines (current_source_symtab, line, line + 1, 0);
set_internalvar (lookup_internalvar ("_"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) line));
current_source_line = max (line - lines_to_list / 2, 1);
return;
Index: gdb-head/gdb/tracepoint.c
===================================================================
--- gdb-head.orig/gdb/tracepoint.c
+++ gdb-head/gdb/tracepoint.c
@@ -220,7 +220,7 @@ set_tracepoint_count (int num)
{
tracepoint_count = num;
set_internalvar (lookup_internalvar ("tpnum"),
- value_from_longest (builtin_type_int, (LONGEST) num));
+ value_from_longest (builtin_type_int32, (LONGEST) num));
}

/* Set traceframe number to NUM. */
@@ -229,7 +229,7 @@ set_traceframe_num (int num)
{
traceframe_number = num;
set_internalvar (lookup_internalvar ("trace_frame"),
- value_from_longest (builtin_type_int, (LONGEST) num));
+ value_from_longest (builtin_type_int32, (LONGEST) num));
}

/* Set tracepoint number to NUM. */
@@ -238,8 +238,7 @@ set_tracepoint_num (int num)
{
tracepoint_number = num;
set_internalvar (lookup_internalvar ("tracepoint"),
- value_from_longest (builtin_type_int,
- (LONGEST) num));
+ value_from_longest (builtin_type_int32, (LONGEST) num));
}

/* Set externally visible debug variables for querying/printing
@@ -252,23 +251,19 @@ set_traceframe_context (CORE_ADDR trace_
static struct type *func_range, *file_range;
struct value *func_val;
struct value *file_val;
- static struct type *charstar;
int len;

- if (charstar == (struct type *) NULL)
- charstar = lookup_pointer_type (builtin_type_char);
-
if (trace_pc == -1) /* Cease debugging any trace buffers. */
{
traceframe_fun = 0;
traceframe_sal.pc = traceframe_sal.line = 0;
traceframe_sal.symtab = NULL;
set_internalvar (lookup_internalvar ("trace_func"),
- value_from_pointer (charstar, (LONGEST) 0));
+ value_from_pointer (builtin_type_void_ptr, 0));
set_internalvar (lookup_internalvar ("trace_file"),
- value_from_pointer (charstar, (LONGEST) 0));
+ value_from_pointer (builtin_type_void_ptr, 0));
set_internalvar (lookup_internalvar ("trace_line"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) - 1));
return;
}
@@ -280,7 +275,7 @@ set_traceframe_context (CORE_ADDR trace_
/* Save linenumber as "$trace_line", a debugger variable visible to
users. */
set_internalvar (lookup_internalvar ("trace_line"),
- value_from_longest (builtin_type_int,
+ value_from_longest (builtin_type_int32,
(LONGEST) traceframe_sal.line));

/* Save func name as "$trace_func", a debugger variable visible to
@@ -288,14 +283,14 @@ set_traceframe_context (CORE_ADDR trace_
if (traceframe_fun == NULL ||
SYMBOL_LINKAGE_NAME (traceframe_fun) == NULL)
set_internalvar (lookup_internalvar ("trace_func"),
- value_from_pointer (charstar, (LONGEST) 0));
+ value_from_pointer (builtin_type_void_ptr, 0));
else
{
len = strlen (SYMBOL_LINKAGE_NAME (traceframe_fun));
func_range = create_range_type (func_range,
- builtin_type_int, 0, len - 1);
+ builtin_type_int32, 0, len - 1);
func_string = create_array_type (func_string,
- builtin_type_char, func_range);
+ builtin_type_true_char, func_range);
func_val = allocate_value (func_string);
deprecated_set_value_type (func_val, func_string);
memcpy (value_contents_raw (func_val),
@@ -310,14 +305,14 @@ set_traceframe_context (CORE_ADDR trace_
if (traceframe_sal.symtab == NULL ||
traceframe_sal.symtab->filename == NULL)
set_internalvar (lookup_internalvar ("trace_file"),
- value_from_pointer (charstar, (LONGEST) 0));
+ value_from_pointer (builtin_type_void_ptr, 0));
else
{
len = strlen (traceframe_sal.symtab->filename);
file_range = create_range_type (file_range,
- builtin_type_int, 0, len - 1);
+ builtin_type_int32, 0, len - 1);
file_string = create_array_type (file_string,
- builtin_type_char, file_range);
+ builtin_type_true_char, file_range);
file_val = allocate_value (file_string);
deprecated_set_value_type (file_val, file_string);
memcpy (value_contents_raw (file_val),
Index: gdb-head/gdb/gdbtypes.c
===================================================================
--- gdb-head.orig/gdb/gdbtypes.c
+++ gdb-head/gdb/gdbtypes.c
@@ -111,6 +111,9 @@ struct type *builtin_type_ia64_quad;
/* Platform-neutral void type. */
struct type *builtin_type_void;

+/* Platform-neutral void pointer type. */
+struct type *builtin_type_void_ptr;
+
/* Platform-neutral character types. */
struct type *builtin_type_true_char;
struct type *builtin_type_true_unsigned_char;
@@ -3333,6 +3336,12 @@ _initialize_gdbtypes (void)
init_type (TYPE_CODE_VOID, 1,
0,
"void", (struct objfile *) NULL);
+ builtin_type_void_ptr =
+ init_type (TYPE_CODE_PTR, sizeof (CORE_ADDR),
+ TYPE_FLAG_UNSIGNED,
+ NULL, (struct objfile *) NULL);
+ TYPE_TARGET_TYPE (builtin_type_void_ptr) = builtin_type_void;
+
builtin_type_true_char =
init_type (TYPE_CODE_CHAR, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
0,
Index: gdb-head/gdb/gdbtypes.h
===================================================================
--- gdb-head.orig/gdb/gdbtypes.h
+++ gdb-head/gdb/gdbtypes.h
@@ -1091,6 +1091,10 @@ extern struct type *builtin_type_ia64_qu
You must use builtin_type (...)->builtin_void in those cases. */
extern struct type *builtin_type_void;

+/* Platform-neutral void pointer type. The size of this type is chosen
+ so it is large enough to hold every CORE_ADDR value. */
+extern struct type *builtin_type_void_ptr;
+
/* Platform-neutral character types.
We use these for the '/c' print format, because c_char is just a
one-byte integral type, which languages less laid back than C