reduced_debug_output.h 4.2 KB

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