| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(COMPILER_MSVC) | 7 #if defined(COMPILER_MSVC) |
| 8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build. | 8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build. |
| 9 extern "C" { | 9 extern "C" { |
| 10 void* _ReturnAddress(); | 10 void* _ReturnAddress(); |
| 11 } | 11 } |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/values.h" | |
| 18 | 17 |
| 19 namespace tracked_objects { | 18 namespace tracked_objects { |
| 20 | 19 |
| 21 Location::Location(const char* function_name, | 20 Location::Location(const char* function_name, |
| 22 const char* file_name, | 21 const char* file_name, |
| 23 int line_number, | 22 int line_number, |
| 24 const void* program_counter) | 23 const void* program_counter) |
| 25 : function_name_(function_name), | 24 : function_name_(function_name), |
| 26 file_name_(file_name), | 25 file_name_(file_name), |
| 27 line_number_(line_number), | 26 line_number_(line_number), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 output->append(">"); | 64 output->append(">"); |
| 66 break; | 65 break; |
| 67 | 66 |
| 68 default: | 67 default: |
| 69 output->push_back(*p); | 68 output->push_back(*p); |
| 70 break; | 69 break; |
| 71 } | 70 } |
| 72 } | 71 } |
| 73 } | 72 } |
| 74 | 73 |
| 75 base::DictionaryValue* Location::ToValue() const { | 74 //------------------------------------------------------------------------------ |
| 76 base::DictionaryValue* dictionary = new base::DictionaryValue; | 75 LocationSnapshot::LocationSnapshot() : line_number(-1) { |
| 77 dictionary->Set("file_name", base::Value::CreateStringValue(file_name_)); | |
| 78 // Note: This function name is not escaped, and templates have less than | |
| 79 // characters, which means this is not suitable for display as HTML unless | |
| 80 // properly escaped. | |
| 81 dictionary->Set("function_name", | |
| 82 base::Value::CreateStringValue(function_name_)); | |
| 83 dictionary->Set("line_number", base::Value::CreateIntegerValue(line_number_)); | |
| 84 return dictionary; | |
| 85 } | 76 } |
| 86 | 77 |
| 78 LocationSnapshot::LocationSnapshot( |
| 79 const tracked_objects::Location& location) |
| 80 : file_name(location.file_name()), |
| 81 function_name(location.function_name()), |
| 82 line_number(location.line_number()) { |
| 83 } |
| 84 |
| 85 LocationSnapshot::~LocationSnapshot() { |
| 86 } |
| 87 |
| 88 //------------------------------------------------------------------------------ |
| 87 #if defined(COMPILER_MSVC) | 89 #if defined(COMPILER_MSVC) |
| 88 __declspec(noinline) | 90 __declspec(noinline) |
| 89 #endif | 91 #endif |
| 90 BASE_EXPORT const void* GetProgramCounter() { | 92 BASE_EXPORT const void* GetProgramCounter() { |
| 91 #if defined(COMPILER_MSVC) | 93 #if defined(COMPILER_MSVC) |
| 92 return _ReturnAddress(); | 94 return _ReturnAddress(); |
| 93 #elif defined(COMPILER_GCC) | 95 #elif defined(COMPILER_GCC) |
| 94 return __builtin_extract_return_addr(__builtin_return_address(0)); | 96 return __builtin_extract_return_addr(__builtin_return_address(0)); |
| 95 #endif // COMPILER_GCC | 97 #endif // COMPILER_GCC |
| 96 | 98 |
| 97 return NULL; | 99 return NULL; |
| 98 } | 100 } |
| 99 | 101 |
| 100 } // namespace tracked_objects | 102 } // namespace tracked_objects |
| OLD | NEW |