From e43b80b633b494eb8b399cd51320b7b3bbe11eaf Mon Sep 17 00:00:00 2001 From: Fish Date: Fri, 14 Apr 2023 11:24:35 -0700 Subject: [PATCH] Separate parameters from local variables. --- cle/backends/elf/elf.py | 7 +++++-- cle/backends/elf/subprogram.py | 1 + cle/backends/elf/variable.py | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cle/backends/elf/elf.py b/cle/backends/elf/elf.py index e823a9ae..e91baa78 100644 --- a/cle/backends/elf/elf.py +++ b/cle/backends/elf/elf.py @@ -851,11 +851,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 diff --git a/cle/backends/elf/subprogram.py b/cle/backends/elf/subprogram.py index c784ca10..b997f3c4 100644 --- a/cle/backends/elf/subprogram.py +++ b/cle/backends/elf/subprogram.py @@ -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] = [] diff --git a/cle/backends/elf/variable.py b/cle/backends/elf/variable.py index d413c620..91e84dda 100644 --- a/cle/backends/elf/variable.py +++ b/cle/backends/elf/variable.py @@ -65,6 +65,7 @@ class Variable: "external", "declaration_only", "_location", + "parameter", ) def __init__(self, elf_object: "ELF"): @@ -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( @@ -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