blob: c6bfbc07dcf307f9c547fabc74b72ce66284278d [file] [log] [blame]
Alexey Samsonovd6aa8202015-11-03 22:20:52 +00001//===- lib/DebugInfo/Symbolize/DIPrinter.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// This file defines the DIPrinter class, which is responsible for printing
11// structures defined in DebugInfo/DIContext.h
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/DebugInfo/Symbolize/DIPrinter.h"
16
17#include "llvm/DebugInfo/DIContext.h"
18
19namespace llvm {
20namespace symbolize {
21
22// By default, DILineInfo contains "<invalid>" for function/filename it
23// cannot fetch. We replace it to "??" to make our output closer to addr2line.
24static const char kDILineInfoBadString[] = "<invalid>";
25static const char kBadString[] = "??";
26
Hemant Kulkarnibdce12a2015-11-11 20:41:43 +000027void DIPrinter::printName(const DILineInfo &Info, bool Inlined) {
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000028 if (PrintFunctionNames) {
29 std::string FunctionName = Info.FunctionName;
30 if (FunctionName == kDILineInfoBadString)
31 FunctionName = kBadString;
Hemant Kulkarnibdce12a2015-11-11 20:41:43 +000032
33 StringRef Delimiter = (PrintPretty == true) ? " at " : "\n";
34 StringRef Prefix = (PrintPretty && Inlined) ? " (inlined by) " : "";
35 OS << Prefix << FunctionName << Delimiter;
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000036 }
37 std::string Filename = Info.FileName;
38 if (Filename == kDILineInfoBadString)
39 Filename = kBadString;
40 OS << Filename << ":" << Info.Line << ":" << Info.Column << "\n";
Hemant Kulkarnibdce12a2015-11-11 20:41:43 +000041}
42
43DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) {
44 printName(Info, false);
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000045 return *this;
46}
47
48DIPrinter &DIPrinter::operator<<(const DIInliningInfo &Info) {
49 uint32_t FramesNum = Info.getNumberOfFrames();
Hemant Kulkarnibdce12a2015-11-11 20:41:43 +000050 if (FramesNum == 0) {
51 printName(DILineInfo(), false);
52 return *this;
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000053 }
Hemant Kulkarnibdce12a2015-11-11 20:41:43 +000054 for (uint32_t i = 0; i < FramesNum; i++)
55 printName(Info.getFrame(i), i > 0);
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000056 return *this;
57}
58
59DIPrinter &DIPrinter::operator<<(const DIGlobal &Global) {
60 std::string Name = Global.Name;
61 if (Name == kDILineInfoBadString)
62 Name = kBadString;
63 OS << Name << "\n";
64 OS << Global.Start << " " << Global.Size << "\n";
65 return *this;
66}
67
68}
69}