2828#include " llvm/BinaryFormat/ELF.h"
2929#include " llvm/Support/Threading.h"
3030
31- #include " ProcessElfGpuCore.h"
3231#include " Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
3332#include " Plugins/ObjectFile/ELF/ObjectFileELF.h"
3433#include " Plugins/Process/elf-core/RegisterUtilities.h"
3534#include " ProcessElfCore.h"
35+ #include " ProcessElfEmbeddedCore.h"
3636#include " ThreadElfCore.h"
3737
3838using namespace lldb_private ;
@@ -273,12 +273,9 @@ Status ProcessElfCore::DoLoadCore() {
273273 }
274274 }
275275 }
276- llvm::Expected<std::shared_ptr<ProcessElfGpuCore>> gpu_process =
277- ProcessElfGpuCore::LoadGpuCore (
278- std::static_pointer_cast<ProcessElfCore>(shared_from_this ()),
279- GetCoreFile ());
280- if (!gpu_process)
281- return Status::FromError (gpu_process.takeError ());
276+ ProcessElfEmbeddedCore::LoadEmbeddedCoreFiles (
277+ std::static_pointer_cast<ProcessElfCore>(shared_from_this ()),
278+ GetCoreFile ());
282279
283280 return error;
284281}
@@ -437,7 +434,7 @@ size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
437434 const lldb::addr_t file_start = address_range->data .GetRangeBase ();
438435 const lldb::addr_t file_end = address_range->data .GetRangeEnd ();
439436 size_t bytes_to_read = size; // Number of bytes to read from the core file
440- size_t bytes_copied = 0 ; // Number of bytes actually read from the core file
437+ size_t bytes_copied = 0 ; // Number of bytes actually read from the core file
441438 lldb::addr_t bytes_left =
442439 0 ; // Number of bytes available in the core file from the given address
443440
@@ -520,8 +517,7 @@ lldb::addr_t ProcessElfCore::GetImageInfoAddress() {
520517
521518// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
522519static void ParseFreeBSDPrStatus (ThreadData &thread_data,
523- const DataExtractor &data,
524- bool lp64) {
520+ const DataExtractor &data, bool lp64) {
525521 lldb::offset_t offset = 0 ;
526522 int pr_version = data.GetU32 (&offset);
527523
@@ -548,8 +544,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
548544
549545// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
550546static void ParseFreeBSDPrPsInfo (ProcessElfCore &process,
551- const DataExtractor &data,
552- bool lp64) {
547+ const DataExtractor &data, bool lp64) {
553548 lldb::offset_t offset = 0 ;
554549 int pr_version = data.GetU32 (&offset);
555550
@@ -568,8 +563,7 @@ static void ParseFreeBSDPrPsInfo(ProcessElfCore &process,
568563}
569564
570565static llvm::Error ParseNetBSDProcInfo (const DataExtractor &data,
571- uint32_t &cpi_nlwps,
572- uint32_t &cpi_signo,
566+ uint32_t &cpi_nlwps, uint32_t &cpi_signo,
573567 uint32_t &cpi_siglwp,
574568 uint32_t &cpi_pid) {
575569 lldb::offset_t offset = 0 ;
@@ -737,8 +731,8 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
737731
738732 if (name == " NetBSD-CORE" ) {
739733 if (note.info .n_type == NETBSD::NT_PROCINFO) {
740- llvm::Error error = ParseNetBSDProcInfo (note. data , nlwps, signo,
741- siglwp, pr_pid);
734+ llvm::Error error =
735+ ParseNetBSDProcInfo (note. data , nlwps, signo, siglwp, pr_pid);
742736 if (error)
743737 return error;
744738 SetID (pr_pid);
@@ -964,7 +958,9 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
964958 Status status = prpsinfo.Parse (note.data , arch);
965959 if (status.Fail ())
966960 return status.ToError ();
967- thread_data.name .assign (prpsinfo.pr_fname , strnlen (prpsinfo.pr_fname , sizeof (prpsinfo.pr_fname )));
961+ thread_data.name .assign (
962+ prpsinfo.pr_fname ,
963+ strnlen (prpsinfo.pr_fname , sizeof (prpsinfo.pr_fname )));
968964 SetID (prpsinfo.pr_pid );
969965 m_executable_name = thread_data.name ;
970966 break ;
@@ -1019,7 +1015,7 @@ llvm::Error ProcessElfCore::ParseThreadContextsFromNoteSegment(
10191015 assert (segment_header.p_type == llvm::ELF::PT_NOTE);
10201016
10211017 auto notes_or_error = parseSegment (segment_data);
1022- if (!notes_or_error)
1018+ if (!notes_or_error)
10231019 return notes_or_error.takeError ();
10241020 switch (GetArchitecture ().GetTriple ().getOS ()) {
10251021 case llvm::Triple::FreeBSD:
@@ -1152,14 +1148,15 @@ bool ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info) {
11521148 return true ;
11531149}
11541150
1155- std::optional<CoreNote> ProcessElfCore::GetAmdGpuNote () {
1151+ std::vector<CoreNote> ProcessElfCore::GetCoreNotes () {
1152+ std::vector<CoreNote> notes;
11561153 ObjectFileELF *core = (ObjectFileELF *)(m_core_module_sp->GetObjectFile ());
11571154 if (core == nullptr )
1158- return std:: nullopt ;
1155+ return notes ;
11591156 llvm::ArrayRef<elf::ELFProgramHeader> program_headers =
11601157 core->ProgramHeaders ();
11611158 if (program_headers.size () == 0 )
1162- return std:: nullopt ;
1159+ return notes ;
11631160
11641161 for (const elf::ELFProgramHeader &H : program_headers) {
11651162 if (H.p_type == llvm::ELF::PT_NOTE) {
@@ -1170,11 +1167,11 @@ std::optional<CoreNote> ProcessElfCore::GetAmdGpuNote() {
11701167 llvm::consumeError (notes_or_error.takeError ());
11711168 continue ;
11721169 }
1173- for ( const auto ¬e : *notes_or_error) {
1174- if ( note. info . n_type == llvm::ELF::NT_AMDGPU_KFD_CORE_STATE)
1175- return note;
1170+ // Append all notes from this segment to our collection
1171+ for ( auto & note : *notes_or_error) {
1172+ notes. push_back ( std::move ( note)) ;
11761173 }
11771174 }
11781175 }
1179- return std:: nullopt ;
1176+ return notes ;
11801177}
0 commit comments