+
+// Scan the pubnames and pubtypes sections and build a map of the
+// various cus and tus they refer to, so we can process the entries
+// when we encounter the die for that cu or tu.
+// Return the just-read table so it can be cached.
+
+Dwarf_pubnames_table*
+Gdb_index::map_pubtable_to_dies(unsigned int attr,
+ Gdb_index_info_reader* dwinfo,
+ Relobj* object,
+ const unsigned char* symbols,
+ off_t symbols_size)
+{
+ uint64_t section_offset = 0;
+ Dwarf_pubnames_table* table;
+ Pubname_offset_map* map;
+
+ if (attr == elfcpp::DW_AT_GNU_pubnames)
+ {
+ table = new Dwarf_pubnames_table(dwinfo, false);
+ map = &this->cu_pubname_map_;
+ }
+ else
+ {
+ table = new Dwarf_pubnames_table(dwinfo, true);
+ map = &this->cu_pubtype_map_;
+ }
+
+ map->clear();
+ if (!table->read_section(object, symbols, symbols_size))
+ return NULL;
+
+ while (table->read_header(section_offset))
+ {
+ map->insert(std::make_pair(table->cu_offset(), section_offset));
+ section_offset += table->subsection_size();
+ }
+
+ return table;
+}
+
+// Wrapper for map_pubtable_to_dies
+
+void
+Gdb_index::map_pubnames_and_types_to_dies(Gdb_index_info_reader* dwinfo,
+ Relobj* object,
+ const unsigned char* symbols,
+ off_t symbols_size)
+{
+ // This is a new object, so reset the relevant variables.
+ this->pubnames_object_ = object;
+ this->stmt_list_offset_ = -1;
+
+ delete this->pubnames_table_;
+ this->pubnames_table_
+ = this->map_pubtable_to_dies(elfcpp::DW_AT_GNU_pubnames, dwinfo,
+ object, symbols, symbols_size);
+ delete this->pubtypes_table_;
+ this->pubtypes_table_
+ = this->map_pubtable_to_dies(elfcpp::DW_AT_GNU_pubtypes, dwinfo,
+ object, symbols, symbols_size);
+}
+
+// Given a cu_offset, find the associated section of the pubnames
+// table.
+
+off_t
+Gdb_index::find_pubname_offset(off_t cu_offset)
+{
+ Pubname_offset_map::iterator it = this->cu_pubname_map_.find(cu_offset);
+ if (it != this->cu_pubname_map_.end())
+ return it->second;
+ return -1;
+}
+
+// Given a cu_offset, find the associated section of the pubnames
+// table.
+
+off_t
+Gdb_index::find_pubtype_offset(off_t cu_offset)
+{
+ Pubname_offset_map::iterator it = this->cu_pubtype_map_.find(cu_offset);
+ if (it != this->cu_pubtype_map_.end())
+ return it->second;
+ return -1;
+}
+