aboutsummaryrefslogtreecommitdiff
path: root/src/common/dwarf_cu_to_module.cc
diff options
context:
space:
mode:
authorjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-07-17 15:14:30 +0000
committerjimblandy <jimblandy@4c0a9323-5329-0410-9bdc-e9ce6186880e>2010-07-17 15:14:30 +0000
commit786275e7195761228374d7c0f5ff02403c7e1ef8 (patch)
tree2d38496971ca3c7eacbbfbb3e240f7b64b4b5a5f /src/common/dwarf_cu_to_module.cc
parentBreakpad Linux dumper: Don't map file into memory a second time just to compu... (diff)
downloadbreakpad-786275e7195761228374d7c0f5ff02403c7e1ef8.tar.xz
Breakpad Linux/Mac symbol dumper: Share duplicate strings that arise in DWARF data.
This patch avoids allocating many copies of identical strings appearing in debugging information. Without this patch, running dump_syms on Mozilla's libxul.so (with 173MiB of debugging information) has a peak resident set of around 450MiB. With this patch, the peak is around 365MiB. a=jimblandy, r=mark git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@626 4c0a9323-5329-0410-9bdc-e9ce6186880e
Diffstat (limited to 'src/common/dwarf_cu_to_module.cc')
-rw-r--r--src/common/dwarf_cu_to_module.cc27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/common/dwarf_cu_to_module.cc b/src/common/dwarf_cu_to_module.cc
index 85d1d8c4..9b538283 100644
--- a/src/common/dwarf_cu_to_module.cc
+++ b/src/common/dwarf_cu_to_module.cc
@@ -36,12 +36,16 @@
#include <assert.h>
#include <algorithm>
+#include <set>
+#include <utility>
#include "common/dwarf_line_to_module.h"
namespace google_breakpad {
using std::map;
+using std::pair;
+using std::set;
using std::vector;
// Data provided by a DWARF specification DIE.
@@ -83,6 +87,17 @@ typedef map<uint64, AbstractOrigin> AbstractOriginByOffset;
// Data global to the DWARF-bearing file that is private to the
// DWARF-to-Module process.
struct DwarfCUToModule::FilePrivate {
+ // A set of strings used in this CU. Before storing a string in one of
+ // our data structures, insert it into this set, and then use the string
+ // from the set.
+ //
+ // Because std::string uses reference counting internally, simply using
+ // strings from this set, even if passed by value, assigned, or held
+ // directly in structures and containers (map<string, ...>, for example),
+ // causes those strings to share a single instance of each distinct piece
+ // of text.
+ set<string> common_strings;
+
// A map from offsets of DIEs within the .debug_info section to
// Specifications describing those DIEs. Specification references can
// cross compilation unit boundaries.
@@ -256,7 +271,17 @@ void DwarfCUToModule::GenericDIEHandler::ProcessAttributeString(
enum DwarfForm form,
const string &data) {
switch (attr) {
- case dwarf2reader::DW_AT_name: name_attribute_ = data; break;
+ case dwarf2reader::DW_AT_name: {
+ // Place the name in our global set of strings, and then use the
+ // string from the set. Even though the assignment looks like a copy,
+ // all the major std::string implementations use reference counting
+ // internally, so the effect is to have all our data structures share
+ // copies of strings whenever possible.
+ pair<set<string>::iterator, bool> result =
+ cu_context_->file_context->file_private->common_strings.insert(data);
+ name_attribute_ = *result.first;
+ break;
+ }
default: break;
}
}