[8/10] Convert msym_..._type to per-gdbarch data
Ulrich Weigand
uweigand@de.ibm.com
Fri Jun 8 23:18:00 GMT 2007
Hello,
another instance of gdbarch-swapped types is the msym_.._type variables used to
represent the contents of variables without debug information.
This patch replace those variables by a per-gdbarch data structure to hold the
types, completely analogous to the main builtin_type.
(The types could have been added to builtin_type, but I prefer this way as it
keeps the parse.c file self-contained.)
Bye,
Ulrich
ChangeLog:
* parse.c (struct msym_type): New data type.
(msym_data): New global variable.
(msym_type): New function.
(msym_post_init): Likewise.
(msym_text_symbol_type, msym_data_symbol_type,
msym_unknown_symbol_type, msym_tls_symbol_type): Remove.
(write_exp_msymbol): Call msym_type instead of using global variables.
(build_parse): Remove.
(_initialize_parse): Do not call build_parse. Do not swap variables.
Register msym_data per-gdbarch data.
diff -urNp gdb-orig/gdb/parse.c gdb-head/gdb/parse.c
--- gdb-orig/gdb/parse.c 2007-06-08 22:17:44.812130679 +0200
+++ gdb-head/gdb/parse.c 2007-06-08 22:21:55.621046338 +0200
@@ -377,6 +377,52 @@ write_exp_bitstring (struct stoken str)
write_exp_elt_longcst ((LONGEST) bits);
}
+
+/* Default data types used for minimal symbols. */
+
+struct msym_type
+ {
+ struct type *text_symbol;
+ struct type *data_symbol;
+ struct type *unknown_symbol;
+ struct type *tls_symbol;
+ };
+
+static struct gdbarch_data *msym_data;
+
+static const struct msym_type *
+msym_type (struct gdbarch *gdbarch)
+{
+ return gdbarch_data (gdbarch, msym_data);
+}
+
+static void *
+msym_post_init (struct gdbarch *gdbarch)
+{
+ struct msym_type *msym_type
+ = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct msym_type);
+
+ msym_type->text_symbol =
+ init_type (TYPE_CODE_FUNC, 1, 0, "<text variable, no debug info>", NULL);
+ TYPE_TARGET_TYPE (msym_type->text_symbol) =
+ init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0, "int", NULL);
+
+ msym_type->data_symbol =
+ init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+ "<data variable, no debug info>", NULL);
+
+ msym_type->unknown_symbol =
+ init_type (TYPE_CODE_INT, 1, 0,
+ "<variable (not text or data), no debug info>",
+ NULL);
+
+ msym_type->tls_symbol =
+ init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
+ "<thread local variable, no debug info>", NULL);
+
+ return msym_type;
+}
+
/* Add the appropriate elements for a minimal symbol to the end of
the expression. The rationale behind passing in text_symbol_type and
data_symbol_type was so that Modula-2 could pass in WORD for
@@ -384,11 +430,6 @@ write_exp_bitstring (struct stoken str)
based on the language, but they no longer have names like "int", so
the initial rationale is gone. */
-static struct type *msym_text_symbol_type;
-static struct type *msym_data_symbol_type;
-static struct type *msym_unknown_symbol_type;
-static struct type *msym_tls_symbol_type;
-
void
write_exp_msymbol (struct minimal_symbol *msymbol,
struct type *text_symbol_type,
@@ -419,7 +460,7 @@ write_exp_msymbol (struct minimal_symbol
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
write_exp_elt_objfile (ofp);
- write_exp_elt_type (msym_tls_symbol_type);
+ write_exp_elt_type (msym_type (current_gdbarch)->tls_symbol);
write_exp_elt_opcode (UNOP_MEMVAL_TLS);
return;
}
@@ -430,18 +471,18 @@ write_exp_msymbol (struct minimal_symbol
case mst_text:
case mst_file_text:
case mst_solib_trampoline:
- write_exp_elt_type (msym_text_symbol_type);
+ write_exp_elt_type (msym_type (current_gdbarch)->text_symbol);
break;
case mst_data:
case mst_file_data:
case mst_bss:
case mst_file_bss:
- write_exp_elt_type (msym_data_symbol_type);
+ write_exp_elt_type (msym_type (current_gdbarch)->data_symbol);
break;
default:
- write_exp_elt_type (msym_unknown_symbol_type);
+ write_exp_elt_type (msym_type (current_gdbarch)->unknown_symbol);
break;
}
write_exp_elt_opcode (UNOP_MEMVAL);
@@ -1175,28 +1216,6 @@ follow_types (struct type *follow_type)
return follow_type;
}
-static void build_parse (void);
-static void
-build_parse (void)
-{
- int i;
-
- msym_text_symbol_type =
- init_type (TYPE_CODE_FUNC, 1, 0, "<text variable, no debug info>", NULL);
- TYPE_TARGET_TYPE (msym_text_symbol_type) = builtin_type_int;
- msym_data_symbol_type =
- init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
- "<data variable, no debug info>", NULL);
- msym_unknown_symbol_type =
- init_type (TYPE_CODE_INT, 1, 0,
- "<variable (not text or data), no debug info>",
- NULL);
-
- msym_tls_symbol_type =
- init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
- "<thread local variable, no debug info>", NULL);
-}
-
/* This function avoids direct calls to fprintf
in the parser generated debug code. */
void
@@ -1222,15 +1241,7 @@ _initialize_parse (void)
type_stack = (union type_stack_elt *)
xmalloc (type_stack_size * sizeof (*type_stack));
- build_parse ();
-
- /* FIXME - For the moment, handle types by swapping them in and out.
- Should be using the per-architecture data-pointer and a large
- struct. */
- DEPRECATED_REGISTER_GDBARCH_SWAP (msym_text_symbol_type);
- DEPRECATED_REGISTER_GDBARCH_SWAP (msym_data_symbol_type);
- DEPRECATED_REGISTER_GDBARCH_SWAP (msym_unknown_symbol_type);
- deprecated_register_gdbarch_swap (NULL, 0, build_parse);
+ msym_data = gdbarch_data_register_post_init (msym_post_init);
add_setshow_zinteger_cmd ("expression", class_maintenance,
&expressiondebug, _("\
--
Dr. Ulrich Weigand
GNU Toolchain for Linux on System z and Cell BE
Ulrich.Weigand@de.ibm.com
More information about the Gdb-patches
mailing list