* dwarf2.c (struct line_sequence): New struct.
[binutils/dougsmingw.git] / gold / reduced_debug_output.h
blobd1682288c3b326d4f5a7ee00c93a19e8fe922806
1 // reduced_debug_output.h -- reduce debugging information -*- C++ -*-
3 // Copyright 2008 Free Software Foundation, Inc.
4 // Written by Caleb Howe <cshowe@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 // Reduce the size of the debug sections by emitting only debug line number
24 // information. We still need to emit skeleton debug_info and debug_abbrev
25 // sections for standard tools to parse the debug information correctly. These
26 // classes remove all debug information entries from the .debug_info section
27 // except for those describing compilation units as these DIEs contain
28 // references to the debug line information needed by most parsers.
30 #ifndef GOLD_REDUCED_DEBUG_OUTPUT_H
31 #define GOLD_REDUCED_DEBUG_OUTPUT_H
33 #include <map>
34 #include <utility>
35 #include <vector>
37 #include "output.h"
39 namespace gold
42 class Output_reduced_debug_abbrev_section : public Output_section
44 public:
45 Output_reduced_debug_abbrev_section(const char* name, elfcpp::Elf_Word flags,
46 elfcpp::Elf_Xword type)
47 : Output_section(name, flags, type), sized_(false),
48 abbrev_count_(0), failed_(false)
49 { this->set_requires_postprocessing(); }
51 unsigned char* get_new_abbrev(uint64_t* abbrev_number,
52 uint64_t abbrev_offset);
54 protected:
55 // Set the final data size.
56 void
57 set_final_data_size();
59 // Write out the new debug abbreviations
60 void
61 do_write(Output_file*);
63 private:
64 void
65 failed(std::string reason)
67 gold_warning("%s", reason.c_str());
68 failed_ = true;
71 // The reduced debug abbreviations
72 std::vector<unsigned char> data_;
74 // We map the abbreviation table offset and abbreviation number of the
75 // old abbreviation to the number and size of the new abbreviation.
76 std::map<std::pair<uint64_t, uint64_t>,
77 std::pair<uint64_t, uint64_t> > abbrev_mapping_;
79 bool sized_;
81 // The count of abbreviations in the output data
82 int abbrev_count_;
84 // Whether or not the debug reduction has failed for any reason
85 bool failed_;
88 class Output_reduced_debug_info_section : public Output_section
90 public:
91 Output_reduced_debug_info_section(const char* name, elfcpp::Elf_Word flags,
92 elfcpp::Elf_Xword type)
93 : Output_section(name, flags, type), failed_(false)
94 { this->set_requires_postprocessing(); }
96 void
97 set_abbreviations(Output_reduced_debug_abbrev_section* abbrevs)
98 { associated_abbrev_ = abbrevs; }
100 protected:
101 // Set the final data size.
102 void
103 set_final_data_size();
105 // Write out the new debug info
106 void
107 do_write(Output_file*);
109 private:
110 void
111 failed(std::string reason)
113 gold_warning("%s", reason.c_str());
114 this->failed_ = true;
117 // Given a pointer to the beginning of a die and the beginning of the
118 // associated abbreviation fills in die_end with the end of the information
119 // entry. If successful returns true. Get_die_end also takes a pointer to
120 // the end of the buffer containing the die. If die_end would be beyond the
121 // end of the buffer, or if an unsupported dwarf form is encountered returns
122 // false.
123 bool
124 get_die_end(unsigned char* die, unsigned char* abbrev,
125 unsigned char** die_end, unsigned char* buffer_end,
126 int address_size, bool is64);
128 // The reduced debug info
129 std::vector<unsigned char> data_;
131 // Each debug info section needs to be associated with a debug abbrev section
132 Output_reduced_debug_abbrev_section* associated_abbrev_;
134 // Whether or not the debug reduction has failed for any reason
135 bool failed_;
138 } // End namespace gold.
140 #endif // !defined(GOLD_REDUCED_DEBUG_OUTPUT_H)