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

Side by Side Diff: base/location.cc

Issue 7879006: Delete Tracked, and move Location to its own file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/location.h ('k') | base/message_loop.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "build/build_config.h"
6
7 #if defined(COMPILER_MSVC)
8 // MSDN says to #include <intrin.h>, but that breaks the VS2005 build.
9 extern "C" {
10 void* _ReturnAddress();
11 }
12 #endif
13
14 #include "base/location.h"
15 #include "base/string_number_conversions.h"
16 #include "base/stringprintf.h"
17
18 namespace tracked_objects {
19
20 Location::Location(const char* function_name,
21 const char* file_name,
22 int line_number,
23 const void* program_counter)
24 : function_name_(function_name),
25 file_name_(file_name),
26 line_number_(line_number),
27 program_counter_(program_counter) {
28 }
29
30 Location::Location()
31 : function_name_("Unknown"),
32 file_name_("Unknown"),
33 line_number_(-1),
34 program_counter_(NULL) {
35 }
36
37 std::string Location::ToString() const {
38 return std::string(function_name_) + "@" + file_name_ + ":" +
39 base::IntToString(line_number_);
40 }
41
42 void Location::Write(bool display_filename, bool display_function_name,
43 std::string* output) const {
44 base::StringAppendF(output, "%s[%d] ",
45 display_filename ? file_name_ : "line",
46 line_number_);
47
48 if (display_function_name) {
49 WriteFunctionName(output);
50 output->push_back(' ');
51 }
52 }
53
54 void Location::WriteFunctionName(std::string* output) const {
55 // Translate "<" to "&lt;" for HTML safety.
56 // TODO(jar): Support ASCII or html for logging in ASCII.
57 for (const char *p = function_name_; *p; p++) {
58 switch (*p) {
59 case '<':
60 output->append("&lt;");
61 break;
62
63 case '>':
64 output->append("&gt;");
65 break;
66
67 default:
68 output->push_back(*p);
69 break;
70 }
71 }
72 }
73
74 #if defined(COMPILER_MSVC)
75 __declspec(noinline)
76 #endif
77 BASE_EXPORT const void* GetProgramCounter() {
78 #if defined(COMPILER_MSVC)
79 return _ReturnAddress();
80 #elif defined(COMPILER_GCC)
81 return __builtin_extract_return_addr(__builtin_return_address(0));
82 #endif // COMPILER_GCC
83
84 return NULL;
85 }
86
87 } // namespace tracked_objects
OLDNEW
« no previous file with comments | « base/location.h ('k') | base/message_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698