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         {
227             error = ParseThreadContextsFromNoteSegment(header, data);
228             if (error.Fail())
229                 return error;
230         }
231         // PT_LOAD segments contains address map
232         if (header->p_type == llvm::ELF::PT_LOAD)
233         {
234             lldb::addr_t last_addr = AddAddressRangeFromLoadSegment(header);
235             if (vm_addr > last_addr)
236                 ranges_are_sorted = false;
237             vm_addr = last_addr;
238         }
239     }
240 
241     if (!ranges_are_sorted)
242     {
243         m_core_aranges.Sort();
244         m_core_range_infos.Sort();
245     }
246 
247     // Even if the architecture is set in the target, we need to override
248     // it to match the core file which is always single arch.
249     ArchSpec arch (m_core_module_sp->GetArchitecture());
250     if (arch.IsValid())
251         GetTarget().SetArchitecture(arch);
252 
253     SetUnixSignals(UnixSignals::Create(GetArchitecture()));
254 
255     // Core files are useless without the main executable. See if we can locate the main
256     // executable using data we found in the core file notes.
257     lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
258     if (!exe_module_sp)
259     {
260         // The first entry in the NT_FILE might be our executable
261         if (!m_nt_file_entries.empty())
262         {
263             ModuleSpec exe_module_spec;
264             exe_module_spec.GetArchitecture() = arch;
265             exe_module_spec.GetFileSpec().SetFile(m_nt_file_entries[0].path.GetCString(), false);
266             if (exe_module_spec.GetFileSpec())
267             {
268                 exe_module_sp = GetTarget().GetSharedModule(exe_module_spec);
269                 if (exe_module_sp)
270                     GetTarget().SetExecutableModule(exe_module_sp, false);
271             }
272         }
273     }
274     return error;
275 }
276 
277 lldb_private::DynamicLoader *
278 ProcessElfCore::GetDynamicLoader ()
279 {
280     if (m_dyld_ap.get() == NULL)
281         m_dyld_ap.reset (DynamicLoader::FindPlugin(this, DynamicLoaderPOSIXDYLD::GetPluginNameStatic().GetCString()));
282     return m_dyld_ap.get();
283 }
284 
285 bool
286 ProcessElfCore::UpdateThreadList (ThreadList &old_thread_list, ThreadList &new_thread_list)
287 {
288     const uint32_t num_threads = GetNumThreadContexts ();
289     if (!m_thread_data_valid)
290         return false;
291 
292     for (lldb::tid_t tid = 0; tid < num_threads; ++tid)
293     {
294         const ThreadData &td = m_thread_data[tid];
295         lldb::ThreadSP thread_sp(new ThreadElfCore (*this, td));
296         new_thread_list.AddThread (thread_sp);
297     }
298     return new_thread_list.GetSize(false) > 0;
299 }
300 
301 void
302 ProcessElfCore::RefreshStateAfterStop ()
303 {
304 }
305 
306 Error
307 ProcessElfCore::DoDestroy ()
308 {
309     return Error();
310 }
311 
312 //------------------------------------------------------------------
313 // Process Queries
314 //------------------------------------------------------------------
315 
316 bool
317 ProcessElfCore::IsAlive ()
318 {
319     return true;
320 }
321 
322 //------------------------------------------------------------------
323 // Process Memory
324 //------------------------------------------------------------------
325 size_t
326 ProcessElfCore::ReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error)
327 {
328     // Don't allow the caching that lldb_private::Process::ReadMemory does
329     // since in core files we have it all cached our our core file anyway.
330     return DoReadMemory (addr, buf, size, error);
331 }
332 
333 Error
334 ProcessElfCore::GetMemoryRegionInfo(lldb::addr_t load_addr, MemoryRegionInfo &region_info)
335 {
336     region_info.Clear();
337     const VMRangeToPermissions::Entry *permission_entry = m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
338     if (permission_entry)
339     {
340         if (permission_entry->Contains(load_addr))
341         {
342             region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
343             region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
344             const Flags permissions(permission_entry->data);
345             region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable) ? MemoryRegionInfo::eYes
346                                                                                  : MemoryRegionInfo::eNo);
347             region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable) ? MemoryRegionInfo::eYes
348                                                                                  : MemoryRegionInfo::eNo);
349             region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable) ? MemoryRegionInfo::eYes
350                                                                                      : MemoryRegionInfo::eNo);
351             region_info.SetMapped(MemoryRegionInfo::eYes);
352         }
353         else if (load_addr < permission_entry->GetRangeBase())
354         {
355             region_info.GetRange().SetRangeBase(load_addr);
356             region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
357             region_info.SetReadable(MemoryRegionInfo::eNo);
358             region_info.SetWritable(MemoryRegionInfo::eNo);
359             region_info.SetExecutable(MemoryRegionInfo::eNo);
360             region_info.SetMapped(MemoryRegionInfo::eNo);
361         }
362         return Error();
363     }
364 
365     region_info.GetRange().SetRangeBase(load_addr);
366     region_info.GetRange().SetRangeEnd(LLDB_INVALID_ADDRESS);
367     region_info.SetReadable(MemoryRegionInfo::eNo);
368     region_info.SetWritable(MemoryRegionInfo::eNo);
369     region_info.SetExecutable(MemoryRegionInfo::eNo);
370     region_info.SetMapped(MemoryRegionInfo::eNo);
371     return Error();
372 }
373 
374 size_t
375 ProcessElfCore::DoReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error)
376 {
377     ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
378 
379     if (core_objfile == NULL)
380         return 0;
381 
382     // Get the address range
383     const VMRangeToFileOffset::Entry *address_range = m_core_aranges.FindEntryThatContains (addr);
384     if (address_range == NULL || address_range->GetRangeEnd() < addr)
385     {
386         error.SetErrorStringWithFormat ("core file does not contain 0x%" PRIx64, addr);
387         return 0;
388     }
389 
390     // Convert the address into core file offset
391     const lldb::addr_t offset = addr - address_range->GetRangeBase();
392     const lldb::addr_t file_start = address_range->data.GetRangeBase();
393     const lldb::addr_t file_end = address_range->data.GetRangeEnd();
394     size_t bytes_to_read = size; // Number of bytes to read from the core file
395     size_t bytes_copied = 0;     // Number of bytes actually read from the core file
396     size_t zero_fill_size = 0;   // Padding
397     lldb::addr_t bytes_left = 0; // Number of bytes available in the core file from the given address
398 
399     // Figure out how many on-disk bytes remain in this segment
400     // starting at the given offset
401     if (file_end > file_start + offset)
402         bytes_left = file_end - (file_start + offset);
403 
404     // Figure out how many bytes we need to zero-fill if we are
405     // reading more bytes than available in the on-disk segment
406     if (bytes_to_read > bytes_left)
407     {
408         zero_fill_size = bytes_to_read - bytes_left;
409         bytes_to_read = bytes_left;
410     }
411 
412     // If there is data available on the core file read it
413     if (bytes_to_read)
414         bytes_copied = core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
415 
416     assert(zero_fill_size <= size);
417     // Pad remaining bytes
418     if (zero_fill_size)
419         memset(((char *)buf) + bytes_copied, 0, zero_fill_size);
420 
421     return bytes_copied + zero_fill_size;
422 }
423 
424 void
425 ProcessElfCore::Clear()
426 {
427     m_thread_list.Clear();
428     m_os = llvm::Triple::UnknownOS;
429 
430     SetUnixSignals(std::make_shared<UnixSignals>());
431 }
432 
433 void
434 ProcessElfCore::Initialize()
435 {
436     static std::once_flag g_once_flag;
437 
438     std::call_once(g_once_flag, []()
439     {
440         PluginManager::RegisterPlugin (GetPluginNameStatic(),
441           GetPluginDescriptionStatic(), CreateInstance);
442     });
443 }
444 
445 lldb::addr_t
446 ProcessElfCore::GetImageInfoAddress()
447 {
448     ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
449     Address addr = obj_file->GetImageInfoAddress(&GetTarget());
450 
451     if (addr.IsValid())
452         return addr.GetLoadAddress(&GetTarget());
453     return LLDB_INVALID_ADDRESS;
454 }
455 
456 /// Core files PT_NOTE segment descriptor types
457 enum {
458     NT_PRSTATUS     = 1,
459     NT_FPREGSET,
460     NT_PRPSINFO,
461     NT_TASKSTRUCT,
462     NT_PLATFORM,
463     NT_AUXV,
464     NT_FILE = 0x46494c45
465 };
466 
467 namespace FREEBSD {
468 
469 enum {
470     NT_PRSTATUS      = 1,
471     NT_FPREGSET,
472     NT_PRPSINFO,
473     NT_THRMISC       = 7,
474     NT_PROCSTAT_AUXV = 16,
475     NT_PPC_VMX       = 0x100
476 };
477 
478 }
479 
480 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
481 static void
482 ParseFreeBSDPrStatus(ThreadData &thread_data, DataExtractor &data,
483                      ArchSpec &arch)
484 {
485     lldb::offset_t offset = 0;
486     bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
487                  arch.GetMachine() == llvm::Triple::mips64 ||
488                  arch.GetMachine() == llvm::Triple::ppc64 ||
489                  arch.GetMachine() == llvm::Triple::x86_64);
490     int pr_version = data.GetU32(&offset);
491 
492     Log *log (GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
493     if (log)
494     {
495         if (pr_version > 1)
496             log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version);
497     }
498 
499     // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
500     if (lp64)
501         offset += 32;
502     else
503         offset += 16;
504 
505     thread_data.signo = data.GetU32(&offset); // pr_cursig
506     thread_data.tid = data.GetU32(&offset); // pr_pid
507     if (lp64)
508         offset += 4;
509 
510     size_t len = data.GetByteSize() - offset;
511     thread_data.gpregset = DataExtractor(data, offset, len);
512 }
513 
514 static void
515 ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data)
516 {
517     lldb::offset_t offset = 0;
518     thread_data.name = data.GetCStr(&offset, 20);
519 }
520 
521 /// Parse Thread context from PT_NOTE segment and store it in the thread list
522 /// Notes:
523 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
524 /// 2) NOTE Entry contains a standard header followed by variable size data.
525 ///   (see ELFNote structure)
526 /// 3) A Thread Context in a core file usually described by 3 NOTE entries.
527 ///    a) NT_PRSTATUS - Register context
528 ///    b) NT_PRPSINFO - Process info(pid..)
529 ///    c) NT_FPREGSET - Floating point registers
530 /// 4) The NOTE entries can be in any order
531 /// 5) If a core file contains multiple thread contexts then there is two data forms
532 ///    a) Each thread context(2 or more NOTE entries) contained in its own segment (PT_NOTE)
533 ///    b) All thread context is stored in a single segment(PT_NOTE).
534 ///        This case is little tricker since while parsing we have to find where the
535 ///        new thread starts. The current implementation marks beginning of
536 ///        new thread when it finds NT_PRSTATUS or NT_PRPSINFO NOTE entry.
537 ///    For case (b) there may be either one NT_PRPSINFO per thread, or a single
538 ///    one that applies to all threads (depending on the platform type).
539 Error
540 ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *segment_header,
541                                                    DataExtractor segment_data)
542 {
543     assert(segment_header && segment_header->p_type == llvm::ELF::PT_NOTE);
544 
545     lldb::offset_t offset = 0;
546     std::unique_ptr<ThreadData> thread_data(new ThreadData);
547     bool have_prstatus = false;
548     bool have_prpsinfo = false;
549 
550     ArchSpec arch = GetArchitecture();
551     ELFLinuxPrPsInfo prpsinfo;
552     ELFLinuxPrStatus prstatus;
553     size_t header_size;
554     size_t len;
555     Error error;
556 
557     // Loop through the NOTE entires in the segment
558     while (offset < segment_header->p_filesz)
559     {
560         ELFNote note = ELFNote();
561         note.Parse(segment_data, &offset);
562 
563         // Beginning of new thread
564         if ((note.n_type == NT_PRSTATUS && have_prstatus) ||
565             (note.n_type == NT_PRPSINFO && have_prpsinfo))
566         {
567             assert(thread_data->gpregset.GetByteSize() > 0);
568             // Add the new thread to thread list
569             m_thread_data.push_back(*thread_data);
570             *thread_data = ThreadData();
571             have_prstatus = false;
572             have_prpsinfo = false;
573         }
574 
575         size_t note_start, note_size;
576         note_start = offset;
577         note_size = llvm::alignTo(note.n_descsz, 4);
578 
579         // Store the NOTE information in the current thread
580         DataExtractor note_data (segment_data, note_start, note_size);
581         note_data.SetAddressByteSize(m_core_module_sp->GetArchitecture().GetAddressByteSize());
582         if (note.n_name == "FreeBSD")
583         {
584             m_os = llvm::Triple::FreeBSD;
585             switch (note.n_type)
586             {
587                 case FREEBSD::NT_PRSTATUS:
588                     have_prstatus = true;
589                     ParseFreeBSDPrStatus(*thread_data, note_data, arch);
590                     break;
591                 case FREEBSD::NT_FPREGSET:
592                     thread_data->fpregset = note_data;
593                     break;
594                 case FREEBSD::NT_PRPSINFO:
595                     have_prpsinfo = true;
596                     break;
597                 case FREEBSD::NT_THRMISC:
598                     ParseFreeBSDThrMisc(*thread_data, note_data);
599                     break;
600                 case FREEBSD::NT_PROCSTAT_AUXV:
601                     // FIXME: FreeBSD sticks an int at the beginning of the note
602                     m_auxv = DataExtractor(segment_data, note_start + 4, note_size - 4);
603                     break;
604                 case FREEBSD::NT_PPC_VMX:
605                     thread_data->vregset = note_data;
606                     break;
607                 default:
608                     break;
609             }
610         }
611         else if (note.n_name == "CORE")
612         {
613             switch (note.n_type)
614             {
615                 case NT_PRSTATUS:
616                     have_prstatus = true;
617                     error = prstatus.Parse(note_data, arch);
618                     if (error.Fail())
619                         return error;
620                     thread_data->signo = prstatus.pr_cursig;
621                     thread_data->tid = prstatus.pr_pid;
622                     header_size = ELFLinuxPrStatus::GetSize(arch);
623                     len = note_data.GetByteSize() - header_size;
624                     thread_data->gpregset = DataExtractor(note_data, header_size, len);
625                     break;
626                 case NT_FPREGSET:
627                     thread_data->fpregset = note_data;
628                     break;
629                 case NT_PRPSINFO:
630                     have_prpsinfo = true;
631                     error = prpsinfo.Parse(note_data, arch);
632                     if (error.Fail())
633                         return error;
634                     thread_data->name = prpsinfo.pr_fname;
635                     SetID(prpsinfo.pr_pid);
636                     break;
637                 case NT_AUXV:
638                     m_auxv = DataExtractor(note_data);
639                     break;
640                 case NT_FILE:
641                     {
642                         m_nt_file_entries.clear();
643                         lldb::offset_t offset = 0;
644                         const uint64_t count = note_data.GetAddress(&offset);
645                         note_data.GetAddress(&offset); // Skip page size
646                         for (uint64_t i = 0; i<count; ++i)
647                         {
648                             NT_FILE_Entry entry;
649                             entry.start = note_data.GetAddress(&offset);
650                             entry.end = note_data.GetAddress(&offset);
651                             entry.file_ofs = note_data.GetAddress(&offset);
652                             m_nt_file_entries.push_back(entry);
653                         }
654                         for (uint64_t i = 0; i<count; ++i)
655                         {
656                             const char *path = note_data.GetCStr(&offset);
657                             if (path && path[0])
658                                 m_nt_file_entries[i].path.SetCString(path);
659                         }
660                     }
661                     break;
662                 default:
663                     break;
664             }
665         }
666 
667         offset += note_size;
668     }
669     // Add last entry in the note section
670     if (thread_data && thread_data->gpregset.GetByteSize() > 0)
671     {
672         m_thread_data.push_back(*thread_data);
673     }
674 
675     return error;
676 }
677 
678 uint32_t
679 ProcessElfCore::GetNumThreadContexts ()
680 {
681     if (!m_thread_data_valid)
682         DoLoadCore();
683     return m_thread_data.size();
684 }
685 
686 ArchSpec
687 ProcessElfCore::GetArchitecture()
688 {
689     ObjectFileELF *core_file = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
690     ArchSpec arch;
691     core_file->GetArchitecture(arch);
692     return arch;
693 }
694 
695 const lldb::DataBufferSP
696 ProcessElfCore::GetAuxvData()
697 {
698     const uint8_t *start = m_auxv.GetDataStart();
699     size_t len = m_auxv.GetByteSize();
700     lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
701     return buffer;
702 }
703 
704 bool
705 ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info)
706 {
707     info.Clear();
708     info.SetProcessID(GetID());
709     info.SetArchitecture(GetArchitecture());
710     lldb::ModuleSP module_sp = GetTarget().GetExecutableModule();
711     if (module_sp)
712     {
713         const bool add_exe_file_as_first_arg = false;
714         info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(), add_exe_file_as_first_arg);
715     }
716     return true;
717 }
718