LLDB  mainline
AuxVector.cpp
Go to the documentation of this file.
1 //===-- AuxVector.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 "AuxVector.h"
10 
12  ParseAuxv(data);
13 }
14 
16  lldb::offset_t offset = 0;
17  const size_t value_type_size = data.GetAddressByteSize() * 2;
18  while (data.ValidOffsetForDataOfSize(offset, value_type_size)) {
19  // We're not reading an address but an int that could be 32 or 64 bit
20  // depending on the address size, which is what GetAddress does.
21  const uint64_t type = data.GetAddress(&offset);
22  const uint64_t value = data.GetAddress(&offset);
23  if (type == AUXV_AT_NULL)
24  break;
25  if (type == AUXV_AT_IGNORE)
26  continue;
27 
28  m_auxv_entries[type] = value;
29  }
30 }
31 
32 llvm::Optional<uint64_t>
33 AuxVector::GetAuxValue(enum EntryType entry_type) const {
34  auto it = m_auxv_entries.find(static_cast<uint64_t>(entry_type));
35  if (it != m_auxv_entries.end())
36  return it->second;
37  return llvm::None;
38 }
39 
41  if (!log)
42  return;
43 
44  log->PutCString("AuxVector: ");
45  for (auto entry : m_auxv_entries) {
46  LLDB_LOGF(log, " %s [%" PRIu64 "]: %" PRIx64,
47  GetEntryName(static_cast<EntryType>(entry.first)), entry.first,
48  entry.second);
49  }
50 }
51 
52 const char *AuxVector::GetEntryName(EntryType type) const {
53  const char *name = "AT_???";
54 
55 #define ENTRY_NAME(_type) \
56  _type: \
57  name = &#_type[5]
58  switch (type) {
59  case ENTRY_NAME(AUXV_AT_NULL); break;
60  case ENTRY_NAME(AUXV_AT_IGNORE); break;
61  case ENTRY_NAME(AUXV_AT_EXECFD); break;
62  case ENTRY_NAME(AUXV_AT_PHDR); break;
63  case ENTRY_NAME(AUXV_AT_PHENT); break;
64  case ENTRY_NAME(AUXV_AT_PHNUM); break;
65  case ENTRY_NAME(AUXV_AT_PAGESZ); break;
66  case ENTRY_NAME(AUXV_AT_BASE); break;
67  case ENTRY_NAME(AUXV_AT_FLAGS); break;
68  case ENTRY_NAME(AUXV_AT_ENTRY); break;
69  case ENTRY_NAME(AUXV_AT_NOTELF); break;
70  case ENTRY_NAME(AUXV_AT_UID); break;
71  case ENTRY_NAME(AUXV_AT_EUID); break;
72  case ENTRY_NAME(AUXV_AT_GID); break;
73  case ENTRY_NAME(AUXV_AT_EGID); break;
74  case ENTRY_NAME(AUXV_AT_CLKTCK); break;
75  case ENTRY_NAME(AUXV_AT_PLATFORM); break;
76  case ENTRY_NAME(AUXV_AT_HWCAP); break;
77  case ENTRY_NAME(AUXV_AT_FPUCW); break;
78  case ENTRY_NAME(AUXV_AT_DCACHEBSIZE); break;
79  case ENTRY_NAME(AUXV_AT_ICACHEBSIZE); break;
80  case ENTRY_NAME(AUXV_AT_UCACHEBSIZE); break;
81  case ENTRY_NAME(AUXV_AT_IGNOREPPC); break;
82  case ENTRY_NAME(AUXV_AT_SECURE); break;
83  case ENTRY_NAME(AUXV_AT_BASE_PLATFORM); break;
84  case ENTRY_NAME(AUXV_AT_RANDOM); break;
85  case ENTRY_NAME(AUXV_AT_HWCAP2); break;
86  case ENTRY_NAME(AUXV_AT_EXECFN); break;
87  case ENTRY_NAME(AUXV_AT_SYSINFO); break;
88  case ENTRY_NAME(AUXV_AT_SYSINFO_EHDR); break;
91  case ENTRY_NAME(AUXV_AT_L2_CACHESHAPE); break;
92  case ENTRY_NAME(AUXV_AT_L3_CACHESHAPE); break;
93  }
94 #undef ENTRY_NAME
95 
96  return name;
97 }
AuxVector::AUXV_AT_SYSINFO_EHDR
@ AUXV_AT_SYSINFO_EHDR
Definition: AuxVector.h:57
AuxVector::AUXV_AT_PHDR
@ AUXV_AT_PHDR
Program headers.
Definition: AuxVector.h:29
AuxVector::GetEntryName
const char * GetEntryName(EntryType type) const
Definition: AuxVector.cpp:52
AuxVector::AUXV_AT_ICACHEBSIZE
@ AUXV_AT_ICACHEBSIZE
Instruction cache block size.
Definition: AuxVector.h:47
AuxVector::AUXV_AT_HWCAP
@ AUXV_AT_HWCAP
Machine dependent hints about processor capabilities.
Definition: AuxVector.h:43
AuxVector::AUXV_AT_FLAGS
@ AUXV_AT_FLAGS
Flags.
Definition: AuxVector.h:34
lldb_private::DataExtractor::GetAddress
uint64_t GetAddress(lldb::offset_t *offset_ptr) const
Extract an address from *offset_ptr.
Definition: DataExtractor.cpp:651
AuxVector::AUXV_AT_BASE_PLATFORM
@ AUXV_AT_BASE_PLATFORM
String identifying real platforms.
Definition: AuxVector.h:51
AuxVector::AUXV_AT_PHNUM
@ AUXV_AT_PHNUM
Number of program headers.
Definition: AuxVector.h:31
AuxVector::AUXV_AT_PHENT
@ AUXV_AT_PHENT
Size of program header.
Definition: AuxVector.h:30
AuxVector::AUXV_AT_L2_CACHESHAPE
@ AUXV_AT_L2_CACHESHAPE
Definition: AuxVector.h:60
AuxVector::AUXV_AT_HWCAP2
@ AUXV_AT_HWCAP2
Extension of AT_HWCAP.
Definition: AuxVector.h:53
LLDB_LOGF
#define LLDB_LOGF(log,...)
Definition: Log.h:249
AuxVector::AUXV_AT_DCACHEBSIZE
@ AUXV_AT_DCACHEBSIZE
Data cache block size.
Definition: AuxVector.h:46
AuxVector::AUXV_AT_UID
@ AUXV_AT_UID
UID.
Definition: AuxVector.h:37
AuxVector::AUXV_AT_EGID
@ AUXV_AT_EGID
Effective GID.
Definition: AuxVector.h:40
lldb::offset_t
uint64_t offset_t
Definition: lldb-types.h:87
AuxVector::AUXV_AT_CLKTCK
@ AUXV_AT_CLKTCK
Clock frequency (e.g. times(2)).
Definition: AuxVector.h:41
AuxVector::AUXV_AT_BASE
@ AUXV_AT_BASE
Interpreter base address.
Definition: AuxVector.h:33
ENTRY_NAME
#define ENTRY_NAME(_type)
AuxVector::AuxVector
AuxVector(const lldb_private::DataExtractor &data)
Definition: AuxVector.cpp:11
AuxVector::AUXV_AT_UCACHEBSIZE
@ AUXV_AT_UCACHEBSIZE
Unified cache block size.
Definition: AuxVector.h:48
AuxVector::AUXV_AT_L1D_CACHESHAPE
@ AUXV_AT_L1D_CACHESHAPE
Definition: AuxVector.h:59
AuxVector::AUXV_AT_NULL
@ AUXV_AT_NULL
End of auxv.
Definition: AuxVector.h:26
AuxVector::AUXV_AT_EUID
@ AUXV_AT_EUID
Effective UID.
Definition: AuxVector.h:38
AuxVector::AUXV_AT_PAGESZ
@ AUXV_AT_PAGESZ
Page size.
Definition: AuxVector.h:32
AuxVector::DumpToLog
void DumpToLog(lldb_private::Log *log) const
Definition: AuxVector.cpp:40
lldb_private::DataExtractor::GetAddressByteSize
uint32_t GetAddressByteSize() const
Get the current address size.
Definition: DataExtractor.h:253
lldb_private::DataExtractor
Definition: DataExtractor.h:48
AuxVector.h
AuxVector::ParseAuxv
void ParseAuxv(const lldb_private::DataExtractor &data)
Definition: AuxVector.cpp:15
AuxVector::AUXV_AT_ENTRY
@ AUXV_AT_ENTRY
Program entry point.
Definition: AuxVector.h:35
AuxVector::AUXV_AT_NOTELF
@ AUXV_AT_NOTELF
Set if program is not an ELF.
Definition: AuxVector.h:36
AuxVector::AUXV_AT_EXECFN
@ AUXV_AT_EXECFN
Filename of executable.
Definition: AuxVector.h:54
AuxVector::AUXV_AT_SYSINFO
@ AUXV_AT_SYSINFO
Pointer to the global system page used for system calls and other nice things.
Definition: AuxVector.h:55
AuxVector::AUXV_AT_L3_CACHESHAPE
@ AUXV_AT_L3_CACHESHAPE
Definition: AuxVector.h:61
AuxVector::EntryType
EntryType
Constants describing the type of entry.
Definition: AuxVector.h:25
AuxVector::AUXV_AT_GID
@ AUXV_AT_GID
GID.
Definition: AuxVector.h:39
AuxVector::AUXV_AT_RANDOM
@ AUXV_AT_RANDOM
Address of 16 random bytes.
Definition: AuxVector.h:52
AuxVector::GetAuxValue
llvm::Optional< uint64_t > GetAuxValue(enum EntryType entry_type) const
Definition: AuxVector.cpp:33
AuxVector::AUXV_AT_EXECFD
@ AUXV_AT_EXECFD
File descriptor of program.
Definition: AuxVector.h:28
AuxVector::m_auxv_entries
std::unordered_map< uint64_t, uint64_t > m_auxv_entries
Definition: AuxVector.h:71
AuxVector::AUXV_AT_SECURE
@ AUXV_AT_SECURE
Boolean, was exec setuid-like?
Definition: AuxVector.h:50
AuxVector::AUXV_AT_IGNORE
@ AUXV_AT_IGNORE
Ignore entry.
Definition: AuxVector.h:27
AuxVector::AUXV_AT_IGNOREPPC
@ AUXV_AT_IGNOREPPC
Entry should be ignored.
Definition: AuxVector.h:49
AuxVector::AUXV_AT_FPUCW
@ AUXV_AT_FPUCW
Used FPU control word.
Definition: AuxVector.h:45
lldb_private::Log
Definition: Log.h:49
AuxVector::AUXV_AT_PLATFORM
@ AUXV_AT_PLATFORM
String identifying platform.
Definition: AuxVector.h:42
lldb_private::DataExtractor::ValidOffsetForDataOfSize
bool ValidOffsetForDataOfSize(lldb::offset_t offset, lldb::offset_t length) const
Test the availability of length bytes of data from offset.
Definition: DataExtractor.h:954
AuxVector::AUXV_AT_L1I_CACHESHAPE
@ AUXV_AT_L1I_CACHESHAPE
Shapes of the caches.
Definition: AuxVector.h:58
lldb_private::Log::PutCString
void PutCString(const char *cstr)
Definition: Log.cpp:118