Added dbgflags.py for easier flag debugging

dbgerr.py and dbgtag.py have proven to be incredibly useful for quick
debugging/introspection, so I figured why not have more of that.

My favorite part is being able to quickly see all flags set on an open
file handle:

  (gdb) p file.o.o.flags
  $2 = 24117517
  (gdb) !./scripts/dbgflags.py o 24117517
  LFS_O_WRONLY   0x00000001  Open a file as write only
  LFS_O_CREAT    0x00000004  Create a file if it does not exist
  LFS_O_EXCL     0x00000008  Fail if a file already exists
  LFS_O_DESYNC   0x00000100  Do not sync or recieve file updates
  LFS_o_REG      0x01000000  Type = regular-file
  LFS_o_UNFLUSH  0x00100000  File's data does not match disk
  LFS_o_UNSYNC   0x00200000  File's metadata does not match disk
  LFS_o_UNCREAT  0x00400000  File does not exist yet

The only concern is if dbgflags.py falls out-of-sync often, I suspect
flag encoding will have quite a bit more churn than flags/tags. But we
can always drop this script in the future if this turns into a problem.

---

While poking around this also ended up with a bunch of other small
changes:

- Added LFS_*_MODE masks for consistency with other "type<->flag
  embeddings"

- Added compat flag comments

- Adopted lowercase prefix for internal flags (LFS_o_ZOMBIE), though
  not sure if I'll keep this yet...

- Tweaked dbgerr.py to also match ERR_ prefixes and to ignore case
This commit is contained in:
Christopher Haster
2025-01-09 15:26:08 -06:00
parent 9ed9cf0ccd
commit 726bf86d21
6 changed files with 429 additions and 104 deletions
+24 -16
View File
@@ -31,35 +31,30 @@ def main(errs, *,
import builtins
list_, list = list, builtins.list
lines = []
# list all known error codes
if list_:
# first find the widths
w = [0, 0]
for n, e, h in ERRS:
w[0] = max(w[0], len('LFS_ERR_')+len(n))
w[1] = max(w[1], len(str(e)))
# print
for n, e, h in ERRS:
print('%-*s %-*s %s' % (
w[0], 'LFS_ERR_'+n,
w[1], e,
h))
lines.append(('LFS_ERR_'+n, str(e), h))
# find these errors
else:
def find_err(err):
# find by LFS_ERR_+name
for n, e, h in ERRS:
if 'LFS_ERR_'+n == err:
if 'LFS_ERR_'+n == err.upper():
return n, e, h
# find by ERR_+name
for n, e, h in ERRS:
if 'ERR_'+n == err.upper():
return n, e, h
# find by name
for n, e, h in ERRS:
if n == err:
if n == err.upper():
return n, e, h
# find by E+name
for n, e, h in ERRS:
if 'E'+n == err:
if 'E'+n == err.upper():
return n, e, h
try:
# find by err code
@@ -78,9 +73,22 @@ def main(errs, *,
for err in errs:
try:
n, e, h = find_err(err)
print('%s %s %s' % ('LFS_ERR_'+n, e, h))
lines.append(('LFS_ERR_'+n, str(e), h))
except KeyError:
print('%s ?' % err)
lines.append(('?', err, 'Unknown err code'))
# first find widths
w = [0, 0]
for l in lines:
w[0] = max(w[0], len(l[0]))
w[1] = max(w[1], len(l[1]))
# then print results
for l in lines:
print('%-*s %-*s %s' % (
w[0], l[0],
w[1], l[1],
l[2]))
if __name__ == "__main__":