OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Crashpad Authors. 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 #include "util/test/mac/mach_errors.h" | |
16 | |
17 #include <servers/bootstrap.h> | |
18 | |
19 #include "base/safe_strerror_posix.h" | |
20 #include "base/strings/stringprintf.h" | |
21 | |
22 namespace { | |
23 | |
24 std::string FormatBase(const std::string& base) { | |
25 if (base.empty()) { | |
26 return std::string(); | |
27 } | |
28 | |
29 return base::StringPrintf("%s: ", base.c_str()); | |
30 } | |
31 | |
32 std::string FormatMachErrorNumber(mach_error_t mach_err) { | |
33 // For the os/kern subsystem, give the error number in decimal as in | |
34 // <mach/kern_return.h>. Otherwise, give it in hexadecimal to make it easier | |
35 // to visualize the various bits. See <mach/error.h>. | |
36 if (mach_err >= 0 && mach_err < KERN_RETURN_MAX) { | |
37 return base::StringPrintf(" (%d)", mach_err); | |
38 } | |
39 return base::StringPrintf(" (0x%08x)", mach_err); | |
40 } | |
41 | |
42 } // namespace | |
43 | |
44 namespace crashpad { | |
45 namespace test { | |
46 | |
47 std::string MachErrorMessage(mach_error_t mach_err, const std::string& base) { | |
48 return base::StringPrintf("%s%s%s", | |
49 FormatBase(base).c_str(), | |
50 mach_error_string(mach_err), | |
51 FormatMachErrorNumber(mach_err).c_str()); | |
52 } | |
53 | |
54 std::string BootstrapErrorMessage(kern_return_t bootstrap_err, | |
55 const std::string& base) { | |
56 switch (bootstrap_err) { | |
57 case BOOTSTRAP_SUCCESS: | |
58 case BOOTSTRAP_NOT_PRIVILEGED: | |
59 case BOOTSTRAP_NAME_IN_USE: | |
60 case BOOTSTRAP_UNKNOWN_SERVICE: | |
61 case BOOTSTRAP_SERVICE_ACTIVE: | |
62 case BOOTSTRAP_BAD_COUNT: | |
63 case BOOTSTRAP_NO_MEMORY: | |
64 case BOOTSTRAP_NO_CHILDREN: | |
65 // Show known bootstrap errors in decimal because that's how they're | |
66 // defined in <servers/bootstrap.h>. | |
67 return base::StringPrintf("%s%s (%d)", | |
68 FormatBase(base).c_str(), | |
69 bootstrap_strerror(bootstrap_err), | |
70 bootstrap_err); | |
71 | |
72 default: | |
73 return MachErrorMessage(bootstrap_err, base); | |
74 } | |
75 } | |
76 | |
77 } // namespace test | |
78 } // namespace crashpad | |
OLD | NEW |