HBehrens / puncover

Analyses C/C++ build output for code size, static variables, and stack usage
MIT License
432 stars 94 forks source link

Stack usage not displayed correctly due to basefile not being parsed in files with extension .su #62

Closed vChavezB closed 1 year ago

vChavezB commented 1 year ago

I was testing the stack usage feature of puncover but found out there is a bug in the code.

I enabled stack usage in the GCC compiler (-fstack-usage) but I was not getting any info on the puncover website. After debugging I noticed that the function parse_stack_usage_line does not parse correctly the so-called base_file_name

This is important because when you are adding the stack usage it compares the base_file_name that was added previously when looking for symbols... i.e., with arm-none-eabi-nm -Sl YOUR_ELF_FILE.elf. Specifically here https://github.com/HBehrens/puncover/blob/ec63f21c8be12fef2724beb28810d0b7238640f9/puncover/collector.py#L102

Therefore parse_stack_usage_line should also extract the base file name.

My suggestion:

   def parse_stack_usage_line(self, line):
        match = self.parse_stack_usage_line_pattern.match(line)
        if not match:
            return False

        file_name = match.group(1)
        base_file_name = os.path.basename(file_name)
        line = int(match.group(3))
        symbol_name = match.group(5)
        stack_size = int(match.group(6))
        stack_qualifier = match.group(7)

        return self.add_stack_usage(base_file_name, line, symbol_name, stack_size, stack_qualifier)