blob: c62cf8996f70e7e7fd3f1c749decebd9cc4cc8c2 [file] [log] [blame]
Jim Laskeye5032892005-12-21 19:48:16 +00001//===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by James M. Laskey and is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains support for writing dwarf debug info into asm files.
11//
12//===----------------------------------------------------------------------===//
13
14
Jim Laskeya7cea6f2006-01-04 13:52:30 +000015#include "llvm/CodeGen/AsmPrinter.h"
Reid Spencer780c8612005-12-22 01:41:00 +000016#include "llvm/CodeGen/DwarfWriter.h"
Jim Laskeya7cea6f2006-01-04 13:52:30 +000017#include "llvm/Support/CommandLine.h"
18
19
20namespace llvm {
21
22static cl::opt<bool>
23DwarfVerbose("dwarf-verbose", cl::Hidden,
24 cl::desc("Add comments to dwarf directives."));
25
26/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
27/// unsigned leb128 value.
28///
29void DwarfWriter::EmitULEB128Bytes(unsigned Value, std::string Comment) {
30 if (hasLEB128) {
31 O << "\t.uleb128\t"
32 << Value;
33 } else {
34 O << Asm->getData8bitsDirective();
35 EmitULEB128(Value);
36 }
37 if (DwarfVerbose) {
38 O << "\t"
39 << Asm->getCommentString()
40 << " "
41 << Comment
42 << " "
43 << Value;
44 }
45 O << "\n";
46}
47
48/// EmitSLEB128Bytes - Emit an assembler byte data directive to compose a
49/// signed leb128 value.
50///
51void DwarfWriter::EmitSLEB128Bytes(int Value, std::string Comment) {
52 if (hasLEB128) {
53 O << "\t.sleb128\t"
54 << Value;
55 } else {
56 O << Asm->getData8bitsDirective();
57 EmitSLEB128(Value);
58 }
59 if (DwarfVerbose) {
60 O << "\t"
61 << Asm->getCommentString()
62 << " "
63 << Comment
64 << " "
65 << Value;
66 }
67 O << "\n";
68}
69
70/// BeginModule - Emit all dwarf sections that should come prior to the content.
71///
72void DwarfWriter::BeginModule() {
Jim Laskey7d78a2a2006-01-04 14:30:12 +000073 if (!DebugInfo.hasInfo()) return;
Jim Laskeya7cea6f2006-01-04 13:52:30 +000074 EmitComment("Dwarf Begin Module");
75
76 // define base addresses for dwarf sections
77 Asm->SwitchSection(DwarfAbbrevSection, 0);
78 EmitLabel("abbrev", 0);
79 Asm->SwitchSection(DwarfInfoSection, 0);
80 EmitLabel("info", 0);
81 Asm->SwitchSection(DwarfLineSection, 0);
82 EmitLabel("line", 0);
83}
84
85/// EndModule - Emit all dwarf sections that should come after the content.
86///
87void DwarfWriter::EndModule() {
Jim Laskey7d78a2a2006-01-04 14:30:12 +000088 if (!DebugInfo.hasInfo()) return;
Jim Laskeya7cea6f2006-01-04 13:52:30 +000089 EmitComment("Dwarf End Module");
90 // Print out dwarf file info
91 std::vector<std::string> Sources = DebugInfo.getSourceFiles();
92 for (unsigned i = 0, N = Sources.size(); i < N; i++) {
93 O << "\t; .file\t" << (i + 1) << "," << "\"" << Sources[i] << "\"" << "\n";
94 }
95}
96
97
98/// BeginFunction - Emit pre-function debug information.
99///
100void DwarfWriter::BeginFunction() {
Jim Laskey7d78a2a2006-01-04 14:30:12 +0000101 if (!DebugInfo.hasInfo()) return;
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000102 EmitComment("Dwarf Begin Function");
103}
104
105/// EndFunction - Emit post-function debug information.
106///
107void DwarfWriter::EndFunction() {
Jim Laskey7d78a2a2006-01-04 14:30:12 +0000108 if (!DebugInfo.hasInfo()) return;
Jim Laskeya7cea6f2006-01-04 13:52:30 +0000109 EmitComment("Dwarf End Function");
110}
111
112
113} // End llvm namespace
114