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

Side by Side Diff: runtime/vm/os_linux.cc

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Format string fixes Created 5 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_LINUX) 6 #if defined(TARGET_OS_LINUX)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <errno.h> // NOLINT 10 #include <errno.h> // NOLINT
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 "Writes jitdump data for profiling with perf annotate"); 42 "Writes jitdump data for profiling with perf annotate");
43 43
44 44
45 class PerfCodeObserver : public CodeObserver { 45 class PerfCodeObserver : public CodeObserver {
46 public: 46 public:
47 PerfCodeObserver() : out_file_(NULL) { 47 PerfCodeObserver() : out_file_(NULL) {
48 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 48 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
49 if (file_open == NULL) { 49 if (file_open == NULL) {
50 return; 50 return;
51 } 51 }
52 const char* format = "/tmp/perf-%" Pd ".map";
53 intptr_t pid = getpid(); 52 intptr_t pid = getpid();
54 intptr_t len = OS::SNPrint(NULL, 0, format, pid); 53 char* filename = NULL;
55 char* filename = new char[len + 1]; 54 SNPRINT(filename, malloc, "/tmp/perf-%" Pd ".map", pid);
56 OS::SNPrint(filename, len + 1, format, pid);
57 out_file_ = (*file_open)(filename, true); 55 out_file_ = (*file_open)(filename, true);
58 delete[] filename; 56 free(filename);
59 } 57 }
60 58
61 ~PerfCodeObserver() { 59 ~PerfCodeObserver() {
62 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 60 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
63 if ((file_close == NULL) || (out_file_ == NULL)) { 61 if ((file_close == NULL) || (out_file_ == NULL)) {
64 return; 62 return;
65 } 63 }
66 (*file_close)(out_file_); 64 (*file_close)(out_file_);
67 } 65 }
68 66
69 virtual bool IsActive() const { 67 virtual bool IsActive() const {
70 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); 68 return FLAG_generate_perf_events_symbols && (out_file_ != NULL);
71 } 69 }
72 70
73 virtual void Notify(const char* name, 71 virtual void Notify(const char* name,
74 uword base, 72 uword base,
75 uword prologue_offset, 73 uword prologue_offset,
76 uword size, 74 uword size,
77 bool optimized) { 75 bool optimized) {
78 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 76 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
79 if ((file_write == NULL) || (out_file_ == NULL)) { 77 if ((file_write == NULL) || (out_file_ == NULL)) {
80 return; 78 return;
81 } 79 }
82 const char* format = "%" Px " %" Px " %s%s\n";
83 const char* marker = optimized ? "*" : ""; 80 const char* marker = optimized ? "*" : "";
84 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); 81 char* buffer = NULL;
85 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 82 SNPRINT(buffer, Thread::Current()->zone()->Alloc<char>,
86 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); 83 "%" Px " %" Px " %s%s\n", base, size, marker, name);
87 { 84 {
88 MutexLocker ml(CodeObservers::mutex()); 85 MutexLocker ml(CodeObservers::mutex());
89 (*file_write)(buffer, len, out_file_); 86 (*file_write)(buffer, strlen(buffer), out_file_);
90 } 87 }
91 } 88 }
92 89
93 private: 90 private:
94 void* out_file_; 91 void* out_file_;
95 92
96 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); 93 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver);
97 }; 94 };
98 95
99 96
100 class GdbCodeObserver : public CodeObserver { 97 class GdbCodeObserver : public CodeObserver {
101 public: 98 public:
102 GdbCodeObserver() { } 99 GdbCodeObserver() { }
103 100
104 virtual bool IsActive() const { 101 virtual bool IsActive() const {
105 return FLAG_generate_gdb_symbols; 102 return FLAG_generate_gdb_symbols;
106 } 103 }
107 104
108 virtual void Notify(const char* name, 105 virtual void Notify(const char* name,
109 uword base, 106 uword base,
110 uword prologue_offset, 107 uword prologue_offset,
111 uword size, 108 uword size,
112 bool optimized) { 109 bool optimized) {
113 if (prologue_offset > 0) { 110 if (prologue_offset > 0) {
114 // In order to ensure that gdb sees the first instruction of a function 111 // In order to ensure that gdb sees the first instruction of a function
115 // as the prologue sequence we register two symbols for the cases when 112 // as the prologue sequence we register two symbols for the cases when
116 // the prologue sequence is not the first instruction: 113 // the prologue sequence is not the first instruction:
117 // <name>_entry is used for code preceding the prologue sequence. 114 // <name>_entry is used for code preceding the prologue sequence.
118 // <name> for rest of the code (first instruction is prologue sequence). 115 // <name> for rest of the code (first instruction is prologue sequence).
119 const char* kFormat = "%s_%s"; 116 char* pname = NULL;
120 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); 117 SNPRINT(pname, Thread::Current()->zone()->Alloc<char>, "%s_%s",
121 char* pname = Thread::Current()->zone()->Alloc<char>(len + 1); 118 name, "entry");
122 OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
123 DebugInfo::RegisterSection(pname, base, size); 119 DebugInfo::RegisterSection(pname, base, size);
124 DebugInfo::RegisterSection(name, 120 DebugInfo::RegisterSection(name,
125 (base + prologue_offset), 121 (base + prologue_offset),
126 (size - prologue_offset)); 122 (size - prologue_offset));
127 } else { 123 } else {
128 DebugInfo::RegisterSection(name, base, size); 124 DebugInfo::RegisterSection(name, base, size);
129 } 125 }
130 } 126 }
131 127
132 private: 128 private:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 struct jr_prefix prefix; 234 struct jr_prefix prefix;
239 uint32_t pid; 235 uint32_t pid;
240 uint32_t tid; 236 uint32_t tid;
241 uint64_t vma; 237 uint64_t vma;
242 uint64_t code_addr; 238 uint64_t code_addr;
243 uint64_t code_size; 239 uint64_t code_size;
244 uint64_t code_index; 240 uint64_t code_index;
245 }; 241 };
246 242
247 const char* GenerateCodeName(const char* name, bool optimized) { 243 const char* GenerateCodeName(const char* name, bool optimized) {
248 const char* format = "%s%s";
249 const char* marker = optimized ? "*" : ""; 244 const char* marker = optimized ? "*" : "";
250 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); 245 char* buffer = NULL;
251 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 246 SNPRINT(buffer, Thread::Current()->zone()->Alloc<char>, "%s%s",
252 OS::SNPrint(buffer, len + 1, format, marker, name); 247 marker, name);
253 return buffer; 248 return buffer;
254 } 249 }
255 250
256 uint32_t GetElfMach() { 251 uint32_t GetElfMach() {
257 #if defined(TARGET_ARCH_IA32) 252 #if defined(TARGET_ARCH_IA32)
258 return kElfMachIA32; 253 return kElfMachIA32;
259 #elif defined(TARGET_ARCH_X64) 254 #elif defined(TARGET_ARCH_X64)
260 return kElfMachX64; 255 return kElfMachX64;
261 #elif defined(TARGET_ARCH_ARM) 256 #elif defined(TARGET_ARCH_ARM)
262 return kElfMachARM; 257 return kElfMachARM;
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 606 }
612 607
613 608
614 void OS::Exit(int code) { 609 void OS::Exit(int code) {
615 exit(code); 610 exit(code);
616 } 611 }
617 612
618 } // namespace dart 613 } // namespace dart
619 614
620 #endif // defined(TARGET_OS_LINUX) 615 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/os_android.cc ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698