22 #include <sys/types.h>
29 for (
size_t i = 0;
i < Size;
i++)
30 Printf(
"0x%x,", (
unsigned)Data[
i]);
43 else if (Byte >= 32 && Byte < 127)
50 for (
size_t i = 0;
i < Size;
i++)
59 bool ToASCII(uint8_t *Data,
size_t Size) {
61 for (
size_t i = 0;
i < Size;
i++) {
65 if (!isspace(NewX) && !isprint(NewX))
75 bool IsASCII(
const uint8_t *Data,
size_t Size) {
76 for (
size_t i = 0;
i < Size;
i++)
77 if (!(isprint(Data[
i]) || isspace(Data[i])))
return false;
83 if (Str.empty())
return false;
84 size_t L = 0, R = Str.size() - 1;
86 while (L < R && isspace(Str[L])) L++;
87 while (R > L && isspace(Str[R])) R--;
88 if (R - L < 2)
return false;
90 if (Str[R] !=
'"')
return false;
93 while (L < R && Str[L] !=
'"') L++;
94 if (L >= R)
return false;
98 for (
size_t Pos = L; Pos <= R; Pos++) {
99 uint8_t V = (uint8_t)Str[Pos];
100 if (!isprint(V) && !isspace(V))
return false;
103 if (Pos + 1 <= R && (Str[Pos + 1] ==
'\\' || Str[Pos + 1] ==
'"')) {
104 U->push_back(Str[Pos + 1]);
109 if (Pos + 3 <= R && Str[Pos + 1] ==
'x'
110 && isxdigit(Str[Pos + 2]) && isxdigit(Str[Pos + 3])) {
112 Hex[2] = Str[Pos + 2];
113 Hex[3] = Str[Pos + 3];
114 U->push_back(strtol(Hex,
nullptr, 16));
129 Printf(
"ParseDictionaryFile: file does not exist or is empty\n");
132 std::istringstream ISS(Text);
137 while (std::getline(ISS, S,
'\n')) {
140 while (Pos < S.size() && isspace(S[Pos])) Pos++;
141 if (Pos == S.size())
continue;
142 if (S[Pos] ==
'#')
continue;
146 Printf(
"ParseDictionaryFile: error in line %d\n\t\t%s\n", LineNo,
155 static const char Table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
156 "abcdefghijklmnopqrstuvwxyz"
160 for (i = 0; i + 2 < U.size(); i += 3) {
161 uint32_t x = (U[
i] << 16) + (U[i + 1] << 8) + U[i + 2];
162 Res += Table[(x >> 18) & 63];
163 Res += Table[(x >> 12) & 63];
164 Res += Table[(x >> 6) & 63];
165 Res += Table[x & 63];
167 if (i + 1 == U.size()) {
169 Res += Table[(x >> 18) & 63];
170 Res += Table[(x >> 12) & 63];
172 }
else if (i + 2 == U.size()) {
173 uint32_t x = (U[
i] << 16) + (U[i + 1] << 8);
174 Res += Table[(x >> 18) & 63];
175 Res += Table[(x >> 12) & 63];
176 Res += Table[(x >> 6) & 63];
183 if (!
EF->__sanitizer_symbolize_pc)
return "<can not symbolize>";
185 EF->__sanitizer_symbolize_pc(reinterpret_cast<void*>(PC),
186 SymbolizedFMT, PcDescr,
sizeof(PcDescr));
187 PcDescr[
sizeof(PcDescr) - 1] = 0;
191 void PrintPC(
const char *SymbolizedFMT,
const char *FallbackFMT, uintptr_t
PC) {
192 if (
EF->__sanitizer_symbolize_pc)
199 unsigned N = std::thread::hardware_concurrency();
201 Printf(
"WARNING: std::thread::hardware_concurrency not well defined for "
202 "your platform. Assuming CPU count of 1.\n");
210 if (!Pipe)
return false;
213 while ((N = fread(Buff, 1,
sizeof(Buff), Pipe)) > 0)
214 Out->append(Buff, N);
void Print(const Unit &v, const char *PrintAfter)
void PrintHexArray(const uint8_t *Data, size_t Size, const char *PrintAfter)
bool ExecuteCommandAndReadOutput(const std::string &Command, std::string *Out)
void PrintASCIIByte(uint8_t Byte)
bool ParseOneDictionaryEntry(const std::string &Str, Unit *U)
std::string DescribePC(const char *SymbolizedFMT, uintptr_t PC)
void Printf(const char *Fmt,...)
static PassOptionList PrintAfter("print-after", llvm::cl::desc("Print IR after specified passes"), cl::Hidden)
std::string Base64(const Unit &U)
bool ParseDictionaryFile(const std::string &Text, std::vector< Unit > *Units)
FILE * OpenProcessPipe(const char *Command, const char *Mode)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
bool ToASCII(uint8_t *Data, size_t Size)
void PrintPC(const char *SymbolizedFMT, const char *FallbackFMT, uintptr_t PC)
SmallVectorImpl< T >::const_pointer c_str(SmallVectorImpl< T > &str)
bool IsASCII(const Unit &U)
std::vector< uint8_t > Unit
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned NumberOfCpuCores()
static void PrintASCII(const Word &W, const char *PrintAfter)