Restrict ownership of symbol data buffers to symbol supplier.

git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@721 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
SiyangXie@gmail.com
2010-11-01 17:31:31 +00:00
parent eabfff133d
commit a8c1c466a1
18 changed files with 200 additions and 126 deletions

View File

@@ -55,6 +55,7 @@ class BasicSourceLineResolver : public SourceLineResolverBase {
using SourceLineResolverBase::LoadModule;
using SourceLineResolverBase::LoadModuleUsingMapBuffer;
using SourceLineResolverBase::LoadModuleUsingMemoryBuffer;
using SourceLineResolverBase::ShouldDeleteMemoryBufferAfterLoadModule;
using SourceLineResolverBase::UnloadModule;
using SourceLineResolverBase::HasModule;
using SourceLineResolverBase::FillSourceLineInfo;
@@ -73,16 +74,6 @@ class BasicSourceLineResolver : public SourceLineResolverBase {
// Module implements SourceLineResolverBase::Module interface.
class Module;
// Helper methods to manage C-String format symbol data.
// See "google_breakpad/processor/source_line_resolver_base.h" for more
// comments about these helper methods.
virtual void DeleteDataAfterLoad(char *symbol_data);
// No-op helper methods.
virtual void DeleteDataUnload(const CodeModule *module) { }
virtual void ClearLocalMemory() { }
virtual void StoreDataBeforeLoad(const CodeModule *module,
char *symbol_data) { }
// Disallow unwanted copy ctor and assignment operator
BasicSourceLineResolver(const BasicSourceLineResolver&);
void operator=(const BasicSourceLineResolver&);

View File

@@ -84,18 +84,10 @@ class FastSourceLineResolver : public SourceLineResolverBase {
// Deserialize raw memory data to construct a WindowsFrameInfo object.
static WindowsFrameInfo CopyWFI(const char *raw_memory);
// Helper methods to manage C-String format symbol data.
// See "google_breakpad/processor/source_line_resolver_base.h" for more
// comments about these helper methods.
virtual void StoreDataBeforeLoad(const CodeModule *module, char *symbol_data);
virtual void DeleteDataUnload(const CodeModule *module);
virtual void ClearLocalMemory();
// No-op helper method.
virtual void DeleteDataAfterLoad(char *symbol_data) { }
// Store memory data allocated in LoadModule and LoadModuleUsingMapBuffer.
typedef std::map<string, char*, CompareString> MemoryMap;
MemoryMap memory_chunks_;
// FastSourceLineResolver requires the memory buffer stays alive during the
// lifetime of a corresponding module, therefore it needs to redefine this
// virtual method.
virtual bool ShouldDeleteMemoryBufferAfterLoadModule();
// Disallow unwanted copy ctor and assignment operator
FastSourceLineResolver(const FastSourceLineResolver&);

View File

@@ -84,6 +84,10 @@ class NetworkSourceLineResolver : public SourceLineResolverInterface,
virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
char *memory_buffer);
// It doesn't matter whether returns true or false, since no memory buffer
// will be allocated in GetCStringSymbolData().
virtual bool ShouldDeleteMemoryBufferAfterLoadModule() { return true; }
void UnloadModule(const CodeModule *module);
virtual bool HasModule(const CodeModule *module);
@@ -112,6 +116,11 @@ class NetworkSourceLineResolver : public SourceLineResolverInterface,
string *symbol_file,
char **symbol_data);
// Delete the data buffer allocated in GetCStringSymbolData().
// Since the above GetCStringSymbolData() won't allocate any memory at all,
// this method is no-op.
virtual void FreeSymbolData(const CodeModule *module) { }
private:
int wait_milliseconds_;
// if false, some part of our network setup failed.

View File

@@ -73,35 +73,13 @@ class SourceLineResolverBase : public SourceLineResolverInterface {
const string &map_buffer);
virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
char *memory_buffer);
virtual bool ShouldDeleteMemoryBufferAfterLoadModule();
virtual void UnloadModule(const CodeModule *module);
virtual bool HasModule(const CodeModule *module);
virtual void FillSourceLineInfo(StackFrame *frame);
virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame);
virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame);
// Helper methods to manage C-String format symbol data.
// These methods are defined as no-op by default.
//
// StoreDataBeforeLoad() will be called in LoadModule() and
// LoadModuleUsingMapBuffer() to let subclass decide whether or how to store
// the dynamicly allocated memory data, before passing the data to
// LoadModuleUsingMemoryBuffer() which actually loads the module.
virtual void StoreDataBeforeLoad(const CodeModule *module, char *symbol_data);
// DeleteDataAfterLoad() will be called at the end of
// LoadModuleUsingMemoryBuffer() to let subclass decide whether to delete the
// allocated memory data or not (which depends on whether the subclass has
// ownership of the data or not).
virtual void DeleteDataAfterLoad(char *symbol_data);
// DeleteDataUnload() will be called in UnloadModule() to let subclass clean
// up dynamicly allocated data associated with the module, if there is any.
virtual void DeleteDataUnload(const CodeModule *module);
// ClearLocalMemory() will be called in destructor to let subclass clean up
// all local memory data it owns, if there is any.
virtual void ClearLocalMemory();
// Nested structs and classes.
struct Line;
struct Function;
@@ -113,10 +91,14 @@ class SourceLineResolverBase : public SourceLineResolverInterface {
class Module;
class AutoFileCloser;
// All of the modules we've loaded
// All of the modules that are loaded.
typedef map<string, Module*, CompareString> ModuleMap;
ModuleMap *modules_;
// All of heap-allocated buffers that are owned locally by resolver.
typedef std::map<string, char*, CompareString> MemoryMap;
MemoryMap *memory_buffers_;
// Creates a concrete module at run-time.
ModuleFactory *module_factory_;

View File

@@ -67,9 +67,15 @@ class SourceLineResolverInterface {
// Add an interface to load symbol using C-String data insteading string.
// This is useful in the optimization design for avoiding unnecessary copying
// of symbol data, in order to improve memory efficiency.
// LoadModuleUsingMemoryBuffer() does NOT take ownership of memory_buffer.
virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
char *memory_buffer) = 0;
// Return true if the memory buffer should be deleted immediately after
// LoadModuleUsingMemoryBuffer(). Return false if the memory buffer has to be
// alive during the lifetime of the corresponding Module.
virtual bool ShouldDeleteMemoryBufferAfterLoadModule() = 0;
// Request that the specified module be unloaded from this resolver.
// A resolver may choose to ignore such a request.
virtual void UnloadModule(const CodeModule *module) = 0;
@@ -79,7 +85,7 @@ class SourceLineResolverInterface {
// Fills in the function_base, function_name, source_file_name,
// and source_line fields of the StackFrame. The instruction and
// module_name fields must already be filled in.
// module_name fields must already be filled in.
virtual void FillSourceLineInfo(StackFrame *frame) = 0;
// If Windows stack walking information is available covering
@@ -87,7 +93,7 @@ class SourceLineResolverInterface {
// describing it. If the information is not available, returns NULL.
// A NULL return value does not indicate an error. The caller takes
// ownership of any returned WindowsFrameInfo object.
virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame) = 0;
virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame) = 0;
// If CFI stack walking information is available covering ADDRESS,
// return a CFIFrameInfo structure describing it. If the information

View File

@@ -76,14 +76,21 @@ class SymbolSupplier {
string *symbol_file,
string *symbol_data) = 0;
// Same as above, except places symbol data into symbol_data as C-string in
// dynamically allocated memory. Using C-string as type of symbol data enables
// passing data by pointer, and thus avoids unncessary copying of data (to
// improve memory efficiency).
// Same as above, except allocates data buffer on heap and then places the
// symbol data into the buffer as C-string.
// SymbolSupplier is responsible for deleting the data buffer. After the call
// to GetCStringSymbolData(), the caller should call FreeSymbolData(const
// Module *module) once the data buffer is no longer needed.
// If symbol_data is not NULL, symbol supplier won't return FOUND unless it
// returns a valid buffer in symbol_data, e.g., returns INTERRUPT on memory
// allocation failure.
virtual SymbolResult GetCStringSymbolData(const CodeModule *module,
const SystemInfo *system_info,
string *symbol_file,
char **symbol_data) = 0;
// Frees the data buffer allocated for the module in GetCStringSymbolData.
virtual void FreeSymbolData(const CodeModule *module) = 0;
};
} // namespace google_breakpad