[Lldb-commits] [PATCH] D40311: elf-core: Split up parsing code into os-specific functions

2017-11-22 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

Looks like a good improvement to me.


https://reviews.llvm.org/D40311



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


[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-19 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis created this revision.
Herald added a subscriber: mgorny.

Add basic OpenBSD support. This is enough to be able to analyze core dumps for 
OpenBSD/amd64, but not much beyond that.

Note that part of the changes to 
source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp fix a bug that probably affects 
other platforms as well.  The GetProgramHeaderByIndex() interface use 1-based 
indices, but in some case when looping over the headers the, the loop starts at 
0 and misses the last header.  This caused problems on OpenBSD since OpenBSD 
core dumps have the PT_NOTE segment as the last program header.


https://reviews.llvm.org/D31131

Files:
  include/lldb/Host/Config.h
  include/lldb/Host/Editline.h
  include/lldb/Host/Host.h
  include/lldb/Host/HostInfo.h
  source/API/SystemInitializerFull.cpp
  source/CMakeLists.txt
  source/Host/CMakeLists.txt
  source/Host/common/Host.cpp
  source/Host/openbsd/Host.cpp
  source/Host/openbsd/HostInfoOpenBSD.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/Platform/CMakeLists.txt
  source/Plugins/Platform/OpenBSD/CMakeLists.txt
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
  source/Plugins/Process/Utility/CMakeLists.txt
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/elf-core/ThreadElfCore.cpp

Index: source/Plugins/Process/elf-core/ThreadElfCore.cpp
===
--- source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -21,6 +21,7 @@
 #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
 #include "ProcessElfCore.h"
@@ -103,6 +104,20 @@
 break;
   case llvm::Triple::x86_64:
 reg_interface = new RegisterContextFreeBSD_x86_64(arch);
+break;
+  default:
+break;
+  }
+  break;
+}
+
+case llvm::Triple::OpenBSD: {
+  switch (arch.GetMachine()) {
+  case llvm::Triple::aarch64:
+reg_interface = new RegisterInfoPOSIX_arm64(arch);
+break;
+  case llvm::Triple::x86_64:
+reg_interface = new RegisterContextOpenBSD_x86_64(arch);
 break;
   default:
 break;
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -431,6 +431,10 @@
   NT_FILE = 0x46494c45,
   NT_PRXFPREG = 0x46e62b7f,
   NT_SIGINFO = 0x53494749,
+  NT_OPENBSD_PROCINFO = 10,
+  NT_OPENBSD_AUXV = 11,
+  NT_OPENBSD_REGS = 20,
+  NT_OPENBSD_FPREGS = 21,
 };
 
 namespace FREEBSD {
@@ -481,6 +485,18 @@
   thread_data.name = data.GetCStr(&offset, 20);
 }
 
+static void ParseOpenBSDProcInfo(ThreadData &thread_data, DataExtractor &data)
+{
+  lldb::offset_t offset = 0;
+  
+  int version = data.GetU32(&offset);
+  if (version != 1)
+	  return;
+
+  offset += 4;
+  thread_data.signo = data.GetU32(&offset);
+}
+
 /// Parse Thread context from PT_NOTE segment and store it in the thread list
 /// Notes:
 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
@@ -568,6 +584,22 @@
 break;
   default:
 break;
+  }
+} else if (strncmp(note.n_name.c_str(), "OpenBSD", 7) == 0) {
+  m_os = llvm::Triple::OpenBSD;
+  switch (note.n_type) {
+  case NT_OPENBSD_PROCINFO:
+	ParseOpenBSDProcInfo(*thread_data, note_data);
+	break;
+  case NT_OPENBSD_AUXV:
+	m_auxv = DataExtractor(note_data);
+	break;
+  case NT_OPENBSD_REGS:
+	thread_data->gpregset = note_data;
+	break;
+  case NT_OPENBSD_FPREGS:
+	thread_data->fpregset = note_data;
+	break;
   }
 } else if (note.n_name == "CORE") {
   switch (note.n_type) {
Index: source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
===
--- source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
+++ source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
@@ -0,0 +1,31 @@
+//===-- RegisterContextOpenBSD_x86_64.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef liblldb_RegisterContextOpenBSD_x86_64_H_
+#define liblldb_RegisterContex

[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-20 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis marked 2 inline comments as done.
kettenis added a comment.

Will revise the diff based on your comments. Thanks!




Comment at: include/lldb/Host/Config.h:35
+
+#include "lldb/Host/openbsd/Config.h"
 

krytarowski wrote:
> krytarowski wrote:
> > Missing in patch?
> I think that Config.h should go away. It's almost empty. But it's beyond the 
> scope of this patch.
> 
> While there I would sort this list of includes again.
Oops yes; missed adding a directory.



Comment at: include/lldb/Host/HostInfo.h:55
+#elif defined(__OpenBSD__)
+#include "lldb/Host/openbsd/HostInfoOpenBSD.h"
+#define HOST_INFO_TYPE HostInfoOpenBSD

krytarowski wrote:
> I would sort includes here.
Do you want me to sort the entire list?



Comment at: source/Host/openbsd/Host.cpp:223
+
+#if 0
+lldb::DataBufferSP Host::GetAuxvData(lldb_private::Process *process) {

labath wrote:
> krytarowski wrote:
> > Wasn't it already gone from there?
> Yep, this should be deleted completely.
Gone.



Comment at: source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp:60
+
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
+// Only accept "unknown" for the OS if the host is BSD and

krytarowski wrote:
> Please delete `__FreeBSD__` here and from the FreeBSD platform switch for 
> `__OpenBSD__`, but I don't insist on doing the FreeBSD tweak within the same 
> commit.
Will do.



Comment at: source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp:158
+case 1:
+  triple.setArchName("i386");
+  break;

labath wrote:
> As far as I can tell, you're only adding x86_64 support, so you should 
> probably remove the others.
True.  I trimmed the list that FreeBSD had.  My intention is to submit support 
for all these architectures. But I can leave the currently unsupported ones out.



Comment at: source/Plugins/Process/elf-core/ProcessElfCore.cpp:588
+  }
+} else if (strncmp(note.n_name.c_str(), "OpenBSD", 7) == 0) {
+  m_os = llvm::Triple::OpenBSD;

krytarowski wrote:
> `note.n_name == "OpenBSD"` ?
That wouldn't work. The notes describing the registers have the thread ID 
attached to this name, i.e. "OpenBSD@250037".  I'll need to parse that string 
to make core dumps of multi-threaded processes work later.



Comment at: source/Plugins/Process/elf-core/ThreadElfCore.cpp:114
+
+case llvm::Triple::OpenBSD: {
+  switch (arch.GetMachine()) {

krytarowski wrote:
> I would consider to keep it sorted - after Linux.
Will do.



Comment at: source/Plugins/Process/elf-core/ThreadElfCore.cpp:117
+  case llvm::Triple::aarch64:
+reg_interface = new RegisterInfoPOSIX_arm64(arch);
+break;

labath wrote:
> Have you checked that the arm64 case would work here? (at least whether the 
> register context have roughly the same layout ?)
I'm actually working on making the layout the same (OpenBSD/arm64 is still 
under heavy development). I'll make sure it works before this diff lands ;)


Repository:
  rL LLVM

https://reviews.llvm.org/D31131



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


[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-23 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis updated this revision to Diff 92857.
kettenis marked an inline comment as done.
kettenis edited the summary of this revision.
kettenis added a comment.
Herald added subscribers: srhines, rengolin, emaste, aemerson.

New diff. This one adds support for OpenBSD/amd64, OpenBSD/arm, OpenBSD/arm64 
and OpenBSD/i386.  I'm holding off on resorting existing code. I'm willing to 
do that in a separate diff.


https://reviews.llvm.org/D31131

Files:
  include/lldb/Host/Config.h
  include/lldb/Host/Editline.h
  include/lldb/Host/Host.h
  include/lldb/Host/HostInfo.h
  include/lldb/Host/openbsd/Config.h
  include/lldb/Host/openbsd/HostInfoOpenBSD.h
  source/API/SystemInitializerFull.cpp
  source/CMakeLists.txt
  source/Host/CMakeLists.txt
  source/Host/common/Host.cpp
  source/Host/openbsd/Host.cpp
  source/Host/openbsd/HostInfoOpenBSD.cpp
  source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/Platform/CMakeLists.txt
  source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  source/Plugins/Platform/OpenBSD/CMakeLists.txt
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
  source/Plugins/Process/Utility/CMakeLists.txt
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/elf-core/ThreadElfCore.cpp

Index: source/Plugins/Process/elf-core/ThreadElfCore.cpp
===
--- source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -21,6 +21,8 @@
 #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
 #include "ProcessElfCore.h"
@@ -126,6 +128,26 @@
 break;
   case llvm::Triple::x86_64:
 reg_interface = new RegisterContextLinux_x86_64(arch);
+break;
+  default:
+break;
+  }
+  break;
+}
+
+case llvm::Triple::OpenBSD: {
+  switch (arch.GetMachine()) {
+  case llvm::Triple::aarch64:
+reg_interface = new RegisterInfoPOSIX_arm64(arch);
+break;
+  case llvm::Triple::arm:
+reg_interface = new RegisterInfoPOSIX_arm(arch);
+break;
+  case llvm::Triple::x86:
+	reg_interface = new RegisterContextOpenBSD_i386(arch);
+	break;
+  case llvm::Triple::x86_64:
+reg_interface = new RegisterContextOpenBSD_x86_64(arch);
 break;
   default:
 break;
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -431,6 +431,10 @@
   NT_FILE = 0x46494c45,
   NT_PRXFPREG = 0x46e62b7f,
   NT_SIGINFO = 0x53494749,
+  NT_OPENBSD_PROCINFO = 10,
+  NT_OPENBSD_AUXV = 11,
+  NT_OPENBSD_REGS = 20,
+  NT_OPENBSD_FPREGS = 21,
 };
 
 namespace FREEBSD {
@@ -481,6 +485,18 @@
   thread_data.name = data.GetCStr(&offset, 20);
 }
 
+static void ParseOpenBSDProcInfo(ThreadData &thread_data, DataExtractor &data)
+{
+  lldb::offset_t offset = 0;
+  
+  int version = data.GetU32(&offset);
+  if (version != 1)
+	  return;
+
+  offset += 4;
+  thread_data.signo = data.GetU32(&offset);
+}
+
 /// Parse Thread context from PT_NOTE segment and store it in the thread list
 /// Notes:
 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
@@ -568,6 +584,24 @@
 break;
   default:
 break;
+  }
+} else if (note.n_name.substr(0, 7) == "OpenBSD") {
+  // OpenBSD per-thread information is stored in notes named
+  // "OpenBSD@nnn" so match on the initial part of the string.
+  m_os = llvm::Triple::OpenBSD;
+  switch (note.n_type) {
+  case NT_OPENBSD_PROCINFO:
+	ParseOpenBSDProcInfo(*thread_data, note_data);
+	break;
+  case NT_OPENBSD_AUXV:
+	m_auxv = DataExtractor(note_data);
+	break;
+  case NT_OPENBSD_REGS:
+	thread_data->gpregset = note_data;
+	break;
+  case NT_OPENBSD_FPREGS:
+	thread_data->fpregset = note_data;
+	break;
   }
 } else if (note.n_name == "CORE") {
   switch (note.n_type) {
Index: source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
===
--- source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_6

[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-23 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis updated this revision to Diff 92861.
kettenis added a comment.

Apologies.  Previous diff contained a bogus change to DYLDRendezvous.cpp and a 
formatting botch.  Please review this updated version instead,


https://reviews.llvm.org/D31131

Files:
  include/lldb/Host/Config.h
  include/lldb/Host/Editline.h
  include/lldb/Host/Host.h
  include/lldb/Host/HostInfo.h
  include/lldb/Host/openbsd/Config.h
  include/lldb/Host/openbsd/HostInfoOpenBSD.h
  source/API/SystemInitializerFull.cpp
  source/CMakeLists.txt
  source/Host/CMakeLists.txt
  source/Host/common/Host.cpp
  source/Host/openbsd/Host.cpp
  source/Host/openbsd/HostInfoOpenBSD.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/Platform/CMakeLists.txt
  source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  source/Plugins/Platform/OpenBSD/CMakeLists.txt
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
  source/Plugins/Process/Utility/CMakeLists.txt
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/elf-core/ThreadElfCore.cpp

Index: source/Plugins/Process/elf-core/ThreadElfCore.cpp
===
--- source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -21,6 +21,8 @@
 #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
 #include "ProcessElfCore.h"
@@ -126,6 +128,26 @@
 break;
   case llvm::Triple::x86_64:
 reg_interface = new RegisterContextLinux_x86_64(arch);
+break;
+  default:
+break;
+  }
+  break;
+}
+
+case llvm::Triple::OpenBSD: {
+  switch (arch.GetMachine()) {
+  case llvm::Triple::aarch64:
+reg_interface = new RegisterInfoPOSIX_arm64(arch);
+break;
+  case llvm::Triple::arm:
+reg_interface = new RegisterInfoPOSIX_arm(arch);
+break;
+  case llvm::Triple::x86:
+	reg_interface = new RegisterContextOpenBSD_i386(arch);
+	break;
+  case llvm::Triple::x86_64:
+reg_interface = new RegisterContextOpenBSD_x86_64(arch);
 break;
   default:
 break;
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -431,6 +431,10 @@
   NT_FILE = 0x46494c45,
   NT_PRXFPREG = 0x46e62b7f,
   NT_SIGINFO = 0x53494749,
+  NT_OPENBSD_PROCINFO = 10,
+  NT_OPENBSD_AUXV = 11,
+  NT_OPENBSD_REGS = 20,
+  NT_OPENBSD_FPREGS = 21,
 };
 
 namespace FREEBSD {
@@ -481,6 +485,18 @@
   thread_data.name = data.GetCStr(&offset, 20);
 }
 
+static void ParseOpenBSDProcInfo(ThreadData &thread_data, DataExtractor &data)
+{
+  lldb::offset_t offset = 0;
+  
+  int version = data.GetU32(&offset);
+  if (version != 1)
+	  return;
+
+  offset += 4;
+  thread_data.signo = data.GetU32(&offset);
+}
+
 /// Parse Thread context from PT_NOTE segment and store it in the thread list
 /// Notes:
 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
@@ -568,6 +584,24 @@
 break;
   default:
 break;
+  }
+} else if (note.n_name.substr(0, 7) == "OpenBSD") {
+  // OpenBSD per-thread information is stored in notes named
+  // "OpenBSD@nnn" so match on the initial part of the string.
+  m_os = llvm::Triple::OpenBSD;
+  switch (note.n_type) {
+  case NT_OPENBSD_PROCINFO:
+	ParseOpenBSDProcInfo(*thread_data, note_data);
+	break;
+  case NT_OPENBSD_AUXV:
+	m_auxv = DataExtractor(note_data);
+	break;
+  case NT_OPENBSD_REGS:
+	thread_data->gpregset = note_data;
+	break;
+  case NT_OPENBSD_FPREGS:
+	thread_data->fpregset = note_data;
+	break;
   }
 } else if (note.n_name == "CORE") {
   switch (note.n_type) {
Index: source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
===
--- source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
+++ source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
@@ -0,0 +1,31 @@
+//===-- RegisterContextOpenBSD_x86_64.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dist

[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-24 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added inline comments.



Comment at: source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp:48
+  GPR gpr;
+  FPR_i386 i387;
+};

krytarowski wrote:
> no DBG regs here?
OpenBSD doesn't actually implement access to the debug registers.


https://reviews.llvm.org/D31131



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


[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-24 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis updated this revision to Diff 92938.
kettenis added a comment.

Updated diff to account for the FileSpec.h move.


https://reviews.llvm.org/D31131

Files:
  include/lldb/Host/Config.h
  include/lldb/Host/Editline.h
  include/lldb/Host/Host.h
  include/lldb/Host/HostInfo.h
  include/lldb/Host/openbsd/Config.h
  include/lldb/Host/openbsd/HostInfoOpenBSD.h
  source/API/SystemInitializerFull.cpp
  source/CMakeLists.txt
  source/Host/CMakeLists.txt
  source/Host/common/Host.cpp
  source/Host/openbsd/Host.cpp
  source/Host/openbsd/HostInfoOpenBSD.cpp
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
  source/Plugins/Platform/CMakeLists.txt
  source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  source/Plugins/Platform/OpenBSD/CMakeLists.txt
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
  source/Plugins/Process/Utility/CMakeLists.txt
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_i386.h
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.cpp
  source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
  source/Plugins/Process/elf-core/ProcessElfCore.cpp
  source/Plugins/Process/elf-core/ThreadElfCore.cpp

Index: source/Plugins/Process/elf-core/ThreadElfCore.cpp
===
--- source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -21,6 +21,8 @@
 #include "Plugins/Process/Utility/RegisterContextLinux_i386.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_s390x.h"
 #include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_i386.h"
+#include "Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"
 #include "Plugins/Process/Utility/RegisterInfoPOSIX_arm64.h"
 #include "ProcessElfCore.h"
@@ -126,6 +128,26 @@
 break;
   case llvm::Triple::x86_64:
 reg_interface = new RegisterContextLinux_x86_64(arch);
+break;
+  default:
+break;
+  }
+  break;
+}
+
+case llvm::Triple::OpenBSD: {
+  switch (arch.GetMachine()) {
+  case llvm::Triple::aarch64:
+reg_interface = new RegisterInfoPOSIX_arm64(arch);
+break;
+  case llvm::Triple::arm:
+reg_interface = new RegisterInfoPOSIX_arm(arch);
+break;
+  case llvm::Triple::x86:
+	reg_interface = new RegisterContextOpenBSD_i386(arch);
+	break;
+  case llvm::Triple::x86_64:
+reg_interface = new RegisterContextOpenBSD_x86_64(arch);
 break;
   default:
 break;
Index: source/Plugins/Process/elf-core/ProcessElfCore.cpp
===
--- source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -431,6 +431,10 @@
   NT_FILE = 0x46494c45,
   NT_PRXFPREG = 0x46e62b7f,
   NT_SIGINFO = 0x53494749,
+  NT_OPENBSD_PROCINFO = 10,
+  NT_OPENBSD_AUXV = 11,
+  NT_OPENBSD_REGS = 20,
+  NT_OPENBSD_FPREGS = 21,
 };
 
 namespace FREEBSD {
@@ -481,6 +485,18 @@
   thread_data.name = data.GetCStr(&offset, 20);
 }
 
+static void ParseOpenBSDProcInfo(ThreadData &thread_data, DataExtractor &data)
+{
+  lldb::offset_t offset = 0;
+  
+  int version = data.GetU32(&offset);
+  if (version != 1)
+	  return;
+
+  offset += 4;
+  thread_data.signo = data.GetU32(&offset);
+}
+
 /// Parse Thread context from PT_NOTE segment and store it in the thread list
 /// Notes:
 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
@@ -568,6 +584,24 @@
 break;
   default:
 break;
+  }
+} else if (note.n_name.substr(0, 7) == "OpenBSD") {
+  // OpenBSD per-thread information is stored in notes named
+  // "OpenBSD@nnn" so match on the initial part of the string.
+  m_os = llvm::Triple::OpenBSD;
+  switch (note.n_type) {
+  case NT_OPENBSD_PROCINFO:
+	ParseOpenBSDProcInfo(*thread_data, note_data);
+	break;
+  case NT_OPENBSD_AUXV:
+	m_auxv = DataExtractor(note_data);
+	break;
+  case NT_OPENBSD_REGS:
+	thread_data->gpregset = note_data;
+	break;
+  case NT_OPENBSD_FPREGS:
+	thread_data->fpregset = note_data;
+	break;
   }
 } else if (note.n_name == "CORE") {
   switch (note.n_type) {
Index: source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
===
--- source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
+++ source/Plugins/Process/Utility/RegisterContextOpenBSD_x86_64.h
@@ -0,0 +1,31 @@
+//===-- RegisterContextOpenBSD_x86_64.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.

[Lldb-commits] [PATCH] D31131: [LLDB] OpenBSD support

2017-03-26 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

Can somebody commit this diff for me?


https://reviews.llvm.org/D31131



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


[Lldb-commits] [PATCH] D31374: Add support for tracing hello-world application on NetBSD

2017-03-26 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

On OpenBSD the register context used in core dumps uses the same layout as 
ptrace(2).  That's not the case on all OSes, but I believe that is the case for 
NetBSD as well.  Would it be possible to re-use the register context data 
structures defined in the source/Plugins/Process/Utility/ directory?


Repository:
  rL LLVM

https://reviews.llvm.org/D31374



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


[Lldb-commits] [PATCH] D31450: Battery of NetBSD support improvements

2017-03-29 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

The core file reading bits look ok to me.




Comment at: source/Plugins/DynamicLoader/POSIX-DYLD/DYLDRendezvous.cpp:383
   // On Linux the executable is indicated by an empty path in the entry. On
   // FreeBSD and on Android it is the full path to the executable.
 

Probably should update this comment



Comment at: source/Plugins/Process/elf-core/ProcessElfCore.cpp:456
+}
+
 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.

Unfortunate that the note numbers are different from architecture to 
architecture on NetBSD.


Repository:
  rL LLVM

https://reviews.llvm.org/D31450



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


[Lldb-commits] [PATCH] D32149: Correct handling NetBSD core(5) files with threads

2017-04-20 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

Generally looks reasonable to me.  A few comments inline.




Comment at: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:1374
+else if ((note.n_name == LLDB_NT_OWNER_NETBSDCORE) &&
+ (note.n_type == LLDB_NT_NETBSD_NT_PROCINFO)) {
   // Set the elf OS version to NetBSD.  Also clear the vendor.

By making this change you risk losing recognition of "normal" NetBSD ELF files, 
i.e. executables and shared libraries.



Comment at: source/Plugins/Process/elf-core/ProcessElfCore.cpp:563
+
+/// Generic (Linux, ...) specific Thread context from PT_NOTE segment
+/// 1) A Thread Context in a core file usually described by 3 NOTE entries.

A bit strange to call something both generic and specific...

I think some of these note types originated on SVR4/Solaris, but I'm not sure 
how much Linux deviated from that design through the years.



Comment at: source/Plugins/Process/elf-core/ProcessElfCore.cpp:815
+return Error("Error parsing NetBSD core(5) notes: Cannot convert "
+ "LWP ID to integer");
+} else if (note.n_type == NETBSD::AMD64::NT_FPREGS) {

Wouldn't it make sense to move the parsing of the LWP ID before the switch. 
Otherwise you'll have to duplicate the code for every NetBSD architecture 
you'll add.


Repository:
  rL LLVM

https://reviews.llvm.org/D32149



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


[Lldb-commits] [PATCH] D32149: Correct handling NetBSD core(5) files with threads

2017-04-20 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added a comment.

In https://reviews.llvm.org/D32149#731887, @labath wrote:

> A test would infinitely times more valuable then a demo script. What is the 
> tiniest core file you can produce on NetBSD? (on linux we've gotten them down 
> to about 20K) Then we could check that in and write a test for it...


The smalles core dumps I managed to create for OpenBSD so far are a bit over 4M.


Repository:
  rL LLVM

https://reviews.llvm.org/D32149



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


[Lldb-commits] [PATCH] D32149: Correct handling NetBSD core(5) files with threads

2017-04-20 Thread Mark Kettenis via Phabricator via lldb-commits
kettenis added inline comments.



Comment at: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp:1374
+else if ((note.n_name == LLDB_NT_OWNER_NETBSDCORE) &&
+ (note.n_type == LLDB_NT_NETBSD_NT_PROCINFO)) {
   // Set the elf OS version to NetBSD.  Also clear the vendor.

krytarowski wrote:
> kettenis wrote:
> > By making this change you risk losing recognition of "normal" NetBSD ELF 
> > files, i.e. executables and shared libraries.
> Hmm, do you mean these notes:
> 
> ```
> $ readelf -n /bin/cat 
> 
> 
> Displaying notes found at file offset 0x0214 with length 0x0018:
>   Owner Data size Description
>   NetBSD  0x0004  IDENT 799005900 (7.99.59)
> 
> Displaying notes found at file offset 0x022c with length 0x0014:
>   Owner Data size Description
>   NetBSD  0x0004  PaX <>
> ```
In particular the first one of these.  On OpenBSD I just have a generic check 
on the name which catches both these and the core file notes.  But on NetBSD 
those use different names.



Comment at: source/Plugins/Process/elf-core/ProcessElfCore.cpp:563
+
+/// Generic (Linux, ...) specific Thread context from PT_NOTE segment
+/// 1) A Thread Context in a core file usually described by 3 NOTE entries.

krytarowski wrote:
> kettenis wrote:
> > A bit strange to call something both generic and specific...
> > 
> > I think some of these note types originated on SVR4/Solaris, but I'm not 
> > sure how much Linux deviated from that design through the years.
> Can we call it: Type1 core (as of now: NetBSD) and Type2 core (Linux, 
> Android, FreeBSD, OpenBSD)?
> 
> I don't care which would be 1 and which 2.
I'd just drop word "specific" from the comment. And OpenBSD will obviously be 
handled in a similar way as NetBSD in the near future.


Repository:
  rL LLVM

https://reviews.llvm.org/D32149



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