mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Add query and script to plot CFG from DB
This commit is contained in:
1
java/ql/test/kotlin/library-tests/controlflow/plot/.gitignore
vendored
Normal file
1
java/ql/test/kotlin/library-tests/controlflow/plot/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
outdir/
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @id test-plot-cfg
|
||||
* @kind graph
|
||||
*/
|
||||
|
||||
import java
|
||||
|
||||
class RelevantNode extends ControlFlowNode {
|
||||
RelevantNode() { this.getLocation().getFile().isSourceFile() }
|
||||
}
|
||||
|
||||
query predicate nodes(RelevantNode n, string attr, string val) {
|
||||
attr = "semmle.order" and
|
||||
val =
|
||||
any(int i |
|
||||
n =
|
||||
rank[i](RelevantNode p, Location l |
|
||||
l = p.getLocation()
|
||||
|
|
||||
p
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn(), p.toString()
|
||||
)
|
||||
).toString()
|
||||
}
|
||||
|
||||
query predicate edges(RelevantNode pred, RelevantNode succ, string attr, string val) {
|
||||
attr = "semmle.label" and
|
||||
succ = pred.getASuccessor() and
|
||||
val = ""
|
||||
or
|
||||
attr = "semmle.order" and
|
||||
val =
|
||||
any(int i |
|
||||
succ =
|
||||
rank[i](RelevantNode s, Location l |
|
||||
s = pred.getASuccessor() and
|
||||
l = s.getLocation()
|
||||
|
|
||||
s
|
||||
order by
|
||||
l.getFile().getBaseName(), l.getFile().getAbsolutePath(), l.getStartLine(),
|
||||
l.getStartColumn(), l.getEndLine(), l.getEndColumn()
|
||||
)
|
||||
).toString()
|
||||
}
|
||||
3
java/ql/test/kotlin/library-tests/controlflow/plot/plot.sh
Executable file
3
java/ql/test/kotlin/library-tests/controlflow/plot/plot.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
codeql database analyze ../basic/basic.testproj --format=dot nodeGraph.ql --output=outdir --rerun
|
||||
dot -Tpdf -O outdir/test-plot-cfg.dot
|
||||
open outdir/test-plot-cfg.dot.pdf
|
||||
Reference in New Issue
Block a user