mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-23 10:03:47 +08: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:
parent
f57d81815f
commit
129bce3604
@ -13700,7 +13700,7 @@ public:
|
||||
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;
|
||||
|
||||
|
@ -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 */
|
||||
|
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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 ());
|
||||
|
@ -887,10 +887,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 ());
|
||||
|
||||
@ -1028,7 +1025,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 ();
|
||||
|
Loading…
Reference in New Issue
Block a user