Page MenuHomeFreeBSD

ddb(4): Enhance functionality for specialized ddb commands
ClosedPublic

Authored by cem on Aug 28 2019, 10:06 PM.

Details

Summary

The CS_LEX_SPACE command flag causes explicit tWSPACE tokens to be yielded,
instead of silently consuming whitespace between other tokens. This can be
useful for whitespace-sensitive CS_OWN commands.

The db_cmd_radix variable is exposed for commands to explicitly set a radix
for use during db_lex() tNUMBER lexing. This overrides the user-specific
db_radix as well as any auto-sensing.

Both of these additions are scoped to the specific command and reset on
return. Commands cannot themselves scope flags like this because a trap may
abort them prior to cleanup; and a lot of ddb(4) lexing state and options
are global.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

cem created this revision.Aug 28 2019, 10:06 PM
cem added a comment.Sep 3 2019, 5:24 PM

I'd like to go ahead and commit this one independent of netdump/debugnet/netgdb, actually, because I have other lexer extensions and ddb commands orthogonal to netdump/debugnet that stack on this. Can I get some eyeballs on this review, please?

markj accepted this revision.Sep 3 2019, 8:45 PM

This looks fine to me.

Is there some reason it isn't easy to add a variant of db_read_token() that will optionally return tWSPACE and can take a caller-supplied radix? That would seem cleaner than adding more global state.

This revision is now accepted and ready to land.Sep 3 2019, 8:45 PM
cem planned changes to this revision.Sep 3 2019, 10:48 PM

Is there some reason it isn't easy to add a variant of db_read_token() that will optionally return tWSPACE and can take a caller-supplied radix? That would seem cleaner than adding more global state.

I don't know any reason that wouldn't be possible off-hand. That does seem like a better idea — thanks.

In fact, it seems plausible to do the same for basically all of my db lexer changes. No?

The only tricky one is radix, but ddb only really supports base 8, 10, and 16, so that could just be two flag bits.

So I'd propose something like this:

#define DRT_RADIX_MASK 0x3
enum {
  _DRT_WSPACE = 2,
  _DRT_HEX = 3,
};
enum db_read_token_flags {
  DRT_WSPACE = BIT(_DRT_WSPACE),
  DRT_HEX = BIT(_DRT_HEX),
};
enum db_read_token_radices {
  DRT_DEFAULT_RADIX = 0,
  DRT_OCTAL,
  DRT_DECIMAL,
  DRT_HEXADECIMAL,
};

int db_read_token(void)
{
    db_read_token_flags(DRT_DEFAULT_RADIX);  // or just zero
}

int db_read_token_flags(int flags)
{
  ...
}
cem updated this revision to Diff 61630.Sep 4 2019, 12:23 AM

Switch from globals to per-lex flags.

markj accepted this revision.Sep 8 2019, 3:57 PM

Sorry for the delay.

sys/ddb/db_lex.h
80 ↗(On Diff #61630)

Style: the function name should appear on a new line.

This revision is now accepted and ready to land.Sep 8 2019, 3:57 PM
This revision was automatically updated to reflect the committed changes.
cem marked an inline comment as done.