11#include "llvm/ADT/StringExtras.h"
12#include "llvm/ADT/StringSwitch.h"
13#include "llvm/Support/Endian.h"
14#include "llvm/Support/FormatVariadic.h"
42 return llvm::StringSwitch<Token>(Str)
43 .Case(
"MODULE", Token::Module)
44 .Case(
"INFO", Token::Info)
45 .Case(
"CODE_ID", Token::CodeID)
46 .Case(
"FILE", Token::File)
47 .Case(
"FUNC", Token::Func)
48 .Case(
"INLINE", Token::Inline)
49 .Case(
"INLINE_ORIGIN", Token::InlineOrigin)
50 .Case(
"PUBLIC", Token::Public)
51 .Case(
"STACK", Token::Stack)
52 .Case(
"CFI", Token::CFI)
53 .Case(
"INIT", Token::Init)
54 .Case(
"WIN", Token::Win)
55 .Default(Token::Unknown);
61 return llvm::StringSwitch<Triple::OSType>(Str)
62 .Case(
"Linux", Triple::Linux)
63 .Case(
"mac", Triple::MacOSX)
64 .Case(
"windows", Triple::Win32)
65 .Default(Triple::UnknownOS);
71 return llvm::StringSwitch<Triple::ArchType>(Str)
72 .Case(
"arm", Triple::arm)
73 .Cases(
"arm64",
"arm64e", Triple::aarch64)
74 .Case(
"mips", Triple::mips)
75 .Case(
"msp430", Triple::msp430)
76 .Case(
"ppc", Triple::ppc)
77 .Case(
"ppc64", Triple::ppc64)
78 .Case(
"s390", Triple::systemz)
79 .Case(
"sparc", Triple::sparc)
80 .Case(
"sparcv9", Triple::sparcv9)
81 .Case(
"x86", Triple::x86)
82 .Cases(
"x86_64",
"x86_64h", Triple::x86_64)
83 .Default(Triple::UnknownArch);
88 llvm::StringRef Token;
89 std::tie(Token, Str) = getToken(Str);
90 return stringTo<T>(Token);
95template <
typename T>
static constexpr size_t hex_digits() {
101 using uuid_t = uint8_t[16];
103 llvm::support::ubig32_t age;
105 static_assert(
sizeof(data) == 20);
110 if (str.size() <= hex_digits<data_t::uuid_t>() ||
111 str.size() > hex_digits<data_t>())
113 if (!all_of(str, llvm::isHexDigit))
116 llvm::StringRef uuid_str = str.take_front(hex_digits<data_t::uuid_t>());
117 llvm::StringRef age_str = str.drop_front(hex_digits<data_t::uuid_t>());
119 llvm::copy(fromHex(uuid_str), data.uuid);
121 bool success = to_integer(age_str, age, 16);
128 return UUID(&data, os == llvm::Triple::Win32 ?
sizeof(data)
129 :
sizeof(data.uuid));
133 Token Tok = consume<Token>(
Line);
146 Tok = consume<Token>(
Line);
157 case Token::InlineOrigin:
172 llvm_unreachable(
"Fully covered switch above!");
177 if (consume<Token>(
Line) != Token::Module)
180 llvm::Triple::OSType
OS = consume<llvm::Triple::OSType>(
Line);
181 if (
OS == llvm::Triple::UnknownOS)
184 llvm::Triple::ArchType
Arch = consume<llvm::Triple::ArchType>(
Line);
185 if (
Arch == llvm::Triple::UnknownArch)
189 std::tie(Str,
Line) = getToken(
Line);
199 return OS <<
"MODULE " << llvm::Triple::getOSTypeName(R.
OS) <<
" "
200 << llvm::Triple::getArchTypeName(R.
Arch) <<
" "
206 if (consume<Token>(
Line) != Token::Info)
209 if (consume<Token>(
Line) != Token::CodeID)
213 std::tie(Str,
Line) = getToken(
Line);
217 if (
Line.trim().empty()) {
232 if (consume<Token>(Line) != TokenType)
237 std::tie(Str, Line) = getToken(Line);
238 if (!to_integer(Str, Number))
241 llvm::StringRef Name = Line.trim();
245 return T(Number, Name);
250 return parseNumberName<FileRecord>(
Line, Token::File);
258std::optional<InlineOriginRecord>
261 return parseNumberName<InlineOriginRecord>(
Line, Token::InlineOrigin);
266 return OS <<
"INLINE_ORIGIN " << R.
Number <<
" " << R.
Name;
276 Token Tok = Size ? Token::Func : Token::Public;
278 if (consume<Token>(Line) != Tok)
282 std::tie(Str, Line) = getToken(Line);
283 Multiple = Str ==
"m";
286 std::tie(Str, Line) = getToken(Line);
287 if (!to_integer(Str,
Address, 16))
290 if (Tok == Token::Func) {
291 std::tie(Str, Line) = getToken(Line);
292 if (!to_integer(Str, *Size, 16))
296 std::tie(Str, Line) = getToken(Line);
297 if (!to_integer(Str, ParamSize, 16))
310 llvm::StringRef
Name;
324 return OS << llvm::formatv(
"FUNC {0}{1:x-} {2:x-} {3:x-} {4}",
332 if (consume<Token>(
Line) != Token::Inline)
335 llvm::SmallVector<llvm::StringRef> Tokens;
336 SplitString(
Line, Tokens,
" ");
337 if (Tokens.size() < 6 || Tokens.size() % 2 == 1)
352 for (
size_t i = 4; i < Tokens.size(); i += 2) {
354 if (!to_integer(Tokens[i],
Address, 16))
357 if (!to_integer(Tokens[i + 1].trim(), Size, 16))
375 for (
const auto &range : R.
Ranges) {
376 OS << llvm::formatv(
" {0:x-} {1:x-}", range.first, range.second);
384 std::tie(Str,
Line) = getToken(
Line);
385 if (!to_integer(Str,
Address, 16))
389 std::tie(Str,
Line) = getToken(
Line);
390 if (!to_integer(Str,
Size, 16))
394 std::tie(Str,
Line) = getToken(
Line);
399 std::tie(Str,
Line) = getToken(
Line);
412 return OS << llvm::formatv(
"{0:x-} {1:x-} {2} {3}", R.
Address, R.
Size,
419 llvm::StringRef
Name;
433 return OS << llvm::formatv(
"PUBLIC {0}{1:x-} {2:x-} {3}",
444 if (consume<Token>(
Line) != Token::Stack)
446 if (consume<Token>(
Line) != Token::CFI)
450 std::tie(Str,
Line) = getToken(
Line);
454 std::tie(Str,
Line) = getToken(
Line);
457 if (!to_integer(Str,
Address, 16))
460 std::optional<lldb::addr_t>
Size;
463 std::tie(Str,
Line) = getToken(
Line);
464 if (!to_integer(Str, *
Size, 16))
481 OS << llvm::formatv(
"{0:x-} ", R.
Address);
483 OS << llvm::formatv(
"{0:x-} ", *R.
Size);
492 if (consume<Token>(
Line) != Token::Stack)
494 if (consume<Token>(
Line) != Token::Win)
499 std::tie(Str,
Line) = getToken(
Line);
505 std::tie(Str,
Line) = getToken(
Line);
506 if (!to_integer(Str,
RVA, 16))
510 std::tie(Str,
Line) = getToken(
Line);
515 std::tie(Str,
Line) = getToken(
Line);
516 std::tie(Str,
Line) = getToken(
Line);
519 std::tie(Str,
Line) = getToken(
Line);
524 std::tie(Str,
Line) = getToken(
Line);
529 std::tie(Str,
Line) = getToken(
Line);
533 std::tie(Str,
Line) = getToken(
Line);
535 uint8_t HasProgramString;
536 std::tie(Str,
Line) = getToken(
Line);
537 if (!to_integer(Str, HasProgramString))
540 if (!HasProgramString)
556 return OS << llvm::formatv(
557 "STACK WIN 4 {0:x-} {1:x-} ? ? {2} {3} {4} ? 1 {5}", R.
RVA,
575 return "INLINE_ORIGIN";
585 llvm_unreachable(
"Unknown record kind!");
static T consume(llvm::StringRef &Str)
static UUID parseModuleId(llvm::Triple::OSType os, llvm::StringRef str)
static constexpr size_t hex_digits()
Return the number of hex digits needed to encode an (POD) object of a given type.
llvm::Triple::ArchType stringTo< llvm::Triple::ArchType >(llvm::StringRef Str)
static T stringTo(llvm::StringRef Str)
llvm::Triple::OSType stringTo< llvm::Triple::OSType >(llvm::StringRef Str)
static bool parsePublicOrFunc(llvm::StringRef Line, bool &Multiple, lldb::addr_t &Address, lldb::addr_t *Size, lldb::addr_t &ParamSize, llvm::StringRef &Name)
Token stringTo< Token >(llvm::StringRef Str)
static std::optional< T > parseNumberName(llvm::StringRef Line, Token TokenType)
A section + offset based address class.
An abstract base class for files.
A class that describes an executable image and its associated object and symbol files.
bool SetFromStringRef(llvm::StringRef str)
std::string GetAsString(llvm::StringRef separator="-") const
static std::optional< FileRecord > parse(llvm::StringRef Line)
static std::optional< FuncRecord > parse(llvm::StringRef Line)
static std::optional< InfoRecord > parse(llvm::StringRef Line)
static std::optional< InlineOriginRecord > parse(llvm::StringRef Line)
static std::optional< InlineRecord > parse(llvm::StringRef Line)
std::vector< std::pair< lldb::addr_t, lldb::addr_t > > Ranges
static std::optional< LineRecord > parse(llvm::StringRef Line)
static std::optional< ModuleRecord > parse(llvm::StringRef Line)
llvm::Triple::ArchType Arch
static std::optional< PublicRecord > parse(llvm::StringRef Line)
static std::optional< Kind > classify(llvm::StringRef Line)
Attempt to guess the kind of the record present in the argument without doing a full parse.
llvm::StringRef UnwindRules
std::optional< lldb::addr_t > Size
static std::optional< StackCFIRecord > parse(llvm::StringRef Line)
llvm::StringRef ProgramString
static std::optional< StackWinRecord > parse(llvm::StringRef Line)
lldb::addr_t ParameterSize
lldb::addr_t SavedRegisterSize
#define UNUSED_IF_ASSERT_DISABLED(x)
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, Record::Kind K)
bool operator==(const ModuleRecord &L, const ModuleRecord &R)
llvm::StringRef toString(Record::Kind K)
A class that represents a running process on the host machine.