source_line_resolver_interface.h revision 5b117cf53af46f357d28761ced3a1d94aeb5df91
1cf55ca5b5cb673677a8493aff1424e1b83211c1ajimblandy// -*- mode: C++ -*-
2cf55ca5b5cb673677a8493aff1424e1b83211c1ajimblandy
383e085b7a331c96237cf8e814f97b3ef4c36a70fjimblandy// Copyright (c) 2010 Google Inc.
47daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// All rights reserved.
5cb91a2f879250f2ef5f74321b5d08807247d41a7bryner//
67daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// Redistribution and use in source and binary forms, with or without
77daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// modification, are permitted provided that the following conditions are
87daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// met:
9cb91a2f879250f2ef5f74321b5d08807247d41a7bryner//
107daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai//     * Redistributions of source code must retain the above copyright
117daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// notice, this list of conditions and the following disclaimer.
127daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai//     * Redistributions in binary form must reproduce the above
137daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// copyright notice, this list of conditions and the following disclaimer
147daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// in the documentation and/or other materials provided with the
157daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// distribution.
167daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai//     * Neither the name of Google Inc. nor the names of its
177daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// contributors may be used to endorse or promote products derived from
187daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// this software without specific prior written permission.
19cb91a2f879250f2ef5f74321b5d08807247d41a7bryner//
207daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
217daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
227daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
237daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
247daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
257daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
267daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
277daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
287daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
297daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
307daf246e4baf0837e25429668cc23e92b6afe3b3mmentovai// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
32fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner// Abstract interface to return function/file/line info for a memory address.
33cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
34e5dc60822e5938fea2ae892ccddb906641ba174emmentovai#ifndef GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
35e5dc60822e5938fea2ae892ccddb906641ba174emmentovai#define GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
36cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
37cb91a2f879250f2ef5f74321b5d08807247d41a7bryner#include <string>
38e5dc60822e5938fea2ae892ccddb906641ba174emmentovai#include "google_breakpad/common/breakpad_types.h"
39b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek#include "google_breakpad/processor/code_module.h"
40cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
41e5dc60822e5938fea2ae892ccddb906641ba174emmentovainamespace google_breakpad {
42cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
43425d256321f590e4ca86e3294055e9fad135f9b2mmentovaiusing std::string;
44cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
45fc1c78e60e9b305386f4c3fc811463f3b24cf6d4mmentovaistruct StackFrame;
46b64d76a3b8a692f431d440f6a4416e7c70aad4efjimblandystruct WindowsFrameInfo;
476d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandystruct CFIFrameInfo;
4839716226cf6ffcfaa37c991f82c3f2b19354413fbryner
49fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbrynerclass SourceLineResolverInterface {
50cb91a2f879250f2ef5f74321b5d08807247d41a7bryner public:
5180e98391dc7ff361355e72c24c0fb222518bcdfcmmentovai  typedef u_int64_t MemAddr;
52cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
53fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner  virtual ~SourceLineResolverInterface() {}
54cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
55cb91a2f879250f2ef5f74321b5d08807247d41a7bryner  // Adds a module to this resolver, returning true on success.
56cb91a2f879250f2ef5f74321b5d08807247d41a7bryner  //
57b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  // module should have at least the code_file, debug_file,
58b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  // and debug_identifier members populated.
59cb91a2f879250f2ef5f74321b5d08807247d41a7bryner  //
60cb91a2f879250f2ef5f74321b5d08807247d41a7bryner  // map_file should contain line/address mappings for this module.
61b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual bool LoadModule(const CodeModule *module,
62fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner                          const string &map_file) = 0;
630fd2f1ae2152782f2127c56fb5302002c95502d3nealsid  // Same as above, but takes the contents of a pre-read map buffer
64b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual bool LoadModuleUsingMapBuffer(const CodeModule *module,
650fd2f1ae2152782f2127c56fb5302002c95502d3nealsid                                        const string &map_buffer) = 0;
66cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
675b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com  // Add an interface to load symbol using C-String data insteading string.
685b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com  // This is useful in the optimization design for avoiding unnecessary copying
695b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com  // of symbol data, in order to improve memory efficiency.
705b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com  virtual bool LoadModuleUsingMemoryBuffer(const CodeModule *module,
715b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com                                           char *memory_buffer) = 0;
725b117cf53af46f357d28761ced3a1d94aeb5df91SiyangXie@gmail.com
73b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  // Request that the specified module be unloaded from this resolver.
74b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  // A resolver may choose to ignore such a request.
75b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual void UnloadModule(const CodeModule *module) = 0;
76b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek
77b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  // Returns true if the module has been loaded.
78b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual bool HasModule(const CodeModule *module) = 0;
79181f307ffe521026d7344ed58d1545321d352ca6bryner
8039716226cf6ffcfaa37c991f82c3f2b19354413fbryner  // Fills in the function_base, function_name, source_file_name,
8139716226cf6ffcfaa37c991f82c3f2b19354413fbryner  // and source_line fields of the StackFrame.  The instruction and
82e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // module_name fields must already be filled in.
83b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual void FillSourceLineInfo(StackFrame *frame) = 0;
84e9faf5482802cb508401881f15b2712eb2f828f2jimblandy
85e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // If Windows stack walking information is available covering
86e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // FRAME's instruction address, return a WindowsFrameInfo structure
87e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // describing it. If the information is not available, returns NULL.
88e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // A NULL return value does not indicate an error. The caller takes
89e9faf5482802cb508401881f15b2712eb2f828f2jimblandy  // ownership of any returned WindowsFrameInfo object.
90b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual WindowsFrameInfo *FindWindowsFrameInfo(const StackFrame *frame) = 0;
91cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
926d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandy  // If CFI stack walking information is available covering ADDRESS,
936d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandy  // return a CFIFrameInfo structure describing it. If the information
946d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandy  // is not available, return NULL. The caller takes ownership of any
956d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandy  // returned CFIFrameInfo object.
96b223627d81c083a64f2ccecf2651a18111421280ted.mielczarek  virtual CFIFrameInfo *FindCFIFrameInfo(const StackFrame *frame) = 0;
976d3a825dbf5b924c2e754309b3008e462af1d8d2jimblandy
98fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner protected:
99fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner  // SourceLineResolverInterface cannot be instantiated except by subclasses
100fd38d48e6d5e56cb66b0fa0f7e25f840a83dac5cbryner  SourceLineResolverInterface() {}
101cb91a2f879250f2ef5f74321b5d08807247d41a7bryner};
102cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
103e5dc60822e5938fea2ae892ccddb906641ba174emmentovai}  // namespace google_breakpad
104cb91a2f879250f2ef5f74321b5d08807247d41a7bryner
105e5dc60822e5938fea2ae892ccddb906641ba174emmentovai#endif  // GOOGLE_BREAKPAD_PROCESSOR_SOURCE_LINE_RESOLVER_INTERFACE_H__
106