diff options
author | Robert Mustacchi <rm@fingolfin.org> | 2021-11-20 06:30:38 +0000 |
---|---|---|
committer | Robert Mustacchi <rm@fingolfin.org> | 2022-01-15 00:41:16 +0000 |
commit | f32691c936d40863e9f2c96ce452c6208bd056f2 (patch) | |
tree | 2f4afdbf7bb34c7b867ebd1db07cdcc52319f21c /usr/src | |
parent | fff59a0859385717fd41a0edf704de81c340ad00 (diff) | |
download | illumos-gate-f32691c936d40863e9f2c96ce452c6208bd056f2.tar.gz |
14269 mdb could support separators in numbers
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Andy Fiddaman <andy@omnios.org>
Approved by: Rich Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src')
16 files changed, 330 insertions, 22 deletions
diff --git a/usr/src/cmd/mdb/common/mdb/mdb_lex.l b/usr/src/cmd/mdb/common/mdb/mdb_lex.l index 7723f00f9e..0e8af790e1 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_lex.l +++ b/usr/src/cmd/mdb/common/mdb/mdb_lex.l @@ -29,6 +29,7 @@ * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2017 by Delphix. All rights reserved. * Copyright 2019, Joyent, Inc. + * Copyright 2021 Oxide Computer Company */ #include <sys/types.h> @@ -122,7 +123,7 @@ RGX_COMMENT "//".*\n * Comments are legal in these three states -- if we see one * eat the line and return the newline character. */ - BEGIN(S_INITIAL); + BEGIN(S_INITIAL); return ('\n'); } @@ -247,7 +248,7 @@ RGX_COMMENT "//".*\n <S_INITIAL>'{RGX_CHR_SEQ}$ | <S_EXPR>'{RGX_CHR_SEQ}$ yyerror("syntax error: ' unmatched"); -<S_INITIAL>'{RGX_CHR_SEQ}' | +<S_INITIAL>'{RGX_CHR_SEQ}' | <S_EXPR>'{RGX_CHR_SEQ}' { char *s, *p, *q; size_t nbytes; @@ -415,8 +416,8 @@ RGX_COMMENT "//".*\n yyerror("invalid cast -- %s\n", yytext); } -<S_INITIAL>0[iI][0-1]+ | -<S_EXPR>0[iI][0-1]+ { +<S_INITIAL>0[iI][0-1][0-1_]* | +<S_EXPR>0[iI][0-1][0-1_]* { /* * Binary immediate value. */ @@ -424,8 +425,8 @@ RGX_COMMENT "//".*\n return (MDB_TOK_IMMEDIATE); } -<S_INITIAL>0[oO][0-7]+ | -<S_EXPR>0[oO][0-7]+ { +<S_INITIAL>0[oO][0-7][0-7_]* | +<S_EXPR>0[oO][0-7][0-7_]* { /* * Octal immediate value. */ @@ -433,8 +434,8 @@ RGX_COMMENT "//".*\n return (MDB_TOK_IMMEDIATE); } -<S_INITIAL>0[tT][0-9]+"."[0-9]+ | -<S_EXPR>0[tT][0-9]+"."[0-9]+ { +<S_INITIAL>0[tT][0-9][0-9_]*"."[0-9][0-9_]* | +<S_EXPR>0[tT][0-9][0-9_]*"."[0-9][0-9_]* { #ifdef _KMDB yyerror("floating point not supported\n"); #else @@ -450,8 +451,14 @@ RGX_COMMENT "//".*\n d = (double)mdb_strtonum(yytext + 2, 10); - for (i = 0; (c = *p++) != '\0'; i++) + i = 0; + while (*p != '\0') { + c = *p++; + if (c == '_') + continue; d = d * 10 + c - '0'; + i++; + } while (i-- != 0) d /= 10; @@ -461,8 +468,8 @@ RGX_COMMENT "//".*\n #endif } -<S_INITIAL>0[tT][0-9]+ | -<S_EXPR>0[tT][0-9]+ { +<S_INITIAL>0[tT][0-9][0-9_]* | +<S_EXPR>0[tT][0-9][0-9_]* { /* * Decimal immediate value. */ @@ -470,8 +477,8 @@ RGX_COMMENT "//".*\n return (MDB_TOK_IMMEDIATE); } -<S_INITIAL>0[xX][0-9a-fA-F]+ | -<S_EXPR>0[xX][0-9a-fA-F]+ { +<S_INITIAL>0[xX][0-9a-fA-F][0-9a-fA-F_]* | +<S_EXPR>0[xX][0-9a-fA-F][0-9a-fA-F_]* { /* * Hexadecimal value. */ @@ -479,8 +486,8 @@ RGX_COMMENT "//".*\n return (MDB_TOK_IMMEDIATE); } -<S_INITIAL>[0-9a-fA-F]+ | -<S_EXPR>[0-9a-fA-F]+ { +<S_INITIAL>[0-9a-fA-F][0-9a-fA-F_]* | +<S_EXPR>[0-9a-fA-F][0-9a-fA-F_]* { GElf_Sym sym; /* * Immediate values without an explicit base are converted @@ -538,7 +545,7 @@ yydiscard(void) int c; /* - * If stdin is a string, pipeline, or tty, throw away all our buffered + * If stdin is a string, pipeline, or tty, throw away all our buffered * data. Otherwise discard characters up to the next likely delimiter. */ if (mdb_iob_isastr(mdb.m_in) || mdb_iob_isatty(mdb.m_in) || @@ -762,7 +769,7 @@ typedef struct mdb_lex_state { int yyprevious; void *yybgin; /* Variables needed by yyparse */ - void *yypv; + void *yypv; int *yyps; int yytmp; int yystate; @@ -775,7 +782,7 @@ typedef struct mdb_lex_state { YYSTYPE yyv[YYMAXDEPTH]; } mdb_lex_state_t; -void +void mdb_lex_state_save(mdb_lex_state_t *s) { ASSERT(s != NULL); @@ -802,7 +809,7 @@ mdb_lex_state_save(mdb_lex_state_t *s) s->yyval = yyval; } -void +void mdb_lex_state_restore(mdb_lex_state_t *s) { ASSERT(s != NULL); diff --git a/usr/src/cmd/mdb/common/mdb/mdb_string.c b/usr/src/cmd/mdb/common/mdb/mdb_string.c index fbcfe82755..f6fca77046 100644 --- a/usr/src/cmd/mdb/common/mdb/mdb_string.c +++ b/usr/src/cmd/mdb/common/mdb/mdb_string.c @@ -22,6 +22,7 @@ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * Copyright 2021 Oxide Computer Company */ #include <netinet/in.h> @@ -132,6 +133,9 @@ mdb_strtonum(const char *s, int base) if (val > multmax) goto oflow; + if (c == '_') + continue; + if ((i = CTOI(c)) >= base) yyerror("digit '%c' is invalid in current base\n", c); diff --git a/usr/src/pkg/manifests/system-test-utiltest.p5m b/usr/src/pkg/manifests/system-test-utiltest.p5m index e1156d322f..8a6d398e4d 100644 --- a/usr/src/pkg/manifests/system-test-utiltest.p5m +++ b/usr/src/pkg/manifests/system-test-utiltest.p5m @@ -1607,9 +1607,22 @@ file path=opt/util-tests/tests/mdb/format/tst.format-j.mdb.out mode=0444 file path=opt/util-tests/tests/mdb/format/tst.format-p.mdb mode=0444 file path=opt/util-tests/tests/mdb/format/tst.format-p.mdb.out mode=0444 file path=opt/util-tests/tests/mdb/mdbtest mode=0555 +dir path=opt/util-tests/tests/mdb/numbers +file path=opt/util-tests/tests/mdb/numbers/tst.badnums.ksh mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.base10.mdb mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.base10.mdb.out mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.binary.mdb mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.binary.mdb.out mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.hex.mdb mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.hex.mdb.out mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.octal.mdb mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.octal.mdb.out mode=0444 +file path=opt/util-tests/tests/mdb/numbers/tst.prefsym.ksh mode=0444 dir path=opt/util-tests/tests/mdb/options file path=opt/util-tests/tests/mdb/options/tst.autowrap.mdb mode=0444 file path=opt/util-tests/tests/mdb/options/tst.autowrap.mdb.out mode=0444 +dir path=opt/util-tests/tests/mdb/progs +file path=opt/util-tests/tests/mdb/progs/number_symbol mode=0555 dir path=opt/util-tests/tests/mdb/typedef file path=opt/util-tests/tests/mdb/typedef/err.badid-leadnum.ksh mode=0444 file path=opt/util-tests/tests/mdb/typedef/err.badid-leadschar.ksh mode=0444 diff --git a/usr/src/test/util-tests/tests/mdb/Makefile b/usr/src/test/util-tests/tests/mdb/Makefile index d7d205bc82..fbf4c74e57 100644 --- a/usr/src/test/util-tests/tests/mdb/Makefile +++ b/usr/src/test/util-tests/tests/mdb/Makefile @@ -11,6 +11,7 @@ # # Copyright 2020 Joyent, Inc. +# Copyright 2021 Oxide Computer Company # include $(SRC)/cmd/Makefile.cmd @@ -19,6 +20,7 @@ include $(SRC)/test/Makefile.com ROOTOPTPKG = $(ROOT)/opt/util-tests TESTDIR = $(ROOTOPTPKG)/tests/mdb +SUBDIRS = progs PROG = mdbtest ROOTPROG = $(PROG:%=$(TESTDIR)/%) @@ -27,6 +29,7 @@ MAKEDIRS = \ exit-e \ format \ options \ + numbers \ typedef FILES = \ @@ -55,6 +58,16 @@ FILES = \ format/tst.format-j.mdb.out \ format/tst.format-p.mdb \ format/tst.format-p.mdb.out \ + numbers/tst.badnums.ksh \ + numbers/tst.base10.mdb \ + numbers/tst.base10.mdb.out \ + numbers/tst.binary.mdb \ + numbers/tst.binary.mdb.out \ + numbers/tst.hex.mdb \ + numbers/tst.hex.mdb.out \ + numbers/tst.octal.mdb \ + numbers/tst.octal.mdb.out \ + numbers/tst.prefsym.ksh \ options/tst.autowrap.mdb \ options/tst.autowrap.mdb.out \ typedef/err.badid-leadnum.ksh \ @@ -112,11 +125,17 @@ FILEMODE = 0444 $(TESTDIR)/mdbtest := FILEMODE = 0555 -all: -install: all $(ROOTFILES) $(ROOTPROG) +all := TARGET = all +install := TARGET = install +clean := TARGET = clean +clobber := TARGET = clobber -clean clobber: +all: $(SUBDIRS) + +install: all $(ROOTFILES) $(ROOTPROG) $(SUBDIRS) + +clean clobber: $(SUBDIRS) $(ROOTFILES): $(TESTDIR) $(ROOTMAKEDIRS) $(FILES) @@ -125,3 +144,6 @@ $(TESTDIR) $(ROOTMAKEDIRS): $(TESTDIR)/%: % $(INS.file) + +$(SUBDIRS): FRC + cd $@; pwd; $(MAKE) $(TARGET) diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.badnums.ksh b/usr/src/test/util-tests/tests/mdb/numbers/tst.badnums.ksh new file mode 100644 index 0000000000..34c4d12eac --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.badnums.ksh @@ -0,0 +1,48 @@ +#!/usr/bin/ksh +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2021 Oxide Computer Company +# + +ERR=0 + +function bad_num +{ + if $MDB -e $*; then + print -u2 "TEST FAILED: $*" + ERR=1 + else + print "TEST PASSED: $*" + fi +} + +bad_num "0x_123=E" +bad_num "0xzasdf=K" +bad_num "0x1__p=K" +bad_num "0i_=K" +bad_num "0i__011=K" +bad_num "0i12345=K" +bad_num "0i0____3=K" +bad_num "0t34___asdf=K" +bad_num "0t_4=K" +bad_num "0tp=K" +bad_num "0tp__4=K" +bad_num "0t4______p=K" +bad_num "0o89=K" +bad_num "0o7____89=K" +bad_num "0o__324=K" +bad_num "0x123456789abcdef123456789abcdef=K" +bad_num "0x12___345678___9abcdef123456789_a_bcdef=K" + +exit $ERR diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb b/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb new file mode 100644 index 0000000000..75411b5b26 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb @@ -0,0 +1,6 @@ +0t23_24_25_26=E +0t123456=K +0t1________2_____________________3 = E +0t10$d +555_5555 = E +44_44_44_44_ = E diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb.out b/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb.out new file mode 100644 index 0000000000..c2d35f86f0 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.base10.mdb.out @@ -0,0 +1,6 @@ + 23242526 + 1e240 + 123 +radix = 10 base ten + 5555555 + 44444444 diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb b/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb new file mode 100644 index 0000000000..5d74bc1300 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb @@ -0,0 +1,6 @@ +0i100_0111=K +0i11_101=j +0i1__1__0______=X +0t2$d +100_0001__0001=K +1_____________0=K diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb.out b/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb.out new file mode 100644 index 0000000000..9758df6149 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.binary.mdb.out @@ -0,0 +1,11 @@ + 47 + 11101 + ||| | + ||| +-- bit 0 mask 0x01 + ||+---- bit 2 mask 0x04 + |+----- bit 3 mask 0x08 + +------ bit 4 mask 0x10 + 6 +radix = 2 base ten + 411 + 2 diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb b/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb new file mode 100644 index 0000000000..1439964700 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb @@ -0,0 +1,7 @@ +0x123456789abcdef=K +0x123____456_789___abcd__ef=K +0x1_2_3_4_5_6_7_8_9_a_b_c_d_e_f____=K +0t16$d +badcafe=K +bad___cafe=K +bad___ca_fe=E diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb.out b/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb.out new file mode 100644 index 0000000000..58af8785c5 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.hex.mdb.out @@ -0,0 +1,7 @@ + 123456789abcdef + 123456789abcdef + 123456789abcdef +radix = 16 base ten + badcafe + badcafe + 195939070 diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb b/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb new file mode 100644 index 0000000000..b1522a2084 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb @@ -0,0 +1,6 @@ +0o775=K +0o7_7_5__=K +0o7______=K +0t8$d +0123_____456=K +000000___________1=K diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb.out b/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb.out new file mode 100644 index 0000000000..966ae6d2f3 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.octal.mdb.out @@ -0,0 +1,6 @@ + 1fd + 1fd + 7 +radix = 8 base ten + a72e + 1 diff --git a/usr/src/test/util-tests/tests/mdb/numbers/tst.prefsym.ksh b/usr/src/test/util-tests/tests/mdb/numbers/tst.prefsym.ksh new file mode 100644 index 0000000000..005413e264 --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/numbers/tst.prefsym.ksh @@ -0,0 +1,75 @@ +#!/usr/bin/ksh +# +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2021 Oxide Computer Company +# + +# +# This test is trying to ensure that mdb still respects symbols over +# numbers that look similar. +# + +set -o pipefail + +tst_root="$(dirname $0)/.." +tst_prog="$tst_root/progs/number_symbol" +tst_sym0="ffffabcde00" +tst_sym1="ffffab_cde00" +tst_sym2="_007" +tst_out= +tst_err=0 + +$MDB -e "$tst_sym0=K" $tst_prog | grep -q "$tst_sym0" +if (( $? == 0 )); then + printf >&2 "%s=K somehow returned itself, did it become a number?\n" \ + "$tst_sym0" +fi + +$MDB -e "$tst_sym0/K | ::eval ./s" $tst_prog | grep -q 'Am I a string?' +if (( $? != 0 )); then + printf >&2 "Failed to find expected output for %s\n" "$tst_sym0" + tst_err=1 +fi + +# +# We grep against tst_sym0 as if mdb does interpret this as a number, +# then it'll show it without the '_' characters. +# +$MDB -e "$tst_sym1=K" $tst_prog | grep -q "$tst_sym0" +if (( $? == 0 )); then + printf >&2 "%s=K somehow returned itself, did it become a number?\n" \ + "$tst_sym0" + tst_err=1 +fi + +$MDB -e "$tst_sym1/K | ::eval ./s" $tst_prog | grep -q 'I am not a string' +if (( $? != 0 )); then + printf >&2 "Failed to find expected output for %s\n" "$tst_sym1" + tst_err=1 +fi + +$MDB -e "$tst_sym2=K" $tst_prog | grep -q "$tst_sym2" +if (( $? == 0 )); then + printf >&2 "%s=K somehow returned itself, did it become a number?\n" \ + "$tst_sym2" + tst_err=1 +fi + +$MDB -e "$tst_sym2::dis" $tst_prog | egrep -qi '^_007:' +if (( $? != 0 )); then + printf >&2 "Failed to find expected output for %s::dis\n" "$tst_sym2" + tst_err=1 +fi + +exit $tst_err diff --git a/usr/src/test/util-tests/tests/mdb/progs/Makefile b/usr/src/test/util-tests/tests/mdb/progs/Makefile new file mode 100644 index 0000000000..cb28d80f2b --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/progs/Makefile @@ -0,0 +1,47 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2021 Oxide Computer Company +# + +include $(SRC)/Makefile.master + +ROOTOPTPKG = $(ROOT)/opt/util-tests +TESTDIR = $(ROOTOPTPKG)/tests/mdb/progs +PROGS = number_symbol + +include $(SRC)/cmd/Makefile.cmd +include $(SRC)/test/Makefile.com + +CMDS = $(PROGS:%=$(TESTDIR)/%) +$(CMDS) := FILEMODE = 0555 + +all: $(PROGS) + +install: all $(CMDS) $(OUTFILES) + +clobber: clean + -$(RM) $(PROGS) + +clean: + +$(CMDS): $(TESTDIR) $(PROG) + +$(TESTDIR): + $(INS.dir) + +$(TESTDIR)/%: % + $(INS.file) + +%: %.c + $(LINK.c) -o $@ $< $(LDLIBS) + $(POST_PROCESS) diff --git a/usr/src/test/util-tests/tests/mdb/progs/number_symbol.c b/usr/src/test/util-tests/tests/mdb/progs/number_symbol.c new file mode 100644 index 0000000000..0efa7600af --- /dev/null +++ b/usr/src/test/util-tests/tests/mdb/progs/number_symbol.c @@ -0,0 +1,37 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2021 Oxide Computer Company + */ + +/* + * This C program has a few symbols whose goal it is to try and make sure mdb + * prints instead of interpretting it as a number. + */ + +#include <stdio.h> + +const char *ffffabcde00 = "Am I a string?"; +const char *ffffab_cde00 = "I am not a string"; + +int +_007(void) +{ + return (7); +} + +int +main(void) +{ + printf("%s", ffffabcde00); + return (_007()); +} |