How to create good debugging problems to enter the competition?

I participate in the competition, and in one case we have debugging issues. I have to develop some really good debugging problems in C and C ++.

How can I create good debugging problems? What aspects should be considered when developing problems?

+4
source share
6 answers

My brainstorming session:

Fine sorting memory leaks are always enjoyable. Worry with classes, constructors, copy constructors, and destructors, and you should easily create a complex task.

Single errors for array loops are also classic.

Then you can just mess with the minds of readers by playing with the names of things. Create variables with subtly different names, variables with random (and slightly different) names, etc., and then let them try to determine the place where you mixed up length and lenght . Do not forget about the differences in the case.

Call conventions can be used to create subtle errors (for example, changing the order of parameters).

Also, don’t forget about the endless hours of pleasure from complex preprocessor options and templates (did you know that C ++ templates are supposedly filled by Turing?) Metaprogramming errors should be interesting.

The next idea that comes to mind is to provide the right program, but erroneous input (subtle, of course). After that, the program will crash if there is no error checking, but there will be some time until people realize that they are looking for problems in the wrong place.

Race conditions are often difficult to reproduce and fix, try playing with multi-threaded.

Under streams / overflows you can easily skip random checking.

And last but not least, if you are a programmer, try to recall what was the last big problem you spent two weeks solving. If you are not a programmer, try to find it and ask. I am a .NET programmer, so, unfortunately, my impressions have little to do with your C / C ++ requirement.

+8
source

For some simple β€œfind error in this source code” exercises, check the PC-lint error of the month archive .

+5
source

In addition to the above, consider side effects. For instance:

 // this function adds two ints and returns the sum int add_em(int &one, int &two) { two += one; return two; } 

As you can see, this code modifies two variables, although the comment does not mention that ...

+3
source

Debugging is a wide area, and it may be wise to reflect this in your questions. Without going into details, I see the following categories:

Source level debugging - no hints

Questions in this category have only source code, without any further hint of what's wrong. The actual error can vary greatly here: from simple logical errors, such as buffer overflows and counting errors, to erroneous assumptions, through mathematical errors, such as rounding errors, to erroneous assumptions, such as the adoption of a particular specification or addition.

Source Level Debugging - Reported Issue

Questions in this category have source code as well as the desired and actual result / behavior. For instance. "This program should print 42, but instead prints from memory. Why?"

Code failure

Questions in this category come not only with the source code, but also with a crash dump.

+1
source

I will add to the answers above that another form of error is the misuse of any library or API code. Outwardly, everything looks fine, but there are some warnings (such as a precondition or restriction) that no one knows about. Interactive debuggers are not so effective on their own in these situations, because they do not reveal this information to you (it is often hidden in the documentation).

For example, in the past I studied this material. I gave the people code that I used (Message API in Java), where the error was that the program got stuck as soon as you try to receive the message. Debugging this interactively was almost impossible. They had to manually figure out what was going on and realize that one of the queues was configured incorrectly.

Such errors are actually quite common.

+1
source

Debugging in the real world will include synchronization synchronization issues and problems between the managed / unmanaged border, so please consider c / C ++ / C #.

Or for real fun, consider using only C # and finding memory leaks.

In addition, you will need to indicate which tools are allowed to use. There are literally many debugging tools in the windows.

0
source

Source: https://habr.com/ru/post/1299006/


All Articles