fprintf: Consider enumerations without members as forward declarations

To avoid emitting:

  enum x86_intercept_stage {
  };

Which isn't compilable.

The DWARF info for this enum in the Linux kernel has the declaration
flag set, but somehow this is not being available when loading from BTF.

So do the best we can at this enumeration__fprintf() time, that is to
just print zero members enumerations as a forward declaration.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2022-02-03 11:30:34 -03:00
parent 6afc296eeb
commit 32cc148172
1 changed files with 10 additions and 1 deletions

View File

@ -419,12 +419,21 @@ size_t enumeration__fprintf(const struct tag *tag, const struct conf_fprintf *co
struct type *type = tag__type(tag);
struct enumerator *pos;
int max_entry_name_len = enumeration__max_entry_name_len(type);
size_t printed = fprintf(fp, "enum%s%s {\n", type__name(type) ? " " : "", type__name(type) ?: "");
size_t printed = fprintf(fp, "enum%s%s", type__name(type) ? " " : "", type__name(type) ?: "");
int indent = conf->indent;
if (indent >= (int)sizeof(tabs))
indent = sizeof(tabs) - 1;
if (type->nr_members) {
printed += fprintf(fp, " {\n");
} else {
// enum x86_intercept_stage in the Linux kernel comes just as a forward
// declaration, but then BTF isn't setting the type->declaration to mark
// it as such, do the best we can and assume is a forward decl.
return printed;
}
type__for_each_enumerator(type, pos) {
printed += fprintf(fp, "%.*s\t%-*s = ", indent, tabs,
max_entry_name_len, enumerator__name(pos));