From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/3] Always pass an explicit language down to c_type_print
Date: Thu, 5 May 2022 19:50:19 +0100 [thread overview]
Message-ID: <20220505185020.3648774-3-pedro@palves.net> (raw)
In-Reply-To: <20220505185020.3648774-1-pedro@palves.net>
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
---
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 *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 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 = buf.release ();
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 @@ class c_language : public language_defn
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 @@ class cplus_language : public language_defn
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 @@ class asm_language : public language_defn
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 @@ class minimal_language : public language_defn
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 46e562df055..c81c3bbc3b8 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. */
+/* LEVEL is the depth to indent lines by. Allows the precise language
+ to be specified, because many languages defer to C type
+ printing. */
-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 3425c829e3f..4f45475dc4a 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 ec4a80a3223..ce6dc058412 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -148,7 +148,7 @@ class d_language : public language_defn
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 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);
}
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 *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 00c362c5c9c..37008da529a 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -270,7 +270,7 @@ class objc_language : public language_defn
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 5145cd4062e..1034d1c91fe 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -969,7 +969,7 @@ class opencl_language : public language_defn
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 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 *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);
}
}
--
2.36.0
next prev parent reply other threads:[~2022-05-05 18:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-05 18:50 [PATCH 0/3] Fix "b func(std::string)", DMGL_VERBOSE, gdb.cp/no-dmgl-verbose.exp Pedro Alves
2022-05-05 18:50 ` [PATCH 1/3] Fix "b f(std::string)", always use DMGL_VERBOSE Pedro Alves
2022-05-05 20:31 ` Keith Seitz via Gdb-patches
2022-05-05 21:49 ` Carl Love via Gdb-patches
2022-05-06 13:21 ` Pedro Alves
2022-05-06 8:10 ` Lancelot SIX via Gdb-patches
2022-05-06 13:09 ` Pedro Alves
2022-05-05 18:50 ` Pedro Alves [this message]
2022-05-05 20:47 ` [PATCH 2/3] Always pass an explicit language down to c_type_print Keith Seitz via Gdb-patches
2022-05-06 12:33 ` Pedro Alves
2022-05-05 18:50 ` [PATCH 3/3] Fix "b f(std::string)" when current language is C Pedro Alves
2022-05-05 20:50 ` Keith Seitz via Gdb-patches
2022-05-06 8:34 ` Lancelot SIX via Gdb-patches
2022-05-06 13:09 ` Pedro Alves
2022-05-09 16:54 ` [PATCH 0/3] Fix "b func(std::string)", DMGL_VERBOSE, gdb.cp/no-dmgl-verbose.exp Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220505185020.3648774-3-pedro@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox