[Lldb-commits] [PATCH] D135664: [wasm] Always treat DWARF expression addresses as load addresses

2022-10-28 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 471484.
pfaffe added a comment.
Herald added a subscriber: lldb-commits.

Full context with arcanist


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135664/new/

https://reviews.llvm.org/D135664

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -401,3 +401,35 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx),
   llvm::HasValue(GetScalar(32, 0x07060504, false)));
 }
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
+
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // Single DW_OP_addr takes a single operand of address size width:
+  uint8_t expr[] = {DW_OP_addr, 0x40, 0x0, 0x0, 0x0};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor,
+  /*unit*/ nullptr, lldb::eRegisterKindLLDB,
+  /*initial_value_ptr*/ nullptr,
+  /*object_address_ptr*/ nullptr, result, &status))
+  << status.ToError();
+
+  ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
+}
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -847,10 +847,12 @@
 
   Process *process = nullptr;
   StackFrame *frame = nullptr;
+  Target *target = nullptr;
 
   if (exe_ctx) {
 process = exe_ctx->GetProcessPtr();
 frame = exe_ctx->GetFramePtr();
+target = exe_ctx->GetTargetPtr();
   }
   if (reg_ctx == nullptr && frame)
 reg_ctx = frame->GetRegisterContext().get();
@@ -906,12 +908,17 @@
 // address and whose size is the size of an address on the target machine.
 case DW_OP_addr:
   stack.push_back(Scalar(opcodes.GetAddress(&offset)));
-  stack.back().SetValueType(Value::ValueType::FileAddress);
-  // Convert the file address to a load address, so subsequent
-  // DWARF operators can operate on it.
-  if (frame)
-stack.back().ConvertToLoadAddress(module_sp.get(),
-  frame->CalculateTarget().get());
+  if (target &&
+  target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+stack.back().SetValueType(Value::ValueType::LoadAddress);
+  } else {
+stack.back().SetValueType(Value::ValueType::FileAddress);
+// Convert the file address to a load address, so subsequent
+// DWARF operators can operate on it.
+if (frame)
+  stack.back().ConvertToLoadAddress(module_sp.get(),
+frame->CalculateTarget().get());
+  }
   break;
 
 // The DW_OP_addr_sect_offset4 is used for any location expressions in
@@ -2507,7 +2514,12 @@
   uint64_t index = opcodes.GetULEB128(&offset);
   lldb::addr_t value = dwarf_cu->ReadAddressFromDebugAddrSection(index);
   stack.push_back(Scalar(value));
-  stack.back().SetValueType(Value::ValueType::FileAddress);
+  if (target &&
+  target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+stack.back().SetValueType(Value::ValueType::LoadAddress);
+  } else {
+stack.back().SetValueType(Value::ValueType::FileAddress);
+  }
 } break;
 
 // OPCODE: DW_OP_GNU_const_index


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -401,3 +401,35 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx),
   llvm::HasValue(GetScalar(32, 0x07060504, false)));
 }
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
+
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance

[Lldb-commits] [PATCH] D135664: [wasm] Always treat DWARF expression addresses as load addresses

2022-10-28 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 471485.
pfaffe added a comment.

Add comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135664/new/

https://reviews.llvm.org/D135664

Files:
  lldb/source/Expression/DWARFExpression.cpp


Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -910,6 +910,8 @@
   stack.push_back(Scalar(opcodes.GetAddress(&offset)));
   if (target &&
   target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses 
can
+// never point into a file section and are always LoadAddresses.
 stack.back().SetValueType(Value::ValueType::LoadAddress);
   } else {
 stack.back().SetValueType(Value::ValueType::FileAddress);
@@ -2516,6 +2518,8 @@
   stack.push_back(Scalar(value));
   if (target &&
   target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses 
can
+// never point into a file section and are always LoadAddresses.
 stack.back().SetValueType(Value::ValueType::LoadAddress);
   } else {
 stack.back().SetValueType(Value::ValueType::FileAddress);


Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -910,6 +910,8 @@
   stack.push_back(Scalar(opcodes.GetAddress(&offset)));
   if (target &&
   target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses can
+// never point into a file section and are always LoadAddresses.
 stack.back().SetValueType(Value::ValueType::LoadAddress);
   } else {
 stack.back().SetValueType(Value::ValueType::FileAddress);
@@ -2516,6 +2518,8 @@
   stack.push_back(Scalar(value));
   if (target &&
   target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses can
+// never point into a file section and are always LoadAddresses.
 stack.back().SetValueType(Value::ValueType::LoadAddress);
   } else {
 stack.back().SetValueType(Value::ValueType::FileAddress);
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D135664: [wasm] Always treat DWARF expression addresses as load addresses

2022-10-28 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 471486.
pfaffe added a comment.

Bring back lost changes...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135664/new/

https://reviews.llvm.org/D135664

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -401,3 +401,35 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx),
   llvm::HasValue(GetScalar(32, 0x07060504, false)));
 }
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
+
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // Single DW_OP_addr takes a single operand of address size width:
+  uint8_t expr[] = {DW_OP_addr, 0x40, 0x0, 0x0, 0x0};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor,
+  /*unit*/ nullptr, lldb::eRegisterKindLLDB,
+  /*initial_value_ptr*/ nullptr,
+  /*object_address_ptr*/ nullptr, result, &status))
+  << status.ToError();
+
+  ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
+}
Index: lldb/source/Expression/DWARFExpression.cpp
===
--- lldb/source/Expression/DWARFExpression.cpp
+++ lldb/source/Expression/DWARFExpression.cpp
@@ -847,10 +847,12 @@
 
   Process *process = nullptr;
   StackFrame *frame = nullptr;
+  Target *target = nullptr;
 
   if (exe_ctx) {
 process = exe_ctx->GetProcessPtr();
 frame = exe_ctx->GetFramePtr();
+target = exe_ctx->GetTargetPtr();
   }
   if (reg_ctx == nullptr && frame)
 reg_ctx = frame->GetRegisterContext().get();
@@ -906,12 +908,19 @@
 // address and whose size is the size of an address on the target machine.
 case DW_OP_addr:
   stack.push_back(Scalar(opcodes.GetAddress(&offset)));
-  stack.back().SetValueType(Value::ValueType::FileAddress);
-  // Convert the file address to a load address, so subsequent
-  // DWARF operators can operate on it.
-  if (frame)
-stack.back().ConvertToLoadAddress(module_sp.get(),
-  frame->CalculateTarget().get());
+  if (target &&
+  target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses 
can
+// never point into a file section and are always LoadAddresses.
+stack.back().SetValueType(Value::ValueType::LoadAddress);
+  } else {
+stack.back().SetValueType(Value::ValueType::FileAddress);
+// Convert the file address to a load address, so subsequent
+// DWARF operators can operate on it.
+if (frame)
+  stack.back().ConvertToLoadAddress(module_sp.get(),
+frame->CalculateTarget().get());
+  }
   break;
 
 // The DW_OP_addr_sect_offset4 is used for any location expressions in
@@ -2507,7 +2516,14 @@
   uint64_t index = opcodes.GetULEB128(&offset);
   lldb::addr_t value = dwarf_cu->ReadAddressFromDebugAddrSection(index);
   stack.push_back(Scalar(value));
-  stack.back().SetValueType(Value::ValueType::FileAddress);
+  if (target &&
+  target->GetArchitecture().GetCore() == ArchSpec::eCore_wasm32) {
+// wasm file sections aren't mapped into memory, therefore addresses 
can
+// never point into a file section and are always LoadAddresses.
+stack.back().SetValueType(Value::ValueType::LoadAddress);
+  } else {
+stack.back().SetValueType(Value::ValueType::FileAddress);
+  }
 } break;
 
 // OPCODE: DW_OP_GNU_const_index


Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -401,3 +401,35 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &e

[Lldb-commits] [PATCH] D135664: [wasm] Always treat DWARF expression addresses as load addresses

2022-10-28 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 471543.
pfaffe added a comment.

Add unittest for DW_OP_addrx as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135664/new/

https://reviews.llvm.org/D135664

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
@@ -401,3 +402,115 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx),
   llvm::HasValue(GetScalar(32, 0x07060504, false)));
 }
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
+  // Set up a wasm target
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // DW_OP_addr takes a single operand of address size width:
+  uint8_t expr[] = {DW_OP_addr, 0x40, 0x0, 0x0, 0x0};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor,
+  /*unit*/ nullptr, lldb::eRegisterKindLLDB,
+  /*initial_value_ptr*/ nullptr,
+  /*object_address_ptr*/ nullptr, result, &status))
+  << status.ToError();
+
+  ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
+}
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr_index) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_addr_base
+  Form:DW_FORM_sec_offset
+
+  debug_info:
+- Version: 5
+  AddrSize:4
+  UnitType:DW_UT_compile
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x8 # Offset of the first Address past the header
+- AbbrCode:0x0
+
+  debug_addr:
+- Version: 5
+  AddressSize: 4
+  Entries:
+- Address: 0x1234
+- Address: 0x5678
+)";
+
+  // Can't use DWARFExpressionTester from above because subsystems overlap with
+  // the fixture.
+  SubsystemRAII subsystems;
+  llvm::Expected file = TestFile::fromYaml(yamldata);
+  EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
+  auto module_sp = std::make_shared(file->moduleSpec());
+  auto *dwarf_cu = llvm::cast(module_sp->GetSymbolFile())
+   ->DebugInfo()
+   .GetUnitAtIndex(0);
+  ASSERT_TRUE(dwarf_cu);
+  dwarf_cu->ExtractDIEsIfNeeded();
+
+  // Set up a wasm target
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // DW_OP_addrx takes a single leb128 operand, the index in the addr table:
+  uint8_t expr[] = {DW_OP_addrx, 0x01};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor, dwarf_cu,
+  lldb::eRegisterKindLLDB,
+  /*initial_value_ptr*/ nullptr,
+   

[Lldb-commits] [PATCH] D135664: [wasm] Always treat DWARF expression addresses as load addresses

2022-11-02 Thread Philip Pfaffe via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd839f654586a: [wasm] Always treat DWARF expression addresses 
as load addresses (authored by pfaffe).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135664/new/

https://reviews.llvm.org/D135664

Files:
  lldb/source/Expression/DWARFExpression.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -8,6 +8,7 @@
 
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
@@ -401,3 +402,115 @@
   Evaluate({DW_OP_lit4, DW_OP_deref, DW_OP_stack_value}, {}, {}, &exe_ctx),
   llvm::HasValue(GetScalar(32, 0x07060504, false)));
 }
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr) {
+  // Set up a wasm target
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // DW_OP_addr takes a single operand of address size width:
+  uint8_t expr[] = {DW_OP_addr, 0x40, 0x0, 0x0, 0x0};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor,
+  /*unit*/ nullptr, lldb::eRegisterKindLLDB,
+  /*initial_value_ptr*/ nullptr,
+  /*object_address_ptr*/ nullptr, result, &status))
+  << status.ToError();
+
+  ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
+}
+
+TEST_F(DWARFExpressionMockProcessTest, WASM_DW_OP_addr_index) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_addr_base
+  Form:DW_FORM_sec_offset
+
+  debug_info:
+- Version: 5
+  AddrSize:4
+  UnitType:DW_UT_compile
+  Entries:
+- AbbrCode:0x0001
+  Values:
+- Value:   0x8 # Offset of the first Address past the header
+- AbbrCode:0x0
+
+  debug_addr:
+- Version: 5
+  AddressSize: 4
+  Entries:
+- Address: 0x1234
+- Address: 0x5678
+)";
+
+  // Can't use DWARFExpressionTester from above because subsystems overlap with
+  // the fixture.
+  SubsystemRAII subsystems;
+  llvm::Expected file = TestFile::fromYaml(yamldata);
+  EXPECT_THAT_EXPECTED(file, llvm::Succeeded());
+  auto module_sp = std::make_shared(file->moduleSpec());
+  auto *dwarf_cu = llvm::cast(module_sp->GetSymbolFile())
+   ->DebugInfo()
+   .GetUnitAtIndex(0);
+  ASSERT_TRUE(dwarf_cu);
+  dwarf_cu->ExtractDIEsIfNeeded();
+
+  // Set up a wasm target
+  ArchSpec arch("wasm32-unknown-unknown-wasm");
+  lldb::PlatformSP host_platform_sp =
+  platform_linux::PlatformLinux::CreateInstance(true, &arch);
+  ASSERT_TRUE(host_platform_sp);
+  Platform::SetHostPlatform(host_platform_sp);
+  lldb::DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+  lldb::TargetSP target_sp;
+  lldb::PlatformSP platform_sp;
+  debugger_sp->GetTargetList().CreateTarget(*debugger_sp, "", arch,
+lldb_private::eLoadDependentsNo,
+platform_sp, target_sp);
+
+  ExecutionContext exe_ctx(target_sp, false);
+  // DW_OP_addrx takes a single leb128 operand, the index in the addr table:
+  uint8_t expr[] = {DW_OP_addrx, 0x01};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  Value result;
+  Status status;
+  ASSERT_TRUE(DWARFExpression::Evaluate(
+  &exe_ctx, /*reg_ctx*/ nullptr, /*module_sp*/ {}, extractor

[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-02 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe created this revision.
pfaffe added reviewers: labath, DavidSpickett.
Herald added a project: All.
pfaffe requested review of this revision.
Herald added subscribers: lldb-commits, aheejin.
Herald added a project: LLDB.

Parsing DWARF expressions currently does not support DW_OPs that are vendor
extensions. With this change expression parsing calls into SymbolFileDWARF for
unknown opcodes, which is the semantically "closest" plugin that we have right
now. Plugins can then extend SymbolFileDWARF to add support for vendor
extensions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137247

Files:
  lldb/include/lldb/Expression/DWARFExpression.h
  lldb/include/lldb/Target/Platform.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/DWARFExpressionList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -9,9 +9,11 @@
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/Host/HostInfo.h"
@@ -514,3 +516,251 @@
   ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
   ASSERT_EQ(result.GetScalar().UInt(), 0x5678u);
 }
+
+class CustomSymbolFileDWARF : public SymbolFileDWARF {
+  static char ID;
+
+public:
+  using SymbolFileDWARF::SymbolFileDWARF;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || SymbolFile::isA(ClassID);
+  }
+  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
+
+  static llvm::StringRef GetPluginNameStatic() { return "custom_dwarf"; }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+return "Symbol file reader with expression extensions.";
+  }
+
+  static void Initialize() {
+PluginManager::RegisterPlugin(GetPluginNameStatic(),
+  GetPluginDescriptionStatic(), CreateInstance,
+  SymbolFileDWARF::DebuggerInitialize);
+  }
+
+  static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+  static lldb_private::SymbolFile *
+  CreateInstance(lldb::ObjectFileSP objfile_sp) {
+return new CustomSymbolFileDWARF(std::move(objfile_sp),
+ /*dwo_section_list*/ nullptr);
+  }
+
+  lldb::offset_t
+  GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data,
+   const lldb::offset_t data_offset,
+   const uint8_t op) const final {
+auto offset = data_offset;
+if (op != DW_OP_WASM_location) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03, 0x04, 0x00, 0x00, 0x00
+// Location type:
+if (data.GetU8(&offset) != /* global */ 0x03) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Index
+if (data.GetU32(&offset) != 0x04) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Report the skipped distance:
+return offset - data_offset;
+  }
+
+  bool
+  ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,
+ std::vector &stack) const final {
+if (op != DW_OP_WASM_location) {
+  return false;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03, 0x04, 0x00, 0x00, 0x00
+// Location type:
+if (opcodes.GetU8(&offset) != /* global */ 0x03) {
+  return false;
+}
+
+// Index:
+if (opcodes.GetU32(&offset) != 0x04) {
+  return false;
+}
+
+// Return some value:
+stack.push_back({GetScalar(32, 42, false)});
+return true;
+  }
+};
+
+char CustomSymbolFileDWARF::ID;
+
+TEST(DWARFExpression, Extensions) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_no
+  debug_info:
+- Version: 4
+  AddrSize:4
+  Entries:
+- AbbrCode:0x1
+- AbbrCode:0x0
+)";
+
+  SubsystemRAII
+  subsystems;
+
+  llvm::Expect

[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-02 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

Yes, you got the context right! Although technically speaking this change isn't 
limited to wasm, plugins can implement any vendor extension on top of this 
change.




Comment at: lldb/source/Expression/DWARFExpressionList.cpp:93
   const DWARFExpression &expr = m_exprs.GetEntryRef(0).data;
-  return expr.ContainsThreadLocalStorage();
+  return expr.ContainsThreadLocalStorage(*m_dwarf_cu);
 }

DavidSpickett wrote:
> I'm not sure that `m_dwarf_cu` is always non null. It might be in practice 
> but for example one use ends up in `UpdateValueTypeFromLocationDescription` 
> which checks that it is not null before use.
> 
> Maybe it is reasonable to assume it is never null (and if it is and you have 
> the time, a preparatory patch to make it a ref would be great).
I think it's worth checking in general. Before 
https://reviews.llvm.org/D125509, the DWARFExpression used to be assiciated 
with its dwarf_cu. I was considering bringing that back, what do you think? 



Comment at: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h:343
+  ParseVendorDWARFOpcode(uint8_t op,
+ const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,

DavidSpickett wrote:
> Seems like clang-format missed a bit here.
Curious, I would have assumed the linter at the very least would have caught 
that.



Comment at: lldb/unittests/Expression/DWARFExpressionTest.cpp:571
+}
+
+// Report the skipped distance:

DavidSpickett wrote:
> Is there not 3 more arguments to read off here? The `0x00 0x00 0x00` from 
> above.
No, the second argument to this opcode is of type uint32_t, the zeros are the 
last three bytes of that. Should I maybe use a simpler/fake opcode? Might be 
dangerous if that fake opcode ever got occupied/implemented.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

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


[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-03 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 472863.
pfaffe marked 4 inline comments as done.
pfaffe added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

Files:
  lldb/include/lldb/Expression/DWARFExpression.h
  lldb/include/lldb/Target/Platform.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/DWARFExpressionList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -9,9 +9,11 @@
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/Host/HostInfo.h"
@@ -514,3 +516,242 @@
   ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
   ASSERT_EQ(result.GetScalar().UInt(), 0x5678u);
 }
+
+class CustomSymbolFileDWARF : public SymbolFileDWARF {
+  static char ID;
+
+public:
+  using SymbolFileDWARF::SymbolFileDWARF;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || SymbolFile::isA(ClassID);
+  }
+  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
+
+  static llvm::StringRef GetPluginNameStatic() { return "custom_dwarf"; }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+return "Symbol file reader with expression extensions.";
+  }
+
+  static void Initialize() {
+PluginManager::RegisterPlugin(GetPluginNameStatic(),
+  GetPluginDescriptionStatic(), CreateInstance,
+  SymbolFileDWARF::DebuggerInitialize);
+  }
+
+  static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+  static lldb_private::SymbolFile *
+  CreateInstance(lldb::ObjectFileSP objfile_sp) {
+return new CustomSymbolFileDWARF(std::move(objfile_sp),
+ /*dwo_section_list*/ nullptr);
+  }
+
+  lldb::offset_t
+  GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data,
+   const lldb::offset_t data_offset,
+   const uint8_t op) const final {
+auto offset = data_offset;
+if (op != DW_OP_WASM_location) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and 0x04
+// Location type:
+if (data.GetU8(&offset) != /* global */ 0x03) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Index
+if (data.GetU32(&offset) != 0x04) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Report the skipped distance:
+return offset - data_offset;
+  }
+
+  bool
+  ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,
+ std::vector &stack) const final {
+if (op != DW_OP_WASM_location) {
+  return false;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and  0x04
+// Location type:
+if (opcodes.GetU8(&offset) != /* global */ 0x03) {
+  return false;
+}
+
+// Index:
+if (opcodes.GetU32(&offset) != 0x04) {
+  return false;
+}
+
+// Return some value:
+stack.push_back({GetScalar(32, 42, false)});
+return true;
+  }
+};
+
+char CustomSymbolFileDWARF::ID;
+
+static auto testExpressionVendorExtensions(lldb::ModuleSP module_sp,
+   DWARFUnit &dwarf_unit) {
+  // Test that expression extensions can be evaluated, for example
+  // DW_OP_WASM_location which is not currently handled by DWARFExpression:
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_WASM_location, 0x03, // WASM_GLOBAL:0x03
+ 0x04, 0x00, 0x00,  // index:u32
+ 0x00, DW_OP_stack_value},
+module_sp, &dwarf_unit),
+   llvm::HasValue(GetScalar(32, 42, false)));
+
+  // Test that searches for opcodes work in the presence of extensions:
+  uint8_t expr[] = {DW_OP_WASM_location,   0x03, 0x04, 0x00, 0x00, 0x00,
+DW_OP_form_tls_address};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/

