[PATCH] D73539: [AVR] Basic support for remote debugging

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 03:46:33 PST 2020


aykevl created this revision.
aykevl added reviewers: dylanmckay, deepak2427, Andrzej, clayborg, labath.
Herald added subscribers: lldb-commits, Jim, aprantl.
Herald added a project: LLDB.

Add bare-metal AVR support to lldb. Loading a binary works, but little else.

Things that work:

  $ ./llvm-build.master/bin/lldb tmp/avr.elf
  (lldb) target create "tmp/avr.elf"
  Current executable set to '/home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.elf' (avr).
  (lldb) image lookup -F main
  1 match found in /home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.elf:
          Address: avr.elf[0x0080] (avr.elf.PT_LOAD[0]..text + 128)
          Summary: avr.elf`main at avr.c:10
  (lldb) image dump line-table avr.c
  Line table for /home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.c in `avr.elf
  0x0080: /home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.c:10
  0x0084: /home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.c:13
  0x0088: /usr/lib/avr/include/util/delay.h:163
  0x009a: /home/ayke/src/github.com/tinygo-org/tinygo/tmp/avr.c:15
  0x009c: /usr/lib/avr/include/util/delay.h:163
  0x00b0: /usr/lib/avr/include/util/delay.h:163

Source code (copied from the internet somewhere):

  #ifndef F_CPU
  #define F_CPU 16000000UL // 16 MHz clock speed
  #endif
  
  #include <avr/io.h>
  #include <util/delay.h>
  
  int main(void)
  {
    DDRC = 0xFF; //Nakes PORTC as Output
    while(1) //infinite loop
    {
      PORTC = 0xFF; //Turns ON All LEDs
      _delay_ms(1000); //1 second delay
      PORTC= 0x00; //Turns OFF All LEDs
      _delay_ms(1000); //1 second delay
    }
  }

Compiled using avr-gcc (with `-gdwarf-4` as it defaults to the stabs debug format in Debian):

  avr-gcc -Og -gdwarf-4 -mmcu=atmega328p -o avr.elf avr.c

Things like disassembling a binary don't work yet, but I think that can be done independently by getting llvm-objdump to work with the AVR target (it currently results in an assertion failure).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73539

Files:
  lldb/include/lldb/Utility/ArchSpec.h
  lldb/source/Utility/ArchSpec.cpp


Index: lldb/source/Utility/ArchSpec.cpp
===================================================================
--- lldb/source/Utility/ArchSpec.cpp
+++ lldb/source/Utility/ArchSpec.cpp
@@ -218,6 +218,8 @@
      ArchSpec::eCore_uknownMach64, "unknown-mach-64"},
     {eByteOrderLittle, 4, 2, 4, llvm::Triple::arc, ArchSpec::eCore_arc, "arc"},
 
+    {eByteOrderLittle, 2, 2, 4, llvm::Triple::avr, ArchSpec::eCore_avr, "avr"},
+
     {eByteOrderLittle, 4, 1, 4, llvm::Triple::wasm32, ArchSpec::eCore_wasm32,
      "wasm32"},
 };
@@ -448,6 +450,8 @@
      LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, // HEXAGON
     {ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
      0xFFFFFFFFu, 0xFFFFFFFFu}, // ARC
+    {ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE,
+     0xFFFFFFFFu, 0xFFFFFFFFu}, // AVR
 };
 
 static const ArchDefinition g_elf_arch_def = {
Index: lldb/include/lldb/Utility/ArchSpec.h
===================================================================
--- lldb/include/lldb/Utility/ArchSpec.h
+++ lldb/include/lldb/Utility/ArchSpec.h
@@ -188,6 +188,8 @@
 
     eCore_arc, // little endian ARC
 
+    eCore_avr,
+
     eCore_wasm32,
 
     kNumCores,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73539.240824.patch
Type: text/x-patch
Size: 1199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/34f97be8/attachment.bin>


More information about the llvm-commits mailing list