1 : // Copyright 2015 Google Inc. All Rights Reserved.
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 : #ifndef SYZYGY_REFINERY_ANALYZERS_STACK_ANALYZER_H_
16 : #define SYZYGY_REFINERY_ANALYZERS_STACK_ANALYZER_H_
17 :
18 : #include <dia2.h>
19 :
20 : #include "base/macros.h"
21 : #include "base/memory/ref_counted.h"
22 : #include "base/win/scoped_comptr.h"
23 : #include "syzygy/refinery/analyzers/analyzer.h"
24 : #include "syzygy/refinery/process_state/process_state_util.h"
25 : #include "syzygy/refinery/symbols/dia_symbol_provider.h"
26 :
27 m : namespace refinery {
28 :
29 : // fwd.
30 m : class StackWalkHelper;
31 :
32 : // The stack analyzer populates the process state with information resulting
33 : // from walking the stack.
34 : // TODO(manzagop): Introduce a system for managing analyzer order prerequisites?
35 m : class StackAnalyzer : public Analyzer {
36 m : public:
37 m : StackAnalyzer();
38 :
39 m : const char* name() const override { return kStackAnalyzerName; }
40 :
41 m : AnalysisResult Analyze(const minidump::Minidump& minidump,
42 m : const ProcessAnalysis& process_analysis) override;
43 :
44 m : ANALYZER_INPUT_LAYERS(ProcessState::BytesLayer,
45 m : ProcessState::ModuleLayer,
46 m : ProcessState::StackLayer)
47 m : ANALYZER_OUTPUT_LAYERS(ProcessState::StackFrameLayer)
48 :
49 m : private:
50 m : AnalysisResult StackWalk(StackRecordPtr stack_record,
51 m : const ProcessAnalysis& process_analysis);
52 :
53 : // Inserts data about @p stack_frame into @p process_state.
54 m : bool InsertStackFrameRecord(IDiaStackFrame* stack_frame,
55 m : const ProcessAnalysis& process_analysis);
56 :
57 m : static const char kStackAnalyzerName[];
58 :
59 m : base::win::ScopedComPtr<IDiaStackWalker> stack_walker_;
60 m : scoped_refptr<StackWalkHelper> stack_walk_helper_;
61 :
62 : // A frame's data is often located relative to the CV_ALLREG_VFRAME. However,
63 : // we observe this is relative to the parent frame's value. For ease of
64 : // access, we store the parent frame's value in the frame's context.
65 m : RegisterInformation* child_frame_context_;
66 :
67 m : DISALLOW_COPY_AND_ASSIGN(StackAnalyzer);
68 m : };
69 :
70 m : } // namespace refinery
71 :
72 : #endif // SYZYGY_REFINERY_ANALYZERS_STACK_ANALYZER_H_
|