joern icon indicating copy to clipboard operation
joern copied to clipboard

PDG lacking of variable declaration nodes

Open Tsai-ky opened this issue 10 months ago • 2 comments

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?

Tsai-ky avatar Mar 14 '25 05:03 Tsai-ky

Could you provide a minimal working example for your task?

max-leuthaeuser avatar Mar 14 '25 07:03 max-leuthaeuser

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 = <(&lt;operator&gt;.assignment,b[5])<SUB>4</SUB>> ]
"146028888064" [label = <(RETURN,return 0;,return 0;)<SUB>10</SUB>> ]
"30064771075" [label = <(&lt;operator&gt;.lessThan,i &lt; 5)<SUB>5</SUB>> ]
"30064771076" [label = <(&lt;operator&gt;.preIncrement,++i)<SUB>5</SUB>> ]
"90194313219" [label = <(LITERAL,0,return 0;)<SUB>10</SUB>> ]
"30064771073" [label = <(&lt;operator&gt;.alloc,b[5])<SUB>4</SUB>> ]
"30064771074" [label = <(&lt;operator&gt;.assignment,i = 0)<SUB>5</SUB>> ]
"30064771077" [label = <(&lt;operator&gt;.assignment,c = a + i)<SUB>7</SUB>> ]
"30064771079" [label = <(&lt;operator&gt;.assignment,b[i] = c)<SUB>8</SUB>> ]
"30064771078" [label = <(&lt;operator&gt;.addition,a + i)<SUB>7</SUB>> ]
"30064771080" [label = <(&lt;operator&gt;.indirectIndexAccess,b[i])<SUB>8</SUB>> ]
  "146028888064" -> "128849018880"  [ label = "DDG: &lt;RET&gt;"] 
  "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 &lt; 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: "] 
}
"""
)

Tsai-ky avatar Mar 14 '25 08:03 Tsai-ky