1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "platform/base/location.h" 6 7 #include <sstream> 8 9 #include "platform/base/macros.h" 10 11 namespace openscreen { 12 13 Location::Location() = default; 14 Location::Location(const Location&) = default; 15 Location::Location(Location&&) noexcept = default; 16 Location(const void * program_counter)17Location::Location(const void* program_counter) 18 : program_counter_(program_counter) {} 19 20 Location& Location::operator=(const Location& other) = default; 21 Location& Location::operator=(Location&& other) = default; 22 ToString() const23std::string Location::ToString() const { 24 if (program_counter_ == nullptr) { 25 return "pc:NULL"; 26 } 27 28 std::ostringstream oss; 29 oss << "pc:" << program_counter_; 30 return oss.str(); 31 } 32 33 #if defined(__GNUC__) 34 #define RETURN_ADDRESS() \ 35 __builtin_extract_return_addr(__builtin_return_address(0)) 36 #else 37 #define RETURN_ADDRESS() nullptr 38 #endif 39 40 // static CreateFromHere()41OSP_NOINLINE Location Location::CreateFromHere() { 42 return Location(RETURN_ADDRESS()); 43 } 44 45 // static GetProgramCounter()46OSP_NOINLINE const void* GetProgramCounter() { 47 return RETURN_ADDRESS(); 48 } 49 50 } // namespace openscreen 51