[lldb-dev] Cross-arch core file loading on FreeBSD

Ed Maste emaste at freebsd.org
Fri Feb 13 10:55:52 PST 2015


FreeBSD userland core files have no section table, so the vendor and
OS detection in ObjectFileELF does not get a chance to set the arch
spec.

There is a special case in ObjectFileELF::GetSectionHeaderInfo for the
case that the ELF file and host have the same core (i.e., CPU) type.
If they do then an unknown OS or vendor is updated to match the host.

Unfortunately this does not work with cross-arch core file debugging -
e.g. debugging a FreeBSD/aarch64 core file on FreeBSD/i386.  I'm using
the following workaround for now:

====
diff --git a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index e7bf20e..772adb6 100644
--- a/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -1395,8 +1395,11 @@
ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl
&section_headers,
     }

     // If there are no section headers we are done.
-    if (header.e_shnum == 0)
+    if (header.e_shnum == 0) {
+        if (arch_spec.GetTriple().getOS() == llvm::Triple::OSType::UnknownOS)
+            arch_spec.GetTriple().setOSName(HostInfo::GetOSString().data());
         return 0;
+    }

     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_MODULES));
====

which isn't quite right, since cross-OS debugging will still not work
- e.g. opening a FreeBSD/i386 core file on Linux/i386, or a
FreeBSD/aarch64 core file on Linux/i386.

What I think we need is:
* Have the special case in ObjectFileELF::GetSectionHeaderInfo not
take effect for core files, so the arch spec remains e.g.
aarch64-unknown-unknown
* Update ObjectFile::SetModulesArchitecture to take a flag specifying
exact or compatible match, and promote unknown vendor or OS to a
specified vendor or OS (but not the other way around)
* Have ObjectFileELF::CreateInstance request a compatible match for
ELF core files (ET_CORE).

Does that sound reasonable?



More information about the lldb-dev mailing list