1 //===-- ProcessElfCore.cpp --------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // C Includes
11 #include <stdlib.h>
12 
13 // C++ Includes
14 #include <mutex>
15 
16 // Other libraries and framework includes
17 #include "lldb/Core/DataBufferHeap.h"
18 #include "lldb/Core/Log.h"
19 #include "lldb/Core/Module.h"
20 #include "lldb/Core/ModuleSpec.h"
21 #include "lldb/Core/PluginManager.h"
22 #include "lldb/Core/Section.h"
23 #include "lldb/Core/State.h"
24 #include "lldb/Target/DynamicLoader.h"
25 #include "lldb/Target/MemoryRegionInfo.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/UnixSignals.h"
28 
29 #include "llvm/Support/ELF.h"
30 
31 #include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
32 #include "Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h"
33 
34 // Project includes
35 #include "ProcessElfCore.h"
36 #include "ThreadElfCore.h"
37 
38 using namespace lldb_private;
39 
40 ConstString
41 ProcessElfCore::GetPluginNameStatic()
42 {
43     static ConstString g_name("elf-core");
44     return g_name;
45 }
46 
47 const char *
48 ProcessElfCore::GetPluginDescriptionStatic()
49 {
50     return "ELF core dump plug-in.";
51 }
52 
53 void
54 ProcessElfCore::Terminate()
55 {
56     PluginManager::UnregisterPlugin (ProcessElfCore::CreateInstance);
57 }
58 
59 
60 lldb::ProcessSP
61 ProcessElfCore::CreateInstance (lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec *crash_file)
62 {
63     lldb::ProcessSP process_sp;
64     if (crash_file)
65     {
66         // Read enough data for a ELF32 header or ELF64 header
67         const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
68 
69         lldb::DataBufferSP data_sp (crash_file->ReadFileContents(0, header_size));
70         if (data_sp && data_sp->GetByteSize() == header_size &&
71             elf::ELFHeader::MagicBytesMatch (data_sp->GetBytes()))
72         {
73             elf::ELFHeader elf_header;
74             DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
75             lldb::offset_t data_offset = 0;
76             if (elf_header.Parse(data, &data_offset))
77             {
78                 if (elf_header.e_type == llvm::ELF::ET_CORE)
79                     process_sp.reset(new ProcessElfCore (target_sp, listener_sp, *crash_file));
80             }
81         }
82     }
83     return process_sp;
84 }
85 
86 bool
87 ProcessElfCore::CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name)
88 {
89     // For now we are just making sure the file exists for a given module
90     if (!m_core_module_sp && m_core_file.Exists())
91     {
92         ModuleSpec core_module_spec(m_core_file, target_sp->GetArchitecture());
93         Error error (ModuleList::GetSharedModule (core_module_spec, m_core_module_sp,
94                                                   NULL, NULL, NULL));
95         if (m_core_module_sp)
96         {
97             ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
98             if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
99                 return true;
100         }
101     }
102     return false;
103 }
104 
105 //----------------------------------------------------------------------
106 // ProcessElfCore constructor
107 //----------------------------------------------------------------------
108 ProcessElfCore::ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp,
109                                const FileSpec &core_file) :
110     Process (target_sp, listener_sp),
111     m_core_module_sp (),
112     m_core_file (core_file),
113     m_dyld_plugin_name (),
114     m_os(llvm::Triple::UnknownOS),
115     m_thread_data_valid(false),
116     m_thread_data(),
117     m_core_aranges ()
118 {
119 }
120 
121 //----------------------------------------------------------------------
122 // Destructor
123 //----------------------------------------------------------------------
124 ProcessElfCore::~ProcessElfCore()
125 {
126     Clear();
127     // We need to call finalize on the process before destroying ourselves
128     // to make sure all of the broadcaster cleanup goes as planned. If we
129     // destruct this class, then Process::~Process() might have problems
130     // trying to fully destroy the broadcaster.
131     Finalize();
132 }
133 
134 //----------------------------------------------------------------------
135 // PluginInterface
136 //----------------------------------------------------------------------
137 ConstString
138 ProcessElfCore::GetPluginName()
139 {
140     return GetPluginNameStatic();
141 }
142 
143 uint32_t
144 ProcessElfCore::GetPluginVersion()
145 {
146     return 1;
147 }
148 
149 lldb::addr_t
150 ProcessElfCore::AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader *header)
151 {
152     const lldb::addr_t addr = header->p_vaddr;
153     FileRange file_range (header->p_offset, header->p_filesz);
154     VMRangeToFileOffset::Entry range_entry(addr, header->p_memsz, file_range);
155 
156     VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
157     if (last_entry &&
158         last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
159         last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
160         last_entry->GetByteSize() == last_entry->data.GetByteSize())
161     {
162         last_entry->SetRangeEnd (range_entry.GetRangeEnd());
163         last_entry->data.SetRangeEnd (range_entry.data.GetRangeEnd());
164     }
165     else
166     {
167         m_core_aranges.Append(range_entry);
168     }
169 
170     // Keep a separate map of permissions that that isn't coalesced so all ranges
171     // are maintained.
172     const uint32_t permissions = ((header->p_flags & llvm::ELF::PF_R) ? lldb::ePermissionsReadable : 0) |
173                                  ((header->p_flags & llvm::ELF::PF_W) ? lldb::ePermissionsWritable : 0) |
174                                  ((header->p_flags & llvm::ELF::PF_X) ? lldb::ePermissionsExecutable : 0);
175 
176     m_core_range_infos.Append(VMRangeToPermissions::Entry(addr, header->p_memsz, permissions));
177 
178     return addr;
179 }
180 
181 //----------------------------------------------------------------------
182 // Process Control
183 //----------------------------------------------------------------------
184 Error
185 ProcessElfCore::DoLoadCore ()
186 {
187     Error error;
188     if (!m_core_module_sp)
189     {
190         error.SetErrorString ("invalid core module");
191         return error;
192     }
193 
194     ObjectFileELF *core = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
195     if (core == NULL)
196     {
197         error.SetErrorString ("invalid core object file");
198         return error;
199     }
200 
201     const uint32_t num_segments = core->GetProgramHeaderCount();
202     if (num_segments == 0)
203     {
204         error.SetErrorString ("core file has no segments");
205         return error;
206     }
207 
208     SetCanJIT(false);
209 
210     m_thread_data_valid = true;
211 
212     bool ranges_are_sorted = true;
213     lldb::addr_t vm_addr = 0;
214     /// Walk through segments and Thread and Address Map information.
215     /// PT_NOTE - Contains Thread and Register information
216     /// PT_LOAD - Contains a contiguous range of Process Address Space
217     for(uint32_t i = 1; i <= num_segments; i++)
218     {
219         const elf::ELFProgramHeader *header = core->GetProgramHeaderByIndex(i);
220         assert(header != NULL);
221 
222         DataExtractor data = core->GetSegmentDataByIndex(i);
223 
224         // Parse thread contexts and auxv structure
225         if (header->p_type == llvm::ELF::PT_NOTE)
226             ParseThreadContextsFromNoteSegment(header, data);
227 
228         // PT_LOAD segments contains address map
229         if (header->p_type == llvm::ELF::PT_LOAD)
230         {
231             lldb::addr_t last_addr = AddAddressRangeFromLoadSegment(header);
232             if (vm_addr > last_addr)
233                 ranges_are_sorted = false;
234             vm_addr = last_addr;
235         }
236     }
237 
238     if (!ranges_are_sorted)
239     {
240         m_core_aranges.Sort();
241         m_core_range_infos.Sort();
242     }
243 
244     // Even if the architecture is set in the target, we need to override
245     // it to match the core file which is always single arch.
246     ArchSpec arch (m_core_module_sp->GetArchitecture());
247     if (arch.IsValid())
248         GetTarget().SetArchitecture(arch);
249 
250     SetUnixSignals(UnixSignals::Create(GetArchitecture()));
251 
252     // Core files are useless without the main executable. See if we can locate the main
253     // executable using data we found in the core file notes.
254     lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
255     if (!exe_module_sp)
256     {
257         // The first entry in the NT_FILE might be our executable
258         if (!m_nt_file_entries.empty())
259         {
260             ModuleSpec exe_module_spec;
261             exe_module_spec.GetArchitecture() = arch;
262             exe_module_spec.GetFileSpec().SetFile(m_nt_file_entries[0].path.GetCString(), false);
263             if (exe_module_spec.GetFileSpec())
264             {
265                 exe_module_sp = GetTarget().GetSharedModule(exe_module_spec);
266                 if (exe_module_sp)
267                     GetTarget().SetExecutableModule(exe_module_sp, false);
268             }
269         }
270     }
271     return error;
272 }
273 
274 lldb_private::DynamicLoader *
275 ProcessElfCore::GetDynamicLoader ()
276 {
277     if (m_dyld_ap.get() == NULL)
278         m_dyld_ap.reset (DynamicLoader::FindPlugin(this, DynamicLoaderPOSIXDYLD::GetPluginNameStatic().GetCString()));
279     return m_dyld_ap.get();
280 }
281 
282 bool
283 ProcessElfCore::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
284 {
285     const uint32_t num_threads = GetNumThreadContexts ();
286     if (!m_thread_data_valid)
287         return false;
288 
289     for (lldb::tid_t tid = 0; tid < num_threads; ++tid)
290     {
291         const ThreadData &td = m_thread_data[tid];
292         lldb::ThreadSP thread_sp(new ThreadElfCore (*this, td));
293         new_thread_list.AddThread (thread_sp);
294     }
295     return new_thread_list.GetSize(false) > 0;
296 }
297 
298 void
299 ProcessElfCore::RefreshStateAfterStop ()
300 {
301 }
302 
303 Error
304 ProcessElfCore::DoDestroy ()
305 {
306     return Error();
307 }
308 
309 //------------------------------------------------------------------
310 // Process Queries
311 //------------------------------------------------------------------
312 
313 bool
314 ProcessElfCore::IsAlive ()
315 {
316     return true;
317 }
318 
319 //------------------------------------------------------------------
320 // Process Memory
321 //------------------------------------------------------------------
322 size_t
323 ProcessElfCore::ReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error)
324 {
325     // Don't allow the caching that lldb_private::Process::ReadMemory does
326     // since in core files we have it all cached our our core file anyway.
327     return DoReadMemory (addr, buf, size, error);
328 }
329 
330 Error
331 ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &region_info)
332 {
333     region_info.Clear();
334     const VMRangeToPermissions::Entry *permission_entry = m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
335     if (permission_entry)
336     {
337         if (permission_entry->Contains(load_addr))
338         {
339             region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
340             region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
341             const Flags permissions(permission_entry->data);
342             region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable) ? MemoryRegionInfo::eYes
343                                                                                  : MemoryRegionInfo::eNo);
344             region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable) ? MemoryRegionInfo::eYes
345                                                                                  : MemoryRegionInfo::eNo);
346             region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable) ? MemoryRegionInfo::eYes
347                                                                                      : MemoryRegionInfo::eNo);
348             region_info.SetMapped(MemoryRegionInfo::eYes);
349         }
350         else if (load_addr < permission_entry->GetRangeBase())
351         {
352             region_info.GetRange().SetRangeBase(load_addr);
353             region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
354             region_info.SetReadable(MemoryRegionInfo::eNo);
355             region_info.SetWritable(MemoryRegionInfo::eNo);
356             region_info.SetExecutable(MemoryRegionInfo::eNo);
357             region_info.SetMapped(MemoryRegionInfo::eNo);
358         }
359         return Error();
360     }
361 
362     region_info.GetRange().SetRangeBase(load_addr);
363     region_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
364     region_info.SetReadable(MemoryRegionInfo::eNo);
365     region_info.SetWritable(MemoryRegionInfo::eNo);
366     region_info.SetExecutable(MemoryRegionInfo::eNo);
367     region_info.SetMapped(MemoryRegionInfo::eNo);
368     return Error();
369 }
370 
371 size_t
372 ProcessElfCore::DoReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error)
373 {
374     ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
375 
376     if (core_objfile == NULL)
377         return 0;
378 
379     // Get the address range
380     const VMRangeToFileOffset::Entry *address_range = m_core_aranges.FindEntryThatContains (addr);
381     if (address_range == NULL || address_range->GetRangeEnd() < addr)
382     {
383         error.SetErrorStringWithFormat ("core file does not contain 0x%" PRIx64, addr);
384         return 0;
385     }
386 
387     // Convert the address into core file offset
388     const lldb::addr_t offset = addr - address_range->GetRangeBase();
389     const lldb::addr_t file_start = address_range->data.GetRangeBase();
390     const lldb::addr_t file_end = address_range->data.GetRangeEnd();
391     size_t bytes_to_read = size; // Number of bytes to read from the core file
392     size_t bytes_copied = 0;     // Number of bytes actually read from the core file
393     size_t zero_fill_size = 0;   // Padding
394     lldb::addr_t bytes_left = 0; // Number of bytes available in the core file from the given address
395 
396     // Figure out how many on-disk bytes remain in this segment
397     // starting at the given offset
398     if (file_end > file_start + offset)
399         bytes_left = file_end - (file_start + offset);
400 
401     // Figure out how many bytes we need to zero-fill if we are
402     // reading more bytes than available in the on-disk segment
403     if (bytes_to_read > bytes_left)
404     {
405         zero_fill_size = bytes_to_read - bytes_left;
406         bytes_to_read = bytes_left;
407     }
408 
409     // If there is data available on the core file read it
410     if (bytes_to_read)
411         bytes_copied = core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
412 
413     assert(zero_fill_size <= size);
414     // Pad remaining bytes
415     if (zero_fill_size)
416         memset(((char *)buf) + bytes_copied, 0, zero_fill_size);
417 
418     return bytes_copied + zero_fill_size;
419 }
420 
421 void
422 ProcessElfCore::Clear()
423 {
424     m_thread_list.Clear();
425     m_os = llvm::Triple::UnknownOS;
426 
427     SetUnixSignals(std::make_shared<UnixSignals>());
428 }
429 
430 void
431 ProcessElfCore::Initialize()
432 {
433     static std::once_flag g_once_flag;
434 
435     std::call_once(g_once_flag, []()
436     {
437         PluginManager::RegisterPlugin (GetPluginNameStatic(),
438           GetPluginDescriptionStatic(), CreateInstance);
439     });
440 }
441 
442 lldb::addr_t
443 ProcessElfCore::GetImageInfoAddress()
444 {
445     ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
446     Address addr = obj_file->GetImageInfoAddress(&GetTarget());
447 
448     if (addr.IsValid())
449         return addr.GetLoadAddress(&GetTarget());
450     return LLDB_INVALID_ADDRESS;
451 }
452 
453 /// Core files PT_NOTE segment descriptor types
454 enum {
455     NT_PRSTATUS     = 1,
456     NT_FPREGSET,
457     NT_PRPSINFO,
458     NT_TASKSTRUCT,
459     NT_PLATFORM,
460     NT_AUXV,
461     NT_FILE = 0x46494c45
462 };
463 
464 namespace FREEBSD {
465 
466 enum {
467     NT_PRSTATUS      = 1,
468     NT_FPREGSET,
469     NT_PRPSINFO,
470     NT_THRMISC       = 7,
471     NT_PROCSTAT_AUXV = 16,
472     NT_PPC_VMX       = 0x100
473 };
474 
475 }
476 
477 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
478 static void
479 ParseFreeBSDPrStatus(ThreadData &thread_data, DataExtractor &data,
480                      ArchSpec &arch)
481 {
482     lldb::offset_t offset = 0;
483     bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
484                  arch.GetMachine() == llvm::Triple::mips64 ||
485                  arch.GetMachine() == llvm::Triple::ppc64 ||
486                  arch.GetMachine() == llvm::Triple::x86_64);
487     int pr_version = data.GetU32(&offset);
488 
489     Log *log (GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
490     if (log)
491     {
492         if (pr_version > 1)
493             log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version);
494     }
495 
496     // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
497     if (lp64)
498         offset += 32;
499     else
500         offset += 16;
501 
502     thread_data.signo = data.GetU32(&offset); // pr_cursig
503     thread_data.tid = data.GetU32(&offset); // pr_pid
504     if (lp64)
505         offset += 4;
506 
507     size_t len = data.GetByteSize() - offset;
508     thread_data.gpregset = DataExtractor(data, offset, len);
509 }
510 
511 static void
512 ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data)
513 {
514     lldb::offset_t offset = 0;
515     thread_data.name = data.GetCStr(&offset, 20);
516 }
517 
518 /// Parse Thread context from PT_NOTE segment and store it in the thread list
519 /// Notes:
520 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
521 /// 2) NOTE Entry contains a standard header followed by variable size data.
522 ///   (see ELFNote structure)
523 /// 3) A Thread Context in a core file usually described by 3 NOTE entries.
524 ///    a) NT_PRSTATUS - Register context
525 ///    b) NT_PRPSINFO - Process info(pid..)
526 ///    c) NT_FPREGSET - Floating point registers
527 /// 4) The NOTE entries can be in any order
528 /// 5) If a core file contains multiple thread contexts then there is two data forms
529 ///    a) Each thread context(2 or more NOTE entries) contained in its own segment (PT_NOTE)
530 ///    b) All thread context is stored in a single segment(PT_NOTE).
531 ///        This case is little tricker since while parsing we have to find where the
532 ///        new thread starts. The current implementation marks beginning of
533 ///        new thread when it finds NT_PRSTATUS or NT_PRPSINFO NOTE entry.
534 ///    For case (b) there may be either one NT_PRPSINFO per thread, or a single
535 ///    one that applies to all threads (depending on the platform type).
536 void
537 ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *segment_header,
538                                                    DataExtractor segment_data)
539 {
540     assert(segment_header && segment_header->p_type == llvm::ELF::PT_NOTE);
541 
542     lldb::offset_t offset = 0;
543     std::unique_ptr<ThreadData> thread_data(new ThreadData);
544     bool have_prstatus = false;
545     bool have_prpsinfo = false;
546 
547     ArchSpec arch = GetArchitecture();
548     ELFLinuxPrPsInfo prpsinfo;
549     ELFLinuxPrStatus prstatus;
550     size_t header_size;
551     size_t len;
552 
553     // Loop through the NOTE entires in the segment
554     while (offset < segment_header->p_filesz)
555     {
556         ELFNote note = ELFNote();
557         note.Parse(segment_data, &offset);
558 
559         // Beginning of new thread
560         if ((note.n_type == NT_PRSTATUS && have_prstatus) ||
561             (note.n_type == NT_PRPSINFO && have_prpsinfo))
562         {
563             assert(thread_data->gpregset.GetByteSize() > 0);
564             // Add the new thread to thread list
565             m_thread_data.push_back(*thread_data);
566             *thread_data = ThreadData();
567             have_prstatus = false;
568             have_prpsinfo = false;
569         }
570 
571         size_t note_start, note_size;
572         note_start = offset;
573         note_size = llvm::alignTo(note.n_descsz, 4);
574 
575         // Store the NOTE information in the current thread
576         DataExtractor note_data (segment_data, note_start, note_size);
577         note_data.SetAddressByteSize(m_core_module_sp->GetArchitecture().GetAddressByteSize());
578         if (note.n_name == "FreeBSD")
579         {
580             m_os = llvm::Triple::FreeBSD;
581             switch (note.n_type)
582             {
583                 case FREEBSD::NT_PRSTATUS:
584                     have_prstatus = true;
585                     ParseFreeBSDPrStatus(*thread_data, note_data, arch);
586                     break;
587                 case FREEBSD::NT_FPREGSET:
588                     thread_data->fpregset = note_data;
589                     break;
590                 case FREEBSD::NT_PRPSINFO:
591                     have_prpsinfo = true;
592                     break;
593                 case FREEBSD::NT_THRMISC:
594                     ParseFreeBSDThrMisc(*thread_data, note_data);
595                     break;
596                 case FREEBSD::NT_PROCSTAT_AUXV:
597                     // FIXME: FreeBSD sticks an int at the beginning of the note
598                     m_auxv = DataExtractor(segment_data, note_start + 4, note_size - 4);
599                     break;
600                 case FREEBSD::NT_PPC_VMX:
601                     thread_data->vregset = note_data;
602                     break;
603                 default:
604                     break;
605             }
606         }
607         else if (note.n_name == "CORE")
608         {
609             switch (note.n_type)
610             {
611                 case NT_PRSTATUS:
612                     have_prstatus = true;
613                     prstatus.Parse(note_data, arch);
614                     thread_data->signo = prstatus.pr_cursig;
615                     thread_data->tid = prstatus.pr_pid;
616                     header_size = ELFLinuxPrStatus::GetSize(arch);
617                     len = note_data.GetByteSize() - header_size;
618                     thread_data->gpregset = DataExtractor(note_data, header_size, len);
619                     break;
620                 case NT_FPREGSET:
621                     thread_data->fpregset = note_data;
622                     break;
623                 case NT_PRPSINFO:
624                     have_prpsinfo = true;
625                     prpsinfo.Parse(note_data, arch);
626                     thread_data->name = prpsinfo.pr_fname;
627                     SetID(prpsinfo.pr_pid);
628                     break;
629                 case NT_AUXV:
630                     m_auxv = DataExtractor(note_data);
631                     break;
632                 case NT_FILE:
633                     {
634                         m_nt_file_entries.clear();
635                         lldb::offset_t offset = 0;
636                         const uint64_t count = note_data.GetAddress(&offset);
637                         note_data.GetAddress(&offset); // Skip page size
638                         for (uint64_t i = 0; i<count; ++i)
639                         {
640                             NT_FILE_Entry entry;
641                             entry.start = note_data.GetAddress(&offset);
642                             entry.end = note_data.GetAddress(&offset);
643                             entry.file_ofs = note_data.GetAddress(&offset);
644                             m_nt_file_entries.push_back(entry);
645                         }
646                         for (uint64_t i = 0; i<count; ++i)
647                         {
648                             const char *path = note_data.GetCStr(&offset);
649                             if (path && path[0])
650                                 m_nt_file_entries[i].path.SetCString(path);
651                         }
652                     }
653                     break;
654                 default:
655                     break;
656             }
657         }
658 
659         offset += note_size;
660     }
661     // Add last entry in the note section
662     if (thread_data && thread_data->gpregset.GetByteSize() > 0)
663     {
664         m_thread_data.push_back(*thread_data);
665     }
666 }
667 
668 uint32_t
669 ProcessElfCore::GetNumThreadContexts ()
670 {
671     if (!m_thread_data_valid)
672         DoLoadCore();
673     return m_thread_data.size();
674 }
675 
676 ArchSpec
677 ProcessElfCore::GetArchitecture()
678 {
679     ObjectFileELF *core_file = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
680     ArchSpec arch;
681     core_file->GetArchitecture(arch);
682     return arch;
683 }
684 
685 const lldb::DataBufferSP
686 ProcessElfCore::GetAuxvData()
687 {
688     const uint8_t *start = m_auxv.GetDataStart();
689     size_t len = m_auxv.GetByteSize();
690     lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
691     return buffer;
692 }
693 
694 bool
695 ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info)
696 {
697     info.Clear();
698     info.SetProcessID(GetID());
699     info.SetArchitecture(GetArchitecture());
700     lldb::ModuleSP module_sp = GetTarget().GetExecutableModule();
701     if (module_sp)
702     {
703         const bool add_exe_file_as_first_arg = false;
704         info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(), add_exe_file_as_first_arg);
705     }
706     return true;
707 }
708