Movatterモバイル変換


[0]ホーム

URL:


Google Git
Sign in
chromium /chromium /src /refs/heads/main /. /base /location.h
blob: f324c409cf2386b0471b718397a6f1b6c5773d4a [file] [log] [blame] [edit]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_LOCATION_H_
#define BASE_LOCATION_H_
#include<compare>
#include<string>
#include"base/base_export.h"
#include"base/memory/raw_ptr_exclusion.h"
#include"base/trace_event/base_tracing_forward.h"
#include"build/build_config.h"
namespacebase{
// Location provides basic info where of an object was constructed, or was
// significantly brought to life.
class BASE_EXPORTLocation{
public:
Location();
Location(constLocation& other);
Location(Location&& other) noexcept;
Location&operator=(constLocation& other);
staticLocationCreateForTesting(constchar* function_name,
constchar* file_name,
int line_number,
constvoid* program_counter){
returnLocation(function_name, file_name, line_number, program_counter);
}
// Comparator for testing. The program counter should uniquely
// identify a location.
friendbooloperator==(constLocation& lhs,constLocation& rhs){
return lhs.program_counter_== rhs.program_counter_;
}
// The program counter should uniquely identify a location. There is no
// guarantee that a program counter corresponds to unique function/file/line
// values, based on how it's constructed, and therefore equivalent locations
// could be distinguishable.
friend std::weak_orderingoperator<=>(constLocation& lhs,
constLocation& rhs){
return lhs.program_counter_<=> rhs.program_counter_;
}
// Returns true if there is source code location info. If this is false,
// the Location object only contains a program counter or is
// default-initialized (the program counter is also null).
bool has_source_info()const{return function_name_&& file_name_;}
// Will be nullptr for default initialized Location objects and when source
// names are disabled.
constchar* function_name()const{return function_name_;}
// Will be nullptr for default initialized Location objects and when source
// names are disabled.
constchar* file_name()const{return file_name_;}
// Will be -1 for default initialized Location objects and when source names
// are disabled.
int line_number()const{return line_number_;}
// The address of the code generating this Location object. Should always be
// valid except for default initialized Location objects, which will be
// nullptr.
constvoid* program_counter()const{return program_counter_;}
// Converts to the most user-readable form possible. If function and filename
// are not available, this will return "pc:<hex address>".
std::stringToString()const;
// Write a representation of this object into a trace.
voidWriteIntoTrace(perfetto::TracedValue context)const;
staticLocationCurrent(constchar* function_name= __builtin_FUNCTION(),
constchar* file_name= __builtin_FILE(),
int line_number= __builtin_LINE());
staticLocationCurrentWithoutFunctionName(
constchar* file_name= __builtin_FILE(),
int line_number= __builtin_LINE());
private:
// Only initializes the file name and program counter, the source information
// will be null for the strings, and -1 for the line number.
// TODO(http://crbug.com/760702) remove file name from this constructor.
Location(constchar* file_name,constvoid* program_counter);
// Constructor should be called with a long-lived char*, such as __FILE__.
// It assumes the provided value will persist as a global constant, and it
// will not make a copy of it.
Location(constchar* function_name,
constchar* file_name,
int line_number,
constvoid* program_counter);
constchar* function_name_=nullptr;
constchar* file_name_=nullptr;
int line_number_=-1;
// `program_counter_` is not a raw_ptr<...> for performance reasons (based on
// analysis of sampling profiler data and tab_search:top100:2020).
RAW_PTR_EXCLUSIONconstvoid* program_counter_=nullptr;
};
BASE_EXPORTconstvoid*GetProgramCounter();
#define FROM_HERE::base::Location::Current()
}// namespace base
#endif// BASE_LOCATION_H_

[8]ページ先頭

©2009-2025 Movatter.jp