c++ - Writing an MCVE (minimal source code that reproduces an error) automatically? -


when want ask question on e.g. stackoverflow have post source code.

the problem is, using quite big custom framework, classes structure etc. , problem-related parts may localized in many places (sometimes it's hard detect parts of code important question). cannot post full source code (it big read efficiently).

for reason make effort write minimal code (usually in 1 main.cpp instead of tons of classes) reproduces problem.

i wonder - is possible automate process? typical things here replace methods/functions' calls bodies, merge files 1 .cpp, remove "not called" methods & classes, unused variables etc.

the real difficulty here telling difference between "it doesn't want", "the bug went away because removed essential code" , case of "it crashes because removed important". , really, hitting delete key after marking code "don't need it" easy part.

finding out essential show problem hard part, , it's difficult automate - because necessary understand difference between code should , does. randomly removing code not work, because "new" code may broken because removed essential step, not because remove unused crud - humans [that understand problem] can that.

consider this:

object* something;  void initialize() {     = new object(1, 2, 3); }  int main() {    initialize();    // more code, of sets = null.    something->dostuff();  // crash if object null. } 

if remove initialize, code fail every time, not every third time. it's because object has not been initialized, rather bug in code [which may should add if (something) before something->dostuff(), or because shouldn't set null in "some more code", "don't that"].

when work on tricky problem, @ work have test systems automatically produce code testing different functionality under different conditions, first step make [or take existing] code "small standalone test", small , simple, , "what necessary", rather trying reduce many thousands of lines of complex code lots of stuff.

for projects, there tools around helps identifying "which bit of code problem", example [bugpoint][1] finds "pass" in llvm guily of causing crash.

if have version control system supports can "bisect" code come version introduced particular fault [at least sometimes]. however, had case @ work of code "apparently broke things", turns out other code "broken time since long time back" because other code not clearing pointer field api manual says should set null, , code inspecting pointer find out if pointing @ right type thing - goes horribly wrong when value "whatever happens in part of stack", not null , not valid pointer. added code made bug apparent rather hiding itself.

[1] http://llvm.org/docs/commandguide/bugpoint.html


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -