Jim Laskey | e503289 | 2005-12-21 19:48:16 +0000 | [diff] [blame] | 1 | //===-- 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 Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/AsmPrinter.h" |
Reid Spencer | 780c861 | 2005-12-22 01:41:00 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/DwarfWriter.h" |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
| 18 | |
| 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | static cl::opt<bool> |
| 23 | DwarfVerbose("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 | /// |
| 29 | void 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 | /// |
| 51 | void 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 | /// |
| 72 | void DwarfWriter::BeginModule() { |
Jim Laskey | 7d78a2a | 2006-01-04 14:30:12 +0000 | [diff] [blame] | 73 | if (!DebugInfo.hasInfo()) return; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 74 | 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 | /// |
| 87 | void DwarfWriter::EndModule() { |
Jim Laskey | 7d78a2a | 2006-01-04 14:30:12 +0000 | [diff] [blame] | 88 | if (!DebugInfo.hasInfo()) return; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 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"; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /// BeginFunction - Emit pre-function debug information. |
| 99 | /// |
| 100 | void DwarfWriter::BeginFunction() { |
Jim Laskey | 7d78a2a | 2006-01-04 14:30:12 +0000 | [diff] [blame] | 101 | if (!DebugInfo.hasInfo()) return; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 102 | EmitComment("Dwarf Begin Function"); |
| 103 | } |
| 104 | |
| 105 | /// EndFunction - Emit post-function debug information. |
| 106 | /// |
| 107 | void DwarfWriter::EndFunction() { |
Jim Laskey | 7d78a2a | 2006-01-04 14:30:12 +0000 | [diff] [blame] | 108 | if (!DebugInfo.hasInfo()) return; |
Jim Laskey | a7cea6f | 2006-01-04 13:52:30 +0000 | [diff] [blame] | 109 | EmitComment("Dwarf End Function"); |
| 110 | } |
| 111 | |
| 112 | |
| 113 | } // End llvm namespace |
| 114 | |