Page MenuHomeFreeBSD

libsysdecode: parse enums
AbandonedPublic

Authored by glebius on Fri, Jun 26, 5:03 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Jul 20, 3:50 AM
Unknown Object (File)
Thu, Jul 2, 11:04 PM
Unknown Object (File)
Mon, Jun 29, 9:38 PM
Unknown Object (File)
Mon, Jun 29, 1:04 PM
Unknown Object (File)
Mon, Jun 29, 6:02 AM
Unknown Object (File)
Sun, Jun 28, 10:26 PM
Unknown Object (File)
Fri, Jun 26, 5:39 PM
Subscribers

Details

Reviewers
kp
Group Reviewers
Src Committers
Summary

Teach mktables script to parse enums. Works only with clang build. As a
demo repair shutdown(2) argument parsing, that was broken since
c3276e02beab.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 74306
Build 71189: arc lint + arc unit

Event Timeline

kp added inline comments.
lib/libsysdecode/mktables
139

This is missing the TABLE_ENTRY.

(Discovered test-building the follow-up pf patch).

  • Pushed one to final version. Fixup.
This revision is now accepted and ready to land.Fri, Jun 26, 2:58 PM

There's no need for a clang-only solution, you can handle enums just fine with only regular expressions as long as the names are sufficiently distinctive.

I don't want this library to dictate naming of enums all around. The whole idea of using text parser to parse C files is fragile. Clang delivers a proper solution. Hopefully gcc will catch up.

To be clear, GCC by design is never going to emit an IR-like thing, so this is a "break forever for GCC" solution. You could perhaps generate a simple .c file with 'enum <foo> x;' and compile it with -g and parse the resulting DWARF with readelf or the like. (Or possibly use CTF as the output from ctfdump is likely easier to post-process than any of the DWARF dumps). That would not be tied to any specific compiler.

Most enums use names distinctive enough to handle with a regex just like we do for #defines. For the few cases where that doesn't work, we can use awk to limit the search to the lines between enum { and };. Give me a few days to come up with a poc, and please approve D57915 in the meantime.

EDIT: perhaps you forget that mktables doesn't need to know the value of each constant, it just needs the name.

In D57865#1329350, @des wrote:

Most enums use names distinctive enough to handle with a regex just like we do for #defines. For the few cases where that doesn't work, we can use awk to limit the search to the lines between enum { and };. Give me a few days to come up with a poc, and please approve D57915 in the meantime.

EDIT: perhaps you forget that mktables doesn't need to know the value of each constant, it just needs the name.

Ok, I'll hold you to that :) Can you please also take over D57866 (pf: revert netlink commands back to enum) then?