You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user would like to find C/C++ function(s) where a specific pattern is found; for example to study how a variable, literal or code comment is used in a project. This can be helpful when doing code review, traceability analysis, data-flow analysis or control-flow analysis.
Here's a similar stack overflow discussion about this topic.
Example:
A user would like to get a list of the function(s) in foo.c that contains the keyword tmp:
intfunc1(int x, int y)
{
return x + y;
}
intfunc2(int x, int y, int z)
{
int tmp = x + y;
tmp *= z;
return tmp;
}
Suggestions
Approach 1: grep -B
$ grep -nHi -B10 tmp
foo.c-1-int func1(int x, int y)
foo.c-2-{
foo.c-3- return x + y;
foo.c-4-}
foo.c-5-int func2(int x, int y, int z)
foo.c-6-{
foo.c:7: int tmp = x + y;
foo.c:8: tmp *= z;
foo.c:9: return tmp;
Cons:
generates much noise
-B might require large numbers for large functions
Approach 2: git grep -p
$ git grep -nHi -p tmp
foo.c=5=int func2(int x, int y, int z)
foo.c:7: int tmp = x + y;
foo.c:8: tmp *= z;
foo.c:9: return tmp;
Pros:
Much less noise than grep -B
Cons:
Also displays the pattern match, which might not always be desirable.
Approach 3: new dextool plugin/feature
Example:
$ dextool analyze -h
-p, --show-function shows the line that contains the function name of a `file:row`
$ grep -nHi -e 'tmp' foo.c | dextool analyze --show-function --from-stdin
foo.c:5: int func2(int x, int y, int z)
$ dextool analyze --show-function foo.c:7
foo.c:1: int func1(int x, int y)
The text was updated successfully, but these errors were encountered:
christoffer-nylen
changed the title
analyze: grep function name
analyze: list C/C++ function(s) where a pattern is found
Mar 7, 2022
christoffer-nylen
changed the title
analyze: list C/C++ function(s) where a pattern is found
analyze: list C/C++ function(s) containing a specified pattern
Mar 7, 2022
christoffer-nylen
changed the title
analyze: list C/C++ function(s) containing a specified pattern
analyze: search for C/C++ function(s) containing a pattern
Mar 7, 2022
The user would like to find C/C++ function(s) where a specific pattern is found; for example to study how a variable, literal or code comment is used in a project. This can be helpful when doing code review, traceability analysis, data-flow analysis or control-flow analysis.
Here's a similar stack overflow discussion about this topic.
Example:
A user would like to get a list of the function(s) in
foo.c
that contains the keywordtmp
:Suggestions
Approach 1: grep -B
Cons:
Approach 2: git grep -p
Pros:
grep -B
Cons:
Approach 3: new dextool plugin/feature
Example:
The text was updated successfully, but these errors were encountered: