1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/mac/mach_logging.h"
10 #include "base/strings/stringprintf.h"
13 #include <servers/bootstrap.h>
18 std::string
FormatMachErrorNumber(mach_error_t mach_err
) {
19 // For the os/kern subsystem, give the error number in decimal as in
20 // <mach/kern_return.h>. Otherwise, give it in hexadecimal to make it easier
21 // to visualize the various bits. See <mach/error.h>.
22 if (mach_err
>= 0 && mach_err
< KERN_RETURN_MAX
) {
23 return base::StringPrintf(" (%d)", mach_err
);
25 return base::StringPrintf(" (0x%08x)", mach_err
);
32 MachLogMessage::MachLogMessage(const char* file_path
,
35 mach_error_t mach_err
)
36 : LogMessage(file_path
, line
, severity
),
40 MachLogMessage::~MachLogMessage() {
42 << mach_error_string(mach_err_
)
43 << FormatMachErrorNumber(mach_err_
);
48 BootstrapLogMessage::BootstrapLogMessage(const char* file_path
,
51 kern_return_t bootstrap_err
)
52 : LogMessage(file_path
, line
, severity
),
53 bootstrap_err_(bootstrap_err
) {
56 BootstrapLogMessage::~BootstrapLogMessage() {
58 << bootstrap_strerror(bootstrap_err_
);
60 switch (bootstrap_err_
) {
61 case BOOTSTRAP_SUCCESS
:
62 case BOOTSTRAP_NOT_PRIVILEGED
:
63 case BOOTSTRAP_NAME_IN_USE
:
64 case BOOTSTRAP_UNKNOWN_SERVICE
:
65 case BOOTSTRAP_SERVICE_ACTIVE
:
66 case BOOTSTRAP_BAD_COUNT
:
67 case BOOTSTRAP_NO_MEMORY
:
68 case BOOTSTRAP_NO_CHILDREN
: {
69 // Show known bootstrap errors in decimal because that's how they're
70 // defined in <servers/bootstrap.h>.
71 stream() << " (" << bootstrap_err_
<< ")";
76 // bootstrap_strerror passes unknown errors to mach_error_string, so
77 // format them as they would be if they were handled by
79 stream() << FormatMachErrorNumber(bootstrap_err_
);
87 } // namespace logging