blob: 45c86641d8a046f59d459e345007e978cedfb2d1 [file] [log] [blame]
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +00001//===-- LLVMSymbolize.cpp -------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Implementation for LLVM symbolization library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "LLVMSymbolize.h"
Alexey Samsonov51283a12013-03-19 15:33:18 +000015#include "llvm/ADT/STLExtras.h"
Alexey Samsonov8228a8d2013-08-26 18:12:03 +000016#include "llvm/Config/config.h"
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +000017#include "llvm/Object/MachO.h"
18#include "llvm/Support/Casting.h"
Alexey Samsonov68894832013-08-14 17:09:30 +000019#include "llvm/Support/Compression.h"
20#include "llvm/Support/DataExtractor.h"
Alexey Samsonov888ca962013-06-04 07:57:38 +000021#include "llvm/Support/FileSystem.h"
Alexey Samsonov68894832013-08-14 17:09:30 +000022#include "llvm/Support/MemoryBuffer.h"
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +000023#include "llvm/Support/Path.h"
24
25#include <sstream>
Alexey Samsonov8228a8d2013-08-26 18:12:03 +000026#include <stdlib.h>
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +000027
28namespace llvm {
29namespace symbolize {
30
Dmitry Vyukovb1819192013-02-14 13:06:18 +000031static bool error(error_code ec) {
Alexey Samsonovc4439c32013-02-15 08:54:47 +000032 if (!ec)
33 return false;
Dmitry Vyukovb1819192013-02-14 13:06:18 +000034 errs() << "LLVMSymbolizer: error reading file: " << ec.message() << ".\n";
35 return true;
36}
37
Alexey Samsonovc4439c32013-02-15 08:54:47 +000038static uint32_t
39getDILineInfoSpecifierFlags(const LLVMSymbolizer::Options &Opts) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +000040 uint32_t Flags = llvm::DILineInfoSpecifier::FileLineInfo |
41 llvm::DILineInfoSpecifier::AbsoluteFilePath;
42 if (Opts.PrintFunctions)
43 Flags |= llvm::DILineInfoSpecifier::FunctionName;
44 return Flags;
45}
46
47static void patchFunctionNameInDILineInfo(const std::string &NewFunctionName,
48 DILineInfo &LineInfo) {
49 std::string FileName = LineInfo.getFileName();
50 LineInfo = DILineInfo(StringRef(FileName), StringRef(NewFunctionName),
51 LineInfo.getLine(), LineInfo.getColumn());
52}
53
Dmitry Vyukovb1819192013-02-14 13:06:18 +000054ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx)
Alexey Samsonovc4439c32013-02-15 08:54:47 +000055 : Module(Obj), DebugInfoContext(DICtx) {
Dmitry Vyukovb1819192013-02-14 13:06:18 +000056 error_code ec;
Alexey Samsonovc4439c32013-02-15 08:54:47 +000057 for (symbol_iterator si = Module->begin_symbols(), se = Module->end_symbols();
58 si != se; si.increment(ec)) {
Dmitry Vyukovb1819192013-02-14 13:06:18 +000059 if (error(ec))
60 return;
61 SymbolRef::Type SymbolType;
62 if (error(si->getType(SymbolType)))
63 continue;
Alexey Samsonovc4439c32013-02-15 08:54:47 +000064 if (SymbolType != SymbolRef::ST_Function &&
65 SymbolType != SymbolRef::ST_Data)
Dmitry Vyukovb1819192013-02-14 13:06:18 +000066 continue;
67 uint64_t SymbolAddress;
Alexey Samsonovc4439c32013-02-15 08:54:47 +000068 if (error(si->getAddress(SymbolAddress)) ||
69 SymbolAddress == UnknownAddressOrSize)
Dmitry Vyukovb1819192013-02-14 13:06:18 +000070 continue;
71 uint64_t SymbolSize;
Alexey Samsonovb6564642013-06-07 15:25:27 +000072 // Getting symbol size is linear for Mach-O files, so assume that symbol
73 // occupies the memory range up to the following symbol.
Alexey Samsonov888ca962013-06-04 07:57:38 +000074 if (isa<MachOObjectFile>(Obj))
75 SymbolSize = 0;
76 else if (error(si->getSize(SymbolSize)) ||
77 SymbolSize == UnknownAddressOrSize)
Dmitry Vyukovb1819192013-02-14 13:06:18 +000078 continue;
79 StringRef SymbolName;
80 if (error(si->getName(SymbolName)))
81 continue;
Alexey Samsonov8c6e3242013-06-28 14:25:52 +000082 // Mach-O symbol table names have leading underscore, skip it.
83 if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
84 SymbolName = SymbolName.drop_front();
Dmitry Vyukovb1819192013-02-14 13:06:18 +000085 // FIXME: If a function has alias, there are two entries in symbol table
86 // with same address size. Make sure we choose the correct one.
Alexey Samsonovc4439c32013-02-15 08:54:47 +000087 SymbolMapTy &M = SymbolType == SymbolRef::ST_Function ? Functions : Objects;
Alexey Samsonovb6564642013-06-07 15:25:27 +000088 SymbolDesc SD = { SymbolAddress, SymbolSize };
Dmitry Vyukovb1819192013-02-14 13:06:18 +000089 M.insert(std::make_pair(SD, SymbolName));
90 }
91}
92
93bool ModuleInfo::getNameFromSymbolTable(SymbolRef::Type Type, uint64_t Address,
94 std::string &Name, uint64_t &Addr,
95 uint64_t &Size) const {
Alexey Samsonovc4439c32013-02-15 08:54:47 +000096 const SymbolMapTy &M = Type == SymbolRef::ST_Function ? Functions : Objects;
Alexey Samsonov888ca962013-06-04 07:57:38 +000097 if (M.empty())
Dmitry Vyukovb1819192013-02-14 13:06:18 +000098 return false;
Alexey Samsonov888ca962013-06-04 07:57:38 +000099 SymbolDesc SD = { Address, Address };
100 SymbolMapTy::const_iterator it = M.upper_bound(SD);
Alexey Samsonovb6564642013-06-07 15:25:27 +0000101 if (it == M.begin())
102 return false;
Alexey Samsonov888ca962013-06-04 07:57:38 +0000103 --it;
Alexey Samsonovb6564642013-06-07 15:25:27 +0000104 if (it->first.Size != 0 && it->first.Addr + it->first.Size <= Address)
Dmitry Vyukovb1819192013-02-14 13:06:18 +0000105 return false;
106 Name = it->second.str();
107 Addr = it->first.Addr;
Alexey Samsonovb6564642013-06-07 15:25:27 +0000108 Size = it->first.Size;
Dmitry Vyukovb1819192013-02-14 13:06:18 +0000109 return true;
110}
111
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000112DILineInfo ModuleInfo::symbolizeCode(
113 uint64_t ModuleOffset, const LLVMSymbolizer::Options &Opts) const {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000114 DILineInfo LineInfo;
115 if (DebugInfoContext) {
116 LineInfo = DebugInfoContext->getLineInfoForAddress(
117 ModuleOffset, getDILineInfoSpecifierFlags(Opts));
118 }
119 // Override function name from symbol table if necessary.
120 if (Opts.PrintFunctions && Opts.UseSymbolTable) {
121 std::string FunctionName;
122 uint64_t Start, Size;
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000123 if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
124 FunctionName, Start, Size)) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000125 patchFunctionNameInDILineInfo(FunctionName, LineInfo);
126 }
127 }
128 return LineInfo;
129}
130
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000131DIInliningInfo ModuleInfo::symbolizeInlinedCode(
132 uint64_t ModuleOffset, const LLVMSymbolizer::Options &Opts) const {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000133 DIInliningInfo InlinedContext;
134 if (DebugInfoContext) {
135 InlinedContext = DebugInfoContext->getInliningInfoForAddress(
136 ModuleOffset, getDILineInfoSpecifierFlags(Opts));
137 }
138 // Make sure there is at least one frame in context.
139 if (InlinedContext.getNumberOfFrames() == 0) {
140 InlinedContext.addFrame(DILineInfo());
141 }
142 // Override the function name in lower frame with name from symbol table.
143 if (Opts.PrintFunctions && Opts.UseSymbolTable) {
144 DIInliningInfo PatchedInlinedContext;
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000145 for (uint32_t i = 0, n = InlinedContext.getNumberOfFrames(); i < n; i++) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000146 DILineInfo LineInfo = InlinedContext.getFrame(i);
147 if (i == n - 1) {
148 std::string FunctionName;
149 uint64_t Start, Size;
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000150 if (getNameFromSymbolTable(SymbolRef::ST_Function, ModuleOffset,
151 FunctionName, Start, Size)) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000152 patchFunctionNameInDILineInfo(FunctionName, LineInfo);
153 }
154 }
155 PatchedInlinedContext.addFrame(LineInfo);
156 }
157 InlinedContext = PatchedInlinedContext;
158 }
159 return InlinedContext;
160}
161
162bool ModuleInfo::symbolizeData(uint64_t ModuleOffset, std::string &Name,
163 uint64_t &Start, uint64_t &Size) const {
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000164 return getNameFromSymbolTable(SymbolRef::ST_Data, ModuleOffset, Name, Start,
165 Size);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000166}
167
Alexey Samsonov638c63c2013-02-04 15:55:26 +0000168const char LLVMSymbolizer::kBadString[] = "??";
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000169
170std::string LLVMSymbolizer::symbolizeCode(const std::string &ModuleName,
171 uint64_t ModuleOffset) {
172 ModuleInfo *Info = getOrCreateModuleInfo(ModuleName);
173 if (Info == 0)
174 return printDILineInfo(DILineInfo());
175 if (Opts.PrintInlining) {
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000176 DIInliningInfo InlinedContext =
177 Info->symbolizeInlinedCode(ModuleOffset, Opts);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000178 uint32_t FramesNum = InlinedContext.getNumberOfFrames();
179 assert(FramesNum > 0);
180 std::string Result;
181 for (uint32_t i = 0; i < FramesNum; i++) {
182 DILineInfo LineInfo = InlinedContext.getFrame(i);
183 Result += printDILineInfo(LineInfo);
184 }
185 return Result;
186 }
187 DILineInfo LineInfo = Info->symbolizeCode(ModuleOffset, Opts);
188 return printDILineInfo(LineInfo);
189}
190
191std::string LLVMSymbolizer::symbolizeData(const std::string &ModuleName,
192 uint64_t ModuleOffset) {
193 std::string Name = kBadString;
194 uint64_t Start = 0;
195 uint64_t Size = 0;
196 if (Opts.UseSymbolTable) {
197 if (ModuleInfo *Info = getOrCreateModuleInfo(ModuleName)) {
Alexey Samsonovc071f892013-06-28 12:06:25 +0000198 if (Info->symbolizeData(ModuleOffset, Name, Start, Size) && Opts.Demangle)
199 Name = DemangleName(Name);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000200 }
201 }
202 std::stringstream ss;
203 ss << Name << "\n" << Start << " " << Size << "\n";
204 return ss.str();
205}
206
Dmitry Vyukove9e10d12013-03-19 10:24:42 +0000207void LLVMSymbolizer::flush() {
Alexey Samsonov51283a12013-03-19 15:33:18 +0000208 DeleteContainerSeconds(Modules);
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000209 DeleteContainerPointers(ParsedBinariesAndObjects);
Alexey Samsonov0ed872c2013-06-28 15:08:29 +0000210 BinaryForPath.clear();
211 ObjectFileForArch.clear();
Dmitry Vyukove9e10d12013-03-19 10:24:42 +0000212}
213
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000214static std::string getDarwinDWARFResourceForPath(const std::string &Path) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000215 StringRef Basename = sys::path::filename(Path);
216 const std::string &DSymDirectory = Path + ".dSYM";
217 SmallString<16> ResourceName = StringRef(DSymDirectory);
218 sys::path::append(ResourceName, "Contents", "Resources", "DWARF");
219 sys::path::append(ResourceName, Basename);
220 return ResourceName.str();
221}
222
Alexey Samsonov68894832013-08-14 17:09:30 +0000223static bool checkFileCRC(StringRef Path, uint32_t CRCHash) {
224 OwningPtr<MemoryBuffer> MB;
225 if (MemoryBuffer::getFileOrSTDIN(Path, MB))
226 return false;
227 return !zlib::isAvailable() || CRCHash == zlib::crc32(MB->getBuffer());
228}
229
230static bool findDebugBinary(const std::string &OrigPath,
231 const std::string &DebuglinkName, uint32_t CRCHash,
232 std::string &Result) {
Alexey Samsonov8228a8d2013-08-26 18:12:03 +0000233 std::string OrigRealPath = OrigPath;
234#if defined(HAVE_REALPATH)
235 if (char *RP = realpath(OrigPath.c_str(), NULL)) {
236 OrigRealPath = RP;
237 free(RP);
238 }
239#endif
240 SmallString<16> OrigDir(OrigRealPath);
Alexey Samsonov68894832013-08-14 17:09:30 +0000241 llvm::sys::path::remove_filename(OrigDir);
242 SmallString<16> DebugPath = OrigDir;
243 // Try /path/to/original_binary/debuglink_name
244 llvm::sys::path::append(DebugPath, DebuglinkName);
245 if (checkFileCRC(DebugPath, CRCHash)) {
246 Result = DebugPath.str();
247 return true;
248 }
249 // Try /path/to/original_binary/.debug/debuglink_name
Alexey Samsonov8228a8d2013-08-26 18:12:03 +0000250 DebugPath = OrigRealPath;
Alexey Samsonov68894832013-08-14 17:09:30 +0000251 llvm::sys::path::append(DebugPath, ".debug", DebuglinkName);
252 if (checkFileCRC(DebugPath, CRCHash)) {
253 Result = DebugPath.str();
254 return true;
255 }
256 // Try /usr/lib/debug/path/to/original_binary/debuglink_name
257 DebugPath = "/usr/lib/debug";
258 llvm::sys::path::append(DebugPath, llvm::sys::path::relative_path(OrigDir),
259 DebuglinkName);
260 if (checkFileCRC(DebugPath, CRCHash)) {
261 Result = DebugPath.str();
262 return true;
263 }
264 return false;
265}
266
267static bool getGNUDebuglinkContents(const Binary *Bin, std::string &DebugName,
268 uint32_t &CRCHash) {
269 const ObjectFile *Obj = dyn_cast<ObjectFile>(Bin);
270 if (!Obj)
271 return false;
272 error_code EC;
273 for (section_iterator I = Obj->begin_sections(), E = Obj->end_sections();
274 I != E; I.increment(EC)) {
275 StringRef Name;
276 I->getName(Name);
277 Name = Name.substr(Name.find_first_not_of("._"));
278 if (Name == "gnu_debuglink") {
279 StringRef Data;
280 I->getContents(Data);
281 DataExtractor DE(Data, Obj->isLittleEndian(), 0);
282 uint32_t Offset = 0;
283 if (const char *DebugNameStr = DE.getCStr(&Offset)) {
284 // 4-byte align the offset.
285 Offset = (Offset + 3) & ~0x3;
286 if (DE.isValidOffsetForDataOfSize(Offset, 4)) {
287 DebugName = DebugNameStr;
288 CRCHash = DE.getU32(&Offset);
289 return true;
290 }
291 }
292 break;
293 }
294 }
295 return false;
296}
297
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000298LLVMSymbolizer::BinaryPair
299LLVMSymbolizer::getOrCreateBinary(const std::string &Path) {
300 BinaryMapTy::iterator I = BinaryForPath.find(Path);
301 if (I != BinaryForPath.end())
302 return I->second;
303 Binary *Bin = 0;
304 Binary *DbgBin = 0;
305 OwningPtr<Binary> ParsedBinary;
306 OwningPtr<Binary> ParsedDbgBinary;
307 if (!error(createBinary(Path, ParsedBinary))) {
308 // Check if it's a universal binary.
309 Bin = ParsedBinary.take();
310 ParsedBinariesAndObjects.push_back(Bin);
311 if (Bin->isMachO() || Bin->isMachOUniversalBinary()) {
312 // On Darwin we may find DWARF in separate object file in
313 // resource directory.
314 const std::string &ResourcePath =
315 getDarwinDWARFResourceForPath(Path);
316 bool ResourceFileExists = false;
317 if (!sys::fs::exists(ResourcePath, ResourceFileExists) &&
318 ResourceFileExists &&
319 !error(createBinary(ResourcePath, ParsedDbgBinary))) {
320 DbgBin = ParsedDbgBinary.take();
321 ParsedBinariesAndObjects.push_back(DbgBin);
322 }
323 }
Alexey Samsonov68894832013-08-14 17:09:30 +0000324 // Try to locate the debug binary using .gnu_debuglink section.
325 if (DbgBin == 0) {
326 std::string DebuglinkName;
327 uint32_t CRCHash;
328 std::string DebugBinaryPath;
329 if (getGNUDebuglinkContents(Bin, DebuglinkName, CRCHash) &&
330 findDebugBinary(Path, DebuglinkName, CRCHash, DebugBinaryPath) &&
331 !error(createBinary(DebugBinaryPath, ParsedDbgBinary))) {
332 DbgBin = ParsedDbgBinary.take();
333 ParsedBinariesAndObjects.push_back(DbgBin);
334 }
335 }
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000336 }
337 if (DbgBin == 0)
338 DbgBin = Bin;
339 BinaryPair Res = std::make_pair(Bin, DbgBin);
340 BinaryForPath[Path] = Res;
341 return Res;
342}
343
344ObjectFile *
345LLVMSymbolizer::getObjectFileFromBinary(Binary *Bin, const std::string &ArchName) {
346 if (Bin == 0)
347 return 0;
348 ObjectFile *Res = 0;
349 if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin)) {
350 ObjectFileForArchMapTy::iterator I = ObjectFileForArch.find(
351 std::make_pair(UB, ArchName));
352 if (I != ObjectFileForArch.end())
353 return I->second;
354 OwningPtr<ObjectFile> ParsedObj;
355 if (!UB->getObjectForArch(Triple(ArchName).getArch(), ParsedObj)) {
356 Res = ParsedObj.take();
357 ParsedBinariesAndObjects.push_back(Res);
358 }
359 ObjectFileForArch[std::make_pair(UB, ArchName)] = Res;
360 } else if (Bin->isObject()) {
361 Res = cast<ObjectFile>(Bin);
362 }
363 return Res;
364}
365
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000366ModuleInfo *
367LLVMSymbolizer::getOrCreateModuleInfo(const std::string &ModuleName) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000368 ModuleMapTy::iterator I = Modules.find(ModuleName);
369 if (I != Modules.end())
370 return I->second;
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000371 std::string BinaryName = ModuleName;
372 std::string ArchName = Opts.DefaultArch;
Alexey Samsonovdf959c72013-07-17 06:45:36 +0000373 size_t ColonPos = ModuleName.find_last_of(':');
374 // Verify that substring after colon form a valid arch name.
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000375 if (ColonPos != std::string::npos) {
Alexey Samsonovdf959c72013-07-17 06:45:36 +0000376 std::string ArchStr = ModuleName.substr(ColonPos + 1);
NAKAMURA Takumi1e65bf22013-07-17 06:53:51 +0000377 if (Triple(ArchStr).getArch() != Triple::UnknownArch) {
Alexey Samsonovdf959c72013-07-17 06:45:36 +0000378 BinaryName = ModuleName.substr(0, ColonPos);
379 ArchName = ArchStr;
380 }
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000381 }
382 BinaryPair Binaries = getOrCreateBinary(BinaryName);
383 ObjectFile *Obj = getObjectFileFromBinary(Binaries.first, ArchName);
384 ObjectFile *DbgObj = getObjectFileFromBinary(Binaries.second, ArchName);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000385
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000386 if (Obj == 0) {
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000387 // Failed to find valid object file.
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000388 Modules.insert(make_pair(ModuleName, (ModuleInfo *)0));
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000389 return 0;
390 }
Alexey Samsonov8175bc32013-06-28 08:15:40 +0000391 DIContext *Context = DIContext::getDWARFContext(DbgObj);
392 assert(Context);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000393 ModuleInfo *Info = new ModuleInfo(Obj, Context);
394 Modules.insert(make_pair(ModuleName, Info));
395 return Info;
396}
397
398std::string LLVMSymbolizer::printDILineInfo(DILineInfo LineInfo) const {
399 // By default, DILineInfo contains "<invalid>" for function/filename it
400 // cannot fetch. We replace it to "??" to make our output closer to addr2line.
401 static const std::string kDILineInfoBadString = "<invalid>";
402 std::stringstream Result;
403 if (Opts.PrintFunctions) {
404 std::string FunctionName = LineInfo.getFunctionName();
405 if (FunctionName == kDILineInfoBadString)
406 FunctionName = kBadString;
Alexey Samsonovc071f892013-06-28 12:06:25 +0000407 else if (Opts.Demangle)
408 FunctionName = DemangleName(FunctionName);
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000409 Result << FunctionName << "\n";
410 }
411 std::string Filename = LineInfo.getFileName();
412 if (Filename == kDILineInfoBadString)
413 Filename = kBadString;
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000414 Result << Filename << ":" << LineInfo.getLine() << ":" << LineInfo.getColumn()
415 << "\n";
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000416 return Result.str();
417}
418
419#if !defined(_MSC_VER)
420// Assume that __cxa_demangle is provided by libcxxabi (except for Windows).
421extern "C" char *__cxa_demangle(const char *mangled_name, char *output_buffer,
422 size_t *length, int *status);
423#endif
424
Alexey Samsonovc071f892013-06-28 12:06:25 +0000425std::string LLVMSymbolizer::DemangleName(const std::string &Name) {
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000426#if !defined(_MSC_VER)
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000427 int status = 0;
428 char *DemangledName = __cxa_demangle(Name.c_str(), 0, 0, &status);
429 if (status != 0)
Alexey Samsonovc071f892013-06-28 12:06:25 +0000430 return Name;
431 std::string Result = DemangledName;
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000432 free(DemangledName);
Alexey Samsonovc071f892013-06-28 12:06:25 +0000433 return Result;
434#else
435 return Name;
Alexey Samsonovc4c7ea32013-01-22 14:21:19 +0000436#endif
437}
438
Alexey Samsonovc4439c32013-02-15 08:54:47 +0000439} // namespace symbolize
440} // namespace llvm