Skip to content

Commit

Permalink
Separate parameters from local variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfish committed Apr 14, 2023
1 parent 197f51f commit 81e5187
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cle/backends/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,11 +848,14 @@ def _load_die_lex_block(
block = LexicalBlock(low_pc, high_pc)

for sub_die in cu.iter_DIE_children(die):
if sub_die.tag in ["DW_TAG_variable", "DW_TAG_formal_parameter"]:
if sub_die.tag in {"DW_TAG_variable", "DW_TAG_formal_parameter"}:
# load local variable
var = Variable.from_die(sub_die, expr_parser, self, dwarf, cu_low_pc, lexical_block=block)
var.decl_file = file_path
subprogram.local_variables.append(var)
if var.parameter:
subprogram.parameters.append(var)
else:
subprogram.local_variables.append(var)
elif sub_die.tag == "DW_TAG_lexical_block":
sub_block = self._load_die_lex_block(
dwarf, sub_die, expr_parser, type_list, cu, file_path, cu_low_pc, subprogram
Expand Down
1 change: 1 addition & 0 deletions cle/backends/elf/subprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ def __init__(self, name, low_pc, high_pc) -> None:
super().__init__(low_pc, high_pc)
self.name = name
self.local_variables: List[Variable] = []
self.parameters: List[Variable] = []
3 changes: 3 additions & 0 deletions cle/backends/elf/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Variable:
"external",
"declaration_only",
"_location",
"parameter",
)

def __init__(self, elf_object: "ELF"):
Expand All @@ -79,6 +80,7 @@ def __init__(self, elf_object: "ELF"):
self.external = False
self.declaration_only = False
self._location: Optional[List[Tuple[int, int, Optional[VariableLocation]]]] = None
self.parameter: bool = False

@staticmethod
def from_die(
Expand Down Expand Up @@ -120,6 +122,7 @@ def from_die(
var.external = True
if "DW_AT_declaration" in die.attributes:
var.declaration_only = True
var.parameter = die.tag == "DW_TAG_formal_parameter"

var.lexical_block = lexical_block

Expand Down

0 comments on commit 81e5187

Please sign in to comment.