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         }
349         else if (load_addr < permission_entry->GetRangeBase())
350         {
351             region_info.GetRange().SetRangeBase(load_addr);
352             region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
353             region_info.SetReadable(MemoryRegionInfo::eNo);
354             region_info.SetWritable(MemoryRegionInfo::eNo);
355             region_info.SetExecutable(MemoryRegionInfo::eNo);
356         }
357         return Error();
358     }
359     return Error("invalid address");
360 }
361 
362 size_t
363 ProcessElfCore::DoReadMemory (lldb::addr_t addr, void *buf, size_t size, Error &error)
364 {
365     ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
366 
367     if (core_objfile == NULL)
368         return 0;
369 
370     // Get the address range
371     const VMRangeToFileOffset::Entry *address_range = m_core_aranges.FindEntryThatContains (addr);
372     if (address_range == NULL || address_range->GetRangeEnd() < addr)
373     {
374         error.SetErrorStringWithFormat ("core file does not contain 0x%" PRIx64, addr);
375         return 0;
376     }
377 
378     // Convert the address into core file offset
379     const lldb::addr_t offset = addr - address_range->GetRangeBase();
380     const lldb::addr_t file_start = address_range->data.GetRangeBase();
381     const lldb::addr_t file_end = address_range->data.GetRangeEnd();
382     size_t bytes_to_read = size; // Number of bytes to read from the core file
383     size_t bytes_copied = 0;     // Number of bytes actually read from the core file
384     size_t zero_fill_size = 0;   // Padding
385     lldb::addr_t bytes_left = 0; // Number of bytes available in the core file from the given address
386 
387     // Figure out how many on-disk bytes remain in this segment
388     // starting at the given offset
389     if (file_end > file_start + offset)
390         bytes_left = file_end - (file_start + offset);
391 
392     // Figure out how many bytes we need to zero-fill if we are
393     // reading more bytes than available in the on-disk segment
394     if (bytes_to_read > bytes_left)
395     {
396         zero_fill_size = bytes_to_read - bytes_left;
397         bytes_to_read = bytes_left;
398     }
399 
400     // If there is data available on the core file read it
401     if (bytes_to_read)
402         bytes_copied = core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
403 
404     assert(zero_fill_size <= size);
405     // Pad remaining bytes
406     if (zero_fill_size)
407         memset(((char *)buf) + bytes_copied, 0, zero_fill_size);
408 
409     return bytes_copied + zero_fill_size;
410 }
411 
412 void
413 ProcessElfCore::Clear()
414 {
415     m_thread_list.Clear();
416     m_os = llvm::Triple::UnknownOS;
417 
418     SetUnixSignals(std::make_shared<UnixSignals>());
419 }
420 
421 void
422 ProcessElfCore::Initialize()
423 {
424     static std::once_flag g_once_flag;
425 
426     std::call_once(g_once_flag, []()
427     {
428         PluginManager::RegisterPlugin (GetPluginNameStatic(),
429           GetPluginDescriptionStatic(), CreateInstance);
430     });
431 }
432 
433 lldb::addr_t
434 ProcessElfCore::GetImageInfoAddress()
435 {
436     ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
437     Address addr = obj_file->GetImageInfoAddress(&GetTarget());
438 
439     if (addr.IsValid())
440         return addr.GetLoadAddress(&GetTarget());
441     return LLDB_INVALID_ADDRESS;
442 }
443 
444 /// Core files PT_NOTE segment descriptor types
445 enum {
446     NT_PRSTATUS     = 1,
447     NT_FPREGSET,
448     NT_PRPSINFO,
449     NT_TASKSTRUCT,
450     NT_PLATFORM,
451     NT_AUXV,
452     NT_FILE = 0x46494c45
453 };
454 
455 namespace FREEBSD {
456 
457 enum {
458     NT_PRSTATUS      = 1,
459     NT_FPREGSET,
460     NT_PRPSINFO,
461     NT_THRMISC       = 7,
462     NT_PROCSTAT_AUXV = 16,
463     NT_PPC_VMX       = 0x100
464 };
465 
466 }
467 
468 // Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
469 static void
470 ParseFreeBSDPrStatus(ThreadData &thread_data, DataExtractor &data,
471                      ArchSpec &arch)
472 {
473     lldb::offset_t offset = 0;
474     bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
475                  arch.GetMachine() == llvm::Triple::mips64 ||
476                  arch.GetMachine() == llvm::Triple::ppc64 ||
477                  arch.GetMachine() == llvm::Triple::x86_64);
478     int pr_version = data.GetU32(&offset);
479 
480     Log *log (GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
481     if (log)
482     {
483         if (pr_version > 1)
484             log->Printf("FreeBSD PRSTATUS unexpected version %d", pr_version);
485     }
486 
487     // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
488     if (lp64)
489         offset += 32;
490     else
491         offset += 16;
492 
493     thread_data.signo = data.GetU32(&offset); // pr_cursig
494     thread_data.tid = data.GetU32(&offset); // pr_pid
495     if (lp64)
496         offset += 4;
497 
498     size_t len = data.GetByteSize() - offset;
499     thread_data.gpregset = DataExtractor(data, offset, len);
500 }
501 
502 static void
503 ParseFreeBSDThrMisc(ThreadData &thread_data, DataExtractor &data)
504 {
505     lldb::offset_t offset = 0;
506     thread_data.name = data.GetCStr(&offset, 20);
507 }
508 
509 /// Parse Thread context from PT_NOTE segment and store it in the thread list
510 /// Notes:
511 /// 1) A PT_NOTE segment is composed of one or more NOTE entries.
512 /// 2) NOTE Entry contains a standard header followed by variable size data.
513 ///   (see ELFNote structure)
514 /// 3) A Thread Context in a core file usually described by 3 NOTE entries.
515 ///    a) NT_PRSTATUS - Register context
516 ///    b) NT_PRPSINFO - Process info(pid..)
517 ///    c) NT_FPREGSET - Floating point registers
518 /// 4) The NOTE entries can be in any order
519 /// 5) If a core file contains multiple thread contexts then there is two data forms
520 ///    a) Each thread context(2 or more NOTE entries) contained in its own segment (PT_NOTE)
521 ///    b) All thread context is stored in a single segment(PT_NOTE).
522 ///        This case is little tricker since while parsing we have to find where the
523 ///        new thread starts. The current implementation marks beginning of
524 ///        new thread when it finds NT_PRSTATUS or NT_PRPSINFO NOTE entry.
525 ///    For case (b) there may be either one NT_PRPSINFO per thread, or a single
526 ///    one that applies to all threads (depending on the platform type).
527 void
528 ProcessElfCore::ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader *segment_header,
529                                                    DataExtractor segment_data)
530 {
531     assert(segment_header && segment_header->p_type == llvm::ELF::PT_NOTE);
532 
533     lldb::offset_t offset = 0;
534     std::unique_ptr<ThreadData> thread_data(new ThreadData);
535     bool have_prstatus = false;
536     bool have_prpsinfo = false;
537 
538     ArchSpec arch = GetArchitecture();
539     ELFLinuxPrPsInfo prpsinfo;
540     ELFLinuxPrStatus prstatus;
541     size_t header_size;
542     size_t len;
543 
544     // Loop through the NOTE entires in the segment
545     while (offset < segment_header->p_filesz)
546     {
547         ELFNote note = ELFNote();
548         note.Parse(segment_data, &offset);
549 
550         // Beginning of new thread
551         if ((note.n_type == NT_PRSTATUS && have_prstatus) ||
552             (note.n_type == NT_PRPSINFO && have_prpsinfo))
553         {
554             assert(thread_data->gpregset.GetByteSize() > 0);
555             // Add the new thread to thread list
556             m_thread_data.push_back(*thread_data);
557             *thread_data = ThreadData();
558             have_prstatus = false;
559             have_prpsinfo = false;
560         }
561 
562         size_t note_start, note_size;
563         note_start = offset;
564         note_size = llvm::alignTo(note.n_descsz, 4);
565 
566         // Store the NOTE information in the current thread
567         DataExtractor note_data (segment_data, note_start, note_size);
568         note_data.SetAddressByteSize(m_core_module_sp->GetArchitecture().GetAddressByteSize());
569         if (note.n_name == "FreeBSD")
570         {
571             m_os = llvm::Triple::FreeBSD;
572             switch (note.n_type)
573             {
574                 case FREEBSD::NT_PRSTATUS:
575                     have_prstatus = true;
576                     ParseFreeBSDPrStatus(*thread_data, note_data, arch);
577                     break;
578                 case FREEBSD::NT_FPREGSET:
579                     thread_data->fpregset = note_data;
580                     break;
581                 case FREEBSD::NT_PRPSINFO:
582                     have_prpsinfo = true;
583                     break;
584                 case FREEBSD::NT_THRMISC:
585                     ParseFreeBSDThrMisc(*thread_data, note_data);
586                     break;
587                 case FREEBSD::NT_PROCSTAT_AUXV:
588                     // FIXME: FreeBSD sticks an int at the beginning of the note
589                     m_auxv = DataExtractor(segment_data, note_start + 4, note_size - 4);
590                     break;
591                 case FREEBSD::NT_PPC_VMX:
592                     thread_data->vregset = note_data;
593                     break;
594                 default:
595                     break;
596             }
597         }
598         else if (note.n_name == "CORE")
599         {
600             switch (note.n_type)
601             {
602                 case NT_PRSTATUS:
603                     have_prstatus = true;
604                     prstatus.Parse(note_data, arch);
605                     thread_data->signo = prstatus.pr_cursig;
606                     thread_data->tid = prstatus.pr_pid;
607                     header_size = ELFLinuxPrStatus::GetSize(arch);
608                     len = note_data.GetByteSize() - header_size;
609                     thread_data->gpregset = DataExtractor(note_data, header_size, len);
610                     break;
611                 case NT_FPREGSET:
612                     thread_data->fpregset = note_data;
613                     break;
614                 case NT_PRPSINFO:
615                     have_prpsinfo = true;
616                     prpsinfo.Parse(note_data, arch);
617                     thread_data->name = prpsinfo.pr_fname;
618                     SetID(prpsinfo.pr_pid);
619                     break;
620                 case NT_AUXV:
621                     m_auxv = DataExtractor(note_data);
622                     break;
623                 case NT_FILE:
624                     {
625                         m_nt_file_entries.clear();
626                         lldb::offset_t offset = 0;
627                         const uint64_t count = note_data.GetAddress(&offset);
628                         note_data.GetAddress(&offset); // Skip page size
629                         for (uint64_t i = 0; i<count; ++i)
630                         {
631                             NT_FILE_Entry entry;
632                             entry.start = note_data.GetAddress(&offset);
633                             entry.end = note_data.GetAddress(&offset);
634                             entry.file_ofs = note_data.GetAddress(&offset);
635                             m_nt_file_entries.push_back(entry);
636                         }
637                         for (uint64_t i = 0; i<count; ++i)
638                         {
639                             const char *path = note_data.GetCStr(&offset);
640                             if (path && path[0])
641                                 m_nt_file_entries[i].path.SetCString(path);
642                         }
643                     }
644                     break;
645                 default:
646                     break;
647             }
648         }
649 
650         offset += note_size;
651     }
652     // Add last entry in the note section
653     if (thread_data && thread_data->gpregset.GetByteSize() > 0)
654     {
655         m_thread_data.push_back(*thread_data);
656     }
657 }
658 
659 uint32_t
660 ProcessElfCore::GetNumThreadContexts ()
661 {
662     if (!m_thread_data_valid)
663         DoLoadCore();
664     return m_thread_data.size();
665 }
666 
667 ArchSpec
668 ProcessElfCore::GetArchitecture()
669 {
670     ObjectFileELF *core_file = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
671     ArchSpec arch;
672     core_file->GetArchitecture(arch);
673     return arch;
674 }
675 
676 const lldb::DataBufferSP
677 ProcessElfCore::GetAuxvData()
678 {
679     const uint8_t *start = m_auxv.GetDataStart();
680     size_t len = m_auxv.GetByteSize();
681     lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
682     return buffer;
683 }
684 
685 bool
686 ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info)
687 {
688     info.Clear();
689     info.SetProcessID(GetID());
690     info.SetArchitecture(GetArchitecture());
691     lldb::ModuleSP module_sp = GetTarget().GetExecutableModule();
692     if (module_sp)
693     {
694         const bool add_exe_file_as_first_arg = false;
695         info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(), add_exe_file_as_first_arg);
696     }
697     return true;
698 }
699