Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(927)

Unified Diff: base/location.cc

Issue 2399053004: Move GetProgramCounter in FROM_HERE to a common function (Closed)
Patch Set: -BASE_EXPORT Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/location.h ('k') | base/location_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « base/location.h ('k') | base/location_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698