joern
joern copied to clipboard
PDG lacking of variable declaration nodes
Hey! I'm trying to parse C file to PDG with Joern. I find that the PDG generated by Joern lacks of variable declaration nodes which are quite important for me. How can I inseret them to the PDG in approate areas and generate any necessary DDG or CFG edges?
Could you provide a minimal working example for your task?
Thank you for your reply! Here is a example of the code.
int func(int a)
{
int c;
int b[5];
for(int i = 0; i < 5; ++i)
{
c = a + i;
b[i] = c;
}
return 0;
}
PDG generated by Joern is as follows. As you can see, I declare some valiables, eg. c and b but in the PDG I can only find the use but no the define information.
joern> cpg.method("func").dotPdg.l
val res1: List[String] = List(
"""digraph "func" {
"111669149697" [label = <(METHOD,func)<SUB>1</SUB>> ]
"128849018880" [label = <(METHOD_RETURN,int)<SUB>1</SUB>> ]
"115964116992" [label = <(PARAM,int a)<SUB>1</SUB>> ]
"30064771072" [label = <(<operator>.assignment,b[5])<SUB>4</SUB>> ]
"146028888064" [label = <(RETURN,return 0;,return 0;)<SUB>10</SUB>> ]
"30064771075" [label = <(<operator>.lessThan,i < 5)<SUB>5</SUB>> ]
"30064771076" [label = <(<operator>.preIncrement,++i)<SUB>5</SUB>> ]
"90194313219" [label = <(LITERAL,0,return 0;)<SUB>10</SUB>> ]
"30064771073" [label = <(<operator>.alloc,b[5])<SUB>4</SUB>> ]
"30064771074" [label = <(<operator>.assignment,i = 0)<SUB>5</SUB>> ]
"30064771077" [label = <(<operator>.assignment,c = a + i)<SUB>7</SUB>> ]
"30064771079" [label = <(<operator>.assignment,b[i] = c)<SUB>8</SUB>> ]
"30064771078" [label = <(<operator>.addition,a + i)<SUB>7</SUB>> ]
"30064771080" [label = <(<operator>.indirectIndexAccess,b[i])<SUB>8</SUB>> ]
"146028888064" -> "128849018880" [ label = "DDG: <RET>"]
"115964116992" -> "128849018880" [ label = "DDG: a"]
"30064771072" -> "128849018880" [ label = "DDG: b"]
"30064771072" -> "128849018880" [ label = "DDG: b[5]"]
"30064771074" -> "128849018880" [ label = "DDG: i = 0"]
"30064771075" -> "128849018880" [ label = "DDG: i"]
"30064771075" -> "128849018880" [ label = "DDG: i < 5"]
"30064771078" -> "128849018880" [ label = "DDG: a"]
"30064771077" -> "128849018880" [ label = "DDG: a + i"]
"30064771077" -> "128849018880" [ label = "DDG: c = a + i"]
"30064771079" -> "128849018880" [ label = "DDG: b[i]"]
"30064771079" -> "128849018880" [ label = "DDG: c"]
"30064771079" -> "128849018880" [ label = "DDG: b[i] = c"]
"30064771076" -> "128849018880" [ label = "DDG: ++i"]
"111669149697" -> "115964116992" [ label = "DDG: "]
"30064771073" -> "30064771072" [ label = "DDG: 5"]
"90194313219" -> "146028888064" [ label = "DDG: 0"]
"111669149697" -> "146028888064" [ label = "DDG: "]
"111669149697" -> "90194313219" [ label = "DDG: "]
"111669149697" -> "30064771073" [ label = "DDG: "]
"111669149697" -> "30064771074" [ label = "DDG: "]
"30064771074" -> "30064771075" [ label = "DDG: i"]
"30064771076" -> "30064771075" [ label = "DDG: i"]
"111669149697" -> "30064771075" [ label = "DDG: "]
"111669149697" -> "30064771076" [ label = "DDG: "]
"30064771075" -> "30064771076" [ label = "DDG: i"]
"115964116992" -> "30064771077" [ label = "DDG: a"]
"111669149697" -> "30064771077" [ label = "DDG: "]
"30064771075" -> "30064771077" [ label = "DDG: i"]
"30064771077" -> "30064771079" [ label = "DDG: c"]
"111669149697" -> "30064771079" [ label = "DDG: "]
"115964116992" -> "30064771078" [ label = "DDG: a"]
"111669149697" -> "30064771078" [ label = "DDG: "]
"30064771075" -> "30064771078" [ label = "DDG: i"]
"30064771075" -> "30064771076" [ label = "CDG: "]
"30064771075" -> "30064771077" [ label = "CDG: "]
"30064771075" -> "30064771078" [ label = "CDG: "]
"30064771075" -> "30064771079" [ label = "CDG: "]
"30064771075" -> "30064771075" [ label = "CDG: "]
"30064771075" -> "30064771080" [ label = "CDG: "]
}
"""
)