summaryrefslogtreecommitdiff
path: root/source/Plugins/Process/elf-core
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2019-10-23 17:53:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2019-10-23 17:53:01 +0000
commitead246455adf1a215ec2715dad6533073a6beb4e (patch)
treef3f97a47d77053bf96fe74cdbd6fae74380e8a92 /source/Plugins/Process/elf-core
parentfdb00c4408990a0a63ef7f496d809ce59f263bc5 (diff)
Notes
Diffstat (limited to 'source/Plugins/Process/elf-core')
-rw-r--r--source/Plugins/Process/elf-core/ProcessElfCore.cpp51
-rw-r--r--source/Plugins/Process/elf-core/RegisterUtilities.h40
-rw-r--r--source/Plugins/Process/elf-core/ThreadElfCore.cpp5
3 files changed, 37 insertions, 59 deletions
diff --git a/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 980169e16c51d..ab23589ae9a99 100644
--- a/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -33,6 +33,7 @@
#include "ThreadElfCore.h"
using namespace lldb_private;
+namespace ELF = llvm::ELF;
ConstString ProcessElfCore::GetPluginNameStatic() {
static ConstString g_name("elf-core");
@@ -117,16 +118,20 @@ lldb::addr_t ProcessElfCore::AddAddressRangeFromLoadSegment(
FileRange file_range(header.p_offset, header.p_filesz);
VMRangeToFileOffset::Entry range_entry(addr, header.p_memsz, file_range);
- VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
- if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
- last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
- last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
- last_entry->SetRangeEnd(range_entry.GetRangeEnd());
- last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
- } else {
- m_core_aranges.Append(range_entry);
+ // Only add to m_core_aranges if the file size is non zero. Some core files
+ // have PT_LOAD segments for all address ranges, but set f_filesz to zero for
+ // the .text sections since they can be retrieved from the object files.
+ if (header.p_filesz > 0) {
+ VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
+ if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
+ last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
+ last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
+ last_entry->SetRangeEnd(range_entry.GetRangeEnd());
+ last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
+ } else {
+ m_core_aranges.Append(range_entry);
+ }
}
-
// Keep a separate map of permissions that that isn't coalesced so all ranges
// are maintained.
const uint32_t permissions =
@@ -417,7 +422,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
if (log) {
if (pr_version > 1)
- log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version);
+ LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version);
}
// Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
@@ -521,8 +526,8 @@ llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
if (note.info.n_name != "FreeBSD")
continue;
- if ((note.info.n_type == FREEBSD::NT_PRSTATUS && have_prstatus) ||
- (note.info.n_type == FREEBSD::NT_PRPSINFO && have_prpsinfo)) {
+ if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
+ (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
assert(thread_data.gpregset.GetByteSize() > 0);
// Add the new thread to thread list
m_thread_data.push_back(thread_data);
@@ -532,19 +537,19 @@ llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
}
switch (note.info.n_type) {
- case FREEBSD::NT_PRSTATUS:
+ case ELF::NT_PRSTATUS:
have_prstatus = true;
ParseFreeBSDPrStatus(thread_data, note.data, GetArchitecture());
break;
- case FREEBSD::NT_PRPSINFO:
+ case ELF::NT_PRPSINFO:
have_prpsinfo = true;
break;
- case FREEBSD::NT_THRMISC: {
+ case ELF::NT_FREEBSD_THRMISC: {
lldb::offset_t offset = 0;
thread_data.name = note.data.GetCStr(&offset, 20);
break;
}
- case FREEBSD::NT_PROCSTAT_AUXV:
+ case ELF::NT_FREEBSD_PROCSTAT_AUXV:
// FIXME: FreeBSD sticks an int at the beginning of the note
m_auxv = DataExtractor(note.data, 4, note.data.GetByteSize() - 4);
break;
@@ -771,8 +776,8 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
if (note.info.n_name != "CORE" && note.info.n_name != "LINUX")
continue;
- if ((note.info.n_type == LINUX::NT_PRSTATUS && have_prstatus) ||
- (note.info.n_type == LINUX::NT_PRPSINFO && have_prpsinfo)) {
+ if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
+ (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
assert(thread_data.gpregset.GetByteSize() > 0);
// Add the new thread to thread list
m_thread_data.push_back(thread_data);
@@ -782,7 +787,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
}
switch (note.info.n_type) {
- case LINUX::NT_PRSTATUS: {
+ case ELF::NT_PRSTATUS: {
have_prstatus = true;
ELFLinuxPrStatus prstatus;
Status status = prstatus.Parse(note.data, arch);
@@ -795,7 +800,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
thread_data.gpregset = DataExtractor(note.data, header_size, len);
break;
}
- case LINUX::NT_PRPSINFO: {
+ case ELF::NT_PRPSINFO: {
have_prpsinfo = true;
ELFLinuxPrPsInfo prpsinfo;
Status status = prpsinfo.Parse(note.data, arch);
@@ -805,7 +810,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
SetID(prpsinfo.pr_pid);
break;
}
- case LINUX::NT_SIGINFO: {
+ case ELF::NT_SIGINFO: {
ELFLinuxSigInfo siginfo;
Status status = siginfo.Parse(note.data, arch);
if (status.Fail())
@@ -813,7 +818,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
thread_data.signo = siginfo.si_signo;
break;
}
- case LINUX::NT_FILE: {
+ case ELF::NT_FILE: {
m_nt_file_entries.clear();
lldb::offset_t offset = 0;
const uint64_t count = note.data.GetAddress(&offset);
@@ -832,7 +837,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
}
break;
}
- case LINUX::NT_AUXV:
+ case ELF::NT_AUXV:
m_auxv = note.data;
break;
default:
diff --git a/source/Plugins/Process/elf-core/RegisterUtilities.h b/source/Plugins/Process/elf-core/RegisterUtilities.h
index d3b3373150f8f..49ad425db4453 100644
--- a/source/Plugins/Process/elf-core/RegisterUtilities.h
+++ b/source/Plugins/Process/elf-core/RegisterUtilities.h
@@ -11,21 +11,11 @@
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
#include "lldb/Utility/DataExtractor.h"
+#include "llvm/BinaryFormat/ELF.h"
namespace lldb_private {
/// Core files PT_NOTE segment descriptor types
-namespace FREEBSD {
-enum {
- NT_PRSTATUS = 1,
- NT_FPREGSET,
- NT_PRPSINFO,
- NT_THRMISC = 7,
- NT_PROCSTAT_AUXV = 16,
- NT_PPC_VMX = 0x100
-};
-}
-
namespace NETBSD {
enum { NT_PROCINFO = 1, NT_AUXV = 2 };
@@ -76,22 +66,6 @@ enum {
};
}
-namespace LINUX {
-enum {
- NT_PRSTATUS = 1,
- NT_FPREGSET,
- NT_PRPSINFO,
- NT_TASKSTRUCT,
- NT_PLATFORM,
- NT_AUXV,
- NT_FILE = 0x46494c45,
- NT_SIGINFO = 0x53494749,
- NT_PPC_VMX = 0x100,
- NT_PPC_VSX = 0x102,
- NT_PRXFPREG = 0x46e62b7f,
-};
-}
-
struct CoreNote {
ELFNote info;
DataExtractor data;
@@ -122,24 +96,24 @@ DataExtractor getRegset(llvm::ArrayRef<CoreNote> Notes,
llvm::ArrayRef<RegsetDesc> RegsetDescs);
constexpr RegsetDesc FPR_Desc[] = {
- {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, FREEBSD::NT_FPREGSET},
+ {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, llvm::ELF::NT_FPREGSET},
// In a i386 core file NT_FPREGSET is present, but it's not the result
// of the FXSAVE instruction like in 64 bit files.
// The result from FXSAVE is in NT_PRXFPREG for i386 core files
- {llvm::Triple::Linux, llvm::Triple::x86, LINUX::NT_PRXFPREG},
- {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_FPREGSET},
+ {llvm::Triple::Linux, llvm::Triple::x86, llvm::ELF::NT_PRXFPREG},
+ {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_FPREGSET},
{llvm::Triple::NetBSD, llvm::Triple::aarch64, NETBSD::AARCH64::NT_FPREGS},
{llvm::Triple::NetBSD, llvm::Triple::x86_64, NETBSD::AMD64::NT_FPREGS},
{llvm::Triple::OpenBSD, llvm::Triple::UnknownArch, OPENBSD::NT_FPREGS},
};
constexpr RegsetDesc PPC_VMX_Desc[] = {
- {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, FREEBSD::NT_PPC_VMX},
- {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_PPC_VMX},
+ {llvm::Triple::FreeBSD, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
+ {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VMX},
};
constexpr RegsetDesc PPC_VSX_Desc[] = {
- {llvm::Triple::Linux, llvm::Triple::UnknownArch, LINUX::NT_PPC_VSX},
+ {llvm::Triple::Linux, llvm::Triple::UnknownArch, llvm::ELF::NT_PPC_VSX},
};
} // namespace lldb_private
diff --git a/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index a5d1fc4a7bfff..508c8a3108a68 100644
--- a/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -181,9 +181,8 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
}
if (!reg_interface) {
- if (log)
- log->Printf("elf-core::%s:: Architecture(%d) or OS(%d) not supported",
- __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
+ LLDB_LOGF(log, "elf-core::%s:: Architecture(%d) or OS(%d) not supported",
+ __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
assert(false && "Architecture or OS not supported");
}