iTranslated by AI
Black Box Debugging
Introduction
When we talk about debugging, using a debugger or inserting print statements is common. However, in reality, there are environments where you must debug without such methods.
For example, my job is LSI design, and naturally, I cannot see the inside of a manufactured LSI while it is running. If some kind of defect occurs, I have to debug it without observing the internal state.
Following the term "black box testing," I will call this debugging approach "black box debugging" here. Black box debugging is not an LSI-specific technique. Even in software, for instance, attaching a debugger or inserting print statements can change the state and cause a bug to no longer reproduce. Also, in large-scale network infrastructure debugging, the target might be too massive to practically observe the details in depth.
This kind of black box debugging often feels like a "traditional art" passed down within specific departments or a set of patterns individuals have developed through years of experience (likely because it requires strong domain-specific knowledge). Nonetheless, I believe there are parts that can be generalized and shared, so I have summarized my thoughts on black box debugging methods.
Methods of Black Box Debugging
In black box debugging, you provide inputs to the target and estimate the cause of the output deviating from the expected value based solely on those input-output pairs.
Below, I will explain what I consider a typical debugging flow. In practice, however, you narrow down the debugging scope by repeating these steps many times.
Gathering Information
Since knowing "a bug was found in a single pair of input and output" tells us very little, the first step is to increase the amount of information. For instance, whether that input-output pair is reproducible is extremely important. There is a huge difference between it happening every time with that specific input versus it happening probabilistically for any input. Also, while we computer engineers tend to focus on digital input values, we also need to vary analog inputs. In the case of LSIs, typical factors include power supply voltage and operating frequency, but even in software, factors like the speed, interval, or timing of inputs may be relevant.
Finding Patterns
Next, you look at the collected information and consider whether there are any regularities. For example, if it only occurs with specific input values, it is quite straightforward, but if it occurs probabilistically, you might take a large amount of data to find differences in the probability of occurrence. Time-series patterns are also possible. For instance, it might happen periodically when the same input is continuously provided, or only when a specific sequence of inputs is provided consecutively.
Forming Hypotheses
Once you find a pattern, you form a hypothesis that can explain it. In other words, a hypothesis such as "if such a phenomenon is occurring internally, it could result in this kind of input-output pair."
This is the part that requires the most knowledge of the target and its surroundings. For LSIs, this would be the analog behavior of semiconductors or board transmission lines; for software, it would be the behavior of the OS, compiler, processor, or network. The more knowledge and experience you have, the more hypotheses you can formulate.
At this stage, it is better to consider simpler hypotheses first. Assuming that a certain level of quality is maintained in the target, the actual number of bugs should be small. Therefore, even if the pattern of input-output pairs indicates a complex phenomenon, it is more likely that a single bug is causing a complex chain of events rather than multiple bugs being intertwined.
Verifying Hypotheses
A hypothesis is just a hypothesis, so it must be verified. Specifically, you generate inputs that are expected to trigger the bug based on that hypothesis and confirm whether you can cause the bug to occur as intended.
Simply succeeding in reproducing the bug with one pattern is not enough to rule out the possibility that it was a coincidental result of another cause, so you should test various patterns to reinforce the hypothesis.
In the end, as long as you cannot directly observe the internal state, you can never be 100% certain, but it is possible to increase the level of confidence through verification.
Supplementary: Reliability of Information
This is not strictly a technique for black box debugging, but I will mention it as a related topic.
In black box debugging, you can only observe the output, which raises the question: are these observed values truly reliable?
In LSIs, I/O can become unreliable particularly due to power-related issues, and even in software—specifically in low-level or embedded systems—there are cases where the output of print statements themselves cannot be trusted.
As with hypothesis testing, 100% certainty is difficult to achieve, but you can increase the level of confidence by, for example, comparing results from multiple output paths or by confirming that the output is valid during a normal state where the bug is not occurring.
Of course, this doesn't exclude the possibility that the output becomes abnormal only when the bug occurs, and there are situations where you have to go as far as doubting that when the cause remains elusive.
However, at the end of the day, if you can't trust the values you observe, you're at a standstill. The practical approach is to establish a certain level of confidence early on and then proceed as if they are reliable.
Concrete Example
Let’s illustrate this with a specific example. Suppose you are debugging a video signal processing LSI for televisions and you encounter the following phenomenon:
While viewing the output video from the LSI on a TV, the screen display occasionally malfunctions.
It is probably not widely known, but engineers who develop video signal processing LSIs will use a stopwatch to measure the intervals between these malfunctions.
(This is exactly the kind of "traditional art" passed down within specific departments...)
Suppose the measurement shows that the malfunctions occur every 463.2 seconds. Since it is impossible to measure with sub-second precision in a single go, you would need to measure multiple times and take the average to improve accuracy.
Now, the clock frequency supplied to the LSI is 148.35 MHz (a common value in video signals). Converting 463.2 seconds into the number of clock cycles:
463.2 * 148.35 * 10^6 = 68,715,720,000
By the way, 2^36 = 68,719,476,736. In other words, the problem occurs roughly every 2^36 clock cycles.
Just like loop variables in software, LSIs often contain counters that track the current clock cycle. The period for a 36-bit counter to overflow and return to zero is exactly 2^36 clock cycles. This means that if you search for where a 36-bit counter is located within the entire LSI, you might get closer to the cause of the bug.
Of course, in reality, it is rare for bugs to be so easily narrowed down. Such debugging might continue for a week to several months before you finally reach the cause (if you're lucky).
Conclusion
I have written about my thoughts on black box debugging. While I assumed a case where the target is a complete black box here, I believe there are parts that can be applied to normal software debugging as well.
For instance, even when doing print debugging, you wouldn't randomly insert print statements into the entire source code; you would likely narrow down the suspected area first. This process of "narrowing it down" corresponds exactly to the hypothesis-forming part I explained above.
In environments like LSI design where black box debugging is the norm, you are almost forcibly trained in these techniques, but keeping them in mind during regular debugging might also help improve your debugging efficiency.
Discussion