OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 19 using base::DictionaryValue; |
| 20 using base::Value; |
17 | 21 |
18 namespace tracked_objects { | 22 namespace tracked_objects { |
19 | 23 |
20 Location::Location(const char* function_name, | 24 Location::Location(const char* function_name, |
21 const char* file_name, | 25 const char* file_name, |
22 int line_number, | 26 int line_number, |
23 const void* program_counter) | 27 const void* program_counter) |
24 : function_name_(function_name), | 28 : function_name_(function_name), |
25 file_name_(file_name), | 29 file_name_(file_name), |
26 line_number_(line_number), | 30 line_number_(line_number), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 output->append(">"); | 68 output->append(">"); |
65 break; | 69 break; |
66 | 70 |
67 default: | 71 default: |
68 output->push_back(*p); | 72 output->push_back(*p); |
69 break; | 73 break; |
70 } | 74 } |
71 } | 75 } |
72 } | 76 } |
73 | 77 |
74 base::DictionaryValue* Location::ToValue() const { | 78 //------------------------------------------------------------------------------ |
75 base::DictionaryValue* dictionary = new base::DictionaryValue; | 79 SerializedLocation::SerializedLocation() { |
76 dictionary->Set("file_name", base::Value::CreateStringValue(file_name_)); | 80 } |
77 // Note: This function name is not escaped, and templates have less than | 81 |
| 82 SerializedLocation::SerializedLocation( |
| 83 const tracked_objects::Location& location) |
| 84 : file_name(location.file_name()), |
| 85 function_name(location.function_name()), |
| 86 line_number(location.line_number()) { |
| 87 } |
| 88 |
| 89 SerializedLocation::~SerializedLocation() { |
| 90 } |
| 91 |
| 92 void SerializedLocation::ToValue(DictionaryValue* dictionary) const { |
| 93 dictionary->Set("file_name", Value::CreateStringValue(file_name)); |
| 94 // Note: This function name is not escaped, and templates have less-than |
78 // characters, which means this is not suitable for display as HTML unless | 95 // characters, which means this is not suitable for display as HTML unless |
79 // properly escaped. | 96 // properly escaped. |
80 dictionary->Set("function_name", | 97 dictionary->Set("function_name", Value::CreateStringValue(function_name)); |
81 base::Value::CreateStringValue(function_name_)); | 98 dictionary->Set("line_number", Value::CreateIntegerValue(line_number)); |
82 dictionary->Set("line_number", base::Value::CreateIntegerValue(line_number_)); | |
83 return dictionary; | |
84 } | 99 } |
85 | 100 |
| 101 //------------------------------------------------------------------------------ |
86 #if defined(COMPILER_MSVC) | 102 #if defined(COMPILER_MSVC) |
87 __declspec(noinline) | 103 __declspec(noinline) |
88 #endif | 104 #endif |
89 BASE_EXPORT const void* GetProgramCounter() { | 105 BASE_EXPORT const void* GetProgramCounter() { |
90 #if defined(COMPILER_MSVC) | 106 #if defined(COMPILER_MSVC) |
91 return _ReturnAddress(); | 107 return _ReturnAddress(); |
92 #elif defined(COMPILER_GCC) | 108 #elif defined(COMPILER_GCC) |
93 return __builtin_extract_return_addr(__builtin_return_address(0)); | 109 return __builtin_extract_return_addr(__builtin_return_address(0)); |
94 #endif // COMPILER_GCC | 110 #endif // COMPILER_GCC |
95 | 111 |
96 return NULL; | 112 return NULL; |
97 } | 113 } |
98 | 114 |
99 } // namespace tracked_objects | 115 } // namespace tracked_objects |
OLD | NEW |