Skip to content

Commit 5ecfad5

Browse files
committed
script: footprint: Improve C++ static variable reporting
Enhance the `size_report` script to correctly categorize static C++ variables in the memory report. Static C++ variables are currently listed under the "No paths" category in the size report. This occurs because the script's address-based mapping logic is designed for functions, which occupy an address range, but fails to handle variables that have only a single memory address. This commit improves the `do_address_range_matching` function to handle single-address mappings. The updated logic now correctly identifies and assigns static C++ variables to their corresponding source file paths in the report tree, providing a more accurate and comprehensive memory footprint analysis for C++ applications. This enhancement ensures that all symbols, regardless of their linkage or type, are correctly placed in the report, providing a more accurate overview of memory usage. Signed-off-by: Nilesh Vyas <[email protected]>
1 parent 376ca57 commit 5ecfad5

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

scripts/footprint/size_report

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def do_address_range_matching(dwarfinfo, symbol_dict, processed):
464464
offset_map[die.offset] = die
465465

466466
for die in cu_list[cu]['dies']:
467-
if not die.tag == 'DW_TAG_subprogram':
467+
if not (die.tag == 'DW_TAG_subprogram' or die.tag == 'DW_TAG_variable'):
468468
continue
469469

470470
path = None
@@ -507,16 +507,32 @@ def do_address_range_matching(dwarfinfo, symbol_dict, processed):
507507
if low is None:
508508
continue
509509

510-
for ums in unmapped_symbols:
511-
for one_sym in symbol_dict[ums]:
512-
symbol = one_sym['symbol']
513-
symaddr = symbol['st_value']
514-
515-
if symaddr not in mapped_addresses:
516-
if low <= symaddr < high:
517-
one_sym['mapped_files'].add(path)
518-
mapped_addresses.add(symaddr)
519-
newly_mapped_syms.add(ums)
510+
# Case 1: Match for a function (using a range)
511+
if die.tag == 'DW_TAG_subprogram':
512+
for ums in unmapped_symbols:
513+
for one_sym in symbol_dict[ums]:
514+
symbol = one_sym['symbol']
515+
symaddr = symbol['st_value']
516+
517+
if symaddr not in mapped_addresses:
518+
if low <= symaddr < high:
519+
one_sym['mapped_files'].add(path)
520+
mapped_addresses.add(symaddr)
521+
newly_mapped_syms.add(ums)
522+
523+
# Case 2: Match for a variable (using a single address)
524+
elif die.tag == 'DW_TAG_variable':
525+
for ums in unmapped_symbols:
526+
for one_sym in symbol_dict[ums]:
527+
symbol = one_sym['symbol']
528+
symaddr = symbol['st_value']
529+
530+
if symaddr not in mapped_addresses:
531+
# We expect the 'high' value to be 'low + 1' for a variable
532+
if low == symaddr:
533+
one_sym['mapped_files'].add(path)
534+
mapped_addresses.add(symaddr)
535+
newly_mapped_syms.add(ums)
520536

521537
mapped_symbols = mapped_symbols.union(newly_mapped_syms)
522538
unmapped_symbols = unmapped_symbols.difference(newly_mapped_syms)

0 commit comments

Comments
 (0)