Skip to main content

GCC has a handy function __builtin_return_address(depth) which should do what you want. To get the return address of the current function (which should be the same whether it's a normal function or an ISR on AVR) you set the depth to 0:

void *addr = __builtin_return_address(0);

EDIT

The address returned above is a word address. Multiply by two to get a byte address as found in the disassembly from avr-objdump -SC firmware.elf >disassembled.txt

The latter is found at ~/.platformio/packages/toolchain-atmelavr/bin/avr-objdump

GCC has a handy function __builtin_return_address(depth) which should do what you want. To get the return address of the current function (which should be the same whether it's a normal function or an ISR on AVR) you set the depth to 0:

void *addr = __builtin_return_address(0);

GCC has a handy function __builtin_return_address(depth) which should do what you want. To get the return address of the current function (which should be the same whether it's a normal function or an ISR on AVR) you set the depth to 0:

void *addr = __builtin_return_address(0);

EDIT

The address returned above is a word address. Multiply by two to get a byte address as found in the disassembly from avr-objdump -SC firmware.elf >disassembled.txt

The latter is found at ~/.platformio/packages/toolchain-atmelavr/bin/avr-objdump

Source Link
Majenko
  • 105.5k
  • 5
  • 80
  • 138

GCC has a handy function __builtin_return_address(depth) which should do what you want. To get the return address of the current function (which should be the same whether it's a normal function or an ISR on AVR) you set the depth to 0:

void *addr = __builtin_return_address(0);