Skip to content

Add dynamic calls as cli arguments#108

Open
paulwuertz wants to merge 2 commits intoHBehrens:masterfrom
paulwuertz:add_dynamic_calls_via_cli
Open

Add dynamic calls as cli arguments#108
paulwuertz wants to merge 2 commits intoHBehrens:masterfrom
paulwuertz:add_dynamic_calls_via_cli

Conversation

@paulwuertz
Copy link

@paulwuertz paulwuertz commented Feb 16, 2025

Enables the user to add dynamic calls like callbacks to the call graph.

Closes #105.

Add the funcion call from func_a calling func_1 by --add-dynamic-calls 'func_a->func_1'.

An example the cannectivity firmware based on zephyr.

It has a driver abstraction calling the chip-specific driver layer, which then calls a user given callback function. In the images below user_callback and driver_implementation have both no callers(1), as they are inserted as function pointers to some structs at runtime. The os_interface function has 3 callees. The worst case max stack recognized for the gs_usb_tx_thread is 712 bytes where the call tree goes up to the os_interface z_impl_can_send and the callback worst case stack usage is 488 bytes(2).

user_callback driver_implementation os_interface
user_callback_without_dynamic_calls can_mcan_send_without_dynamic_calls z_impl_can_send_without_dynamic_calls

When adding the 3 dynamic calls os_interface->driver_implementation->user_callback as arguments:

  • --add-dynamic-calls "z_impl_can_send->can_mcan_send"
  • --add-dynamic-calls "can_mcan_send->gs_usb_can_tx_callback"
puncover --elf_file ~/git/cannectivity/build/zephyr/zephyr.elf --build_dir ~/git/cannectivity/build/  --add-dynamic-calls "z_impl_can_send->can_mcan_send" --add-dynamic-calls "can_mcan_send->gs_usb_can_tx_callback"

Then we get user_callback and driver_implementation having one caller (3) getting called from z_impl_can_send (4) and all are in the same worst stack path with now using up to 856 bytes.

user_callback driver_implementation os_interface
user_callback_with_dynamic_calls Screen Shot 2025-02-16 at 19 49 32 Screen Shot 2025-02-16 at 19 49 19

With the open PR #106 for the conig file it looks like this:

elf_file: ~/git/cannectivity/build/zephyr/zephyr.elf   
build_dir: ~/git/cannectivity/build/
add-dynamic-calls: [
    z_impl_can_send->can_mcan_send,
    can_mcan_send->gs_usb_can_tx_callback,
]

@paulwuertz paulwuertz marked this pull request as draft February 17, 2025 00:04
@paulwuertz paulwuertz force-pushed the add_dynamic_calls_via_cli branch 2 times, most recently from 97ae62a to 43914be Compare September 30, 2025 22:10
@paulwuertz paulwuertz marked this pull request as ready for review September 30, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chasing callbacks/function pointers?

1 participant