sed-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"sed --debug" feature


From: Assaf Gordon
Subject: "sed --debug" feature
Date: Fri, 27 Jul 2018 04:28:52 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

Hi all,

While investigating the two recent bugs [1][2],
I developed some debugging code for sed, which makes
troubleshooting much easier.

[1] https://lists.gnu.org/r/bug-sed/2018-07/msg00004.html
[2] https://lists.gnu.org/r/bug-sed/2018-07/msg00018.html

First,
It turns cryptic code into more readable sed code:

  $ cat bug32271.sed
  s0^004
  s5505
  s5505
  s5505
  s5505
  N
  W0
  s5$55M
  s55550
  s55550
  s5555
  D

  $ ./sed/sed --debug -f bug32271.sed
  SED PROGRAM:
  s/^//4
  s//0/
  s//0/
  s//0/
  s//0/
  N
  W0
  s/$//m
  s///50
  s///50
  s///5
  D

and

  $ cat bug32082.sed
  10s11\91
  \0^0s1011
  \00a
  \0^0s111w0

  $ ./sed/sed --debug -f bug32082.sed
  SED PROGRAM:
  10 s//\9/
  /^/ s/0//
  // a\

  /^/ s///w0



Second, it also traces step-by-step each command
while printing the pattern/hold buffers:

  $ seq 5 | sed --debug 'N;s/3/X/'
  SED PROGRAM:
  N
  s/3/X/
  INPUT:   STDIN line 1
  PATTERN: 1
  COMMAND: N
  PATTERN: 1\n2
  COMMAND: s/3/X/
  PATTERN: 1\n2
  END-OF-CYCLE:
  1
  2
  INPUT:   STDIN line 3
  PATTERN: 3
  COMMAND: N
  PATTERN: 3\n4
  COMMAND: s/3/X/
  PATTERN: X\n4
  END-OF-CYCLE:
  X
  4
  INPUT:   STDIN line 5
  PATTERN: 5
  COMMAND: N
  END-OF-CYCLE:
  5


I'm not sure this should go into mainline sed (too specialized and border-line bloat), but I thought to share it here for future reference.

comments welcomed,
 - assaf

Attachment: 0001-sed-add-debug-feature-work-in-progress.patch.gz
Description: application/gzip


reply via email to

[Prev in Thread] Current Thread [Next in Thread]