Chromium Code Reviews| Index: util/win/ntstatus_logging.cc |
| diff --git a/util/win/ntstatus_logging.cc b/util/win/ntstatus_logging.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..963119e269a26ddc882e3353effe39d6749caebe |
| --- /dev/null |
| +++ b/util/win/ntstatus_logging.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2015 The Crashpad Authors. All rights reserved. |
| +// |
| +// Licensed under the Apache License, Version 2.0 (the "License"); |
| +// you may not use this file except in compliance with the License. |
| +// You may obtain a copy of the License at |
| +// |
| +// http://www.apache.org/licenses/LICENSE-2.0 |
| +// |
| +// Unless required by applicable law or agreed to in writing, software |
| +// distributed under the License is distributed on an "AS IS" BASIS, |
| +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| +// See the License for the specific language governing permissions and |
| +// limitations under the License. |
| + |
| +#include "util/win/ntstatus_logging.h" |
| + |
| +#include <string.h> |
|
Mark Mentovai
2015/09/15 02:22:32
<string>, no .h
scottmg
2015/09/15 04:33:51
Done.
|
| + |
| +#include "base/strings/stringprintf.h" |
| + |
| +namespace { |
| + |
| +std::string FormatNtstatus(DWORD ntstatus) { |
| + char msgbuf[256]; |
| + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | |
|
Mark Mentovai
2015/09/15 02:22:32
Optional: const, or write inline in the FormatMess
scottmg
2015/09/15 04:33:51
Done.
|
| + FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_FROM_HMODULE; |
| + DWORD len = FormatMessageA(flags, |
| + GetModuleHandle(L"ntdll.dll"), |
| + ntstatus, |
| + 0, |
| + msgbuf, |
| + arraysize(msgbuf), |
| + NULL); |
|
Mark Mentovai
2015/09/15 02:22:32
nullptr
scottmg
2015/09/15 04:33:51
Done.
|
| + if (len) { |
| + return msgbuf; |
| + } else { |
| + return base::StringPrintf("<failed to retrieve error message (0x%x)>", |
|
Mark Mentovai
2015/09/15 02:22:32
base/strings/stringprintf.h
scottmg
2015/09/15 04:33:51
Already there?
|
| + GetLastError()); |
| + } |
| +} |
| + |
| +} // namespace |
| + |
| +namespace logging { |
| + |
| +NtstatusLogMessage::NtstatusLogMessage(const char* function, |
| + const char* file_path, |
| + int line, |
| + LogSeverity severity, |
| + DWORD ntstatus) |
| + : LogMessage(function, file_path, line, severity), ntstatus_(ntstatus) { |
|
Mark Mentovai
2015/09/15 02:22:32
:(
mini_chromium has a function argument and Chro
scottmg
2015/09/15 04:33:51
Do you find the function in the log particularly u
Mark Mentovai
2015/09/15 12:52:57
scottmg wrote:
|
| +} |
| + |
| +NtstatusLogMessage::~NtstatusLogMessage() { |
| + stream() << ": " << FormatNtstatus(ntstatus_) |
| + << base::StringPrintf(" (0x%04x)", ntstatus_); |
|
Mark Mentovai
2015/09/15 02:22:32
According to https://msdn.microsoft.com/en-us/libr
scottmg
2015/09/15 04:33:51
Done. (No idea what I was thinking there... 4 byte
|
| +} |
| + |
| +} // namespace logging |