1

是否有任何工具可以让我对系统代码执行自由文本搜索,但仅限于在特定调用期间实际执行的代码?

提供一些背景知识,在学习新系统的方法时,我经常发现自己想发现某些特定值的来源,但是搜索整个代码库会发现比我单独评估的要多得多。

对于它的价值,我曾经希望在 Perl 和 Java 中使用它,但我很想知道是否有任何语言具有支持此功能的系统。

4

1 回答 1

1

You can generally twist a code coverage tool's arm and get a report that shows the paths that have been executed during a given run. This report should show the code itself, with the first few columns marked up according to the coverage tool's particular notation on whether a given path was executed.

You might be able to use this straight up, or you might have to preprocess it and either remove the code that was not executed, or add a new notation on each line that tells whether it was executed (most tools will only show path information at control points):

So from a coverage tool you might get a report like this:

T- if(sometest)
   {
x     somecode;
   }
   else
   {
-     someother_code;
   }

The notation T- indicates that the if statement only ever evaluated to true, and so only the first part of the code executed. The later notation 'x' indicates that this line was executed.

You should be able to form a regex that matches only when the first column contains a T, F, or x so you can capture all the control statements executed and lines executed.

Sometimes you'll only get coverage information at each control point, which then requires you to parse the C file and mark the execute lines yourself. Not as easy, but not impossible either.

Still, this sounds like an interesting question where the solution is probably more work than it's worth...

-Adam

于 2008-09-07T04:15:38.720 回答