1 //===-- AuxVector.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
13 #include <sys/types.h>
16 // Other libraries and framework includes
17 #include "lldb/Core/DataBufferHeap.h"
18 #include "lldb/Core/DataExtractor.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Target/Process.h"
22 #if defined(__linux__) || defined(__FreeBSD__)
23 #include "Plugins/Process/elf-core/ProcessElfCore.h"
26 #include "AuxVector.h"
29 using namespace lldb_private;
32 GetMaxU64(DataExtractor &data,
33 lldb::offset_t *offset_ptr,
35 unsigned int byte_size)
37 lldb::offset_t saved_offset = *offset_ptr;
38 *value = data.GetMaxU64(offset_ptr, byte_size);
39 return *offset_ptr != saved_offset;
43 ParseAuxvEntry(DataExtractor &data,
44 AuxVector::Entry &entry,
45 lldb::offset_t *offset_ptr,
46 unsigned int byte_size)
48 if (!GetMaxU64(data, offset_ptr, &entry.type, byte_size))
51 if (!GetMaxU64(data, offset_ptr, &entry.value, byte_size))
58 AuxVector::GetAuxvData()
60 #if defined(__linux__) || defined(__FreeBSD__)
61 if (m_process->GetPluginName() == ProcessElfCore::GetPluginNameStatic())
62 return static_cast<ProcessElfCore *>(m_process)->GetAuxvData();
64 return lldb_private::Host::GetAuxvData(m_process);
68 AuxVector::ParseAuxv(DataExtractor &data)
70 const unsigned int byte_size = m_process->GetAddressByteSize();
71 lldb::offset_t offset = 0;
77 if (!ParseAuxvEntry(data, entry, &offset, byte_size))
80 if (entry.type == AT_NULL)
83 if (entry.type == AT_IGNORE)
86 m_auxv.push_back(entry);
90 AuxVector::AuxVector(Process *process)
94 Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER));
96 data.SetData(GetAuxvData());
97 data.SetByteOrder(m_process->GetByteOrder());
98 data.SetAddressByteSize(m_process->GetAddressByteSize());
107 AuxVector::FindEntry(EntryType type) const
109 for (iterator I = begin(); I != end(); ++I)
111 if (I->type == static_cast<uint64_t>(type))
119 AuxVector::DumpToLog(Log *log) const
124 log->PutCString("AuxVector: ");
125 for (iterator I = begin(); I != end(); ++I)
127 log->Printf(" %s [%" PRIu64 "]: %" PRIx64, GetEntryName(*I), I->type, I->value);
132 AuxVector::GetEntryName(EntryType type)
134 const char *name = "AT_???";
136 #define ENTRY_NAME(_type) _type: name = #_type
139 case ENTRY_NAME(AT_NULL); break;
140 case ENTRY_NAME(AT_IGNORE); break;
141 case ENTRY_NAME(AT_EXECFD); break;
142 case ENTRY_NAME(AT_PHDR); break;
143 case ENTRY_NAME(AT_PHENT); break;
144 case ENTRY_NAME(AT_PHNUM); break;
145 case ENTRY_NAME(AT_PAGESZ); break;
146 case ENTRY_NAME(AT_BASE); break;
147 case ENTRY_NAME(AT_FLAGS); break;
148 case ENTRY_NAME(AT_ENTRY); break;
149 case ENTRY_NAME(AT_NOTELF); break;
150 case ENTRY_NAME(AT_UID); break;
151 case ENTRY_NAME(AT_EUID); break;
152 case ENTRY_NAME(AT_GID); break;
153 case ENTRY_NAME(AT_EGID); break;
154 case ENTRY_NAME(AT_CLKTCK); break;
155 case ENTRY_NAME(AT_PLATFORM); break;
156 case ENTRY_NAME(AT_HWCAP); break;
157 case ENTRY_NAME(AT_FPUCW); break;
158 case ENTRY_NAME(AT_DCACHEBSIZE); break;
159 case ENTRY_NAME(AT_ICACHEBSIZE); break;
160 case ENTRY_NAME(AT_UCACHEBSIZE); break;
161 case ENTRY_NAME(AT_IGNOREPPC); break;
162 case ENTRY_NAME(AT_SECURE); break;
163 case ENTRY_NAME(AT_BASE_PLATFORM); break;
164 case ENTRY_NAME(AT_RANDOM); break;
165 case ENTRY_NAME(AT_EXECFN); break;
166 case ENTRY_NAME(AT_SYSINFO); break;
167 case ENTRY_NAME(AT_SYSINFO_EHDR); break;
168 case ENTRY_NAME(AT_L1I_CACHESHAPE); break;
169 case ENTRY_NAME(AT_L1D_CACHESHAPE); break;
170 case ENTRY_NAME(AT_L2_CACHESHAPE); break;
171 case ENTRY_NAME(AT_L3_CACHESHAPE); break;