blob: dd20b5cd5134c05b65b2b0b046ef673a3ce35792 [file] [log] [blame]
Christopher Ferris63860cb2015-11-16 17:30:32 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070029#include <assert.h>
Christopher Ferris63860cb2015-11-16 17:30:32 -080030#include <ctype.h>
31#include <errno.h>
32#include <limits.h>
33#include <signal.h>
34#include <stdlib.h>
35#include <string.h>
36#include <sys/cdefs.h>
37
38#include <string>
39#include <vector>
40
Christopher Ferris63860cb2015-11-16 17:30:32 -080041#include <private/bionic_macros.h>
42
43#include "Config.h"
44#include "debug_log.h"
45
Christopher Ferris549e5222016-02-22 19:23:26 -080046// Config constants
47static constexpr uint8_t DEFAULT_FILL_ALLOC_VALUE = 0xeb;
48static constexpr uint8_t DEFAULT_FILL_FREE_VALUE = 0xef;
49
50static constexpr uint8_t DEFAULT_FRONT_GUARD_VALUE = 0xaa;
51static constexpr uint8_t DEFAULT_REAR_GUARD_VALUE = 0xbb;
52
53// Used as the default for all guard values.
54static constexpr size_t DEFAULT_GUARD_BYTES = 32;
55static constexpr size_t MAX_GUARD_BYTES = 16384;
56
57static constexpr size_t DEFAULT_BACKTRACE_FRAMES = 16;
58static constexpr size_t MAX_BACKTRACE_FRAMES = 256;
Christopher Ferris602b88c2017-08-04 13:04:04 -070059static constexpr const char DEFAULT_BACKTRACE_DUMP_PREFIX[] = "/data/local/tmp/backtrace_heap";
Christopher Ferris549e5222016-02-22 19:23:26 -080060
61static constexpr size_t DEFAULT_EXPAND_BYTES = 16;
62static constexpr size_t MAX_EXPAND_BYTES = 16384;
63
64static constexpr size_t DEFAULT_FREE_TRACK_ALLOCATIONS = 100;
65static constexpr size_t MAX_FREE_TRACK_ALLOCATIONS = 16384;
66
Christopher Ferris7bd01782016-04-20 12:30:58 -070067static constexpr size_t DEFAULT_RECORD_ALLOCS = 8000000;
68static constexpr size_t MAX_RECORD_ALLOCS = 50000000;
69static constexpr const char DEFAULT_RECORD_ALLOCS_FILE[] = "/data/local/tmp/record_allocs.txt";
Christopher Ferris63860cb2015-11-16 17:30:32 -080070
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070071const std::unordered_map<std::string, Config::OptionInfo> Config::kOptions = {
Christopher Ferris4da25032018-03-07 13:38:48 -080072 {
73 "guard", {FRONT_GUARD | REAR_GUARD | TRACK_ALLOCS, &Config::SetGuard},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070074 },
Christopher Ferris4da25032018-03-07 13:38:48 -080075 {
76 "front_guard", {FRONT_GUARD | TRACK_ALLOCS, &Config::SetFrontGuard},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070077 },
Christopher Ferris4da25032018-03-07 13:38:48 -080078 {
79 "rear_guard", {REAR_GUARD | TRACK_ALLOCS, &Config::SetRearGuard},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070080 },
Christopher Ferris7bd01782016-04-20 12:30:58 -070081
Christopher Ferris4da25032018-03-07 13:38:48 -080082 {
83 "backtrace", {BACKTRACE | TRACK_ALLOCS, &Config::SetBacktrace},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070084 },
Christopher Ferris4da25032018-03-07 13:38:48 -080085 {
86 "backtrace_enable_on_signal",
87 {BACKTRACE | TRACK_ALLOCS, &Config::SetBacktraceEnableOnSignal},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -070088 },
Christopher Ferris7bd01782016-04-20 12:30:58 -070089
Christopher Ferris4da25032018-03-07 13:38:48 -080090 {
91 "backtrace_dump_on_exit", {0, &Config::SetBacktraceDumpOnExit},
Christopher Ferris602b88c2017-08-04 13:04:04 -070092 },
Christopher Ferris4da25032018-03-07 13:38:48 -080093 {
94 "backtrace_dump_prefix", {0, &Config::SetBacktraceDumpPrefix},
Christopher Ferris602b88c2017-08-04 13:04:04 -070095 },
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070096 {
97 "backtrace_full", {BACKTRACE_FULL, &Config::VerifyValueEmpty},
98 },
Christopher Ferris602b88c2017-08-04 13:04:04 -070099
Christopher Ferris4da25032018-03-07 13:38:48 -0800100 {
101 "fill", {FILL_ON_ALLOC | FILL_ON_FREE, &Config::SetFill},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700102 },
Christopher Ferris4da25032018-03-07 13:38:48 -0800103 {
104 "fill_on_alloc", {FILL_ON_ALLOC, &Config::SetFillOnAlloc},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700105 },
Christopher Ferris4da25032018-03-07 13:38:48 -0800106 {
107 "fill_on_free", {FILL_ON_FREE, &Config::SetFillOnFree},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700108 },
Christopher Ferris7bd01782016-04-20 12:30:58 -0700109
Christopher Ferris4da25032018-03-07 13:38:48 -0800110 {
111 "expand_alloc", {EXPAND_ALLOC, &Config::SetExpandAlloc},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700112 },
Christopher Ferris7bd01782016-04-20 12:30:58 -0700113
Christopher Ferris4da25032018-03-07 13:38:48 -0800114 {
115 "free_track", {FREE_TRACK | FILL_ON_FREE | TRACK_ALLOCS, &Config::SetFreeTrack},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700116 },
Christopher Ferris4da25032018-03-07 13:38:48 -0800117 {
118 "free_track_backtrace_num_frames", {0, &Config::SetFreeTrackBacktraceNumFrames},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700119 },
120
Christopher Ferris4da25032018-03-07 13:38:48 -0800121 {
122 "leak_track", {LEAK_TRACK | TRACK_ALLOCS, &Config::VerifyValueEmpty},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700123 },
124
Christopher Ferris4da25032018-03-07 13:38:48 -0800125 {
126 "record_allocs", {RECORD_ALLOCS, &Config::SetRecordAllocs},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700127 },
Christopher Ferris4da25032018-03-07 13:38:48 -0800128 {
129 "record_allocs_file", {0, &Config::SetRecordAllocsFile},
130 },
131
132 {
133 "verify_pointers", {TRACK_ALLOCS, &Config::VerifyValueEmpty},
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700134 },
Iris Chang7f209a92019-01-16 11:17:15 +0800135 {
136 "abort_on_error", {ABORT_ON_ERROR, &Config::VerifyValueEmpty},
137 },
Christopher Ferris63860cb2015-11-16 17:30:32 -0800138};
139
Christopher Ferris4da25032018-03-07 13:38:48 -0800140bool Config::ParseValue(const std::string& option, const std::string& value, size_t min_value,
141 size_t max_value, size_t* parsed_value) const {
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700142 assert(!value.empty());
Christopher Ferris7bd01782016-04-20 12:30:58 -0700143
144 // Parse the value into a size_t value.
145 errno = 0;
146 char* end;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700147 long long_value = strtol(value.c_str(), &end, 10);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700148 if (errno != 0) {
Christopher Ferris4da25032018-03-07 13:38:48 -0800149 error_log("%s: bad value for option '%s': %s", getprogname(), option.c_str(), strerror(errno));
Christopher Ferris7bd01782016-04-20 12:30:58 -0700150 return false;
151 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700152 if (end == value.c_str()) {
153 error_log("%s: bad value for option '%s'", getprogname(), option.c_str());
Christopher Ferris7bd01782016-04-20 12:30:58 -0700154 return false;
155 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700156 if (static_cast<size_t>(end - value.c_str()) != value.size()) {
Christopher Ferris4da25032018-03-07 13:38:48 -0800157 error_log("%s: bad value for option '%s', non space found after option: %s", getprogname(),
158 option.c_str(), end);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700159 return false;
160 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700161 if (long_value < 0) {
Christopher Ferris4da25032018-03-07 13:38:48 -0800162 error_log("%s: bad value for option '%s', value cannot be negative: %ld", getprogname(),
163 option.c_str(), long_value);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700164 return false;
165 }
166
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700167 if (static_cast<size_t>(long_value) < min_value) {
Christopher Ferris4da25032018-03-07 13:38:48 -0800168 error_log("%s: bad value for option '%s', value must be >= %zu: %ld", getprogname(),
169 option.c_str(), min_value, long_value);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700170 return false;
171 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700172 if (static_cast<size_t>(long_value) > max_value) {
Christopher Ferris4da25032018-03-07 13:38:48 -0800173 error_log("%s: bad value for option '%s', value must be <= %zu: %ld", getprogname(),
174 option.c_str(), max_value, long_value);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700175 return false;
176 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700177 *parsed_value = static_cast<size_t>(long_value);
Christopher Ferris7bd01782016-04-20 12:30:58 -0700178 return true;
179}
180
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700181bool Config::ParseValue(const std::string& option, const std::string& value, size_t default_value,
182 size_t min_value, size_t max_value, size_t* new_value) const {
183 if (value.empty()) {
184 *new_value = default_value;
185 return true;
186 }
187 return ParseValue(option, value, min_value, max_value, new_value);
188}
Christopher Ferris63860cb2015-11-16 17:30:32 -0800189
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700190bool Config::SetGuard(const std::string& option, const std::string& value) {
191 if (value.empty()) {
192 // Set the defaults.
193 front_guard_bytes_ = DEFAULT_GUARD_BYTES;
194 rear_guard_bytes_ = DEFAULT_GUARD_BYTES;
195 return true;
196 }
Christopher Ferris63860cb2015-11-16 17:30:32 -0800197
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700198 if (!ParseValue(option, value, 1, MAX_GUARD_BYTES, &rear_guard_bytes_)) {
Christopher Ferris63860cb2015-11-16 17:30:32 -0800199 return false;
200 }
201
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700202 // It's necessary to align the front guard to MINIMUM_ALIGNMENT_BYTES to
203 // make sure that the header is aligned properly.
Dan Alberta613d0d2017-10-05 16:39:33 -0700204 front_guard_bytes_ = __BIONIC_ALIGN(rear_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700205 return true;
206}
Christopher Ferris63860cb2015-11-16 17:30:32 -0800207
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700208bool Config::SetFrontGuard(const std::string& option, const std::string& value) {
209 if (!ParseValue(option, value, DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, &front_guard_bytes_)) {
210 return false;
211 }
212 // It's necessary to align the front guard to MINIMUM_ALIGNMENT_BYTES to
213 // make sure that the header is aligned properly.
Dan Alberta613d0d2017-10-05 16:39:33 -0700214 front_guard_bytes_ = __BIONIC_ALIGN(front_guard_bytes_, MINIMUM_ALIGNMENT_BYTES);
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700215 return true;
216}
Christopher Ferris63860cb2015-11-16 17:30:32 -0800217
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700218bool Config::SetRearGuard(const std::string& option, const std::string& value) {
219 return ParseValue(option, value, DEFAULT_GUARD_BYTES, 1, MAX_GUARD_BYTES, &rear_guard_bytes_);
220}
Christopher Ferris63860cb2015-11-16 17:30:32 -0800221
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700222bool Config::SetFill(const std::string& option, const std::string& value) {
223 if (value.empty()) {
224 // Set the defaults.
225 fill_on_alloc_bytes_ = SIZE_MAX;
226 fill_on_free_bytes_ = SIZE_MAX;
227 return true;
228 }
Christopher Ferris7bd01782016-04-20 12:30:58 -0700229
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700230 if (!ParseValue(option, value, 1, SIZE_MAX, &fill_on_alloc_bytes_)) {
231 return false;
232 }
233 fill_on_free_bytes_ = fill_on_alloc_bytes_;
234 return true;
235}
Christopher Ferris7bd01782016-04-20 12:30:58 -0700236
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700237bool Config::SetFillOnAlloc(const std::string& option, const std::string& value) {
238 return ParseValue(option, value, SIZE_MAX, 1, SIZE_MAX, &fill_on_alloc_bytes_);
239}
240
241bool Config::SetFillOnFree(const std::string& option, const std::string& value) {
242 return ParseValue(option, value, SIZE_MAX, 1, SIZE_MAX, &fill_on_free_bytes_);
243}
244
245bool Config::SetBacktrace(const std::string& option, const std::string& value) {
246 backtrace_enabled_ = true;
247 return ParseValue(option, value, DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES,
248 &backtrace_frames_);
249}
250
251bool Config::SetBacktraceEnableOnSignal(const std::string& option, const std::string& value) {
252 backtrace_enable_on_signal_ = true;
253 return ParseValue(option, value, DEFAULT_BACKTRACE_FRAMES, 1, MAX_BACKTRACE_FRAMES,
254 &backtrace_frames_);
255}
256
Christopher Ferris602b88c2017-08-04 13:04:04 -0700257bool Config::SetBacktraceDumpOnExit(const std::string& option, const std::string& value) {
258 if (Config::VerifyValueEmpty(option, value)) {
259 backtrace_dump_on_exit_ = true;
260 return true;
261 }
262 return false;
263}
264
265bool Config::SetBacktraceDumpPrefix(const std::string&, const std::string& value) {
266 if (value.empty()) {
267 backtrace_dump_prefix_ = DEFAULT_BACKTRACE_DUMP_PREFIX;
268 } else {
269 backtrace_dump_prefix_ = value;
270 }
271 return true;
272}
273
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700274bool Config::SetExpandAlloc(const std::string& option, const std::string& value) {
275 return ParseValue(option, value, DEFAULT_EXPAND_BYTES, 1, MAX_EXPAND_BYTES, &expand_alloc_bytes_);
276}
277
278bool Config::SetFreeTrack(const std::string& option, const std::string& value) {
279 // This option enables fill on free, so set the bytes to the default value.
280 if (fill_on_free_bytes_ == 0) {
281 fill_on_free_bytes_ = SIZE_MAX;
282 }
283 if (free_track_backtrace_num_frames_ == 0) {
284 free_track_backtrace_num_frames_ = DEFAULT_BACKTRACE_FRAMES;
285 }
286
287 return ParseValue(option, value, DEFAULT_FREE_TRACK_ALLOCATIONS, 1, MAX_FREE_TRACK_ALLOCATIONS,
288 &free_track_allocations_);
289}
290
291bool Config::SetFreeTrackBacktraceNumFrames(const std::string& option, const std::string& value) {
292 return ParseValue(option, value, DEFAULT_BACKTRACE_FRAMES, 0, MAX_BACKTRACE_FRAMES,
293 &free_track_backtrace_num_frames_);
294}
295
296bool Config::SetRecordAllocs(const std::string& option, const std::string& value) {
297 if (record_allocs_file_.empty()) {
298 record_allocs_file_ = DEFAULT_RECORD_ALLOCS_FILE;
299 }
300 return ParseValue(option, value, DEFAULT_RECORD_ALLOCS, 1, MAX_RECORD_ALLOCS,
301 &record_allocs_num_entries_);
302}
303
304bool Config::SetRecordAllocsFile(const std::string&, const std::string& value) {
305 if (value.empty()) {
306 // Set the default.
307 record_allocs_file_ = DEFAULT_RECORD_ALLOCS_FILE;
308 return true;
309 }
310 record_allocs_file_ = value;
311 return true;
312}
313
314bool Config::VerifyValueEmpty(const std::string& option, const std::string& value) {
315 if (!value.empty()) {
316 // This is not valid.
Christopher Ferris4da25032018-03-07 13:38:48 -0800317 error_log("%s: value set for option '%s' which does not take a value", getprogname(),
318 option.c_str());
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700319 return false;
Christopher Ferris63860cb2015-11-16 17:30:32 -0800320 }
321 return true;
322}
323
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700324void Config::LogUsage() const {
Christopher Ferris770cbb32018-05-25 12:46:55 -0700325 error_log("For malloc debug option descriptions go to:");
326 error_log(" https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md");
Christopher Ferris63860cb2015-11-16 17:30:32 -0800327}
328
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700329bool Config::GetOption(const char** options_str, std::string* option, std::string* value) {
330 const char* cur = *options_str;
331 // Process each property name we can find.
Christopher Ferris4da25032018-03-07 13:38:48 -0800332 while (isspace(*cur)) ++cur;
Christopher Ferris63860cb2015-11-16 17:30:32 -0800333
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700334 if (*cur == '\0') {
335 *options_str = cur;
336 return false;
Christopher Ferris7bd01782016-04-20 12:30:58 -0700337 }
338
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700339 const char* start = cur;
Christopher Ferris4da25032018-03-07 13:38:48 -0800340 while (!isspace(*cur) && *cur != '=' && *cur != '\0') ++cur;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700341
342 *option = std::string(start, cur - start);
343
344 // Skip any spaces after the name.
Christopher Ferris4da25032018-03-07 13:38:48 -0800345 while (isspace(*cur)) ++cur;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700346
347 value->clear();
348 if (*cur == '=') {
349 ++cur;
350 // Skip the space after the equal.
Christopher Ferris4da25032018-03-07 13:38:48 -0800351 while (isspace(*cur)) ++cur;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700352
353 start = cur;
Christopher Ferris4da25032018-03-07 13:38:48 -0800354 while (!isspace(*cur) && *cur != '\0') ++cur;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700355
356 if (cur != start) {
357 *value = std::string(start, cur - start);
Christopher Ferris63860cb2015-11-16 17:30:32 -0800358 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700359 }
360 *options_str = cur;
361 return true;
362}
363
364bool Config::Init(const char* options_str) {
365 // Initialize a few default values.
366 fill_alloc_value_ = DEFAULT_FILL_ALLOC_VALUE;
367 fill_free_value_ = DEFAULT_FILL_FREE_VALUE;
368 front_guard_value_ = DEFAULT_FRONT_GUARD_VALUE;
369 rear_guard_value_ = DEFAULT_REAR_GUARD_VALUE;
370 backtrace_signal_ = SIGRTMAX - 19;
Christopher Ferris602b88c2017-08-04 13:04:04 -0700371 backtrace_dump_signal_ = SIGRTMAX - 17;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700372 record_allocs_signal_ = SIGRTMAX - 18;
373 free_track_backtrace_num_frames_ = 0;
374 record_allocs_file_.clear();
375 fill_on_free_bytes_ = 0;
376 backtrace_enable_on_signal_ = false;
377 backtrace_enabled_ = false;
Christopher Ferris602b88c2017-08-04 13:04:04 -0700378 backtrace_dump_on_exit_ = false;
379 backtrace_dump_prefix_ = DEFAULT_BACKTRACE_DUMP_PREFIX;
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700380
381 // Process each option name we can find.
382 std::string option;
383 std::string value;
384 bool valid = true;
385 while (GetOption(&options_str, &option, &value)) {
386 auto entry = kOptions.find(option);
387 if (entry == kOptions.end()) {
388 error_log("%s: unknown option %s", getprogname(), option.c_str());
Christopher Ferris63860cb2015-11-16 17:30:32 -0800389 valid = false;
390 break;
391 }
Christopher Ferris63860cb2015-11-16 17:30:32 -0800392
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700393 const OptionInfo* info = &entry->second;
394 auto process_func = info->process_func;
395 if (process_func != nullptr && !(this->*process_func)(option, value)) {
396 valid = false;
397 break;
Christopher Ferris63860cb2015-11-16 17:30:32 -0800398 }
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700399 options_ |= info->option;
Christopher Ferris63860cb2015-11-16 17:30:32 -0800400 }
401
Christopher Ferris2b2b25b2017-04-05 19:13:03 -0700402 if (!valid || *options_str != '\0') {
403 LogUsage();
404 return false;
405 }
406
407 return true;
Christopher Ferris63860cb2015-11-16 17:30:32 -0800408}