1 : // Copyright 2012 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_AGENT_ASAN_LOGGER_H_
16 : #define SYZYGY_AGENT_ASAN_LOGGER_H_
17 :
18 : #include <string>
19 :
20 : #include "base/logging.h"
21 : #include "syzygy/agent/asan/error_info.h"
22 : #include "syzygy/common/rpc/helpers.h"
23 :
24 : namespace agent {
25 : namespace asan {
26 :
27 : struct AsanErrorInfo;
28 :
29 : // A wrapper class to manage the singleton Asan RPC logger instance.
30 : class AsanLogger {
31 : public:
32 : AsanLogger();
33 :
34 : // Set the RPC instance ID to use. If an instance-id is to be used by the
35 : // logger, it must be set before calling Init().
36 : const std::wstring& instance_id() const { return instance_id_; }
37 E : void set_instance_id(const base::StringPiece16& instance_id) {
38 E : DCHECK(rpc_binding_.Get() == NULL);
39 E : instance_id_.assign(instance_id.begin(), instance_id.end());
40 E : }
41 :
42 : // Set whether to write text to the asan log.
43 E : bool log_as_text() const { return log_as_text_; }
44 E : void set_log_as_text(bool value) { log_as_text_ = value; }
45 :
46 : // Set whether to save a minidump on error.
47 : bool minidump_on_failure() const { return minidump_on_failure_; }
48 E : void set_minidump_on_failure(bool value) { minidump_on_failure_ = value; }
49 :
50 : // Initialize the logger.
51 : void Init();
52 :
53 : // Stop the logger.
54 : void Stop();
55 :
56 : // Write a @p message to the logger.
57 : void Write(const std::string& message);
58 :
59 : // Write a @p message to the logger, and have the logger include the most
60 : // detailed and accurate stack trace it can derive given the execution
61 : // @p context .
62 : void WriteWithContext(const std::string& message, const CONTEXT& context);
63 :
64 : // Write a @p message to the logger, with an optional stack @p trace
65 : // containing @p trace_length elements.
66 : void WriteWithStackTrace(const std::string& message,
67 : const void* const* trace_data,
68 : size_t trace_length);
69 :
70 : // Ask the logger to capture a minidump of the process for a given context.
71 : // @param context The context for which we want a minidump.
72 : // @param error_info The information about the error.
73 : // @param protobuf The crashdata protobuf to include in the minidump.
74 : // @param memory_ranges The memory ranges that we want to include in this
75 : // report.
76 : void SaveMinidumpWithProtobufAndMemoryRanges(
77 : CONTEXT* context,
78 : AsanErrorInfo* error_info,
79 : const std::string& protobuf,
80 : const MemoryRanges& memory_ranges);
81 :
82 : protected:
83 : // The RPC binding.
84 : ::common::rpc::ScopedRpcBinding rpc_binding_;
85 :
86 : // The logger's instance id.
87 : std::wstring instance_id_;
88 :
89 : // True if the runtime has been asked to write text to the logger.
90 : // Default: true.
91 : bool log_as_text_;
92 :
93 : // True if the runtime has been asked to save a minidump on error.
94 : // Default: false.
95 : bool minidump_on_failure_;
96 :
97 : private:
98 : DISALLOW_COPY_AND_ASSIGN(AsanLogger);
99 : };
100 :
101 : } // namespace asan
102 : } // namespace agent
103 :
104 : #endif // SYZYGY_AGENT_ASAN_LOGGER_H_
|