blob: 8bbf6edaa4a6299169f9224631d17f7745444342 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/location.h"
#if defined(COMPILER_MSVC)
#include <intrin.h>
#include "base/compiler_specific.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
namespace base {
Location::Location() = default;
Location::Location(const Location& other) = default;
Location::Location(const char* file_name, const void* program_counter)
: file_name_(file_name), program_counter_(program_counter) {}
Location::Location(const char* function_name,
const char* file_name,
int line_number,
const void* program_counter)
: function_name_(function_name),
program_counter_(program_counter) {
#if !defined(OS_NACL)
// The program counter should not be null except in a default constructed
// (empty) Location object. This value is used for identity, so if it doesn't
// uniquely identify a location, things will break.
// The program counter isn't supported in NaCl so location objects won't work
// properly in that context.
std::string Location::ToString() const {
if (has_source_info()) {
return std::string(function_name_) + "@" + file_name_ + ":" +
return StringPrintf("pc:%p", program_counter_);
#if defined(COMPILER_MSVC)
#define RETURN_ADDRESS() _ReturnAddress()
#elif defined(COMPILER_GCC) && !defined(OS_NACL)
#define RETURN_ADDRESS() \
#define RETURN_ADDRESS() nullptr
// static
NOINLINE Location Location::CreateFromHere(const char* file_name) {
return Location(file_name, RETURN_ADDRESS());
// static
NOINLINE Location Location::CreateFromHere(const char* function_name,
const char* file_name,
int line_number) {
return Location(function_name, file_name, line_number, RETURN_ADDRESS());
NOINLINE const void* GetProgramCounter() {
} // namespace base