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