OLD | NEW |
1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "syzygy/refinery/analyzers/stack_frame_analyzer.h" | 15 #include "syzygy/refinery/analyzers/stack_frame_analyzer.h" |
16 | 16 |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/win/scoped_comptr.h" | 21 #include "base/win/scoped_comptr.h" |
22 #include "syzygy/common/com_utils.h" | 22 #include "syzygy/common/com_utils.h" |
23 #include "syzygy/pe/dia_util.h" | 23 #include "syzygy/pe/dia_util.h" |
24 #include "syzygy/refinery/analyzers/stack_frame_analyzer_impl.h" | 24 #include "syzygy/refinery/analyzers/stack_frame_analyzer_impl.h" |
| 25 #include "syzygy/refinery/process_state/layer_data.h" |
25 #include "syzygy/refinery/types/type_repository.h" | 26 #include "syzygy/refinery/types/type_repository.h" |
26 | 27 |
27 namespace refinery { | 28 namespace refinery { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 bool GetInnerMostScopeForVA(IDiaSession* session, | 32 bool GetInnerMostScopeForVA(IDiaSession* session, |
32 Address va, | 33 Address va, |
33 base::win::ScopedComPtr<IDiaSymbol>* scope) { | 34 base::win::ScopedComPtr<IDiaSymbol>* scope) { |
34 DCHECK(session); | 35 DCHECK(session); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 95 |
95 const StackFrame& frame_proto = frame_record->data(); | 96 const StackFrame& frame_proto = frame_record->data(); |
96 Address instruction_pointer = | 97 Address instruction_pointer = |
97 static_cast<Address>(frame_proto.register_info().eip()); | 98 static_cast<Address>(frame_proto.register_info().eip()); |
98 | 99 |
99 // Retrieve symbol information. | 100 // Retrieve symbol information. |
100 if (!SetSymbolInformation(instruction_pointer, process_state)) { | 101 if (!SetSymbolInformation(instruction_pointer, process_state)) { |
101 LOG(INFO) << "Unable to get symbol information for frame. Skipping."; | 102 LOG(INFO) << "Unable to get symbol information for frame. Skipping."; |
102 return true; // Not an error. | 103 return true; // Not an error. |
103 } | 104 } |
| 105 ModuleLayerAccessor accessor(process_state); |
| 106 ModuleId module_id = accessor.GetModuleId(instruction_pointer); |
| 107 if (module_id == kNoModuleId) { |
| 108 LOG(INFO) << "No module corresponding to instruction pointer."; |
| 109 return false; |
| 110 } |
104 | 111 |
105 // Get the innermost scope, be it a block or the function itself. | 112 // Get the innermost scope, be it a block or the function itself. |
106 // TODO(manzagop): Identical code folding means there may be more than one | 113 // TODO(manzagop): Identical code folding means there may be more than one |
107 // symbol for a given address. Look into this. | 114 // symbol for a given address. Look into this. |
108 base::win::ScopedComPtr<IDiaSymbol> scope; | 115 base::win::ScopedComPtr<IDiaSymbol> scope; |
109 if (!GetInnerMostScopeForVA(dia_session_.get(), instruction_pointer, &scope)) | 116 if (!GetInnerMostScopeForVA(dia_session_.get(), instruction_pointer, &scope)) |
110 return false; | 117 return false; |
111 | 118 |
112 // Walk up the scopes, processing scope's data. | 119 // Walk up the scopes, processing scope's data. |
113 StackFrameDataAnalyzer data_analyzer(frame_record, typename_index_, | 120 StackFrameDataAnalyzer data_analyzer(frame_record, typename_index_, module_id, |
114 process_state); | 121 process_state); |
115 while (true) { | 122 while (true) { |
116 // Process each SymTagData child in the block / function. | 123 // Process each SymTagData child in the block / function. |
117 // TODO(manzagop): the data visitor will stop visiting at the first error. | 124 // TODO(manzagop): the data visitor will stop visiting at the first error. |
118 // Figure out how to surface issues without preventing processing (eg | 125 // Figure out how to surface issues without preventing processing (eg |
119 // with a callback). | 126 // with a callback). |
120 pe::ChildVisitor data_visitor(scope.get(), SymTagData); | 127 pe::ChildVisitor data_visitor(scope.get(), SymTagData); |
121 if (!data_visitor.VisitChildren( | 128 if (!data_visitor.VisitChildren( |
122 base::Bind(&StackFrameDataAnalyzer::Analyze, | 129 base::Bind(&StackFrameDataAnalyzer::Analyze, |
123 base::Unretained(&data_analyzer)))) { | 130 base::Unretained(&data_analyzer)))) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // Get dia session for the module. | 165 // Get dia session for the module. |
159 if (!dia_symbol_provider_->FindOrCreateDiaSession( | 166 if (!dia_symbol_provider_->FindOrCreateDiaSession( |
160 instruction_pointer, process_state, &dia_session_)) { | 167 instruction_pointer, process_state, &dia_session_)) { |
161 return false; | 168 return false; |
162 } | 169 } |
163 | 170 |
164 return true; | 171 return true; |
165 } | 172 } |
166 | 173 |
167 } // namespace refinery | 174 } // namespace refinery |
OLD | NEW |