HBehrens / puncover

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

First time use not working #61

Open hudi84 opened 1 year ago

hudi84 commented 1 year ago

Hi all maybe someone can help me here. I tried to use puncover on a fresh debian 11 installation. I installed puncover with

apt-get install pip pip3 install puncover

When I try it with a simple little program, this is what I get (same result when setting --arm_tools_dir or --gcc_tools_base to the appropriate correct subdir (using xPacks arm-none-eabi for bare metal here):

dev@qemuarm:~/project_dir$ puncover --elf_file main.elf DEPRECATED: argument --arm_tools_dir will be removed, use --gcc_tools_base instead. parsing ELF at main.elf Traceback (most recent call last): File "/usr/local/bin/puncover", line 8, in sys.exit(main()) File "/usr/local/lib/python3.9/dist-packages/puncover/puncover.py", line 69, in main builder.build_if_needed() File "/usr/local/lib/python3.9/dist-packages/puncover/builders.py", line 32, in build_if_needed self.build() File "/usr/local/lib/python3.9/dist-packages/puncover/builders.py", line 22, in build self.collector.parse_elf(self.get_elf_path()) File "/usr/local/lib/python3.9/dist-packages/puncover/collector.py", line 306, in parse_elf self.parse_assembly_text("".join(self.gcc_tools.get_assembly_lines(elf_file))) File "/usr/local/lib/python3.9/dist-packages/puncover/gcc_tools.py", line 28, in get_assembly_lines return self.gcc_tool_lines('objdump', ['-dslw', os.path.basename(elf_file)], os.path.dirname(elf_file)) File "/usr/local/lib/python3.9/dist-packages/puncover/gcc_tools.py", line 24, in gcc_tool_lines proc = subprocess.Popen([self.gcc_tool_path(name)] + args, stdout=subprocess.PIPE, cwd=cwd) File "/usr/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.9/subprocess.py", line 1823, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: ''

I am not a python expert. But searching around in the code a little makes me feel that the subprocess.Popen interface has changed and the "objcopy" executable parameter is not forwarded into this call??? I also have added some prints to gcc_tools.py and the subprocces call that is built up there can be executed on the command line without any problems...

Hope someone can help me with this

Didi

noahp commented 1 year ago

Hello @hudi84 , thank you for reporting this issue!

You'll need to specify the tools prefix as described in the help:

❯ puncover --help                                      
usage: puncover [-h] [--arm_tools_dir ARM_TOOLS_DIR] [--gcc_tools_base GCC_TOOLS_BASE] --elf_file ELF_FILE [--src_root SRC_ROOT] [--build_dir BUILD_DIR] [--debug] [--port PORT] [--host HOST] [--no-open-browser]

Analyses C/C++ build output for code size, static variables, and stack usage.

options:
  -h, --help            show this help message and exit
  --arm_tools_dir ARM_TOOLS_DIR
                        DEPRECATED! location of your arm tools.
  --gcc_tools_base GCC_TOOLS_BASE
                        filename prefix for your gcc tools, e.g. ~/arm-cs-tools/bin/arm-none-eabi-

For example:

❯ puncover --elf_file test.elf --gcc_tools_base ~/Downloads/xpack-arm-none-eabi-gcc-11.2.1-1.2-linux-x64/bin/arm-none-eabi-

Notice the prefix includes arm-none-eabi-.

Let us know if that fixes the problem!

Ecco commented 1 year ago

Got hit by the same problem. A workaround was to pass an absolute path for the elf file. Like this:

puncover \
  --elf_file /path/to/my/test.elf \
  --gcc_tools_base ~/Downloads/xpack-arm-none-eabi-gcc-11.2.1-1.2-linux-x64/bin/arm-none-eabi-