LLDB mainline
ProcessElfCore.cpp
Go to the documentation of this file.
1//===-- ProcessElfCore.cpp ------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <cstdlib>
10
11#include <memory>
12#include <mutex>
13
14#include "lldb/Core/Module.h"
17#include "lldb/Core/Section.h"
18#include "lldb/Target/ABI.h"
21#include "lldb/Target/Target.h"
25#include "lldb/Utility/Log.h"
26#include "lldb/Utility/State.h"
27
28#include "llvm/BinaryFormat/ELF.h"
29#include "llvm/Support/Threading.h"
30
34#include "ProcessElfCore.h"
35#include "ThreadElfCore.h"
36
37using namespace lldb_private;
38namespace ELF = llvm::ELF;
39
41
43 return "ELF core dump plug-in.";
44}
45
49
51 lldb::ListenerSP listener_sp,
52 const FileSpec *crash_file,
53 bool can_connect) {
54 lldb::ProcessSP process_sp;
55 if (crash_file && !can_connect) {
56 // Read enough data for an ELF32 header or ELF64 header Note: Here we care
57 // about e_type field only, so it is safe to ignore possible presence of
58 // the header extension.
59 const size_t header_size = sizeof(llvm::ELF::Elf64_Ehdr);
60
62 crash_file->GetPath(), header_size, 0);
63 if (data_sp && data_sp->GetByteSize() == header_size &&
64 elf::ELFHeader::MagicBytesMatch(data_sp->GetBytes())) {
65 elf::ELFHeader elf_header;
66 DataExtractor data(data_sp, lldb::eByteOrderLittle, 4);
67 lldb::offset_t data_offset = 0;
68 if (elf_header.Parse(data, &data_offset)) {
69 // Check whether we're dealing with a raw FreeBSD "full memory dump"
70 // ELF vmcore that needs to be handled via FreeBSDKernel plugin instead.
71 if (elf_header.e_ident[7] == 0xFF && elf_header.e_version == 0)
72 return process_sp;
73 if (elf_header.e_type == llvm::ELF::ET_CORE)
74 process_sp = std::make_shared<ProcessElfCore>(target_sp, listener_sp,
75 *crash_file);
76 }
77 }
78 }
79 return process_sp;
80}
81
83 bool plugin_specified_by_name) {
84 // For now we are just making sure the file exists for a given module
86 ModuleSpec core_module_spec(m_core_file, target_sp->GetArchitecture());
88 nullptr, nullptr, nullptr));
89 if (m_core_module_sp) {
90 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
91 if (core_objfile && core_objfile->GetType() == ObjectFile::eTypeCoreFile)
92 return true;
93 }
94 }
95 return false;
96}
97
98// ProcessElfCore constructor
100 lldb::ListenerSP listener_sp,
101 const FileSpec &core_file)
102 : PostMortemProcess(target_sp, listener_sp, core_file), m_uuids() {}
103
104// Destructor
106 Clear();
107 // We need to call finalize on the process before destroying ourselves to
108 // make sure all of the broadcaster cleanup goes as planned. If we destruct
109 // this class, then Process::~Process() might have problems trying to fully
110 // destroy the broadcaster.
111 Finalize(true /* destructing */);
112}
113
115 const elf::ELFProgramHeader &header) {
116 const lldb::addr_t addr = header.p_vaddr;
117 FileRange file_range(header.p_offset, header.p_filesz);
118 VMRangeToFileOffset::Entry range_entry(addr, header.p_memsz, file_range);
119
120 // Only add to m_core_aranges if the file size is non zero. Some core files
121 // have PT_LOAD segments for all address ranges, but set f_filesz to zero for
122 // the .text sections since they can be retrieved from the object files.
123 if (header.p_filesz > 0) {
124 VMRangeToFileOffset::Entry *last_entry = m_core_aranges.Back();
125 if (last_entry && last_entry->GetRangeEnd() == range_entry.GetRangeBase() &&
126 last_entry->data.GetRangeEnd() == range_entry.data.GetRangeBase() &&
127 last_entry->GetByteSize() == last_entry->data.GetByteSize()) {
128 last_entry->SetRangeEnd(range_entry.GetRangeEnd());
129 last_entry->data.SetRangeEnd(range_entry.data.GetRangeEnd());
130 } else {
131 m_core_aranges.Append(range_entry);
132 }
133 }
134 // Keep a separate map of permissions that isn't coalesced so all ranges
135 // are maintained.
136 const uint32_t permissions =
137 ((header.p_flags & llvm::ELF::PF_R) ? lldb::ePermissionsReadable : 0u) |
138 ((header.p_flags & llvm::ELF::PF_W) ? lldb::ePermissionsWritable : 0u) |
139 ((header.p_flags & llvm::ELF::PF_X) ? lldb::ePermissionsExecutable : 0u);
140
141 m_core_range_infos.Append(
142 VMRangeToPermissions::Entry(addr, header.p_memsz, permissions));
143
144 return addr;
145}
146
148 const elf::ELFProgramHeader &header) {
149 // If lldb understood multiple kinds of tag segments we would record the type
150 // of the segment here also. As long as there is only 1 type lldb looks for,
151 // there is no need.
152 FileRange file_range(header.p_offset, header.p_filesz);
153 m_core_tag_ranges.Append(
154 VMRangeToFileOffset::Entry(header.p_vaddr, header.p_memsz, file_range));
155
156 return header.p_vaddr;
157}
158
159// Process Control
162 if (!m_core_module_sp) {
163 error = Status::FromErrorString("invalid core module");
164 return error;
165 }
166
167 ObjectFileELF *core = (ObjectFileELF *)(m_core_module_sp->GetObjectFile());
168 if (core == nullptr) {
169 error = Status::FromErrorString("invalid core object file");
170 return error;
171 }
172
173 llvm::ArrayRef<elf::ELFProgramHeader> segments = core->ProgramHeaders();
174 if (segments.size() == 0) {
175 error = Status::FromErrorString("core file has no segments");
176 return error;
177 }
178
179 // Even if the architecture is set in the target, we need to override it to
180 // match the core file which is always single arch.
181 ArchSpec arch(m_core_module_sp->GetArchitecture());
182
183 ArchSpec target_arch = GetTarget().GetArchitecture();
184 ArchSpec core_arch(m_core_module_sp->GetArchitecture());
185 target_arch.MergeFrom(core_arch);
186 GetTarget().SetArchitecture(target_arch, /*set_platform*/ true);
187
189
190 SetCanJIT(false);
191
192 m_thread_data_valid = true;
193
194 bool ranges_are_sorted = true;
195 lldb::addr_t vm_addr = 0;
196 lldb::addr_t tag_addr = 0;
197 /// Walk through segments and Thread and Address Map information.
198 /// PT_NOTE - Contains Thread and Register information
199 /// PT_LOAD - Contains a contiguous range of Process Address Space
200 /// PT_AARCH64_MEMTAG_MTE - Contains AArch64 MTE memory tags for a range of
201 /// Process Address Space.
202 for (const elf::ELFProgramHeader &H : segments) {
203 DataExtractor data = core->GetSegmentData(H);
204
205 // Parse thread contexts and auxv structure
206 if (H.p_type == llvm::ELF::PT_NOTE) {
207 if (llvm::Error error = ParseThreadContextsFromNoteSegment(H, data))
208 return Status::FromError(std::move(error));
209 }
210 // PT_LOAD segments contains address map
211 if (H.p_type == llvm::ELF::PT_LOAD) {
213 if (vm_addr > last_addr)
214 ranges_are_sorted = false;
215 vm_addr = last_addr;
216 } else if (H.p_type == llvm::ELF::PT_AARCH64_MEMTAG_MTE) {
218 if (tag_addr > last_addr)
219 ranges_are_sorted = false;
220 tag_addr = last_addr;
221 }
222 }
223
224 if (!ranges_are_sorted) {
225 m_core_aranges.Sort();
226 m_core_range_infos.Sort();
227 m_core_tag_ranges.Sort();
228 }
229
230 // Ensure we found at least one thread that was stopped on a signal.
231 bool siginfo_signal_found = false;
232 bool prstatus_signal_found = false;
233 // Check we found a signal in a SIGINFO note.
234 for (const auto &thread_data : m_thread_data) {
235 if (!thread_data.siginfo_bytes.empty() || thread_data.signo != 0)
236 siginfo_signal_found = true;
237 if (thread_data.prstatus_sig != 0)
238 prstatus_signal_found = true;
239 }
240 if (!siginfo_signal_found) {
241 // If we don't have signal from SIGINFO use the signal from each threads
242 // PRSTATUS note.
243 if (prstatus_signal_found) {
244 for (auto &thread_data : m_thread_data)
245 thread_data.signo = thread_data.prstatus_sig;
246 } else if (m_thread_data.size() > 0) {
247 // If all else fails force the first thread to be SIGSTOP
248 m_thread_data.begin()->signo =
249 GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
250 }
251 }
252
253 // Try to find gnu build id before we load the executable.
255
256 // Core files are useless without the main executable. See if we can locate
257 // the main executable using data we found in the core file notes.
258 lldb::ModuleSP exe_module_sp = GetTarget().GetExecutableModule();
259 if (!exe_module_sp) {
260 if (!m_nt_file_entries.empty()) {
261 llvm::StringRef executable_path = GetMainExecutablePath();
262 ModuleSpec exe_module_spec;
263 exe_module_spec.GetArchitecture() = arch;
264 exe_module_spec.GetUUID() = FindModuleUUID(executable_path);
265 exe_module_spec.GetFileSpec().SetFile(executable_path,
266 FileSpec::Style::native);
267 if (exe_module_spec.GetFileSpec()) {
268 exe_module_sp =
269 GetTarget().GetOrCreateModule(exe_module_spec, true /* notify */);
270 if (exe_module_sp)
272 }
273 }
274 }
275 return error;
276}
277
280 m_uuids.clear();
281 for (NT_FILE_Entry &entry : m_nt_file_entries) {
282 UUID uuid = FindBuidIdInCoreMemory(entry.start);
283 if (uuid.IsValid()) {
284 // Assert that either the path is not in the map or the UUID matches
285 assert(m_uuids.count(entry.path) == 0 || m_uuids[entry.path] == uuid);
286 m_uuids[entry.path] = uuid;
287 if (log)
288 LLDB_LOGF(log, "%s found UUID @ %16.16" PRIx64 ": %s \"%s\"",
289 __FUNCTION__, entry.start, uuid.GetAsString().c_str(),
290 entry.path.c_str());
291 }
292 }
293}
294
296 if (m_nt_file_entries.empty())
297 return "";
298
299 // The first entry in the NT_FILE might be our executable
300 llvm::StringRef executable_path = m_nt_file_entries[0].path;
301 // Prefer the NT_FILE entry matching m_executable_name as main executable.
302 for (const NT_FILE_Entry &file_entry : m_nt_file_entries)
303 if (llvm::StringRef(file_entry.path).ends_with("/" + m_executable_name)) {
304 executable_path = file_entry.path;
305 break;
306 }
307 return executable_path;
308}
309
310UUID ProcessElfCore::FindModuleUUID(const llvm::StringRef path) {
311 // Lookup the UUID for the given path in the map.
312 // Note that this could be called by multiple threads so make sure
313 // we access the map in a thread safe way (i.e. don't use operator[]).
314 auto it = m_uuids.find(std::string(path));
315 if (it != m_uuids.end())
316 return it->second;
317 return UUID();
318}
319
326
328 ThreadList &new_thread_list) {
329 const uint32_t num_threads = GetNumThreadContexts();
331 return false;
332
333 for (lldb::tid_t tid = 0; tid < num_threads; ++tid) {
334 const ThreadData &td = m_thread_data[tid];
335 lldb::ThreadSP thread_sp(new ThreadElfCore(*this, td));
336 new_thread_list.AddThread(thread_sp);
337 }
338 return new_thread_list.GetSize(false) > 0;
339}
340
342
344
345// Process Queries
346
347bool ProcessElfCore::IsAlive() { return true; }
348
349// Process Memory
350size_t ProcessElfCore::ReadMemory(lldb::addr_t addr, void *buf, size_t size,
351 Status &error) {
352 if (lldb::ABISP abi_sp = GetABI())
353 addr = abi_sp->FixAnyAddress(addr);
354
355 // Don't allow the caching that lldb_private::Process::ReadMemory does since
356 // in core files we have it all cached our our core file anyway.
357 return DoReadMemory(addr, buf, size, error);
358}
359
361 MemoryRegionInfo &region_info) {
362 region_info.Clear();
363 const VMRangeToPermissions::Entry *permission_entry =
364 m_core_range_infos.FindEntryThatContainsOrFollows(load_addr);
365 if (permission_entry) {
366 if (permission_entry->Contains(load_addr)) {
367 region_info.GetRange().SetRangeBase(permission_entry->GetRangeBase());
368 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeEnd());
369 const Flags permissions(permission_entry->data);
370 region_info.SetReadable(permissions.Test(lldb::ePermissionsReadable)
373 region_info.SetWritable(permissions.Test(lldb::ePermissionsWritable)
376 region_info.SetExecutable(permissions.Test(lldb::ePermissionsExecutable)
380
381 // A region is memory tagged if there is a memory tag segment that covers
382 // the exact same range.
384 const VMRangeToFileOffset::Entry *tag_entry =
385 m_core_tag_ranges.FindEntryStartsAt(permission_entry->GetRangeBase());
386 if (tag_entry &&
387 tag_entry->GetRangeEnd() == permission_entry->GetRangeEnd())
389 } else if (load_addr < permission_entry->GetRangeBase()) {
390 region_info.GetRange().SetRangeBase(load_addr);
391 region_info.GetRange().SetRangeEnd(permission_entry->GetRangeBase());
395 region_info.SetMapped(MemoryRegionInfo::eNo);
397 }
398 return Status();
399 }
400
401 region_info.GetRange().SetRangeBase(load_addr);
406 region_info.SetMapped(MemoryRegionInfo::eNo);
408 return Status();
409}
410
411size_t ProcessElfCore::DoReadMemory(lldb::addr_t addr, void *buf, size_t size,
412 Status &error) {
413 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
414
415 if (core_objfile == nullptr)
416 return 0;
417
418 // Get the address range
419 const VMRangeToFileOffset::Entry *address_range =
420 m_core_aranges.FindEntryThatContains(addr);
421 if (address_range == nullptr || address_range->GetRangeEnd() < addr) {
423 "core file does not contain 0x%" PRIx64, addr);
424 return 0;
425 }
426
427 // Convert the address into core file offset
428 const lldb::addr_t offset = addr - address_range->GetRangeBase();
429 const lldb::addr_t file_start = address_range->data.GetRangeBase();
430 const lldb::addr_t file_end = address_range->data.GetRangeEnd();
431 size_t bytes_to_read = size; // Number of bytes to read from the core file
432 size_t bytes_copied = 0; // Number of bytes actually read from the core file
433 lldb::addr_t bytes_left =
434 0; // Number of bytes available in the core file from the given address
435
436 // Don't proceed if core file doesn't contain the actual data for this
437 // address range.
438 if (file_start == file_end)
439 return 0;
440
441 // Figure out how many on-disk bytes remain in this segment starting at the
442 // given offset
443 if (file_end > file_start + offset)
444 bytes_left = file_end - (file_start + offset);
445
446 if (bytes_to_read > bytes_left)
447 bytes_to_read = bytes_left;
448
449 // If there is data available on the core file read it
450 if (bytes_to_read)
451 bytes_copied =
452 core_objfile->CopyData(offset + file_start, bytes_to_read, buf);
453
454 return bytes_copied;
455}
456
457llvm::Expected<std::vector<lldb::addr_t>>
459 ObjectFile *core_objfile = m_core_module_sp->GetObjectFile();
460 if (core_objfile == nullptr)
461 return llvm::createStringError(llvm::inconvertibleErrorCode(),
462 "No core object file.");
463
464 llvm::Expected<const MemoryTagManager *> tag_manager_or_err =
466 if (!tag_manager_or_err)
467 return tag_manager_or_err.takeError();
468
469 // LLDB only supports AArch64 MTE tag segments so we do not need to worry
470 // about the segment type here. If you got here then you must have a tag
471 // manager (meaning you are debugging AArch64) and all the segments in this
472 // list will have had type PT_AARCH64_MEMTAG_MTE.
473 const VMRangeToFileOffset::Entry *tag_entry =
474 m_core_tag_ranges.FindEntryThatContains(addr);
475 // If we don't have a tag segment or the range asked for extends outside the
476 // segment.
477 if (!tag_entry || (addr + len) >= tag_entry->GetRangeEnd())
478 return llvm::createStringError(llvm::inconvertibleErrorCode(),
479 "No tag segment that covers this range.");
480
481 const MemoryTagManager *tag_manager = *tag_manager_or_err;
482 return tag_manager->UnpackTagsFromCoreFileSegment(
483 [core_objfile](lldb::offset_t offset, size_t length, void *dst) {
484 return core_objfile->CopyData(offset, length, dst);
485 },
486 tag_entry->GetRangeBase(), tag_entry->data.GetRangeBase(), addr, len);
487}
488
490 m_thread_list.Clear();
491
492 SetUnixSignals(std::make_shared<UnixSignals>());
493}
494
496 static llvm::once_flag g_once_flag;
497
498 llvm::call_once(g_once_flag, []() {
501 });
502}
503
505 ObjectFile *obj_file = GetTarget().GetExecutableModule()->GetObjectFile();
506 Address addr = obj_file->GetImageInfoAddress(&GetTarget());
507
508 if (addr.IsValid())
509 return addr.GetLoadAddress(&GetTarget());
511}
512
513// Parse a FreeBSD NT_PRSTATUS note - see FreeBSD sys/procfs.h for details.
514static void ParseFreeBSDPrStatus(ThreadData &thread_data,
515 const DataExtractor &data,
516 bool lp64) {
517 lldb::offset_t offset = 0;
518 int pr_version = data.GetU32(&offset);
519
521 if (log) {
522 if (pr_version > 1)
523 LLDB_LOGF(log, "FreeBSD PRSTATUS unexpected version %d", pr_version);
524 }
525
526 // Skip padding, pr_statussz, pr_gregsetsz, pr_fpregsetsz, pr_osreldate
527 if (lp64)
528 offset += 32;
529 else
530 offset += 16;
531
532 thread_data.signo = data.GetU32(&offset); // pr_cursig
533 thread_data.tid = data.GetU32(&offset); // pr_pid
534 if (lp64)
535 offset += 4;
536
537 size_t len = data.GetByteSize() - offset;
538 thread_data.gpregset = DataExtractor(data, offset, len);
539}
540
541// Parse a FreeBSD NT_PRPSINFO note - see FreeBSD sys/procfs.h for details.
543 const DataExtractor &data,
544 bool lp64) {
545 lldb::offset_t offset = 0;
546 int pr_version = data.GetU32(&offset);
547
549 if (log) {
550 if (pr_version > 1)
551 LLDB_LOGF(log, "FreeBSD PRPSINFO unexpected version %d", pr_version);
552 }
553
554 // Skip pr_psinfosz, pr_fname, pr_psargs
555 offset += 108;
556 if (lp64)
557 offset += 4;
558
559 process.SetID(data.GetU32(&offset)); // pr_pid
560}
561
562static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data,
563 uint32_t &cpi_nlwps,
564 uint32_t &cpi_signo,
565 uint32_t &cpi_siglwp,
566 uint32_t &cpi_pid) {
567 lldb::offset_t offset = 0;
568
569 uint32_t version = data.GetU32(&offset);
570 if (version != 1)
571 return llvm::make_error<llvm::StringError>(
572 "Error parsing NetBSD core(5) notes: Unsupported procinfo version",
573 llvm::inconvertibleErrorCode());
574
575 uint32_t cpisize = data.GetU32(&offset);
576 if (cpisize != NETBSD::NT_PROCINFO_SIZE)
577 return llvm::make_error<llvm::StringError>(
578 "Error parsing NetBSD core(5) notes: Unsupported procinfo size",
579 llvm::inconvertibleErrorCode());
580
581 cpi_signo = data.GetU32(&offset); /* killing signal */
582
588 cpi_pid = data.GetU32(&offset);
598 cpi_nlwps = data.GetU32(&offset); /* number of LWPs */
599
601 cpi_siglwp = data.GetU32(&offset); /* LWP target of killing signal */
602
603 return llvm::Error::success();
604}
605
606static void ParseOpenBSDProcInfo(ThreadData &thread_data,
607 const DataExtractor &data) {
608 lldb::offset_t offset = 0;
609
610 int version = data.GetU32(&offset);
611 if (version != 1)
612 return;
613
614 offset += 4;
615 thread_data.signo = data.GetU32(&offset);
616}
617
618llvm::Expected<std::vector<CoreNote>>
620 lldb::offset_t offset = 0;
621 std::vector<CoreNote> result;
622
623 while (offset < segment.GetByteSize()) {
624 ELFNote note = ELFNote();
625 if (!note.Parse(segment, &offset))
626 return llvm::make_error<llvm::StringError>(
627 "Unable to parse note segment", llvm::inconvertibleErrorCode());
628
629 size_t note_start = offset;
630 size_t note_size = llvm::alignTo(note.n_descsz, 4);
631
632 result.push_back({note, DataExtractor(segment, note_start, note_size)});
633 offset += note_size;
634 }
635
636 return std::move(result);
637}
638
639llvm::Error ProcessElfCore::parseFreeBSDNotes(llvm::ArrayRef<CoreNote> notes) {
640 ArchSpec arch = GetArchitecture();
641 bool lp64 = (arch.GetMachine() == llvm::Triple::aarch64 ||
642 arch.GetMachine() == llvm::Triple::mips64 ||
643 arch.GetMachine() == llvm::Triple::ppc64 ||
644 arch.GetMachine() == llvm::Triple::x86_64);
645 bool have_prstatus = false;
646 bool have_prpsinfo = false;
647 ThreadData thread_data;
648 for (const auto &note : notes) {
649 if (note.info.n_name != "FreeBSD")
650 continue;
651
652 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
653 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
654 assert(thread_data.gpregset.GetByteSize() > 0);
655 // Add the new thread to thread list
656 m_thread_data.push_back(thread_data);
657 thread_data = ThreadData();
658 have_prstatus = false;
659 have_prpsinfo = false;
660 }
661
662 switch (note.info.n_type) {
663 case ELF::NT_PRSTATUS:
664 have_prstatus = true;
665 ParseFreeBSDPrStatus(thread_data, note.data, lp64);
666 break;
667 case ELF::NT_PRPSINFO:
668 have_prpsinfo = true;
669 ParseFreeBSDPrPsInfo(*this, note.data, lp64);
670 break;
671 case ELF::NT_FREEBSD_THRMISC: {
672 lldb::offset_t offset = 0;
673 thread_data.name = note.data.GetCStr(&offset, 20);
674 break;
675 }
676 case ELF::NT_FREEBSD_PROCSTAT_AUXV:
677 // FIXME: FreeBSD sticks an int at the beginning of the note
678 m_auxv = DataExtractor(note.data, 4, note.data.GetByteSize() - 4);
679 break;
680 default:
681 thread_data.notes.push_back(note);
682 break;
683 }
684 }
685 if (!have_prstatus) {
686 return llvm::make_error<llvm::StringError>(
687 "Could not find NT_PRSTATUS note in core file.",
688 llvm::inconvertibleErrorCode());
689 }
690 m_thread_data.push_back(thread_data);
691 return llvm::Error::success();
692}
693
694/// NetBSD specific Thread context from PT_NOTE segment
695///
696/// NetBSD ELF core files use notes to provide information about
697/// the process's state. The note name is "NetBSD-CORE" for
698/// information that is global to the process, and "NetBSD-CORE@nn",
699/// where "nn" is the lwpid of the LWP that the information belongs
700/// to (such as register state).
701///
702/// NetBSD uses the following note identifiers:
703///
704/// ELF_NOTE_NETBSD_CORE_PROCINFO (value 1)
705/// Note is a "netbsd_elfcore_procinfo" structure.
706/// ELF_NOTE_NETBSD_CORE_AUXV (value 2; since NetBSD 8.0)
707/// Note is an array of AuxInfo structures.
708///
709/// NetBSD also uses ptrace(2) request numbers (the ones that exist in
710/// machine-dependent space) to identify register info notes. The
711/// info in such notes is in the same format that ptrace(2) would
712/// export that information.
713///
714/// For more information see /usr/include/sys/exec_elf.h
715///
716llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
717 ThreadData thread_data;
718 bool had_nt_regs = false;
719
720 // To be extracted from struct netbsd_elfcore_procinfo
721 // Used to sanity check of the LWPs of the process
722 uint32_t nlwps = 0;
723 uint32_t signo = 0; // killing signal
724 uint32_t siglwp = 0; // LWP target of killing signal
725 uint32_t pr_pid = 0;
726
727 for (const auto &note : notes) {
728 llvm::StringRef name = note.info.n_name;
729
730 if (name == "NetBSD-CORE") {
731 if (note.info.n_type == NETBSD::NT_PROCINFO) {
732 llvm::Error error = ParseNetBSDProcInfo(note.data, nlwps, signo,
733 siglwp, pr_pid);
734 if (error)
735 return error;
736 SetID(pr_pid);
737 } else if (note.info.n_type == NETBSD::NT_AUXV) {
738 m_auxv = note.data;
739 }
740 } else if (name.consume_front("NetBSD-CORE@")) {
741 lldb::tid_t tid;
742 if (name.getAsInteger(10, tid))
743 return llvm::make_error<llvm::StringError>(
744 "Error parsing NetBSD core(5) notes: Cannot convert LWP ID "
745 "to integer",
746 llvm::inconvertibleErrorCode());
747
748 switch (GetArchitecture().GetMachine()) {
749 case llvm::Triple::aarch64: {
750 // Assume order PT_GETREGS, PT_GETFPREGS
751 if (note.info.n_type == NETBSD::AARCH64::NT_REGS) {
752 // If this is the next thread, push the previous one first.
753 if (had_nt_regs) {
754 m_thread_data.push_back(thread_data);
755 thread_data = ThreadData();
756 had_nt_regs = false;
757 }
758
759 thread_data.gpregset = note.data;
760 thread_data.tid = tid;
761 if (thread_data.gpregset.GetByteSize() == 0)
762 return llvm::make_error<llvm::StringError>(
763 "Could not find general purpose registers note in core file.",
764 llvm::inconvertibleErrorCode());
765 had_nt_regs = true;
766 } else if (note.info.n_type == NETBSD::AARCH64::NT_FPREGS) {
767 if (!had_nt_regs || tid != thread_data.tid)
768 return llvm::make_error<llvm::StringError>(
769 "Error parsing NetBSD core(5) notes: Unexpected order "
770 "of NOTEs PT_GETFPREG before PT_GETREG",
771 llvm::inconvertibleErrorCode());
772 thread_data.notes.push_back(note);
773 }
774 } break;
775 case llvm::Triple::x86: {
776 // Assume order PT_GETREGS, PT_GETFPREGS
777 if (note.info.n_type == NETBSD::I386::NT_REGS) {
778 // If this is the next thread, push the previous one first.
779 if (had_nt_regs) {
780 m_thread_data.push_back(thread_data);
781 thread_data = ThreadData();
782 had_nt_regs = false;
783 }
784
785 thread_data.gpregset = note.data;
786 thread_data.tid = tid;
787 if (thread_data.gpregset.GetByteSize() == 0)
788 return llvm::make_error<llvm::StringError>(
789 "Could not find general purpose registers note in core file.",
790 llvm::inconvertibleErrorCode());
791 had_nt_regs = true;
792 } else if (note.info.n_type == NETBSD::I386::NT_FPREGS) {
793 if (!had_nt_regs || tid != thread_data.tid)
794 return llvm::make_error<llvm::StringError>(
795 "Error parsing NetBSD core(5) notes: Unexpected order "
796 "of NOTEs PT_GETFPREG before PT_GETREG",
797 llvm::inconvertibleErrorCode());
798 thread_data.notes.push_back(note);
799 }
800 } break;
801 case llvm::Triple::x86_64: {
802 // Assume order PT_GETREGS, PT_GETFPREGS
803 if (note.info.n_type == NETBSD::AMD64::NT_REGS) {
804 // If this is the next thread, push the previous one first.
805 if (had_nt_regs) {
806 m_thread_data.push_back(thread_data);
807 thread_data = ThreadData();
808 had_nt_regs = false;
809 }
810
811 thread_data.gpregset = note.data;
812 thread_data.tid = tid;
813 if (thread_data.gpregset.GetByteSize() == 0)
814 return llvm::make_error<llvm::StringError>(
815 "Could not find general purpose registers note in core file.",
816 llvm::inconvertibleErrorCode());
817 had_nt_regs = true;
818 } else if (note.info.n_type == NETBSD::AMD64::NT_FPREGS) {
819 if (!had_nt_regs || tid != thread_data.tid)
820 return llvm::make_error<llvm::StringError>(
821 "Error parsing NetBSD core(5) notes: Unexpected order "
822 "of NOTEs PT_GETFPREG before PT_GETREG",
823 llvm::inconvertibleErrorCode());
824 thread_data.notes.push_back(note);
825 }
826 } break;
827 default:
828 break;
829 }
830 }
831 }
832
833 // Push the last thread.
834 if (had_nt_regs)
835 m_thread_data.push_back(thread_data);
836
837 if (m_thread_data.empty())
838 return llvm::make_error<llvm::StringError>(
839 "Error parsing NetBSD core(5) notes: No threads information "
840 "specified in notes",
841 llvm::inconvertibleErrorCode());
842
843 if (m_thread_data.size() != nlwps)
844 return llvm::make_error<llvm::StringError>(
845 "Error parsing NetBSD core(5) notes: Mismatch between the number "
846 "of LWPs in netbsd_elfcore_procinfo and the number of LWPs specified "
847 "by MD notes",
848 llvm::inconvertibleErrorCode());
849
850 // Signal targeted at the whole process.
851 if (siglwp == 0) {
852 for (auto &data : m_thread_data)
853 data.signo = signo;
854 }
855 // Signal destined for a particular LWP.
856 else {
857 bool passed = false;
858
859 for (auto &data : m_thread_data) {
860 if (data.tid == siglwp) {
861 data.signo = signo;
862 passed = true;
863 break;
864 }
865 }
866
867 if (!passed)
868 return llvm::make_error<llvm::StringError>(
869 "Error parsing NetBSD core(5) notes: Signal passed to unknown LWP",
870 llvm::inconvertibleErrorCode());
871 }
872
873 return llvm::Error::success();
874}
875
876llvm::Error ProcessElfCore::parseOpenBSDNotes(llvm::ArrayRef<CoreNote> notes) {
877 ThreadData thread_data = {};
878 for (const auto &note : notes) {
879 // OpenBSD per-thread information is stored in notes named "OpenBSD@nnn" so
880 // match on the initial part of the string.
881 if (!llvm::StringRef(note.info.n_name).starts_with("OpenBSD"))
882 continue;
883
884 switch (note.info.n_type) {
886 ParseOpenBSDProcInfo(thread_data, note.data);
887 break;
888 case OPENBSD::NT_AUXV:
889 m_auxv = note.data;
890 break;
891 case OPENBSD::NT_REGS:
892 thread_data.gpregset = note.data;
893 break;
894 default:
895 thread_data.notes.push_back(note);
896 break;
897 }
898 }
899 if (thread_data.gpregset.GetByteSize() == 0) {
900 return llvm::make_error<llvm::StringError>(
901 "Could not find general purpose registers note in core file.",
902 llvm::inconvertibleErrorCode());
903 }
904 m_thread_data.push_back(thread_data);
905 return llvm::Error::success();
906}
907
908/// A description of a linux process usually contains the following NOTE
909/// entries:
910/// - NT_PRPSINFO - General process information like pid, uid, name, ...
911/// - NT_SIGINFO - Information about the signal that terminated the process
912/// - NT_AUXV - Process auxiliary vector
913/// - NT_FILE - Files mapped into memory
914///
915/// Additionally, for each thread in the process the core file will contain at
916/// least the NT_PRSTATUS note, containing the thread id and general purpose
917/// registers. It may include additional notes for other register sets (floating
918/// point and vector registers, ...). The tricky part here is that some of these
919/// notes have "CORE" in their owner fields, while other set it to "LINUX".
920llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
921 const ArchSpec &arch = GetArchitecture();
922 bool have_prstatus = false;
923 bool have_prpsinfo = false;
924 ThreadData thread_data;
925 for (const auto &note : notes) {
926 if (note.info.n_name != "CORE" && note.info.n_name != "LINUX")
927 continue;
928
929 if ((note.info.n_type == ELF::NT_PRSTATUS && have_prstatus) ||
930 (note.info.n_type == ELF::NT_PRPSINFO && have_prpsinfo)) {
931 assert(thread_data.gpregset.GetByteSize() > 0);
932 // Add the new thread to thread list
933 m_thread_data.push_back(thread_data);
934 thread_data = ThreadData();
935 have_prstatus = false;
936 have_prpsinfo = false;
937 }
938
939 switch (note.info.n_type) {
940 case ELF::NT_PRSTATUS: {
941 have_prstatus = true;
942 ELFLinuxPrStatus prstatus;
943 Status status = prstatus.Parse(note.data, arch);
944 if (status.Fail())
945 return status.ToError();
946 thread_data.prstatus_sig = prstatus.pr_cursig;
947 thread_data.tid = prstatus.pr_pid;
948 uint32_t header_size = ELFLinuxPrStatus::GetSize(arch);
949 size_t len = note.data.GetByteSize() - header_size;
950 thread_data.gpregset = DataExtractor(note.data, header_size, len);
951 break;
952 }
953 case ELF::NT_PRPSINFO: {
954 have_prpsinfo = true;
955 ELFLinuxPrPsInfo prpsinfo;
956 Status status = prpsinfo.Parse(note.data, arch);
957 if (status.Fail())
958 return status.ToError();
959 thread_data.name.assign (prpsinfo.pr_fname, strnlen (prpsinfo.pr_fname, sizeof (prpsinfo.pr_fname)));
960 SetID(prpsinfo.pr_pid);
961 m_executable_name = thread_data.name;
962 break;
963 }
964 case ELF::NT_SIGINFO: {
965 lldb::offset_t size = note.data.GetByteSize();
966 lldb::offset_t offset = 0;
967 const char *bytes =
968 static_cast<const char *>(note.data.GetData(&offset, size));
969 thread_data.siginfo_bytes = llvm::StringRef(bytes, size);
970 break;
971 }
972 case ELF::NT_FILE: {
973 m_nt_file_entries.clear();
974 lldb::offset_t offset = 0;
975 const uint64_t count = note.data.GetAddress(&offset);
976 note.data.GetAddress(&offset); // Skip page size
977 for (uint64_t i = 0; i < count; ++i) {
978 NT_FILE_Entry entry;
979 entry.start = note.data.GetAddress(&offset);
980 entry.end = note.data.GetAddress(&offset);
981 entry.file_ofs = note.data.GetAddress(&offset);
982 m_nt_file_entries.push_back(entry);
983 }
984 for (uint64_t i = 0; i < count; ++i) {
985 const char *path = note.data.GetCStr(&offset);
986 if (path && path[0])
987 m_nt_file_entries[i].path.assign(path);
988 }
989 break;
990 }
991 case ELF::NT_AUXV:
992 m_auxv = note.data;
993 break;
994 default:
995 thread_data.notes.push_back(note);
996 break;
997 }
998 }
999 // Add last entry in the note section
1000 if (have_prstatus)
1001 m_thread_data.push_back(thread_data);
1002 return llvm::Error::success();
1003}
1004
1005/// Parse Thread context from PT_NOTE segment and store it in the thread list
1006/// A note segment consists of one or more NOTE entries, but their types and
1007/// meaning differ depending on the OS.
1009 const elf::ELFProgramHeader &segment_header,
1010 const DataExtractor &segment_data) {
1011 assert(segment_header.p_type == llvm::ELF::PT_NOTE);
1012
1013 auto notes_or_error = parseSegment(segment_data);
1014 if(!notes_or_error)
1015 return notes_or_error.takeError();
1016 switch (GetArchitecture().GetTriple().getOS()) {
1017 case llvm::Triple::FreeBSD:
1018 return parseFreeBSDNotes(*notes_or_error);
1019 case llvm::Triple::Linux:
1020 return parseLinuxNotes(*notes_or_error);
1021 case llvm::Triple::NetBSD:
1022 return parseNetBSDNotes(*notes_or_error);
1023 case llvm::Triple::OpenBSD:
1024 return parseOpenBSDNotes(*notes_or_error);
1025 default:
1026 return llvm::make_error<llvm::StringError>(
1027 "Don't know how to parse core file. Unsupported OS.",
1028 llvm::inconvertibleErrorCode());
1029 }
1030}
1031
1033 UUID invalid_uuid;
1034 const uint32_t addr_size = GetAddressByteSize();
1035 const size_t elf_header_size = addr_size == 4 ? sizeof(llvm::ELF::Elf32_Ehdr)
1036 : sizeof(llvm::ELF::Elf64_Ehdr);
1037
1038 std::vector<uint8_t> elf_header_bytes;
1039 elf_header_bytes.resize(elf_header_size);
1040 Status error;
1041 size_t byte_read =
1042 ReadMemory(address, elf_header_bytes.data(), elf_header_size, error);
1043 if (byte_read != elf_header_size ||
1044 !elf::ELFHeader::MagicBytesMatch(elf_header_bytes.data()))
1045 return invalid_uuid;
1046 DataExtractor elf_header_data(elf_header_bytes.data(), elf_header_size,
1047 GetByteOrder(), addr_size);
1048 lldb::offset_t offset = 0;
1049
1050 elf::ELFHeader elf_header;
1051 elf_header.Parse(elf_header_data, &offset);
1052
1053 const lldb::addr_t ph_addr = address + elf_header.e_phoff;
1054
1055 std::vector<uint8_t> ph_bytes;
1056 ph_bytes.resize(elf_header.e_phentsize);
1057 lldb::addr_t base_addr = 0;
1058 bool found_first_load_segment = false;
1059 for (unsigned int i = 0; i < elf_header.e_phnum; ++i) {
1060 byte_read = ReadMemory(ph_addr + i * elf_header.e_phentsize,
1061 ph_bytes.data(), elf_header.e_phentsize, error);
1062 if (byte_read != elf_header.e_phentsize)
1063 break;
1064 DataExtractor program_header_data(ph_bytes.data(), elf_header.e_phentsize,
1065 GetByteOrder(), addr_size);
1066 offset = 0;
1067 elf::ELFProgramHeader program_header;
1068 program_header.Parse(program_header_data, &offset);
1069 if (program_header.p_type == llvm::ELF::PT_LOAD &&
1070 !found_first_load_segment) {
1071 base_addr = program_header.p_vaddr;
1072 found_first_load_segment = true;
1073 }
1074 if (program_header.p_type != llvm::ELF::PT_NOTE)
1075 continue;
1076
1077 std::vector<uint8_t> note_bytes;
1078 note_bytes.resize(program_header.p_memsz);
1079
1080 // We need to slide the address of the p_vaddr as these values don't get
1081 // relocated in memory.
1082 const lldb::addr_t vaddr = program_header.p_vaddr + address - base_addr;
1083 byte_read =
1084 ReadMemory(vaddr, note_bytes.data(), program_header.p_memsz, error);
1085 if (byte_read != program_header.p_memsz)
1086 continue;
1087 DataExtractor segment_data(note_bytes.data(), note_bytes.size(),
1088 GetByteOrder(), addr_size);
1089 auto notes_or_error = parseSegment(segment_data);
1090 if (!notes_or_error) {
1091 llvm::consumeError(notes_or_error.takeError());
1092 return invalid_uuid;
1093 }
1094 for (const CoreNote &note : *notes_or_error) {
1095 if (note.info.n_namesz == 4 &&
1096 note.info.n_type == llvm::ELF::NT_GNU_BUILD_ID &&
1097 "GNU" == note.info.n_name &&
1098 note.data.ValidOffsetForDataOfSize(0, note.info.n_descsz))
1099 return UUID(note.data.GetData().take_front(note.info.n_descsz));
1100 }
1101 }
1102 return invalid_uuid;
1103}
1104
1107 DoLoadCore();
1108 return m_thread_data.size();
1109}
1110
1112 ArchSpec arch = m_core_module_sp->GetObjectFile()->GetArchitecture();
1113
1114 ArchSpec target_arch = GetTarget().GetArchitecture();
1115 arch.MergeFrom(target_arch);
1116
1117 // On MIPS there is no way to differentiate betwenn 32bit and 64bit core
1118 // files and this information can't be merged in from the target arch so we
1119 // fail back to unconditionally returning the target arch in this config.
1120 if (target_arch.IsMIPS()) {
1121 return target_arch;
1122 }
1123
1124 return arch;
1125}
1126
1128 assert(m_auxv.GetByteSize() == 0 ||
1129 (m_auxv.GetByteOrder() == GetByteOrder() &&
1130 m_auxv.GetAddressByteSize() == GetAddressByteSize()));
1131 return DataExtractor(m_auxv);
1132}
1133
1135 info.Clear();
1136 info.SetProcessID(GetID());
1139 if (module_sp) {
1140 const bool add_exe_file_as_first_arg = false;
1141 info.SetExecutableFile(GetTarget().GetExecutableModule()->GetFileSpec(),
1142 add_exe_file_as_first_arg);
1143 }
1144 return true;
1145}
static llvm::raw_ostream & error(Stream &strm)
static llvm::raw_ostream & note(Stream &strm)
#define LLDB_LOGF(log,...)
Definition Log.h:376
#define LLDB_PLUGIN_DEFINE(PluginName)
static void ParseOpenBSDProcInfo(ThreadData &thread_data, const DataExtractor &data)
static void ParseFreeBSDPrPsInfo(ProcessElfCore &process, const DataExtractor &data, bool lp64)
static void ParseFreeBSDPrStatus(ThreadData &thread_data, const DataExtractor &data, bool lp64)
static llvm::Error ParseNetBSDProcInfo(const DataExtractor &data, uint32_t &cpi_nlwps, uint32_t &cpi_signo, uint32_t &cpi_siglwp, uint32_t &cpi_pid)
static llvm::StringRef GetPluginNameStatic()
Generic COFF object file reader.
lldb_private::DataExtractor GetSegmentData(const elf::ELFProgramHeader &H)
llvm::ArrayRef< elf::ELFProgramHeader > ProgramHeaders()
std::vector< NT_FILE_Entry > m_nt_file_entries
lldb_private::UUID FindModuleUUID(const llvm::StringRef path) override
lldb::addr_t GetImageInfoAddress() override
Get the image information address for the current process.
lldb::addr_t AddAddressRangeFromMemoryTagSegment(const elf::ELFProgramHeader &header)
lldb_private::DataExtractor m_auxv
llvm::Error parseLinuxNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
A description of a linux process usually contains the following NOTE entries:
llvm::Error ParseThreadContextsFromNoteSegment(const elf::ELFProgramHeader &segment_header, const lldb_private::DataExtractor &segment_data)
Parse Thread context from PT_NOTE segment and store it in the thread list A note segment consists of ...
void UpdateBuildIdForNTFileEntries()
std::vector< ThreadData > m_thread_data
lldb_private::Range< lldb::addr_t, lldb::addr_t > FileRange
static void Initialize()
bool DoUpdateThreadList(lldb_private::ThreadList &old_thread_list, lldb_private::ThreadList &new_thread_list) override
Update the thread list following process plug-in's specific logic.
size_t ReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Read of memory from a process.
VMRangeToPermissions m_core_range_infos
static llvm::StringRef GetPluginDescriptionStatic()
std::unordered_map< std::string, lldb_private::UUID > m_uuids
llvm::Expected< std::vector< lldb_private::CoreNote > > parseSegment(const lldb_private::DataExtractor &segment)
lldb::addr_t AddAddressRangeFromLoadSegment(const elf::ELFProgramHeader &header)
~ProcessElfCore() override
llvm::Error parseFreeBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
llvm::StringRef GetMainExecutablePath()
lldb_private::UUID FindBuidIdInCoreMemory(lldb::addr_t address)
VMRangeToFileOffset m_core_aranges
lldb_private::Status DoGetMemoryRegionInfo(lldb::addr_t load_addr, lldb_private::MemoryRegionInfo &region_info) override
DoGetMemoryRegionInfo is called by GetMemoryRegionInfo after it has removed non address bits from loa...
size_t DoReadMemory(lldb::addr_t addr, void *buf, size_t size, lldb_private::Status &error) override
Actually do the reading of memory from a process.
VMRangeToFileOffset m_core_tag_ranges
llvm::Error parseNetBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
NetBSD specific Thread context from PT_NOTE segment.
lldb_private::Status DoLoadCore() override
static void Terminate()
ProcessElfCore(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec &core_file)
lldb_private::DynamicLoader * GetDynamicLoader() override
Get the dynamic loader plug-in for this process.
llvm::Expected< std::vector< lldb::addr_t > > ReadMemoryTags(lldb::addr_t addr, size_t len) override
Read memory tags for the range addr to addr+len.
lldb_private::DataExtractor GetAuxvData() override
bool IsAlive() override
Check if a process is still alive.
uint32_t GetNumThreadContexts()
std::string m_executable_name
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const lldb_private::FileSpec *crash_file_path, bool can_connect)
llvm::Error parseOpenBSDNotes(llvm::ArrayRef< lldb_private::CoreNote > notes)
void RefreshStateAfterStop() override
Currently called as part of ShouldStop.
lldb_private::ArchSpec GetArchitecture()
bool CanDebug(lldb::TargetSP target_sp, bool plugin_specified_by_name) override
Check if a plug-in instance can debug the file in module.
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override
static llvm::StringRef GetPluginNameStatic()
lldb::ModuleSP m_core_module_sp
lldb_private::Status DoDestroy() override
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
An architecture specification class.
Definition ArchSpec.h:31
void MergeFrom(const ArchSpec &other)
Merges fields from another ArchSpec into this ArchSpec.
Definition ArchSpec.cpp:803
bool IsMIPS() const
if MIPS architecture return true.
Definition ArchSpec.cpp:555
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition ArchSpec.cpp:677
An data extractor class.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint64_t GetByteSize() const
Get the number of bytes contained in this object.
A plug-in interface definition class for dynamic loaders.
static DynamicLoader * FindPlugin(Process *process, llvm::StringRef plugin_name)
Find a dynamic loader plugin for a given process.
A file utility class.
Definition FileSpec.h:57
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
Definition FileSpec.cpp:174
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:374
static FileSystem & Instance()
std::shared_ptr< DataBuffer > CreateDataBuffer(const llvm::Twine &path, uint64_t size=0, uint64_t offset=0)
Create memory buffer from path.
A class to manage flags.
Definition Flags.h:22
bool Test(ValueType bit) const
Test a single flag bit.
Definition Flags.h:96
void SetMapped(OptionalBool val)
void SetMemoryTagged(OptionalBool val)
void SetReadable(OptionalBool val)
void SetExecutable(OptionalBool val)
void SetWritable(OptionalBool val)
virtual llvm::Expected< std::vector< lldb::addr_t > > UnpackTagsFromCoreFileSegment(CoreReaderFn reader, lldb::addr_t tag_segment_virtual_address, lldb::addr_t tag_segment_data_address, lldb::addr_t addr, size_t len) const =0
static Status GetSharedModule(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp, const FileSpecList *module_search_paths_ptr, llvm::SmallVectorImpl< lldb::ModuleSP > *old_modules, bool *did_create_ptr, bool always_create=false)
FileSpec & GetFileSpec()
Definition ModuleSpec.h:53
ArchSpec & GetArchitecture()
Definition ModuleSpec.h:89
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:45
virtual lldb_private::Address GetImageInfoAddress(Target *target)
Similar to Process::GetImageInfoAddress().
Definition ObjectFile.h:466
@ eTypeCoreFile
A core file that has a checkpoint of a program's execution state.
Definition ObjectFile.h:52
size_t CopyData(lldb::offset_t offset, size_t length, void *dst) const
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
PostMortemProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp, const FileSpec &core_file)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
void SetArchitecture(const ArchSpec &arch)
Definition ProcessInfo.h:66
void SetProcessID(lldb::pid_t pid)
Definition ProcessInfo.h:70
lldb::pid_t GetID() const
Returns the pid of the process or LLDB_INVALID_PROCESS_ID if there is no known pid.
Definition Process.h:556
void SetUnixSignals(lldb::UnixSignalsSP &&signals_sp)
Definition Process.cpp:3606
void SetCanJIT(bool can_jit)
Sets whether executing JIT-compiled code in this process is possible.
Definition Process.cpp:2486
lldb::DynamicLoaderUP m_dyld_up
Definition Process.h:3179
llvm::Expected< const MemoryTagManager * > GetMemoryTagManager()
If this architecture and process supports memory tagging, return a tag manager that can be used to ma...
Definition Process.cpp:6451
lldb::ByteOrder GetByteOrder() const
Definition Process.cpp:3616
void SetID(lldb::pid_t new_pid)
Sets the stored pid.
Definition Process.h:561
uint32_t GetAddressByteSize() const
Definition Process.cpp:3620
virtual void Finalize(bool destructing)
This object is about to be destroyed, do any necessary cleanup.
Definition Process.cpp:538
ThreadList m_thread_list
The threads for this process as the user will see them.
Definition Process.h:3152
const lldb::UnixSignalsSP & GetUnixSignals()
Definition Process.cpp:3611
const lldb::ABISP & GetABI()
Definition Process.cpp:1481
friend class ThreadList
Definition Process.h:364
Target & GetTarget()
Get the target object pointer for this module.
Definition Process.h:1270
RangeData< lldb::addr_t, lldb::addr_t, FileRange > Entry
Definition RangeMap.h:462
An error handling class.
Definition Status.h:118
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
Definition Status.cpp:139
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:294
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:137
lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, Status *error_ptr=nullptr)
Find a binary on the system and return its Module, or return an existing Module that is already in th...
Definition Target.cpp:2339
bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform=false, bool merge=true)
Set the architecture for this target.
Definition Target.cpp:1697
lldb::ModuleSP GetExecutableModule()
Gets the module for the main executable.
Definition Target.cpp:1517
const ArchSpec & GetArchitecture() const
Definition Target.h:1056
void SetExecutableModule(lldb::ModuleSP &module_sp, LoadDependentFiles load_dependent_files=eLoadDependentsDefault)
Set the main executable module.
Definition Target.cpp:1568
void AddThread(const lldb::ThreadSP &thread_sp)
uint32_t GetSize(bool can_update=true)
Represents UUID's of various sizes.
Definition UUID.h:27
std::string GetAsString(llvm::StringRef separator="-") const
Definition UUID.cpp:54
bool IsValid() const
Definition UUID.h:69
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:332
std::shared_ptr< lldb_private::ABI > ABISP
std::shared_ptr< lldb_private::Thread > ThreadSP
uint64_t offset_t
Definition lldb-types.h:85
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::Listener > ListenerSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
uint64_t tid_t
Definition lldb-types.h:84
std::shared_ptr< lldb_private::Module > ModuleSP
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
static size_t GetSize(const lldb_private::ArchSpec &arch)
lldb_private::Status Parse(const lldb_private::DataExtractor &data, const lldb_private::ArchSpec &arch)
lldb::addr_t file_ofs
lldb::addr_t end
lldb::addr_t start
llvm::StringRef siginfo_bytes
lldb::tid_t tid
std::string name
lldb_private::DataExtractor gpregset
std::vector< lldb_private::CoreNote > notes
Generic representation of an ELF file header.
Definition ELFHeader.h:56
elf_off e_phoff
File offset of program header table.
Definition ELFHeader.h:59
elf_half e_phentsize
Size of a program header table entry.
Definition ELFHeader.h:66
static bool MagicBytesMatch(const uint8_t *magic)
Examines at most EI_NIDENT bytes starting from the given pointer and determines if the magic ELF iden...
bool Parse(lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFHeader entry starting at position offset and update the data extractor with the address s...
elf_word e_phnum
Number of program header entries.
Definition ELFHeader.h:75
elf_word e_version
Version of object file (always 1).
Definition ELFHeader.h:62
unsigned char e_ident[llvm::ELF::EI_NIDENT]
ELF file identification.
Definition ELFHeader.h:57
elf_half e_type
Object file type.
Definition ELFHeader.h:63
Generic representation of an ELF program header.
Definition ELFHeader.h:192
bool Parse(const lldb_private::DataExtractor &data, lldb::offset_t *offset)
Parse an ELFProgramHeader entry from the given DataExtractor starting at position offset.
elf_word p_flags
Segment attributes.
Definition ELFHeader.h:194
elf_xword p_filesz
Byte size of the segment in file.
Definition ELFHeader.h:198
elf_off p_offset
Start of segment from beginning of file.
Definition ELFHeader.h:195
elf_addr p_vaddr
Virtual address of segment in memory.
Definition ELFHeader.h:196
elf_xword p_memsz
Byte size of the segment in memory.
Definition ELFHeader.h:199
elf_word p_type
Type of program segment.
Definition ELFHeader.h:193
bool Contains(BaseType r) const
Definition RangeMap.h:93
BaseType GetRangeBase() const
Definition RangeMap.h:45
void SetRangeEnd(BaseType end)
Definition RangeMap.h:80
SizeType GetByteSize() const
Definition RangeMap.h:87
void SetRangeBase(BaseType b)
Set the start value for the range, and keep the same size.
Definition RangeMap.h:48
BaseType GetRangeEnd() const
Definition RangeMap.h:78