Is using static bytecode analysis to determine all the possible paths through a given method a variant of trying to solve the Halting Problem?

我的梦境 提交于 2019-12-02 01:27:41

问题


Is it possible to determine all the possible execution paths by reading the bytecode of a given method, or will that be equivalent to trying to solve the halting problem? If it can't be reduced to the halting problem, then how far can I go with static analysis without crossing the boundary of trying to solve the halting problem?

Related question: "Finding all the code in a given binary is equivalent to the Halting problem." Really?


回答1:


Yes, this is easily equivalent to solving the halting problem. Consider the following if statement:

if (TuringMachine(x)) then goto fred;

OK, is it really possible to goto fred? You can only answer this question if you can analyze a Turing machine. There's an equivalent set of bytecodes for this.

Now, if the only problem is to determine all plausible paths, and you don't care if you get some false positives, the answer is No. Consider the following program:

if (false) then x else y ;

The possbile paths: eval(false);do x and eval(false);do y is a complete enumeration.

You have to treat loops specially, as zero, one, two, or some maximum bounded number of iterations, it you want a computable answer. If a loop can repeat forever, some of your paths will be infinitely long and you can't report them with a algorithm and finite time :-{



来源:https://stackoverflow.com/questions/5658964/is-using-static-bytecode-analysis-to-determine-all-the-possible-paths-through-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!