bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 1 | // Copyright (C) 2006 Google Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // SourceLineResolver returns function/file/line info for a memory address. |
| 16 | // It uses address map files produced by a compatible writer, e.g. |
| 17 | // PDBSourceLineWriter. |
| 18 | |
bryner | 07f8ef5 | 2006-09-05 19:42:57 +0000 | [diff] [blame] | 19 | #ifndef PROCESSOR_SOURCE_LINE_RESOLVER_H__ |
| 20 | #define PROCESSOR_SOURCE_LINE_RESOLVER_H__ |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 21 | |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 22 | #include <string> |
| 23 | #include <ext/hash_map> |
| 24 | |
mmentovai | 425d256 | 2006-08-30 20:05:05 +0000 | [diff] [blame] | 25 | namespace google_airbag { |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 26 | |
mmentovai | 425d256 | 2006-08-30 20:05:05 +0000 | [diff] [blame] | 27 | using std::string; |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 28 | using __gnu_cxx::hash_map; |
| 29 | |
bryner | 3971622 | 2006-09-07 17:26:17 +0000 | [diff] [blame] | 30 | class StackFrame; |
| 31 | |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 32 | class SourceLineResolver { |
| 33 | public: |
| 34 | typedef unsigned long long MemAddr; |
| 35 | |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 36 | SourceLineResolver(); |
| 37 | ~SourceLineResolver(); |
| 38 | |
| 39 | // Adds a module to this resolver, returning true on success. |
| 40 | // |
| 41 | // module_name may be an arbitrary string. Typically, it will be the |
| 42 | // filename of the module, optionally with version identifiers. |
| 43 | // |
| 44 | // map_file should contain line/address mappings for this module. |
| 45 | bool LoadModule(const string &module_name, const string &map_file); |
| 46 | |
bryner | 3971622 | 2006-09-07 17:26:17 +0000 | [diff] [blame] | 47 | // Fills in the function_base, function_name, source_file_name, |
| 48 | // and source_line fields of the StackFrame. The instruction and |
| 49 | // module_name fields must already be filled in. |
| 50 | void FillSourceLineInfo(StackFrame *frame) const; |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | template<class T> class MemAddrMap; |
| 54 | struct Line; |
| 55 | struct Function; |
| 56 | struct File; |
| 57 | struct HashString { |
| 58 | size_t operator()(const string &s) const; |
| 59 | }; |
| 60 | class Module; |
| 61 | |
| 62 | // All of the modules we've loaded |
| 63 | typedef hash_map<string, Module*, HashString> ModuleMap; |
| 64 | ModuleMap *modules_; |
| 65 | |
| 66 | // Disallow unwanted copy ctor and assignment operator |
| 67 | SourceLineResolver(const SourceLineResolver&); |
| 68 | void operator=(const SourceLineResolver&); |
| 69 | }; |
| 70 | |
mmentovai | 425d256 | 2006-08-30 20:05:05 +0000 | [diff] [blame] | 71 | } // namespace google_airbag |
bryner | cb91a2f | 2006-08-25 21:14:45 +0000 | [diff] [blame] | 72 | |
bryner | 07f8ef5 | 2006-09-05 19:42:57 +0000 | [diff] [blame] | 73 | #endif // PROCESSOR_SOURCE_LINE_RESOLVER_H__ |