[Lldb-commits] [lldb] ec1efe7 - [LLDB] Let DataExtractor deal with two-byte addresses

2020-02-25 Thread Ayke van Laethem via lldb-commits

Author: Ayke van Laethem
Date: 2020-02-25T16:27:38+01:00
New Revision: ec1efe71130f5b049e53828281204b50d89d4cf6

URL: 
https://github.com/llvm/llvm-project/commit/ec1efe71130f5b049e53828281204b50d89d4cf6
DIFF: 
https://github.com/llvm/llvm-project/commit/ec1efe71130f5b049e53828281204b50d89d4cf6.diff

LOG: [LLDB] Let DataExtractor deal with two-byte addresses

AVR usually uses two byte addresses. By making DataExtractor deal with
this, it is possible to load AVR binaries that don't have debug info
associated with them.

Differential Revision: https://reviews.llvm.org/D73969

Added: 


Modified: 
lldb/source/Utility/DataExtractor.cpp
lldb/unittests/Utility/DataExtractorTest.cpp

Removed: 




diff  --git a/lldb/source/Utility/DataExtractor.cpp 
b/lldb/source/Utility/DataExtractor.cpp
index fd4b7643cdc5..40819f107052 100644
--- a/lldb/source/Utility/DataExtractor.cpp
+++ b/lldb/source/Utility/DataExtractor.cpp
@@ -133,7 +133,7 @@ DataExtractor::DataExtractor(const void *data, offset_t 
length,
   m_end(const_cast(static_cast(data)) + 
length),
   m_byte_order(endian), m_addr_size(addr_size), m_data_sp(),
   m_target_byte_size(target_byte_size) {
-  assert(addr_size == 4 || addr_size == 8);
+  assert(addr_size >= 1 && addr_size <= 8);
 }
 
 // Make a shared pointer reference to the shared data in "data_sp" and set the
@@ -146,7 +146,7 @@ DataExtractor::DataExtractor(const DataBufferSP &data_sp, 
ByteOrder endian,
 : m_start(nullptr), m_end(nullptr), m_byte_order(endian),
   m_addr_size(addr_size), m_data_sp(),
   m_target_byte_size(target_byte_size) {
-  assert(addr_size == 4 || addr_size == 8);
+  assert(addr_size >= 1 && addr_size <= 8);
   SetData(data_sp);
 }
 
@@ -160,7 +160,7 @@ DataExtractor::DataExtractor(const DataExtractor &data, 
offset_t offset,
 : m_start(nullptr), m_end(nullptr), m_byte_order(data.m_byte_order),
   m_addr_size(data.m_addr_size), m_data_sp(),
   m_target_byte_size(target_byte_size) {
-  assert(m_addr_size == 4 || m_addr_size == 8);
+  assert(m_addr_size >= 1 && m_addr_size <= 8);
   if (data.ValidOffset(offset)) {
 offset_t bytes_available = data.GetByteSize() - offset;
 if (length > bytes_available)
@@ -173,7 +173,7 @@ DataExtractor::DataExtractor(const DataExtractor &rhs)
 : m_start(rhs.m_start), m_end(rhs.m_end), m_byte_order(rhs.m_byte_order),
   m_addr_size(rhs.m_addr_size), m_data_sp(rhs.m_data_sp),
   m_target_byte_size(rhs.m_target_byte_size) {
-  assert(m_addr_size == 4 || m_addr_size == 8);
+  assert(m_addr_size >= 1 && m_addr_size <= 8);
 }
 
 // Assignment operator
@@ -251,7 +251,7 @@ lldb::offset_t DataExtractor::SetData(const DataExtractor 
&data,
   offset_t data_offset,
   offset_t data_length) {
   m_addr_size = data.m_addr_size;
-  assert(m_addr_size == 4 || m_addr_size == 8);
+  assert(m_addr_size >= 1 && m_addr_size <= 8);
   // If "data" contains shared pointer to data, then we can use that
   if (data.m_data_sp) {
 m_byte_order = data.m_byte_order;
@@ -680,12 +680,12 @@ long double DataExtractor::GetLongDouble(offset_t 
*offset_ptr) const {
 //
 // RETURNS the address that was extracted, or zero on failure.
 uint64_t DataExtractor::GetAddress(offset_t *offset_ptr) const {
-  assert(m_addr_size == 4 || m_addr_size == 8);
+  assert(m_addr_size >= 1 && m_addr_size <= 8);
   return GetMaxU64(offset_ptr, m_addr_size);
 }
 
 uint64_t DataExtractor::GetAddress_unchecked(offset_t *offset_ptr) const {
-  assert(m_addr_size == 4 || m_addr_size == 8);
+  assert(m_addr_size >= 1 && m_addr_size <= 8);
   return GetMaxU64_unchecked(offset_ptr, m_addr_size);
 }
 

diff  --git a/lldb/unittests/Utility/DataExtractorTest.cpp 
b/lldb/unittests/Utility/DataExtractorTest.cpp
index 0b0832431f8c..f412ab8e79ab 100644
--- a/lldb/unittests/Utility/DataExtractorTest.cpp
+++ b/lldb/unittests/Utility/DataExtractorTest.cpp
@@ -112,6 +112,39 @@ TEST(DataExtractorTest, GetCStrAtNullOffset) {
   EXPECT_EQ(4U, offset);
 }
 
+TEST(DataExtractorTest, UncommonAddressSize) {
+  uint8_t buffer[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+  DataExtractor E2(buffer, sizeof buffer, lldb::eByteOrderLittle, 2);
+  DataExtractor E5(buffer, sizeof buffer, lldb::eByteOrderLittle, 5);
+  DataExtractor E7(buffer, sizeof buffer, lldb::eByteOrderLittle, 7);
+
+  lldb::offset_t offset;
+
+  // Test 2-byte addresses (for AVR).
+  offset = 0;
+  EXPECT_EQ(0x0201U, E2.GetMaxU64(&offset, 2));
+  EXPECT_EQ(2U, offset);
+  offset = 0;
+  EXPECT_EQ(0x0201U, E2.GetAddress(&offset));
+  EXPECT_EQ(2U, offset);
+
+  // Test 5-byte addresses.
+  offset = 0;
+  EXPECT_EQ(0x030201U, E5.GetMaxU64(&offset, 3));
+  EXPECT_EQ(3U, offset);
+  offset = 3;
+  EXPECT_EQ(0x0807060504U, E5.GetAddress(&offset));
+  EXPECT_EQ(8U, offset);
+
+  // Test 7-byte addresses.
+  offset = 0;
+  EXPECT_EQ(0x05

[Lldb-commits] [lldb] 0818e6c - [LLDB] Add support for AVR breakpoints

2020-03-17 Thread Ayke van Laethem via lldb-commits

Author: Ayke van Laethem
Date: 2020-03-17T13:17:48+01:00
New Revision: 0818e6cf1d30dcac1fc4dcde60e01f8389e725f9

URL: 
https://github.com/llvm/llvm-project/commit/0818e6cf1d30dcac1fc4dcde60e01f8389e725f9
DIFF: 
https://github.com/llvm/llvm-project/commit/0818e6cf1d30dcac1fc4dcde60e01f8389e725f9.diff

LOG: [LLDB] Add support for AVR breakpoints

I believe the actual opcode does not matter because the AVR architecture
is a Harvard architecture that does not support writing to program
memory. Therefore, debuggers and emulators provide hardware breakpoints.
But for some reason, this opcode must be defined or else LLDB will crash
with an assertion error.

Differential Revision: https://reviews.llvm.org/D74255

Added: 


Modified: 
lldb/source/Target/Platform.cpp

Removed: 




diff  --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index eaa71b9cbbd0..3069a363736f 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -1865,6 +1865,12 @@ size_t Platform::GetSoftwareBreakpointTrapOpcode(Target 
&target,
 }
   } break;
 
+  case llvm::Triple::avr: {
+static const uint8_t g_hex_opcode[] = {0x98, 0x95};
+trap_opcode = g_hex_opcode;
+trap_opcode_size = sizeof(g_hex_opcode);
+  } break;
+
   case llvm::Triple::mips:
   case llvm::Triple::mips64: {
 static const uint8_t g_hex_opcode[] = {0x00, 0x00, 0x00, 0x0d};



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 727ed11 - [AVR] Recognize the AVR architecture in lldb

2020-01-30 Thread Ayke van Laethem via lldb-commits

Author: Ayke van Laethem
Date: 2020-01-30T13:40:31+01:00
New Revision: 727ed11b24c08c84a608886a1716b81c93640d80

URL: 
https://github.com/llvm/llvm-project/commit/727ed11b24c08c84a608886a1716b81c93640d80
DIFF: 
https://github.com/llvm/llvm-project/commit/727ed11b24c08c84a608886a1716b81c93640d80.diff

LOG: [AVR] Recognize the AVR architecture in lldb

This commit adds AVR support to lldb. With this change, it can load a
binary and do basic things like dump a line table.

Not much else has been implemented, that should be done in later
changes.

Differential Revision: https://reviews.llvm.org/D73539

Added: 
lldb/test/Shell/ObjectFile/ELF/avr-basic-info.yaml

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

Removed: 




diff  --git a/lldb/include/lldb/Utility/ArchSpec.h 
b/lldb/include/lldb/Utility/ArchSpec.h
index 6e209dfd2e46..d1a257bedd36 100644
--- a/lldb/include/lldb/Utility/ArchSpec.h
+++ b/lldb/include/lldb/Utility/ArchSpec.h
@@ -188,6 +188,8 @@ class ArchSpec {
 
 eCore_arc, // little endian ARC
 
+eCore_avr,
+
 eCore_wasm32,
 
 kNumCores,

diff  --git a/lldb/source/Utility/ArchSpec.cpp 
b/lldb/source/Utility/ArchSpec.cpp
index 08931b58cd2c..bb4771c6488c 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -218,6 +218,8 @@ static const CoreDefinition g_core_definitions[] = {
  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 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
  LLDB_INVALID_CPUTYPE, 0xu, 0xu}, // HEXAGON
 {ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
  0xu, 0xu}, // ARC
+{ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE,
+ 0xu, 0xu}, // AVR
 };
 
 static const ArchDefinition g_elf_arch_def = {

diff  --git a/lldb/test/Shell/ObjectFile/ELF/avr-basic-info.yaml 
b/lldb/test/Shell/ObjectFile/ELF/avr-basic-info.yaml
new file mode 100644
index ..3326ce66fa5d
--- /dev/null
+++ b/lldb/test/Shell/ObjectFile/ELF/avr-basic-info.yaml
@@ -0,0 +1,30 @@
+# RUN: yaml2obj %s > %t
+# RUN: lldb-test object-file %t | FileCheck %s
+# CHECK: Plugin name: elf
+# CHECK: Architecture: avr--
+# CHECK: Executable: true
+# CHECK: Stripped: false
+# CHECK: Type: executable
+# CHECK: Strata: user
+# CHECK:   Name: .text
+# CHECK-NEXT:   Type: code
+# CHECK-NEXT:   Permissions: r-x
+# CHECK-NEXT:   Thread specific: no
+# CHECK-NEXT:   VM address: 0x0
+# CHECK-NEXT:   VM size: 4
+# CHECK-NEXT:   File size: 4
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_AVR
+  Flags:   [ EF_AVR_ARCH_AVR1, EF_AVR_ARCH_AVR4 ]
+Sections:
+  - Name:.text
+Type:SHT_PROGBITS
+Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
+AddressAlign:0x0001
+Content: 'FECF'
+...



___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits