1 //===-- llvm/CodeGen/DwarfWriter.cpp - Dwarf Framework ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf debug info into asm files.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/CodeGen/DwarfWriter.h"
17 #include "llvm/Support/CommandLine.h"
23 DwarfVerbose("dwarf-verbose", cl::Hidden,
24 cl::desc("Add comments to dwarf directives."));
26 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
27 /// unsigned leb128 value.
29 void DwarfWriter::EmitULEB128Bytes(unsigned Value, std::string Comment) {
34 O << Asm->getData8bitsDirective();
39 << Asm->getCommentString()
48 /// EmitSLEB128Bytes - Emit an assembler byte data directive to compose a
49 /// signed leb128 value.
51 void DwarfWriter::EmitSLEB128Bytes(int Value, std::string Comment) {
56 O << Asm->getData8bitsDirective();
61 << Asm->getCommentString()
70 /// BeginModule - Emit all dwarf sections that should come prior to the content.
72 void DwarfWriter::BeginModule() {
73 if (!DebugInfo.hasInfo()) return;
74 EmitComment("Dwarf Begin Module");
76 // define base addresses for dwarf sections
77 Asm->SwitchSection(DwarfAbbrevSection, 0);
78 EmitLabel("abbrev", 0);
79 Asm->SwitchSection(DwarfInfoSection, 0);
81 Asm->SwitchSection(DwarfLineSection, 0);
85 /// EndModule - Emit all dwarf sections that should come after the content.
87 void DwarfWriter::EndModule() {
88 if (!DebugInfo.hasInfo()) return;
89 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";
98 /// BeginFunction - Emit pre-function debug information.
100 void DwarfWriter::BeginFunction() {
101 if (!DebugInfo.hasInfo()) return;
102 EmitComment("Dwarf Begin Function");
105 /// EndFunction - Emit post-function debug information.
107 void DwarfWriter::EndFunction() {
108 if (!DebugInfo.hasInfo()) return;
109 EmitComment("Dwarf End Function");
113 } // End llvm namespace