platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
140 stars 105 forks source link

avr-gdb in toolchain atmelavr is obsolete and depends on libncurses5 #313

Open jjchico opened 1 year ago

jjchico commented 1 year ago

What kind of issue is this?

You can erase any parts of this template not applicable to your Issue.


Configuration

Operating system:

$ cat /etc/issue Ubuntu 22.04.2 LTS \n \l

PlatformIO Version (platformio --version):

./pio --version PlatformIO Core, version 6.1.7

Description of problem

avr-gdb in Atmel AVR platform is obsolete and requires libncurses5, which brakes debugging unless libncurses5 is installed in the system. libncurses5 is no present by default in Ubuntu 22.04 and other major Linux distributions.

Steps to Reproduce

Through VSCode IDE:

  1. Try to debug any atmel-avr project by using "PIO Debug"

  2. See the debug console. Example:

Downloading... Unpacking... Tool Manager: tool-simavr@1.10700.210831 has been installed! Warning! Please install 99-platformio-udev.rules. More details: https://docs.platformio.org/en/latest/core/installation/udev-rules.html Preparing firmware for debugging... Processing uno (platform: atmelavr; board: uno)

Verbose mode can be enabled via -v, --verbose option CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html PLATFORM: Atmel AVR (4.1.0) > Arduino Uno HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 31.50KB Flash DEBUG: Current (simavr) External (avr-stub, simavr) PACKAGES:

Actual Results

The debugger does not start.

Expected Results

The debugger starts and the debugging session can be executed.

If problems with PlatformIO Build System:

The content of platformio.ini:

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:uno]
platform = atmelavr
board = uno

; No framework means PIO will use just gcc and the standard C library.
;framework = arduino

; Use the simulator for debugging
debug_tool = simavr

; Use this file for peripheral definitions, that will be shown by the debugger.
debug_svd_path = atmega328p.svd

; Remove compiler optimizations from regular and debug builds. Use it to
; make compiled code closer to the original C source and to keep things like
; waiting loops that the compiler would simplify otherwise.
;build_unflags = -Os

; Remove optimizations from debug builds.
; Default: -Og -g2 -ggdb2
;debug_build_flags = -O0

Source file to reproduce issue:

; Blinking LED demo
; Jorge Juan-Chico. May, 2021
;
; Blink: demo LED parpadeante para placas Arduino.

#include <avr/io.h>

; Blink delay
.equ DELAY, 16000

; LED bit in PORTB
.equ LED, PB5   ; Arduino Uno (atmega328p)
;.equ LED, PB7   ; Arduino Mega 2560 (atmega2560)

.text

;
; Main program
;
.global main
main:

    ; Initialization code
    ; cycle counter: r22:r21:r20 (24 bits)
    ldi r22,hi8(DELAY)
    ldi r21,lo8(DELAY)
    eor r20,r20
    ldi r16,0xff                    ; all bits in PORTB are output
    out _SFR_IO_ADDR(DDRB),r16

    ; Main loop
loop:
    sbi _SFR_IO_ADDR(PORTB),LED     ; LED on
    call delay                      ; wait
    cbi _SFR_IO_ADDR(PORTB),LED     ; LED off
    call delay                      ; wait
    rjmp loop                       ; repeat

;
; Delay subroutine
;
delay:
    subi r20,1
    sbc r21,r1
    sbc r22,r1
    brne delay
    ldi r22,hi8(DELAY)
    ldi r21,lo8(DELAY)
    ret

Additional info

avr-gdb linked libs

$ ldd .platformio/packages/toolchain-atmelavr/bin/avr-gdb linux-vdso.so.1 (0x00007ffd702d3000) libncurses.so.5 => not found libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f998fab9000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f998f9d2000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f998f7aa000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f998f7a5000) /lib64/ld-linux-x86-64.so.2 (0x00007f998fb06000)

Workaround

It can be solved in Ubuntu 22.04 just by installing the libncurses5 package.

$ sudo apt install libncurses5

$ .platformio/packages/toolchain-atmelavr/bin/avr-gdb --version GNU gdb (GDB) 7.8 Copyright (C) 2014 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=avr". Type "show configuration" for configuration details.

thirstyice commented 8 months ago

libncurses5 is no longer available starting with Ubuntu 23.10, meaning that Ubuntu users can no longer debug AVR in platformio until this is updated.