Skip to content

Commit e43b80b

Browse files
committed
Separate parameters from local variables.
1 parent 9964b54 commit e43b80b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

cle/backends/elf/elf.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,14 @@ def _load_die_lex_block(
851851
block = LexicalBlock(low_pc, high_pc)
852852

853853
for sub_die in cu.iter_DIE_children(die):
854-
if sub_die.tag in ["DW_TAG_variable", "DW_TAG_formal_parameter"]:
854+
if sub_die.tag in {"DW_TAG_variable", "DW_TAG_formal_parameter"}:
855855
# load local variable
856856
var = Variable.from_die(sub_die, expr_parser, self, dwarf, cu_low_pc, lexical_block=block)
857857
var.decl_file = file_path
858-
subprogram.local_variables.append(var)
858+
if var.parameter:
859+
subprogram.parameters.append(var)
860+
else:
861+
subprogram.local_variables.append(var)
859862
elif sub_die.tag == "DW_TAG_lexical_block":
860863
sub_block = self._load_die_lex_block(
861864
dwarf, sub_die, expr_parser, type_list, cu, file_path, cu_low_pc, subprogram

cle/backends/elf/subprogram.py

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ def __init__(self, name, low_pc, high_pc) -> None:
4747
super().__init__(low_pc, high_pc)
4848
self.name = name
4949
self.local_variables: List[Variable] = []
50+
self.parameters: List[Variable] = []

cle/backends/elf/variable.py

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Variable:
6565
"external",
6666
"declaration_only",
6767
"_location",
68+
"parameter",
6869
)
6970

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

8385
@staticmethod
8486
def from_die(
@@ -120,6 +122,7 @@ def from_die(
120122
var.external = True
121123
if "DW_AT_declaration" in die.attributes:
122124
var.declaration_only = True
125+
var.parameter = die.tag == "DW_TAG_formal_parameter"
123126

124127
var.lexical_block = lexical_block
125128

0 commit comments

Comments
 (0)