[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-03 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added inline comments.



Comment at: lldb/unittests/Expression/DWARFExpressionTest.cpp:719
+  Type:ET_EXEC
+  Machine: EM_386
+Sections:

DavidSpickett wrote:
> I know it's just a test but is there an `EM_WASM` you could use?
> 
> Maybe lldb doesn't understand that name yet so it makes no difference anyway.
There's no EM_WASM, in fact wasm has it's own non-ELF container. I picked x86 
ELF  because ELFYAML has the DWARF section which is convenient, WASMYAML sadly 
does not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

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


[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-15 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 475399.
pfaffe added a comment.

Stray change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

Files:
  lldb/include/lldb/Expression/DWARFExpression.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/DWARFExpressionList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -9,9 +9,11 @@
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/Host/HostInfo.h"
@@ -514,3 +516,242 @@
   ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
   ASSERT_EQ(result.GetScalar().UInt(), 0x5678u);
 }
+
+class CustomSymbolFileDWARF : public SymbolFileDWARF {
+  static char ID;
+
+public:
+  using SymbolFileDWARF::SymbolFileDWARF;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || SymbolFile::isA(ClassID);
+  }
+  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
+
+  static llvm::StringRef GetPluginNameStatic() { return "custom_dwarf"; }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+return "Symbol file reader with expression extensions.";
+  }
+
+  static void Initialize() {
+PluginManager::RegisterPlugin(GetPluginNameStatic(),
+  GetPluginDescriptionStatic(), CreateInstance,
+  SymbolFileDWARF::DebuggerInitialize);
+  }
+
+  static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+  static lldb_private::SymbolFile *
+  CreateInstance(lldb::ObjectFileSP objfile_sp) {
+return new CustomSymbolFileDWARF(std::move(objfile_sp),
+ /*dwo_section_list*/ nullptr);
+  }
+
+  lldb::offset_t
+  GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data,
+   const lldb::offset_t data_offset,
+   const uint8_t op) const final {
+auto offset = data_offset;
+if (op != DW_OP_WASM_location) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and 0x04
+// Location type:
+if (data.GetU8(&offset) != /* global */ 0x03) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Index
+if (data.GetU32(&offset) != 0x04) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Report the skipped distance:
+return offset - data_offset;
+  }
+
+  bool
+  ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,
+ std::vector &stack) const final {
+if (op != DW_OP_WASM_location) {
+  return false;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and  0x04
+// Location type:
+if (opcodes.GetU8(&offset) != /* global */ 0x03) {
+  return false;
+}
+
+// Index:
+if (opcodes.GetU32(&offset) != 0x04) {
+  return false;
+}
+
+// Return some value:
+stack.push_back({GetScalar(32, 42, false)});
+return true;
+  }
+};
+
+char CustomSymbolFileDWARF::ID;
+
+static auto testExpressionVendorExtensions(lldb::ModuleSP module_sp,
+   DWARFUnit &dwarf_unit) {
+  // Test that expression extensions can be evaluated, for example
+  // DW_OP_WASM_location which is not currently handled by DWARFExpression:
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_WASM_location, 0x03, // WASM_GLOBAL:0x03
+ 0x04, 0x00, 0x00,  // index:u32
+ 0x00, DW_OP_stack_value},
+module_sp, &dwarf_unit),
+   llvm::HasValue(GetScalar(32, 42, false)));
+
+  // Test that searches for opcodes work in the presence of extensions:
+  uint8_t expr[] = {DW_OP_WASM_location,   0x03, 0x04, 0x00, 0x00, 0x00,
+DW_OP_form_tls_address};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+  /*addr_size*/ 4);
+  DWARFExpression dwarf_expr(extractor);
+  ASSERT_TRUE(dwarf_expr.ContainsTh

[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-17 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

I threaded dwarf_cu down to where it's really used and added the necessary 
check, so if it is nullptr, the fallback will be skipped.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

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


[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-22 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 477099.
pfaffe marked 2 inline comments as done.
pfaffe added a comment.

Override new functions in DWOs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

Files:
  lldb/include/lldb/Expression/DWARFExpression.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/DWARFExpressionList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -9,9 +9,11 @@
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/Host/HostInfo.h"
@@ -514,3 +516,242 @@
   ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
   ASSERT_EQ(result.GetScalar().UInt(), 0x5678u);
 }
+
+class CustomSymbolFileDWARF : public SymbolFileDWARF {
+  static char ID;
+
+public:
+  using SymbolFileDWARF::SymbolFileDWARF;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || SymbolFile::isA(ClassID);
+  }
+  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
+
+  static llvm::StringRef GetPluginNameStatic() { return "custom_dwarf"; }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+return "Symbol file reader with expression extensions.";
+  }
+
+  static void Initialize() {
+PluginManager::RegisterPlugin(GetPluginNameStatic(),
+  GetPluginDescriptionStatic(), CreateInstance,
+  SymbolFileDWARF::DebuggerInitialize);
+  }
+
+  static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+  static lldb_private::SymbolFile *
+  CreateInstance(lldb::ObjectFileSP objfile_sp) {
+return new CustomSymbolFileDWARF(std::move(objfile_sp),
+ /*dwo_section_list*/ nullptr);
+  }
+
+  lldb::offset_t
+  GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data,
+   const lldb::offset_t data_offset,
+   const uint8_t op) const final {
+auto offset = data_offset;
+if (op != DW_OP_WASM_location) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and 0x04
+// Location type:
+if (data.GetU8(&offset) != /* global */ 0x03) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Index
+if (data.GetU32(&offset) != 0x04) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Report the skipped distance:
+return offset - data_offset;
+  }
+
+  bool
+  ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,
+ std::vector &stack) const final {
+if (op != DW_OP_WASM_location) {
+  return false;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and  0x04
+// Location type:
+if (opcodes.GetU8(&offset) != /* global */ 0x03) {
+  return false;
+}
+
+// Index:
+if (opcodes.GetU32(&offset) != 0x04) {
+  return false;
+}
+
+// Return some value:
+stack.push_back({GetScalar(32, 42, false)});
+return true;
+  }
+};
+
+char CustomSymbolFileDWARF::ID;
+
+static auto testExpressionVendorExtensions(lldb::ModuleSP module_sp,
+   DWARFUnit &dwarf_unit) {
+  // Test that expression extensions can be evaluated, for example
+  // DW_OP_WASM_location which is not currently handled by DWARFExpression:
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_WASM_location, 0x03, // WASM_GLOBAL:0x03
+ 0x04, 0x00, 0x00,  // index:u32
+ 0x00, DW_OP_stack_value},
+module_sp, &dwarf_unit),
+   llvm::HasValue(GetScalar(32, 42, false)));
+
+  // Test that searches for opcodes work in the presence of extensions:
+  uint8_t expr[] = {DW_OP_WASM_location,   0x03, 0x04, 0x00, 0x00, 0x00,
+DW_OP_form_tls_address};
+  DataExtractor extractor(expr, sizeof(expr), lldb::eByteOrderLittle,
+ 

[Lldb-commits] [PATCH] D137247: [lldb] Allow plugins to extend DWARF expression parsing for vendor extensions

2022-11-22 Thread Philip Pfaffe via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc08d3b08f6d7: [lldb] Allow plugins to extend DWARF 
expression parsing for vendor extensions (authored by pfaffe).

Changed prior to commit:
  https://reviews.llvm.org/D137247?vs=477099&id=477175#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137247/new/

https://reviews.llvm.org/D137247

Files:
  lldb/include/lldb/Expression/DWARFExpression.h
  lldb/source/Expression/DWARFExpression.cpp
  lldb/source/Expression/DWARFExpressionList.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h
  lldb/unittests/Expression/DWARFExpressionTest.cpp

Index: lldb/unittests/Expression/DWARFExpressionTest.cpp
===
--- lldb/unittests/Expression/DWARFExpressionTest.cpp
+++ lldb/unittests/Expression/DWARFExpressionTest.cpp
@@ -9,9 +9,11 @@
 #include "lldb/Expression/DWARFExpression.h"
 #include "Plugins/Platform/Linux/PlatformLinux.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDebugInfo.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARFDwo.h"
 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
 #include "lldb/Core/Value.h"
 #include "lldb/Core/dwarf.h"
 #include "lldb/Host/HostInfo.h"
@@ -514,3 +516,242 @@
   ASSERT_EQ(result.GetValueType(), Value::ValueType::LoadAddress);
   ASSERT_EQ(result.GetScalar().UInt(), 0x5678u);
 }
