From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1551) id 5F2A23856265; Tue, 10 May 2022 13:18:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F2A23856265 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Pedro Alves To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Always pass an explicit language down to c_type_print X-Act-Checkin: binutils-gdb X-Git-Author: Pedro Alves X-Git-Refname: refs/heads/master X-Git-Oldrev: cb2cd8cba82a0a5480a147d95b16098ad74d33c6 X-Git-Newrev: 1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941 Message-Id: <20220510131819.5F2A23856265@sourceware.org> Date: Tue, 10 May 2022 13:18:19 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 May 2022 13:18:19 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1c6fbf42e5bd= 3045a41ad32c5efbc2ab8ca5e941 commit 1c6fbf42e5bd3045a41ad32c5efbc2ab8ca5e941 Author: Pedro Alves Date: Fri Apr 29 23:21:18 2022 +0100 Always pass an explicit language down to c_type_print =20 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()... =20 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. =20 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. =20 Change-Id: Ib54fab4cf0fd307bfd55bf1dd5056830096a653b Diff: --- gdb/ada-typeprint.c | 2 +- gdb/c-exp.y | 1 + gdb/c-lang.c | 8 ++++---- gdb/c-lang.h | 17 +++++++++-------- gdb/c-typeprint.c | 25 +++++-------------------- gdb/d-lang.c | 2 +- gdb/gnu-v3-abi.c | 3 ++- gdb/go-typeprint.c | 2 +- gdb/objc-lang.c | 2 +- gdb/opencl-lang.c | 2 +- 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 0eb95cb0a73..05ffb8b8331 100644 --- a/gdb/ada-typeprint.c +++ b/gdb/ada-typeprint.c @@ -981,7 +981,7 @@ ada_print_type (struct type *type0, const char *varstri= ng, { 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 517ab42b229..72f8dd32d93 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 =3D buf.release (); =20 diff --git a/gdb/c-lang.c b/gdb/c-lang.c index be9ee073f58..76896352954 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= ); } =20 /* 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= ); } =20 /* 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= ); } =20 /* 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= ); } =20 /* See language.h. */ diff --git a/gdb/c-lang.h b/gdb/c-lang.h index 46e562df055..096eb027fd7 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 *); =20 /* Defined in c-typeprint.c */ -extern void c_print_type (struct type *, const char *, - struct ui_file *, int, int, - const struct type_print_options *); =20 -/* 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. */ =20 -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); =20 extern void c_print_typedef (struct type *, struct symbol *, diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c index 3425c829e3f..4f45475dc4a 100644 --- a/gdb/c-typeprint.c +++ b/gdb/c-typeprint.c @@ -163,22 +163,6 @@ c_print_type_1 (struct type *type, } } =20 -/* 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. */ =20 void @@ -303,7 +287,7 @@ cp_type_print_method_args (struct type *mtype, const ch= ar *prefix, if (FIELD_ARTIFICIAL (arg)) continue; =20 - c_print_type (arg.type (), "", stream, 0, 0, flags); + c_print_type (arg.type (), "", stream, 0, 0, language, flags); =20 if (i =3D=3D nargs && varargs) gdb_printf (stream, ", ..."); @@ -872,7 +856,8 @@ c_type_print_varspec_suffix (struct type *type, =20 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 =3D 1, i; =20 @@ -899,7 +884,7 @@ c_type_print_template_args (const struct type_print_opt= ions *flags, gdb_printf (stream, "%s =3D ", sym->linkage_name ()); } =20 - c_print_type (sym->type (), "", stream, -1, 0, flags); + c_print_type (sym->type (), "", stream, -1, 0, language, flags); } =20 if (!first) @@ -1094,7 +1079,7 @@ c_type_print_base_struct_union (struct type *type, st= ruct ui_file *stream, struct type *basetype; int vptr_fieldno; =20 - c_type_print_template_args (&local_flags, type, stream); + c_type_print_template_args (&local_flags, type, stream, language); =20 /* Add in template parameters when printing derivation info. */ if (local_flags.local_typedefs !=3D NULL) diff --git a/gdb/d-lang.c b/gdb/d-lang.c index ec4a80a3223..ce6dc058412 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= ); } =20 /* See language.h. */ diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c index 7aac0ca4f9c..953645e7411 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); } =20 diff --git a/gdb/go-typeprint.c b/gdb/go-typeprint.c index f8f155fbb64..4995ac39186 100644 --- a/gdb/go-typeprint.c +++ b/gdb/go-typeprint.c @@ -59,5 +59,5 @@ go_language::print_type (struct type *type, const char *v= arstring, } =20 /* 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 00c362c5c9c..37008da529a 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= ); } =20 /* See language.h. */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 5145cd4062e..1034d1c91fe 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -969,7 +969,7 @@ public: show =3D 0; } =20 - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, la_language, flags= ); } =20 /* See language.h. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index bf8dba99ecd..746f565947b 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -669,7 +669,7 @@ rust_print_struct_def (struct type *type, const char *v= arstring, =20 /* 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, fla= gs); =20 if (flags->print_offsets) { @@ -922,7 +922,8 @@ rust_internal_print_type (struct type *type, const char= *varstring, =20 default: c_printer: - c_print_type (type, varstring, stream, show, level, flags); + c_print_type (type, varstring, stream, show, level, language_rust, + flags); } }