diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2015-11-03 22:20:52 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2015-11-03 22:20:52 +0000 |
commit | d6aa8202627d8ee1296283c135a1805408846d82 (patch) | |
tree | 6eeeb488719eb0498fb9e1fbe583cc8d794bfbfa /llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | |
parent | 61362ce876073358a2af67c4b05cff617b4a5c22 (diff) | |
download | bcm5719-llvm-d6aa8202627d8ee1296283c135a1805408846d82.tar.gz bcm5719-llvm-d6aa8202627d8ee1296283c135a1805408846d82.zip |
[LLVMSymbolize] Factor out the logic for printing structs from DIContext. NFC.
Introduce DIPrinter which takes care of rendering DILineInfo and
friends. This allows LLVMSymbolizer class to return a structured data
instead of plain std::strings.
llvm-svn: 251989
Diffstat (limited to 'llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp new file mode 100644 index 00000000000..ad5f693d77e --- /dev/null +++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp @@ -0,0 +1,61 @@ +//===- lib/DebugInfo/Symbolize/DIPrinter.cpp ------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the DIPrinter class, which is responsible for printing +// structures defined in DebugInfo/DIContext.h +// +//===----------------------------------------------------------------------===// + +#include "llvm/DebugInfo/Symbolize/DIPrinter.h" + +#include "llvm/DebugInfo/DIContext.h" + +namespace llvm { +namespace symbolize { + +// By default, DILineInfo contains "<invalid>" for function/filename it +// cannot fetch. We replace it to "??" to make our output closer to addr2line. +static const char kDILineInfoBadString[] = "<invalid>"; +static const char kBadString[] = "??"; + +DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) { + if (PrintFunctionNames) { + std::string FunctionName = Info.FunctionName; + if (FunctionName == kDILineInfoBadString) + FunctionName = kBadString; + OS << FunctionName << "\n"; + } + std::string Filename = Info.FileName; + if (Filename == kDILineInfoBadString) + Filename = kBadString; + OS << Filename << ":" << Info.Line << ":" << Info.Column << "\n"; + return *this; +} + +DIPrinter &DIPrinter::operator<<(const DIInliningInfo &Info) { + uint32_t FramesNum = Info.getNumberOfFrames(); + if (FramesNum == 0) + return (*this << DILineInfo()); + for (uint32_t i = 0; i < FramesNum; i++) { + *this << Info.getFrame(i); + } + return *this; +} + +DIPrinter &DIPrinter::operator<<(const DIGlobal &Global) { + std::string Name = Global.Name; + if (Name == kDILineInfoBadString) + Name = kBadString; + OS << Name << "\n"; + OS << Global.Start << " " << Global.Size << "\n"; + return *this; +} + +} +} |