Upload and Debug for ATmega328P with Atmel ICE

The platformio.ini settings are OS-independent. Does

[env:ATmega328P]
platform = atmelavr
board = ATmega328P
framework = arduino
upload_protocol = atmelice_isp
upload_flags = -e
upload_port = usb

not work?

Debugging AVR chips with an Atmel-ICE is not supported out-of-the-box, upload is. The currently support debug methods for Atmel chips are by simulation (simavr) or by a serial GDB stub program loaded into the firmware (avr-stub).

The problem is the GDB server for an atmel-ice (and other chips), Atmel does not supply a program like that since they don’t use GDB under the hood. But, free alternative programs like AVaRICE exist (Debugging AVR / Arduino with ATMELICE / JTAGICE3 and avarice / avr-gdb) but seemed buggy at the point of testing. There’s also dwire (VSCode PIO debugger for AVR).