Re: [RFA] More problems with language in printing symbols

Eli Zaretskii
2009-05-17T16:17:51Z

> Date: Sat, 16 May 2009 20:59:48 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: gdb-patches@sourceware.org
>
> The new dump_symtab does this:
>
> /* Set the current language to the language of the symtab we're dumping
> because certain routines used during dump_symtab() use the current
> language to print an image of the symbol. We'll restore it later. */
> saved_lang = set_language (symtab->language);
>
> dump_symtab_1 (objfile, symtab, outfile);
>
> set_language (saved_lang);
>
> However, it does not check what is the value of symtab->language. It
> so happens that coffread.c creates a symtab for a "_globals_"
> pseudo-file, whose symtab gets its language set to language_unknown,
> because deduce_language_from_filename does not recognize such a file
> name. And, of course, trying to print symbols with language_unknown
> as the current language does not give good results...
>
> I'm unsure how best to fix that. We could try recognizing "_globals_"
> in deduce_language_from_filename, but what language to use for it? Or
> we could add some defensive fallback in dump_symtab which would not
> switch the language if it is language_unknown.
>
> Comments? ideas?

Here's a patch that implements 2 ideas: it uses language_minimal for
the "_globals_" pseudo-file, and it makes dump_symtab be defensive
about the language of the symtab we are dumping.

OK to commit?

2009-05-17 Eli Zaretskii <eliz@gnu.org>

* symmisc.c (dump_symtab): Switch the current language to
the language of the symtab we are dumping only if the symtab's
language is neither language_auto nor language_unknown.

* coffread.c (coff_symtab_read): Set language_minimal as the
language for the "_globals_" pseudo-file.

--- coffread.c~1 2009-05-16 19:24:27.843781500 +0300
+++ coffread.c 2009-05-17 19:07:34.874125000 +0300
@@ -758,6 +758,11 @@ coff_symtab_read (long symtab_offset, un
coff_end_symtab (objfile);

coff_start_symtab ("_globals_");
+ /* coff_start_symtab will set the language of this symtab to
+ language_unknown, since such a ``file name'' is not
+ recognized. Override that with the minimal language to
+ allow printing values in this symtab. */
+ current_subfile->language = language_minimal;
complete_symtab ("_globals_", 0, 0);
/* done with all files, everything from here on out is globals */
}

--- symmisc.c~0 2009-01-03 09:57:53.000000000 +0200
+++ symmisc.c 2009-05-17 19:02:46.139750000 +0300
@@ -496,16 +496,23 @@ static void
dump_symtab (struct objfile *objfile, struct symtab *symtab,
struct ui_file *outfile)
{
- enum language saved_lang;
-
/* Set the current language to the language of the symtab we're dumping
because certain routines used during dump_symtab() use the current
- language to print an image of the symbol. We'll restore it later. */
- saved_lang = set_language (symtab->language);
+ 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)
+ {
+ enum language saved_lang;
+
+ saved_lang = set_language (symtab->language);

- dump_symtab_1 (objfile, symtab, outfile);
+ dump_symtab_1 (objfile, symtab, outfile);

- set_language (saved_lang);
+ set_language (saved_lang);
+ }
+ else
+ dump_symtab_1 (objfile, symtab, outfile);
}

void