Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Andrew Koenig

Dr. Dobb's Bloggers

Are You Sure You Know What's Broken?

December 19, 2012

Last week, I described a bug in a multipass compiler in which:

  • One of the compiler's passes would sometimes — but not always — complain about spurious characters in the input that it had obtained from the previous pass.
  • It was possible to capture the file that the previous pass produced for this pass as input.
  • When I did so, and ran the failing compiler pass on the captured file, it would always work.

More Insights

White Papers

More >>


More >>


More >>

I invited readers to speculate about what might cause such a state of affairs, and got a number of interesting comments. In fact, several of these comments are closely related to what turned out to be the actual problem, as we shall see.

Let me simplify the description of the situation by calling the two compiler passes A and B. What I had learned was:

  • If I run A and send its output to B, it sometimes fails.
  • If I run A, capture its output, and run B with the captured file as its input, B always succeeds.

One reader speculated that the problem must be in how the file is being passed from A to B, and that's what I thought, too. However, when I looked at what was happening, the framework around the compiler was doing exactly the same thing that I was doing: Run A with its output directed to a temporary file, then run B with its input coming from the temporary file.

After thinking about this situation for a long time, I realized that there was one crucial difference between how the compiler was normally run and how I ran it when I was trying to provoke a failure:

When the compiler ran normally, phase A ran afresh every time; when I captured the output and ran phase B with the captured file, I ran A only once and then ran B repeatedly.

What if I was looking in the wrong place? That is, what if the problem was not that B was behaving differently with the same input, but rather that A was sometimes producing different output? Such questions are easy to answer once asked: I wrote a shell script to run A repeatedly and compare its output each time with that from the previous run.

Sure enough, once in a while, compiler phase A would produce different output from what it normally produced. Moreover, that difference was that occasional characters would be replaced by zero characters. Not a byte with all bits zero, but the ASCII representation of the digit 0.

What I had just learned was that regardless of what might or might not be wrong with phase B, there was something wrong with phase A — and until I found that problem, there was no point in looking further at phase B. More generally, when a program occasionally produces different output from the same input, maybe you're mistaken about it being the same input.

Of course, I now had to figure out why phase A occasionally produced output with spurious characters in it. Next week, I'll reveal more details about what I learned.

Related Reading

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.