Index: base/location.cc |
diff --git a/base/location.cc b/base/location.cc |
index 1333e6ec45354b1a633ae16de6088db47bab147d..77d205c6bae77c55c5f82fe3430fc3296fe11c6d 100644 |
--- a/base/location.cc |
+++ b/base/location.cc |
@@ -13,6 +13,25 @@ |
#include "base/strings/stringprintf.h" |
namespace tracked_objects { |
+namespace { |
+ |
+#if defined(COMPILER_MSVC) |
+__forceinline |
+#elif defined(COMPILER_GCC) && !defined(OS_NACL) |
+__attribute__((always_inline)) |
+inline |
+#endif |
+const void* GetReturnAddress() { |
+#if defined(COMPILER_MSVC) |
+ return _ReturnAddress(); |
+#elif defined(COMPILER_GCC) && !defined(OS_NACL) |
+ return __builtin_extract_return_addr(__builtin_return_address(0)); |
+#else |
+ return nullptr; |
+#endif |
+} |
+ |
+} // namespace |
Location::Location(const char* function_name, |
const char* file_name, |
@@ -38,6 +57,18 @@ Location::Location(const Location& other) |
program_counter_(other.program_counter_) { |
} |
+// static |
+#if defined(COMPILER_MSVC) |
+__declspec(noinline) |
+#endif |
+Location Location::CreateForCurrentProgramCounter( |
+ const char* function_name, |
+ const char* file_name, |
+ int line_number) { |
+ const void* program_counter = GetReturnAddress(); |
+ return Location(function_name, file_name, line_number, program_counter); |
+} |
+ |
std::string Location::ToString() const { |
return std::string(function_name_) + "@" + file_name_ + ":" + |
base::IntToString(line_number_); |
@@ -94,13 +125,7 @@ LocationSnapshot::~LocationSnapshot() { |
__declspec(noinline) |
#endif |
BASE_EXPORT const void* GetProgramCounter() { |
-#if defined(COMPILER_MSVC) |
- return _ReturnAddress(); |
-#elif defined(COMPILER_GCC) && !defined(OS_NACL) |
- return __builtin_extract_return_addr(__builtin_return_address(0)); |
-#else |
- return NULL; |
-#endif |
+ return GetReturnAddress(); |
} |
} // namespace tracked_objects |