Path: blob/main/contrib/llvm-project/compiler-rt/lib/memprof/memprof_flags.cpp
35236 views
//===-- memprof_flags.cpp --------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of MemProfiler, a memory profiler.9//10// MemProf flag parsing logic.11//===----------------------------------------------------------------------===//1213#include "memprof_flags.h"14#include "memprof_interface_internal.h"15#include "memprof_stack.h"16#include "sanitizer_common/sanitizer_common.h"17#include "sanitizer_common/sanitizer_flag_parser.h"18#include "sanitizer_common/sanitizer_flags.h"1920namespace __memprof {2122Flags memprof_flags_dont_use_directly; // use via flags().2324static const char *MaybeUseMemprofDefaultOptionsCompileDefinition() {25#ifdef MEMPROF_DEFAULT_OPTIONS26return SANITIZER_STRINGIFY(MEMPROF_DEFAULT_OPTIONS);27#else28return "";29#endif30}3132void Flags::SetDefaults() {33#define MEMPROF_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;34#include "memprof_flags.inc"35#undef MEMPROF_FLAG36}3738static void RegisterMemprofFlags(FlagParser *parser, Flags *f) {39#define MEMPROF_FLAG(Type, Name, DefaultValue, Description) \40RegisterFlag(parser, #Name, Description, &f->Name);41#include "memprof_flags.inc"42#undef MEMPROF_FLAG43}4445void InitializeFlags() {46// Set the default values and prepare for parsing MemProf and common flags.47SetCommonFlagsDefaults();48{49CommonFlags cf;50cf.CopyFrom(*common_flags());51cf.external_symbolizer_path = GetEnv("MEMPROF_SYMBOLIZER_PATH");52cf.malloc_context_size = kDefaultMallocContextSize;53cf.intercept_tls_get_addr = true;54cf.exitcode = 1;55OverrideCommonFlags(cf);56}57Flags *f = flags();58f->SetDefaults();5960FlagParser memprof_parser;61RegisterMemprofFlags(&memprof_parser, f);62RegisterCommonFlags(&memprof_parser);6364// Override from MemProf compile definition.65const char *memprof_compile_def =66MaybeUseMemprofDefaultOptionsCompileDefinition();67memprof_parser.ParseString(memprof_compile_def);6869// Override from user-specified string.70const char *memprof_default_options = __memprof_default_options();71memprof_parser.ParseString(memprof_default_options);7273// Override from command line.74memprof_parser.ParseStringFromEnv("MEMPROF_OPTIONS");7576InitializeCommonFlags();7778if (Verbosity())79ReportUnrecognizedFlags();8081if (common_flags()->help) {82memprof_parser.PrintFlagDescriptions();83}8485CHECK_LE((uptr)common_flags()->malloc_context_size, kStackTraceMax);86}8788} // namespace __memprof8990SANITIZER_INTERFACE_WEAK_DEF(const char *, __memprof_default_options, void) {91return "";92}939495