[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-05-11 Thread via lldb-commits

aokblast wrote:

I extend this feature to all kernel module in 
[here](https://reviews.freebsd.org/D45161/new/). Then I will write the 
corresponding code for LLDB later. Since kernel is also in linker_files 
structure. So I convinced that it can fix the problem.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-05-01 Thread Ed Maste via lldb-commits

emaste wrote:

> However, for minimal dump, the build-id section won't loaded because minimal 
> dump only dump the used memory by kernel.

If we fall back to no-UUID-found in that case and don't require that it matches 
this is still an improvement, yeah?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-03-23 Thread via lldb-commits

aokblast wrote:

I think this feature is work now in FreeBSD. If you don't find any other 
problem. Please help me merge this patch. Thanks!

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

aokblast wrote:

Sorry, I don't notice that. I fixed it.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, );
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader  : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t _debuglink_crc,
  lldb_private::ArchSpec _spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From 9df99033e10650d2afc68d5438f658bfbcdc0a29 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 22:38:57 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 41 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 36 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..c134f1d46c275 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr ,
+   Elf_Ehdr ,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, 

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

DavidSpickett wrote:

Sorry, Github ate the `<>` in my comment. It was meant to say `include the 
 in core dumps`.

Replace with the actual name, `.note.gnu.build-id` I presume.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

aokblast wrote:

Fix it

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, );
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader  : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t _debuglink_crc,
  lldb_private::ArchSpec _spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From aeeb32888f0137fd72fe067d9d7a03a5e1299cc6 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 22:06:08 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 40 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..ddebe87999fdb 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr ,
+   Elf_Ehdr ,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, 

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +234,18 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+  UUID memory_module_uuid = memory_module_sp->GetUUID();
+  if (memory_module_uuid.IsValid() &&

DavidSpickett wrote:

Add a comment here like "// FreeBSD did not always include the  in core dumps, only check if present.".

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, );
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader  : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t _debuglink_crc,
  lldb_private::ArchSpec _spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From ebcee01c88b9064b1b9da8fdca0561a569bb6271 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 21:56:24 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 38 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..5ac629552de7c 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr ,
+   Elf_Ehdr ,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, 

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

aokblast wrote:

Oh, yes, you are right. I am just thinking the same things. XD

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Thanks, the logic is clearer now.

Should this check be limited to only when a uuid is actually found? This would 
allow debugging of older FreeBSDs with a newer lldb.



https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

aokblast wrote:

All of the problem is fixed.

However, FreeBSD doesn't load PT_NOTE segment originally and I add it yesterday 
in [this](https://reviews.freebsd.org/D43757) patch with this LLDB patch at the 
same time. Currently, FreeBSD phabricator has no any response yet. I think we 
should land the patch in FreeBSD first or the LLDB will failed in the UUID 
check. 

Maybe I can tag some guys in FreeBSD like @emaste to check if the patch in 
FreeBSD make senses?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, );
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader  : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t _debuglink_crc,
  lldb_private::ArchSpec _spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From deb85785cd28e2f2975a84e839b243a7b583b264 Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 21:15:55 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 37 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 32 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..b77e089ce2fe6 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr ,
+   Elf_Ehdr ,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,23 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  // If the memory module is 64bit, we should use the Elf64_Ehdr or the e_shoff
+  // would be wrong
+  ModuleSP memory_module_sp;
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr elf64_header;
+if (!ReadELFHeader(process, addr, elf64_header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, elf64_header.e_shoff);
+  } else {
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, 

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

DavidSpickett wrote:

Yes that sounds good.

"Cannot match" to me reads as many possible reasons like we couldn't read the 
ID from one of the files, it was in the wrong format, whatever. So I prefer 
what you've suggested.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

DavidSpickett wrote:

Ok, so we're relying on the first few fields of the header being the same for 
32 and 64 bit. Which is fine.

However I would like to see it as much as possible written as:
```
if 64 bit:
64 bit stuff
else:
   32 bit stuff
```
Even if it means repeating a couple of things, because the program flow here is 
getting confusing.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits

https://github.com/aokblast edited 
https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 

aokblast wrote:

The need is in here:
```c++
llvm::ELF::Elf64_Ehdr header;
if (!ReadELFHeader(process, addr, header)) {
  *read_error = true;
  return UUID();
}
```

In this case the header is Elf64 instead of Elf32. So I try to use generic to 
handle different version of Elf

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

aokblast wrote:

Does this message ".note.gnu.build-id mismatched. Maybe you are using 
incompatible coredump with kernel binary?" like this is good?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

aokblast wrote:

```c++
ModuleSP memory_module_sp = process->ReadModuleFromMemory(
  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
```

This code segment is already handle the 32bit case as the original header 
structure is the 32bit ELF Ehdr. I just check if the ELF is 64bit version and 
replace it with the correct 64bit ELF Ehdr.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 

DavidSpickett wrote:

Exactly why does this change? I don't see a need for it in this PR.

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {

DavidSpickett wrote:

Does this not happen for 32 bit kernels?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-06 Thread David Spickett via lldb-commits


@@ -218,10 +230,16 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // In here, I should check is_kernel for memory_module_sp
-  // However, the ReadModuleFromMemory reads wrong section so that this check
-  // will failed
-  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
+  memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
+
+  if (memory_module_sp->GetUUID() !=
+  process->GetTarget().GetExecutableModule()->GetUUID()) {
+LLDB_LOGF(log, "DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress "

DavidSpickett wrote:

Could we log more specific failure reasons before the other `return` statements 
above and then make this more specific "coredump build-id did not match binary"?

https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-05 Thread via lldb-commits

https://github.com/aokblast updated 
https://github.com/llvm/llvm-project/pull/80785

>From 5f9eac19a45cd4b71afe48643fc0cf8b4b4ab6be Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:18:34 +0800
Subject: [PATCH 1/2] [LLDB] Fetch UUID from note section in coredump

---
 .../Plugins/ObjectFile/ELF/ObjectFileELF.cpp  | 29 +++
 .../Plugins/ObjectFile/ELF/ObjectFileELF.h|  3 ++
 2 files changed, 32 insertions(+)

diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 0d95a1c12bde3..3b047e3d5c759 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -795,6 +795,32 @@ bool ObjectFileELF::ParseHeader() {
   return m_header.Parse(m_data, );
 }
 
+UUID ObjectFileELF::GetUUIDByNoteSection() {
+  if (!ParseProgramHeaders())
+return UUID();
+  for (const ELFProgramHeader  : m_program_headers) {
+if (H.p_type == llvm::ELF::PT_NOTE) {
+  const elf_off ph_offset = H.p_offset;
+  const size_t ph_size = H.p_filesz;
+
+  DataExtractor segment_data;
+  if (segment_data.SetData(m_data, ph_offset, ph_size) != ph_size) {
+// The ELF program header contained incorrect data, probably corefile
+// is incomplete or corrupted.
+break;
+  }
+
+  UUID uuid;
+  ArchSpec arch;
+
+  if (RefineModuleDetailsFromNote(segment_data, arch, uuid).Success())
+return uuid;
+}
+  }
+
+  return UUID();
+}
+
 UUID ObjectFileELF::GetUUID() {
   // Need to parse the section list to get the UUIDs, so make sure that's been
   // done.
@@ -809,6 +835,9 @@ UUID ObjectFileELF::GetUUID() {
   if (!ParseProgramHeaders())
 return UUID();
 
+  if ((m_uuid = GetUUIDByNoteSection()).IsValid())
+return m_uuid;
+
   core_notes_crc =
   CalculateELFNotesSegmentsCRC32(m_program_headers, m_data);
 
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h 
b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index bc8e34981a9d8..6954bd96b753a 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -272,6 +272,9 @@ class ObjectFileELF : public lldb_private::ObjectFile {
  uint32_t _debuglink_crc,
  lldb_private::ArchSpec _spec);
 
+  // Use Note Section to get uuid.
+  lldb_private::UUID GetUUIDByNoteSection();
+
   /// Scans the dynamic section and locates all dependent modules (shared
   /// libraries) populating m_filespec_up.  This method will compute the
   /// dependent module list only once.  Returns the number of dependent

>From 659d3446fd975fcafe997d63983830e5c45b41bc Mon Sep 17 00:00:00 2001
From: aokblast 
Date: Tue, 6 Feb 2024 10:48:05 +0800
Subject: [PATCH 2/2] Add match check between binary and coredump of FreeBSD
 kernel

---
 .../DynamicLoaderFreeBSDKernel.cpp| 32 +++
 .../DynamicLoaderFreeBSDKernel.h  |  3 +-
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index e504e6cbf6921..1a7e811ac1233 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -153,9 +153,10 @@ addr_t DynamicLoaderFreeBSDKernel::FindKernelAtLoadAddress(
 }
 
 // Read ELF header from memry and return
+template 
 bool DynamicLoaderFreeBSDKernel::ReadELFHeader(Process *process,
lldb::addr_t addr,
-   llvm::ELF::Elf32_Ehdr ,
+   Elf_Ehdr ,
bool *read_error) {
   Status error;
   if (read_error)
@@ -200,8 +201,19 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
   if (header.e_type != llvm::ELF::ET_EXEC)
 return UUID();
 
-  ModuleSP memory_module_sp =
-  process->ReadModuleFromMemory(FileSpec("temp_freebsd_kernel"), addr);
+  ArchSpec kernel_arch(llvm::ELF::convertEMachineToArchName(header.e_machine));
+
+  ModuleSP memory_module_sp = process->ReadModuleFromMemory(
+  FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  if (header.e_ident[llvm::ELF::EI_CLASS] == llvm::ELF::ELFCLASS64) {
+llvm::ELF::Elf64_Ehdr header;
+if (!ReadELFHeader(process, addr, header)) {
+  *read_error = true;
+  return UUID();
+}
+memory_module_sp = process->ReadModuleFromMemory(
+FileSpec("temp_freebsd_kernel"), addr, header.e_shoff);
+  }
 
   if (!memory_module_sp.get()) {
 *read_error = true;
@@ -218,10 +230,16 @@ lldb_private::UUID 

[Lldb-commits] [lldb] [LLDB] Add FreeBSD kernel coredump matching check. (PR #80785)

2024-02-05 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 78b4e7c5e349d8c101b50affbd260eb109748f8f 
e506f292dd07bcdd26a668d9fcf87a258864db95 -- 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp 
lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.h 
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp 
lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
``





View the diff from clang-format here.


``diff
diff --git 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
index 6a7618ee59..1a7e811ac1 100644
--- 
a/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
+++ 
b/lldb/source/Plugins/DynamicLoader/FreeBSD-Kernel/DynamicLoaderFreeBSDKernel.cpp
@@ -230,8 +230,8 @@ lldb_private::UUID 
DynamicLoaderFreeBSDKernel::CheckForKernelImageAtAddress(
 return UUID();
   }
 
-  // Because the memory module is read from memory and in the memory, the type 
is eTypeExecutable
-  // so we have to assign the type manually
+  // Because the memory module is read from memory and in the memory, the type
+  // is eTypeExecutable so we have to assign the type manually
   memory_module_sp->GetObjectFile()->SetType(ObjectFile::eTypeCoreFile);
 
   if (memory_module_sp->GetUUID() !=

``




https://github.com/llvm/llvm-project/pull/80785
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits