mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-25 16:57:52 +00:00
gdb: remove language_auto
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 Reviewed-By: Tom Tromey <tom@tromey.com>
This commit is contained in:
133
gdb/language.c
133
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;
|
||||
if (strcmp (lang->name (), language) != 0)
|
||||
continue;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* 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 @@ public:
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user