blob: 9d67553f0534335a6926da62917fde93c7577e3f [file] [log] [blame]
brynercb91a2f2006-08-25 21:14:45 +00001// 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
bryner07f8ef52006-09-05 19:42:57 +000019#ifndef PROCESSOR_SOURCE_LINE_RESOLVER_H__
20#define PROCESSOR_SOURCE_LINE_RESOLVER_H__
brynercb91a2f2006-08-25 21:14:45 +000021
brynercb91a2f2006-08-25 21:14:45 +000022#include <string>
23#include <ext/hash_map>
24
mmentovai425d2562006-08-30 20:05:05 +000025namespace google_airbag {
brynercb91a2f2006-08-25 21:14:45 +000026
mmentovai425d2562006-08-30 20:05:05 +000027using std::string;
brynercb91a2f2006-08-25 21:14:45 +000028using __gnu_cxx::hash_map;
29
bryner39716222006-09-07 17:26:17 +000030class StackFrame;
31
brynercb91a2f2006-08-25 21:14:45 +000032class SourceLineResolver {
33 public:
34 typedef unsigned long long MemAddr;
35
brynercb91a2f2006-08-25 21:14:45 +000036 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
bryner39716222006-09-07 17:26:17 +000047 // 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;
brynercb91a2f2006-08-25 21:14:45 +000051
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
mmentovai425d2562006-08-30 20:05:05 +000071} // namespace google_airbag
brynercb91a2f2006-08-25 21:14:45 +000072
bryner07f8ef52006-09-05 19:42:57 +000073#endif // PROCESSOR_SOURCE_LINE_RESOLVER_H__