From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 3/3] gdb: remove language_auto
Date: Tue, 18 Apr 2023 16:27:51 -0400 [thread overview]
Message-ID: <20230418202751.117181-4-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230418202751.117181-1-simon.marchi@efficios.com>
I think that the language_auto enumerator and the auto_language class
can be removed. There isn't really an "auto" language, it's only a
construct of the "set language" command to say "pick the appropriate
language automatically". But "auto" is never the current language. The
`current_language` points to the current effective language, and the
fact that we're in "auto language" mode is noted by the language_mode
global.
- Change set_language to handle the "auto" (and "local", which is a
synonym) early, instead of in the for loop. I think it makes the two
cases (auto vs explicit language) more clearly separated anyway.
- Adjust add_set_language_command to hard-code the "auto" string,
instead of using the "auto" language definition.
- Remove auto_language, rename auto_or_unknown_language to
unknown_language and move the bits of the existing unknown_language
in there.
- Remove the set_language at the end of _initialize_language. I think
it's not needed, because we call set_language in gdb_init, after all
_initialize functions are called. There is some chance that an
_initialize function that runs after _initialize_language implicitly
depends on current_language being set, but my testsuite runs haven't
found anything like that.
- Use language_unknown instead of language_auto when creating a minimal
symbol (minimal_symbol_reader::record_full). I think that this value
is used to indicate that we don't know the symbol of the minimal
symbol (yet), so language_unknown makes sense to me. Update a
condition accordingly in ada-lang.c. symbol_find_demangled_name also
appears to "normalize" this value from "unknown" to "auto", remove
that part and update the condition to just check for
language_unknown.
Change-Id: I47bcd6c15f607d9818f2e6e413053c2dc8ec5034
---
gdb/ada-lang.c | 2 +-
gdb/defs.h | 1 -
gdb/language.c | 135 +++++++++++++++-------------------------------
gdb/mi/mi-parse.c | 3 +-
gdb/minsyms.c | 2 +-
gdb/symmisc.c | 3 +-
gdb/symtab.c | 7 +--
7 files changed, 49 insertions(+), 104 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 97e03f78d5da..3a9f554ce4ce 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13700,7 +13700,7 @@ class ada_language : public language_defn
C++ symbols (using an old mangling scheme), such as "name__2Xn"
-> "Xn::name(void)" and thus some Ada minimal symbols end up
with the wrong language set. Paper over that issue here. */
- if (symbol_language == language_auto
+ if (symbol_language == language_unknown
|| symbol_language == language_cplus)
symbol_language = language_ada;
diff --git a/gdb/defs.h b/gdb/defs.h
index 8dbb68e440b0..454475b203c3 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -210,7 +210,6 @@ extern void quit_serial_event_clear (void);
enum language
{
language_unknown, /* Language not known */
- language_auto, /* Placeholder for automatic setting */
language_c, /* C */
language_objc, /* Objective-C */
language_rust, /* Rust */
diff --git a/gdb/language.c b/gdb/language.c
index 42bce92c647c..a1bf4d14ad49 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -142,49 +142,45 @@ set_language (const char *language)
enum language flang = language_unknown;
/* "local" is a synonym of "auto". */
- if (strcmp (language, "local") == 0)
- language = "auto";
+ if (strcmp (language, "auto") == 0
+ || strcmp (language, "local") == 0)
+ {
+ /* Enter auto mode. Set to the current frame's language, if
+ known, or fallback to the initial language. */
+ language_mode = language_mode_auto;
+ try
+ {
+ frame_info_ptr frame;
+
+ frame = get_selected_frame (NULL);
+ flang = get_frame_language (frame);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ flang = language_unknown;
+ }
+
+ if (flang != language_unknown)
+ set_language (flang);
+ else
+ set_initial_language ();
+
+ expected_language = current_language;
+ return;
+ }
/* Search the list of languages for a match. */
for (const auto &lang : language_defn::languages)
{
- if (strcmp (lang->name (), language) == 0)
- {
- /* Found it! Go into manual mode, and use this language. */
- if (lang->la_language == language_auto)
- {
- /* Enter auto mode. Set to the current frame's language, if
- known, or fallback to the initial language. */
- language_mode = language_mode_auto;
- try
- {
- frame_info_ptr frame;
-
- frame = get_selected_frame (NULL);
- flang = get_frame_language (frame);
- }
- catch (const gdb_exception_error &ex)
- {
- flang = language_unknown;
- }
-
- if (flang != language_unknown)
- set_language (flang);
- else
- set_initial_language ();
- expected_language = current_language;
- return;
- }
- else
- {
- /* Enter manual mode. Set the specified language. */
- language_mode = language_mode_manual;
- current_language = lang;
- set_range_case ();
- expected_language = current_language;
- return;
- }
- }
+ if (strcmp (lang->name (), language) != 0)
+ continue;
+
+ /* Found it! Go into manual mode, and use this language. */
+ language_mode = language_mode_manual;
+ current_language = lang;
+ set_range_case ();
+ expected_language = current_language;
+ return;
}
internal_error ("Couldn't find language `%s' in known languages list.",
@@ -434,9 +430,6 @@ language_enum (const char *str)
if (strcmp (lang->name (), str) == 0)
return lang->la_language;
- if (strcmp (str, "local") == 0)
- return language_auto;
-
return language_unknown;
}
@@ -468,22 +461,21 @@ add_set_language_command ()
static const char **language_names;
/* Build the language names array, to be used as enumeration in the
- "set language" enum command. +1 for "local" and +1 for NULL
+ "set language" enum command. +3 for "auto", "local" and NULL
termination. */
- language_names = new const char *[ARRAY_SIZE (language_defn::languages) + 2];
+ language_names = new const char *[ARRAY_SIZE (language_defn::languages) + 3];
/* Display "auto", "local" and "unknown" first, and then the rest,
alpha sorted. */
const char **language_names_p = language_names;
- *language_names_p++ = language_def (language_auto)->name ();;
+ *language_names_p++ = "auto";
*language_names_p++ = "local";
*language_names_p++ = language_def (language_unknown)->name ();
const char **sort_begin = language_names_p;
for (const auto &lang : language_defn::languages)
{
/* Already handled above. */
- if (lang->la_language == language_auto
- || lang->la_language == language_unknown)
+ if (lang->la_language == language_unknown)
continue;
*language_names_p++ = lang->name ();
}
@@ -505,8 +497,7 @@ add_set_language_command ()
for (const auto &lang : language_defn::languages)
{
/* Already dealt with these above. */
- if (lang->la_language == language_unknown
- || lang->la_language == language_auto)
+ if (lang->la_language == language_unknown)
continue;
/* Note that we add the newline at the front, so we don't wind
@@ -703,15 +694,12 @@ language_defn::varobj_ops () const
return &c_varobj_ops;
}
-/* Parent class for both the "auto" and "unknown" languages. These two
- pseudo-languages are very similar so merging their implementations like
- this makes sense. */
+/* Class representing the "unknown" language. */
-class auto_or_unknown_language : public language_defn
+class unknown_language : public language_defn
{
public:
- auto_or_unknown_language (enum language lang)
- : language_defn (lang)
+ unknown_language () : language_defn (language_unknown)
{ /* Nothing. */ }
/* See language.h. */
@@ -823,40 +811,6 @@ class auto_or_unknown_language : public language_defn
const char *name_of_this () const override
{ return "this"; }
-};
-
-/* Class representing the fake "auto" language. */
-
-class auto_language : public auto_or_unknown_language
-{
-public:
- auto_language ()
- : auto_or_unknown_language (language_auto)
- { /* Nothing. */ }
-
- /* See language.h. */
-
- const char *name () const override
- { return "auto"; }
-
- /* See language.h. */
-
- const char *natural_name () const override
- { return "Auto"; }
-};
-
-/* Single instance of the fake "auto" language. */
-
-static auto_language auto_language_defn;
-
-/* Class representing the unknown language. */
-
-class unknown_language : public auto_or_unknown_language
-{
-public:
- unknown_language ()
- : auto_or_unknown_language (language_unknown)
- { /* Nothing. */ }
/* See language.h. */
@@ -1131,7 +1085,4 @@ For Fortran the default is off; for other languages the default is on."),
&setlist, &showlist);
add_set_language_command ();
-
- /* Have the above take effect. */
- set_language (language_auto);
}
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index e334968cc88b..737ec57eddd0 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -351,8 +351,7 @@ mi_parse (const char *cmd, char **token)
std::string lang_name = extract_arg (&chp);
parse->language = language_enum (lang_name.c_str ());
- if (parse->language == language_unknown
- || parse->language == language_auto)
+ if (parse->language == language_unknown)
error (_("Invalid --language argument: %s"), lang_name.c_str ());
}
else
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 3fa07f47b9fc..a2c139db24d4 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -1189,7 +1189,7 @@ minimal_symbol_reader::record_full (gdb::string_view name,
m_msym_bunch = newobj;
}
msymbol = &m_msym_bunch->contents[m_msym_bunch_index];
- msymbol->set_language (language_auto,
+ msymbol->set_language (language_unknown,
&m_objfile->per_bfd->storage_obstack);
if (copy_name)
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 3d7fd5609564..4b68f2b1f6fb 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -365,8 +365,7 @@ dump_symtab (struct symtab *symtab, struct ui_file *outfile)
because certain routines used during dump_symtab() use the current
language to print an image of the symbol. We'll restore it later.
But use only real languages, not placeholders. */
- if (symtab->language () != language_unknown
- && symtab->language () != language_auto)
+ if (symtab->language () != language_unknown)
{
scoped_restore_current_language save_lang;
set_language (symtab->language ());
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 9e9798676cbe..cbd8671f8499 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -874,10 +874,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
gdb::unique_xmalloc_ptr<char> demangled;
int i;
- if (gsymbol->language () == language_unknown)
- gsymbol->m_language = language_auto;
-
- if (gsymbol->language () != language_auto)
+ if (gsymbol->language () != language_unknown)
{
const struct language_defn *lang = language_def (gsymbol->language ());
@@ -1015,7 +1012,7 @@ general_symbol_info::compute_and_set_names (gdb::string_view linkage_name,
(*slot)->demangled = std::move (demangled_name);
(*slot)->language = language ();
}
- else if (language () == language_unknown || language () == language_auto)
+ else if (language () == language_unknown)
m_language = (*slot)->language;
m_name = (*slot)->mangled.data ();
--
2.40.0
next prev parent reply other threads:[~2023-04-18 20:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 20:27 [PATCH 0/3] Some language cleanups Simon Marchi
2023-04-18 20:27 ` [PATCH 1/3] gdb: remove return value of set_language Simon Marchi
2023-04-18 20:27 ` [PATCH 2/3] gdb: switch "set language" to getter/setter Simon Marchi
2023-04-18 20:27 ` Simon Marchi [this message]
2023-04-21 14:26 ` [PATCH 0/3] Some language cleanups Tom Tromey
2023-04-21 18:10 ` Simon Marchi
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=20230418202751.117181-4-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).