Is there any tool which will allow me to perform a free text search over a system's code, but only over the code which was actually executed during a particular invocation?
是否有任何工具可以让我在系统代码上执行*文本搜索,但只能在特定调用期间实际执行的代码上执行?
To give a bit of background, when learning my way around a new system, I frequently find myself wanting to discover where some particular value came from, but searching the entire code base turns up far more matches than I can reasonably assess individually.
为了给出一些背景知识,在学习新系统的过程中,我经常发现自己想要发现某些特定值的来源,但是搜索整个代码库会出现比我单独合理评估的更多匹配。
For what it's worth, I've wanted this in Perl and Java at one time or another, but I'd love to know if any languages have a system supporting this feature.
对于它的价值,我曾经在Perl和Java中曾经想过这个,但是我想知道是否有任何语言都有支持这个功能的系统。
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.
您通常可以扭曲代码覆盖工具的臂并获取一个报告,该报告显示在给定运行期间已执行的路径。此报告应显示代码本身,并根据coverage工具关于是否执行给定路径的特定符号标记前几列。
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.
符号T-表示if语句只被评估为true,因此只执行了代码的第一部分。后面的符号'x'表示该行已执行。
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.
您应该能够形成仅在第一列包含T,F或x时匹配的正则表达式,以便您可以捕获所有执行的控制语句和执行的行。
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.
有时您只会在每个控制点获取覆盖信息,然后需要您解析C文件并自己标记执行行。不是那么容易,但也不是不可能。
Still, this sounds like an interesting question where the solution is probably more work than it's worth...
不过,这听起来像一个有趣的问题,解决方案可能更多的工作,而不是它的价值......
-Adam
#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.
您通常可以扭曲代码覆盖工具的臂并获取一个报告,该报告显示在给定运行期间已执行的路径。此报告应显示代码本身,并根据coverage工具关于是否执行给定路径的特定符号标记前几列。
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.
符号T-表示if语句只被评估为true,因此只执行了代码的第一部分。后面的符号'x'表示该行已执行。
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.
您应该能够形成仅在第一列包含T,F或x时匹配的正则表达式,以便您可以捕获所有执行的控制语句和执行的行。
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.
有时您只会在每个控制点获取覆盖信息,然后需要您解析C文件并自己标记执行行。不是那么容易,但也不是不可能。
Still, this sounds like an interesting question where the solution is probably more work than it's worth...
不过,这听起来像一个有趣的问题,解决方案可能更多的工作,而不是它的价值......
-Adam