add debug pretty-printing for sync record status flags as well

This commit is contained in:
Oswald Buddenhagen 2021-12-23 17:43:59 +01:00
parent c902f69c6f
commit 17db5de0ca
4 changed files with 61 additions and 6 deletions

View File

@ -18,22 +18,33 @@ while (<>) {
$conts =~ s/\s//g; $conts =~ s/\s//g;
$conts =~ s/,$//; $conts =~ s/,$//;
my @vals = split(/,/, $conts); my @vals = split(/,/, $conts);
my $pfx; my ($pfx, $pfx1);
for my $e (@vals) { for my $e (@vals) {
if (!defined($pfx)) { if (!defined($pfx)) {
$pfx = ($e =~ /^([A-Z]+_)/) ? $1 : ""; $pfx1 = $pfx = ($e =~ /^([A-Z]+_)/) ? $1 : "";
} elsif (length($pfx)) { } elsif (length($pfx)) {
$pfx = "" if ((($e =~ /^([A-Z]+_)/) ? $1 : "") ne $pfx); $pfx = "" if ((($e =~ /^([A-Z]+_)/) ? $1 : "") ne $pfx);
} }
} }
my $bit = 1; my $bit = 1;
my $bitn = 0; my $bitn = 0;
my (@names, @nameos);
my $nameo = 0;
for my $e (@vals) { for my $e (@vals) {
my $bits = ($e =~ s/\((\d+)\)$//) ? $1 : 1; my $bits = ($e =~ s/\((\d+)\)$//) ? $1 : 1;
my $n = substr($e, length($pfx));
if ($bits != 1) { if ($bits != 1) {
die("Unsupported field size $bits\n") if ($bits != 2);
print "#define $e(b) ($bit << (b))\n"; print "#define $e(b) ($bit << (b))\n";
push @names, "F-".$n, "N-".$n;
my $nl = length($n) + 3;
push @nameos, $nameo, $nameo + $nl;
$nameo += $nl * 2;
} else { } else {
print "#define $e $bit\n"; print "#define $e $bit\n";
push @names, $n;
push @nameos, $nameo;
$nameo += length($n) + 1;
} }
$bit <<= $bits; $bit <<= $bits;
$bitn += $bits; $bitn += $bits;
@ -41,6 +52,10 @@ while (<>) {
if (length($pfx)) { if (length($pfx)) {
print "#define ${pfx}_NUM_BITS $bitn\n"; print "#define ${pfx}_NUM_BITS $bitn\n";
} }
if (length($pfx1)) {
print "#define ${pfx1}_STRINGS \"".join("\\0", @names)."\"\n";
print "#define ${pfx1}_OFFSETS ".join(", ", @nameos)."\n";
}
print "\n"; print "\n";
$in_enum = 0; $in_enum = 0;
} else { } else {

View File

@ -193,6 +193,30 @@ int equals( const char *str, int strl, const char *cmp, uint cmpl );
time_t timegm( struct tm *tm ); time_t timegm( struct tm *tm );
#endif #endif
void fmt_bits( uint bits, uint num_bits, const char *bit_str, const int *bit_off, char *buf );
#define BIT_FORMATTER_RET(name, pfx) \
struct name##_str { char str[sizeof(pfx##__STRINGS)]; };
#define BIT_FORMATTER_PROTO(name, pfx, storage) \
storage struct name##_str ATTR_OPTIMIZE /* force RVO */ \
fmt_##name( uint bits )
#define BIT_FORMATTER_IMPL(name, pfx, storage) \
BIT_FORMATTER_PROTO(name, pfx, storage) \
{ \
static const char strings[] = pfx##__STRINGS; \
static const int offsets[] = { pfx##__OFFSETS }; \
\
struct name##_str buf; \
fmt_bits( bits, as(offsets), strings, offsets, buf.str ); \
return buf; \
}
#define BIT_FORMATTER_FUNCTION(name, pfx) \
BIT_FORMATTER_RET(name, pfx) \
BIT_FORMATTER_IMPL(name, pfx, static)
void *nfmalloc( size_t sz ); void *nfmalloc( size_t sz );
void *nfzalloc( size_t sz ); void *nfzalloc( size_t sz );
void *nfrealloc( void *mem, size_t sz ); void *nfrealloc( void *mem, size_t sz );

View File

@ -17,6 +17,8 @@
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" }; const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
BIT_FORMATTER_FUNCTION(sts, S)
static char * static char *
clean_strdup( const char *s ) clean_strdup( const char *s )
{ {
@ -208,9 +210,8 @@ load_state( sync_vars_t *svars )
srec->status = S_SKIPPED; srec->status = S_SKIPPED;
} }
srec->flags = parse_flags( s ); srec->flags = parse_flags( s );
debug( " entry (%u,%u,%s,%s%s)\n", srec->uid[F], srec->uid[N], fmt_flags( srec->flags ).str, debug( " entry (%u,%u,%s,%s)\n", srec->uid[F], srec->uid[N],
(srec->status & S_SKIPPED) ? "SKIP" : (srec->status & S_EXPIRED) ? "XPIRE" : "", fmt_flags( srec->flags ).str, fmt_sts( srec->status ).str );
(srec->status & S_DUMMY(F)) ? ",F-DUMMY" : (srec->status & S_DUMMY(N)) ? ",N-DUMMY" : "" );
*svars->srecadd = srec; *svars->srecadd = srec;
svars->srecadd = &srec->next; svars->srecadd = &srec->next;
svars->nsrecs++; svars->nsrecs++;
@ -384,7 +385,7 @@ load_state( sync_vars_t *svars )
srec->status = (srec->status & ~S_LOGGED) | t3; srec->status = (srec->status & ~S_LOGGED) | t3;
if ((srec->status & S_EXPIRED) && svars->maxxfuid < srec->uid[F]) if ((srec->status & S_EXPIRED) && svars->maxxfuid < srec->uid[F])
svars->maxxfuid = srec->uid[F]; svars->maxxfuid = srec->uid[F];
debug( "status now %#x\n", srec->status ); debug( "status now %s\n", fmt_sts( srec->status ).str );
break; break;
case '_': case '_':
debug( "has placeholder now\n" ); debug( "has placeholder now\n" );

View File

@ -378,6 +378,21 @@ timegm( struct tm *t )
} }
#endif #endif
void
fmt_bits( uint bits, uint num_bits, const char *bit_str, const int *bit_off, char *buf )
{
uint d = 0;
for (uint i = 0, val = 1; i < num_bits; i++, val <<= 1) {
if (bits & val) {
if (d)
buf[d++] = ',';
for (const char *s = bit_str + bit_off[i]; *s; s++)
buf[d++] = *s;
}
}
buf[d] = 0;
}
void void
oob( void ) oob( void )
{ {