Refactor the logic of resolving source line info into helper class.

http://breakpad.appspot.com/459002/


git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1068 4c0a9323-5329-0410-9bdc-e9ce6186880e
This commit is contained in:
SiyangXie@gmail.com 2012-10-10 21:41:52 +00:00
parent f72b9c6ff4
commit bab770045b
22 changed files with 813 additions and 926 deletions

View file

@ -48,19 +48,16 @@
#include "google_breakpad/common/breakpad_types.h"
#include "google_breakpad/processor/code_modules.h"
#include "google_breakpad/processor/memory_region.h"
#include "google_breakpad/processor/stack_frame_symbolizer.h"
namespace google_breakpad {
class CallStack;
class MinidumpContext;
class SourceLineResolverInterface;
struct StackFrame;
class SymbolSupplier;
struct SystemInfo;
class StackFrameSymbolizer;
using std::set;
class Stackwalker {
public:
virtual ~Stackwalker() {}
@ -69,17 +66,17 @@ class Stackwalker {
// GetCallerFrame. The frames are further processed to fill all available
// data. Returns true if the stackwalk completed, or false if it was
// interrupted by SymbolSupplier::GetSymbolFile().
bool Walk(CallStack *stack);
bool Walk(CallStack* stack);
// Returns a new concrete subclass suitable for the CPU that a stack was
// generated on, according to the CPU type indicated by the context
// argument. If no suitable concrete subclass exists, returns NULL.
static Stackwalker* StackwalkerForCPU(const SystemInfo *system_info,
MinidumpContext *context,
MemoryRegion *memory,
const CodeModules *modules,
SymbolSupplier *supplier,
SourceLineResolverInterface *resolver);
static Stackwalker* StackwalkerForCPU(
const SystemInfo* system_info,
MinidumpContext* context,
MemoryRegion* memory,
const CodeModules* modules,
StackFrameSymbolizer* resolver_helper);
static void set_max_frames(u_int32_t max_frames) { max_frames_ = max_frames; }
static u_int32_t max_frames() { return max_frames_; }
@ -89,16 +86,15 @@ class Stackwalker {
// memory identifies a MemoryRegion that provides the stack memory
// for the stack to walk. modules, if non-NULL, is a CodeModules
// object that is used to look up which code module each stack frame is
// associated with. supplier is an optional caller-supplied SymbolSupplier
// implementation. If supplier is NULL, source line info will not be
// resolved. resolver is an instance of SourceLineResolverInterface
// (see source_line_resolver_interface.h and basic_source_line_resolver.h).
// If resolver is NULL, source line info will not be resolved.
Stackwalker(const SystemInfo *system_info,
MemoryRegion *memory,
const CodeModules *modules,
SymbolSupplier *supplier,
SourceLineResolverInterface *resolver);
// associated with. frame_symbolizer is a StackFrameSymbolizer object that
// encapsulates the logic of how source line resolver interacts with symbol
// supplier to symbolize stack frame and look up caller frame information
// (see stack_frame_symbolizer.h).
// frame_symbolizer MUST NOT be NULL (asserted).
Stackwalker(const SystemInfo* system_info,
MemoryRegion* memory,
const CodeModules* modules,
StackFrameSymbolizer* frame_symbolizer);
// This can be used to filter out potential return addresses when
// the stack walker resorts to stack scanning.
@ -112,8 +108,8 @@ class Stackwalker {
template<typename InstructionType>
bool ScanForReturnAddress(InstructionType location_start,
InstructionType *location_found,
InstructionType *ip_found) {
InstructionType* location_found,
InstructionType* ip_found) {
const int kRASearchWords = 30;
return ScanForReturnAddress(location_start, location_found, ip_found,
kRASearchWords);
@ -130,8 +126,8 @@ class Stackwalker {
// location in memory.
template<typename InstructionType>
bool ScanForReturnAddress(InstructionType location_start,
InstructionType *location_found,
InstructionType *ip_found,
InstructionType* location_found,
InstructionType* ip_found,
int searchwords) {
for (InstructionType location = location_start;
location <= location_start + searchwords * sizeof(InstructionType);
@ -142,7 +138,6 @@ class Stackwalker {
if (modules_ && modules_->GetModuleForAddress(ip) &&
InstructionAddressSeemsValid(ip)) {
*ip_found = ip;
*location_found = location;
return true;
@ -154,19 +149,19 @@ class Stackwalker {
// Information about the system that produced the minidump. Subclasses
// and the SymbolSupplier may find this information useful.
const SystemInfo *system_info_;
const SystemInfo* system_info_;
// The stack memory to walk. Subclasses will require this region to
// get information from the stack.
MemoryRegion *memory_;
MemoryRegion* memory_;
// A list of modules, for populating each StackFrame's module information.
// This field is optional and may be NULL.
const CodeModules *modules_;
const CodeModules* modules_;
protected:
// The SourceLineResolver implementation.
SourceLineResolverInterface *resolver_;
// The StackFrameSymbolizer implementation.
StackFrameSymbolizer* frame_symbolizer_;
private:
// Obtains the context frame, the innermost called procedure in a stack
@ -183,15 +178,7 @@ class Stackwalker {
// the end of the stack has been reached). GetCallerFrame allocates a new
// StackFrame (or StackFrame subclass), ownership of which is taken by
// the caller.
virtual StackFrame* GetCallerFrame(const CallStack *stack) = 0;
// The optional SymbolSupplier for resolving source line info.
SymbolSupplier *supplier_;
// A list of modules that we haven't found symbols for. We track
// this in order to avoid repeatedly looking them up again within
// one minidump.
set<string> no_symbol_modules_;
virtual StackFrame* GetCallerFrame(const CallStack* stack) = 0;
// The maximum number of frames Stackwalker will walk through.
// This defaults to 1024 to prevent infinite loops.