blob: ad5f693d77e4cbfcc1a2062b6231c90f084bfb46 [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
Colin LeMahieuda6caff2015-11-11 18:11:06 +000027DIPrinter &DIPrinter::operator<<(const DILineInfo &Info) {
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000028 if (PrintFunctionNames) {
29 std::string FunctionName = Info.FunctionName;
30 if (FunctionName == kDILineInfoBadString)
31 FunctionName = kBadString;
Colin LeMahieuda6caff2015-11-11 18:11:06 +000032 OS << FunctionName << "\n";
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000033 }
34 std::string Filename = Info.FileName;
35 if (Filename == kDILineInfoBadString)
36 Filename = kBadString;
37 OS << Filename << ":" << Info.Line << ":" << Info.Column << "\n";
38 return *this;
39}
40
41DIPrinter &DIPrinter::operator<<(const DIInliningInfo &Info) {
42 uint32_t FramesNum = Info.getNumberOfFrames();
Colin LeMahieuda6caff2015-11-11 18:11:06 +000043 if (FramesNum == 0)
44 return (*this << DILineInfo());
45 for (uint32_t i = 0; i < FramesNum; i++) {
46 *this << Info.getFrame(i);
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000047 }
Alexey Samsonovd6aa8202015-11-03 22:20:52 +000048 return *this;
49}
50
51DIPrinter &DIPrinter::operator<<(const DIGlobal &Global) {
52 std::string Name = Global.Name;
53 if (Name == kDILineInfoBadString)
54 Name = kBadString;
55 OS << Name << "\n";
56 OS << Global.Start << " " << Global.Size << "\n";
57 return *this;
58}
59
60}
61}