diff options
author | Pedro Alves <pedro@palves.net> | 2022-04-29 23:21:18 +0100 |
---|---|---|
committer | Pedro Alves <pedro@palves.net> | 2022-05-10 14:16:21 +0100 |
commit | 1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941 (patch) | |
tree | de24937c9c0144720c3fcd4414b0028f0c0bce7b /gdb | |
parent | cb2cd8cba82a0a5480a147d95b16098ad74d33c6 (diff) | |
download | gdb-1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941.zip gdb-1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941.tar.gz gdb-1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941.tar.bz2 |
Always pass an explicit language down to c_type_print
The next patch will want to do language->print_type(type, ...), to
print a type in a given language, avoiding a dependency on the current
language. That doesn't work correctly currently, however, because
most language implementations of language_defn::print_type call
c_print_type without passing down the language. There are two
overloads of c_print_type, one that takes a language, and one that
does not. The one that does not uses the current language, defeating
the point of calling language->print_type()...
This commit removes the c_print_type overload that does not take a
language, and adjusts the codebase throughout to always pass down a
language. In most places, there's already an enum language handy.
language_defn::print_type implementations naturally pass down
this->la_language. In a couple spots, like in ada-typeprint.c and
rust-lang.c there's no enum language handy, but the code is written
for a specific language, so we just hardcode the language.
In gnuv3_print_method_ptr, I wasn't sure whether we could hardcode C++
here, and we don't have an enum language handy, so I made it use the
current language, just like today. Can always be improved later.
Change-Id: Ib54fab4cf0fd307bfd55bf1dd5056830096a653b
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ada-typeprint.c | 2 | ||||
-rw-r--r-- | gdb/c-exp.y | 1 | ||||
-rw-r--r-- | gdb/c-lang.c | 8 | ||||
-rw-r--r-- | gdb/c-lang.h | 17 | ||||
-rw-r--r-- | gdb/c-typeprint.c | 25 | ||||
-rw-r--r-- | gdb/d-lang.c | 2 | ||||
-rw-r--r-- | gdb/gnu-v3-abi.c | 3 | ||||
-rw-r--r-- | gdb/go-typeprint.c | 2 | ||||
-rw-r--r-- | gdb/objc-lang.c | 2 | ||||
-rw-r--r-- | gdb/opencl-lang.c | 2 | ||||
-rw-r--r-- | gdb/rust-lang.c | 5 |
11 files changed, 29 insertions, 40 deletions
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c index 0eb95cb..05ffb8b 100644 --- a/gdb/ada-typeprint.c +++ b/gdb/ada-typeprint.c @@ -981,7 +981,7 @@ ada_print_type (struct type *type0, const char *varstring, { default: gdb_printf (stream, "<"); - c_print_type (type, "", stream, show, level, flags); + c_print_type (type, "", stream, show, level, language_ada, flags); gdb_printf (stream, ">"); break; case TYPE_CODE_PTR: diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 517ab42..72f8dd3 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -1783,6 +1783,7 @@ oper: OPERATOR NEW { string_file buf; c_print_type ($2, NULL, &buf, -1, 0, + pstate->language ()->la_language, &type_print_raw_options); std::string name = buf.release (); diff --git a/gdb/c-lang.c b/gdb/c-lang.c index be9ee07..7689635 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -820,7 +820,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ @@ -966,7 +966,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ @@ -1066,7 +1066,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ @@ -1118,7 +1118,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 46e562d..096eb02 100644 --- a/gdb/c-lang.h +++ b/gdb/c-lang.h @@ -65,16 +65,17 @@ extern int c_parse (struct parser_state *); extern int c_parse_escape (const char **, struct obstack *); /* Defined in c-typeprint.c */ -extern void c_print_type (struct type *, const char *, - struct ui_file *, int, int, - const struct type_print_options *); -/* Print a type but allow the precise language to be specified. */ +/* Print TYPE to STREAM using syntax appropriate for LANGUAGE, a + C-like language. The other parameters are like + type_language_defn::print_type's. */ -extern void c_print_type (struct type *, const char *, - struct ui_file *, int, int, - enum language, - const struct type_print_options *); +extern void c_print_type (struct type *type, + const char *varstring, + struct ui_file *stream, + int show, int level, + enum language language, + const struct type_print_options *flags); extern void c_print_typedef (struct type *, struct symbol *, diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 3425c82..4f45475 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -163,22 +163,6 @@ c_print_type_1 (struct type *type, } } -/* LEVEL is the depth to indent lines by. */ - -void -c_print_type (struct type *type, - const char *varstring, - struct ui_file *stream, - int show, int level, - const struct type_print_options *flags) -{ - struct print_offset_data podata (flags); - - c_print_type_1 (type, varstring, stream, show, level, - current_language->la_language, flags, &podata); -} - - /* See c-lang.h. */ void @@ -303,7 +287,7 @@ cp_type_print_method_args (struct type *mtype, const char *prefix, if (FIELD_ARTIFICIAL (arg)) continue; - c_print_type (arg.type (), "", stream, 0, 0, flags); + c_print_type (arg.type (), "", stream, 0, 0, language, flags); if (i == nargs && varargs) gdb_printf (stream, ", ..."); @@ -872,7 +856,8 @@ c_type_print_varspec_suffix (struct type *type, static void c_type_print_template_args (const struct type_print_options *flags, - struct type *type, struct ui_file *stream) + struct type *type, struct ui_file *stream, + enum language language) { int first = 1, i; @@ -899,7 +884,7 @@ c_type_print_template_args (const struct type_print_options *flags, gdb_printf (stream, "%s = ", sym->linkage_name ()); } - c_print_type (sym->type (), "", stream, -1, 0, flags); + c_print_type (sym->type (), "", stream, -1, 0, language, flags); } if (!first) @@ -1094,7 +1079,7 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream, struct type *basetype; int vptr_fieldno; - c_type_print_template_args (&local_flags, type, stream); + c_type_print_template_args (&local_flags, type, stream, language); /* Add in template parameters when printing derivation info. */ if (local_flags.local_typedefs != NULL) diff --git a/gdb/d-lang.c b/gdb/d-lang.c index ec4a80a..ce6dc05 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -148,7 +148,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 7aac0ca..953645e 100644 --- a/gdb/gnu-v3-abi.c +++ b/gdb/gnu-v3-abi.c @@ -659,7 +659,8 @@ gnuv3_print_method_ptr (const gdb_byte *contents, { /* Found a non-virtual function: print out the type. */ gdb_puts ("(", stream); - c_print_type (type, "", stream, -1, 0, &type_print_raw_options); + c_print_type (type, "", stream, -1, 0, current_language->la_language, + &type_print_raw_options); gdb_puts (") ", stream); } diff --git a/gdb/go-typeprint.c b/gdb/go-typeprint.c index f8f155f..4995ac3 100644 --- a/gdb/go-typeprint.c +++ b/gdb/go-typeprint.c @@ -59,5 +59,5 @@ go_language::print_type (struct type *type, const char *varstring, } /* Punt the rest to C for now. */ - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 00c362c..37008da 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -270,7 +270,7 @@ public: struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override { - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 5145cd4..1034d1c 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -969,7 +969,7 @@ public: show = 0; } - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags); } /* See language.h. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index bf8dba9..746f565 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -669,7 +669,7 @@ rust_print_struct_def (struct type *type, const char *varstring, /* If we see a base class, delegate to C. */ if (TYPE_N_BASECLASSES (type) > 0) - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, language_rust, flags); if (flags->print_offsets) { @@ -922,7 +922,8 @@ rust_internal_print_type (struct type *type, const char *varstring, default: c_printer: - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, language_rust, + flags); } } |