+
+class CustomSymbolFileDWARF : public SymbolFileDWARF {
+  static char ID;
+
+public:
+  using SymbolFileDWARF::SymbolFileDWARF;
+
+  bool isA(const void *ClassID) const override {
+return ClassID == &ID || SymbolFile::isA(ClassID);
+  }
+  static bool classof(const SymbolFile *obj) { return obj->isA(&ID); }
+
+  static llvm::StringRef GetPluginNameStatic() { return "custom_dwarf"; }
+
+  static llvm::StringRef GetPluginDescriptionStatic() {
+return "Symbol file reader with expression extensions.";
+  }
+
+  static void Initialize() {
+PluginManager::RegisterPlugin(GetPluginNameStatic(),
+  GetPluginDescriptionStatic(), CreateInstance,
+  SymbolFileDWARF::DebuggerInitialize);
+  }
+
+  static void Terminate() { PluginManager::UnregisterPlugin(CreateInstance); }
+
+  static lldb_private::SymbolFile *
+  CreateInstance(lldb::ObjectFileSP objfile_sp) {
+return new CustomSymbolFileDWARF(std::move(objfile_sp),
+ /*dwo_section_list*/ nullptr);
+  }
+
+  lldb::offset_t
+  GetVendorDWARFOpcodeSize(const lldb_private::DataExtractor &data,
+   const lldb::offset_t data_offset,
+   const uint8_t op) const final {
+auto offset = data_offset;
+if (op != DW_OP_WASM_location) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and 0x04
+// Location type:
+if (data.GetU8(&offset) != /* global */ 0x03) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Index
+if (data.GetU32(&offset) != 0x04) {
+  return LLDB_INVALID_OFFSET;
+}
+
+// Report the skipped distance:
+return offset - data_offset;
+  }
+
+  bool
+  ParseVendorDWARFOpcode(uint8_t op, const lldb_private::DataExtractor &opcodes,
+ lldb::offset_t &offset,
+ std::vector &stack) const final {
+if (op != DW_OP_WASM_location) {
+  return false;
+}
+
+// DW_OP_WASM_location WASM_GLOBAL:0x03 index:u32
+// Called with "arguments" 0x03 and  0x04
+// Location type:
+if (opcodes.GetU8(&offset) != /* global */ 0x03) {
+  return false;
+}
+
+// Index:
+if (opcodes.GetU32(&offset) != 0x04) {
+  return false;
+}
+
+// Return some value:
+stack.push_back({GetScalar(32, 42, false)});
+return true;
+  }
+};
+
+char CustomSymbolFileDWARF::ID;
+
+static auto testExpressionVendorExtensions(lldb::ModuleSP module_sp,
+   DWARFUnit &dwarf_unit) {
+  // Test that expression extensions can be evaluated, for example
+  // DW_OP_WASM_location which is not currently handled by DWARFExpression:
+  EXPECT_THAT_EXPECTED(Evaluate({DW_OP_WASM_location, 0x03, // WASM_GLOBAL:0x03
+ 0x04, 0x00, 0x00,  // index:u32
+ 0x00, DW_OP_stack_value},
+module_sp, &dwarf_unit),
+   llvm::HasValue(GetScalar(32, 42, false)));
+
+  // Test that searches for opcodes work in the presence of extensions:
+  uint8_t expr[] = {DW_OP_WASM_location,   

[Lldb-commits] [PATCH] D97786: LLDB: Use path relative to binary, not relative to debugger CWD, for finding .dwo files.

2021-08-30 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

This change breaks all existing uses of relative comp_dirs that don't 
accidentally make all of them relative to the executable's directory already.

It's easy to construct broken use cases: Consider compiling your program like 
`clang -g ./src/src.c -gsplit-dwarf -o ./out/src -fdebug-prefix-map=$(pwd)=.`. 
This will create `src.dwo` in $(pwd) and set the DW_AT_comp_dir of `src` to 
".";  the change makes it impossible to load `src.dwo`.

The problem is easy to see in this slightly constructed example and could be 
fixed here by moving around the dwo files or setting the prefix to '..' to make 
it point to the executable. But that's not always possible! What if we have a 
static library that gets linked into multiple executables in different 
locations? What do we set comp_dir to in the library objects?

The change also introduces different behavior for loading dwos vs. source 
files. The latter will still be loaded relative to the CWD.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97786/new/

https://reviews.llvm.org/D97786

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


[Lldb-commits] [PATCH] D97786: LLDB: Use path relative to binary, not relative to debugger CWD, for finding .dwo files.

2021-09-05 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

In D97786#2974879 , @dblaikie wrote:

> Not fixable? Not sure I follow. In the case of cwd-relative (old behavior) 
> you can fix the behavior by changing where you invoke the debugger from, and 
> in the case of exe-relative you can fix the behavior by moving the 
> executable? (once both source and dwo lookup is implemented consistently, at 
> least)

Thanks, I totally missed the fact that the patch intended to keep cwd-relative 
lookup working! Kudos for that! I overlooked it being mentioned in the 
discussion, and it's not in the commit message and the implementation is quite 
subtle. That eliminates most of my concerns!

That being said the implementation looks like it only does this partially. If I 
understand this correctly, the cwd-relative check happens in line 1646, but 
that only checks if the `dwo_name` exists. Below, `comp_dir/dwo_name` is 
however not checked against cwd. That means that we only get the old behavior 
if comp_dir happens to be `.`; any non-trivial relative comp_dir will behave 
differently, in that I need to cd into the comp_dir manually first to make 
things work. That's much better than I originally feared (chromium, e.g., uses 
`.`, so they're fine), but I still think we should retain the old behavior for 
non-trivial comp_dirs as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97786/new/

https://reviews.llvm.org/D97786

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


[Lldb-commits] [PATCH] D97786: LLDB: Use path relative to binary, not relative to debugger CWD, for finding .dwo files.

2021-09-05 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

In D97786#2973868 , @dblaikie wrote:

> This doesn't solve all use cases/it's not a terribly general purpose 
> situation - using -fdebug-prefix-map/-fdebug-compilation-dir requires 
> knowledge of these limitations/how to use these features together. (though I 
> agree that changes in this area should apply to all relative comp_dir lookups 
> - source and dwo files alike, rather than handling one group differently from 
> the other when they're all defined as comp_dir relative)

My main concern is that even with knowledge of how the debug-compilation-dir 
features work, there are use cases that stop working after this change and are 
unfixable on the user's end. Anything that involves linking shared objects into 
multiple executables for example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97786/new/

https://reviews.llvm.org/D97786

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


[Lldb-commits] [PATCH] D93621: [lldb][wasm] Parse DWO section names

2020-12-21 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe created this revision.
Herald added subscribers: sunfish, sbc100.
pfaffe requested review of this revision.
Herald added subscribers: lldb-commits, aheejin.
Herald added a project: LLDB.

Mirror ELF section parsing to support DWARF section names for
debug fission.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93621

Files:
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp


Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
===
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -253,6 +253,43 @@
 
 Symtab *ObjectFileWasm::GetSymtab() { return nullptr; }
 
+static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
+  if (Name.consume_front(".debug_") || Name.consume_front(".zdebug_")) {
+return llvm::StringSwitch(Name)
+.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
+.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
+.Case("addr", eSectionTypeDWARFDebugAddr)
+.Case("aranges", eSectionTypeDWARFDebugAranges)
+.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
+.Case("frame", eSectionTypeDWARFDebugFrame)
+.Case("info", eSectionTypeDWARFDebugInfo)
+.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
+.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
+.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
+.Case("loc", eSectionTypeDWARFDebugLoc)
+.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
+.Case("loclists", eSectionTypeDWARFDebugLocLists)
+.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
+.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
+.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
+.Case("names", eSectionTypeDWARFDebugNames)
+.Case("pubnames", eSectionTypeDWARFDebugPubNames)
+.Case("pubtypes", eSectionTypeDWARFDebugPubTypes)
+.Case("ranges", eSectionTypeDWARFDebugRanges)
+.Case("rnglists", eSectionTypeDWARFDebugRngLists)
+.Case("rnglists.dwo", eSectionTypeDWARFDebugRngListsDwo)
+.Case("str", eSectionTypeDWARFDebugStr)
+.Case("str.dwo", eSectionTypeDWARFDebugStrDwo)
+.Case("str_offsets", eSectionTypeDWARFDebugStrOffsets)
+.Case("str_offsets.dwo", eSectionTypeDWARFDebugStrOffsetsDwo)
+.Case("tu_index", eSectionTypeDWARFDebugTuIndex)
+.Case("types", eSectionTypeDWARFDebugTypes)
+.Case("types.dwo", eSectionTypeDWARFDebugTypesDwo)
+.Default(eSectionTypeOther);
+  }
+  return eSectionTypeOther;
+}
+
 void ObjectFileWasm::CreateSections(SectionList &unified_section_list) {
   if (m_sections_up)
 return;
@@ -280,29 +317,7 @@
   // Code section.
   vm_addr = 0;
 } else {
-  section_type =
-  llvm::StringSwitch(sect_info.name.GetStringRef())
-  .Case(".debug_abbrev", eSectionTypeDWARFDebugAbbrev)
-  .Case(".debug_addr", eSectionTypeDWARFDebugAddr)
-  .Case(".debug_aranges", eSectionTypeDWARFDebugAranges)
-  .Case(".debug_cu_index", eSectionTypeDWARFDebugCuIndex)
-  .Case(".debug_frame", eSectionTypeDWARFDebugFrame)
-  .Case(".debug_info", eSectionTypeDWARFDebugInfo)
-  .Case(".debug_line", eSectionTypeDWARFDebugLine)
-  .Case(".debug_line_str", eSectionTypeDWARFDebugLineStr)
-  .Case(".debug_loc", eSectionTypeDWARFDebugLoc)
-  .Case(".debug_loclists", eSectionTypeDWARFDebugLocLists)
-  .Case(".debug_macinfo", eSectionTypeDWARFDebugMacInfo)
-  .Case(".debug_macro", eSectionTypeDWARFDebugMacro)
-  .Case(".debug_names", eSectionTypeDWARFDebugNames)
-  .Case(".debug_pubnames", eSectionTypeDWARFDebugPubNames)
-  .Case(".debug_pubtypes", eSectionTypeDWARFDebugPubTypes)
-  .Case(".debug_ranges", eSectionTypeDWARFDebugRanges)
-  .Case(".debug_rnglists", eSectionTypeDWARFDebugRngLists)
-  .Case(".debug_str", eSectionTypeDWARFDebugStr)
-  .Case(".debug_str_offsets", eSectionTypeDWARFDebugStrOffsets)
-  .Case(".debug_types", eSectionTypeDWARFDebugTypes)
-  .Default(eSectionTypeOther);
+  section_type = GetSectionTypeFromName(sect_info.name.GetStringRef());
   if (section_type == eSectionTypeOther)
 continue;
   section_name = sect_info.name;


Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
===
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -253,6 +253,43 @@
 
 Symtab *ObjectFileWasm::GetSymtab() { return nullptr; }
 
+static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
+  if (Name.consume_front(".debug_") || Name.

[Lldb-commits] [PATCH] D93621: [lldb][wasm] Parse DWO section names

2020-12-22 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe updated this revision to Diff 313321.
pfaffe added a comment.

Add the new dwo sections to the testcase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93621/new/

https://reviews.llvm.org/D93621

Files:
  lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
  lldb/test/Shell/ObjectFile/wasm/embedded-debug-sections.yaml

Index: lldb/test/Shell/ObjectFile/wasm/embedded-debug-sections.yaml
===
--- lldb/test/Shell/ObjectFile/wasm/embedded-debug-sections.yaml
+++ lldb/test/Shell/ObjectFile/wasm/embedded-debug-sections.yaml
@@ -40,6 +40,73 @@
 # CHECK: VM size: 0
 # CHECK: File size: 3
 
+# CHECK: Name: .debug_abbrev.dwo
+# CHECK: Type: dwarf-abbrev-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_info.dwo
+# CHECK: Type: dwarf-info-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_line.dwo
+# CHECK: Type: dwarf-line
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_line_str.dwo
+# CHECK: Type: dwarf-line-str
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_loc.dwo
+# CHECK: Type: dwarf-loc-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_loclists.dwo
+# CHECK: Type: dwarf-loclists-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_macro.dwo
+# CHECK: Type: dwarf-macro
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_rnglists.dwo
+# CHECK: Type: dwarf-rnglists-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_str.dwo
+# CHECK: Type: dwarf-str-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_str_offsets.dwo
+# CHECK: Type: dwarf-str-offsets-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+# CHECK: Name: .debug_types.dwo
+# CHECK: Type: dwarf-types-dwo
+# CHECK: VM address: 0x0
+# CHECK: VM size: 0
+# CHECK: File size: 4
+
+
 --- !WASM
 FileHeader:
   Version: 0x0001
@@ -64,4 +131,37 @@
   - Type:CUSTOM
 Name:.debug_str
 Payload: 636CFF
+  - Type:CUSTOM
+Name:.debug_abbrev.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_info.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_line.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_line_str.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_loc.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_loclists.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_macro.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_rnglists.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_str.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_str_offsets.dwo
+Payload: DEADBEEF
+  - Type:CUSTOM
+Name:.debug_types.dwo
+Payload: DEADBEEF
 ...
Index: lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
===
--- lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
+++ lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp
@@ -253,6 +253,43 @@
 
 Symtab *ObjectFileWasm::GetSymtab() { return nullptr; }
 
+static SectionType GetSectionTypeFromName(llvm::StringRef Name) {
+  if (Name.consume_front(".debug_") || Name.consume_front(".zdebug_")) {
+return llvm::StringSwitch(Name)
+.Case("abbrev", eSectionTypeDWARFDebugAbbrev)
+.Case("abbrev.dwo", eSectionTypeDWARFDebugAbbrevDwo)
+.Case("addr", eSectionTypeDWARFDebugAddr)
+.Case("aranges", eSectionTypeDWARFDebugAranges)
+.Case("cu_index", eSectionTypeDWARFDebugCuIndex)
+.Case("frame", eSectionTypeDWARFDebugFrame)
+.Case("info", eSectionTypeDWARFDebugInfo)
+.Case("info.dwo", eSectionTypeDWARFDebugInfoDwo)
+.Cases("line", "line.dwo", eSectionTypeDWARFDebugLine)
+.Cases("line_str", "line_str.dwo", eSectionTypeDWARFDebugLineStr)
+.Case("loc", eSectionTypeDWARFDebugLoc)
+.Case("loc.dwo", eSectionTypeDWARFDebugLocDwo)
+.Case("loclists", eSectionTypeDWARFDebugLocLists)
+.Case("loclists.dwo", eSectionTypeDWARFDebugLocListsDwo)
+.Case("macinfo", eSectionTypeDWARFDebugMacInfo)
+.Cases("macro", "macro.dwo", eSectionTypeDWARFDebugMacro)
+.Case("names", eSectionTypeDWARFDebugNames)
+ 

[Lldb-commits] [PATCH] D93621: [lldb][wasm] Parse DWO section names

2021-01-12 Thread Philip Pfaffe via Phabricator via lldb-commits
pfaffe added a comment.

Thanks! Would you mind landing the change for me? I'm not a github comitter.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93621/new/

https://reviews.llvm.org/D93621

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