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

Side by Side Diff: test/cctest/test-log-stack-tracer.cc

Issue 2083005: CPU profiler: add secure profiles by filtering out functions using security tokens. (Closed)
Patch Set: Reworded comment Created 10 years, 7 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
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | test/cctest/test-profile-generator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 the V8 project authors. All rights reserved.
2 // 2 //
3 // Tests of profiler-related functions from log.h 3 // Tests of profiler-related functions from log.h
4 4
5 #ifdef ENABLE_LOGGING_AND_PROFILING 5 #ifdef ENABLE_LOGGING_AND_PROFILING
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "v8.h" 9 #include "v8.h"
10 10
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // pure JS code is being executed 59 // pure JS code is being executed
60 static void DoTraceHideCEntryFPAddress(Address fp) { 60 static void DoTraceHideCEntryFPAddress(Address fp) {
61 v8::internal::Address saved_c_frame_fp = *(Top::c_entry_fp_address()); 61 v8::internal::Address saved_c_frame_fp = *(Top::c_entry_fp_address());
62 CHECK(saved_c_frame_fp); 62 CHECK(saved_c_frame_fp);
63 *(Top::c_entry_fp_address()) = 0; 63 *(Top::c_entry_fp_address()) = 0;
64 DoTrace(fp); 64 DoTrace(fp);
65 *(Top::c_entry_fp_address()) = saved_c_frame_fp; 65 *(Top::c_entry_fp_address()) = saved_c_frame_fp;
66 } 66 }
67 67
68 68
69 static void CheckRetAddrIsInFunction(const char* func_name,
70 Address ret_addr,
71 Address func_start_addr,
72 unsigned int func_len) {
73 printf("CheckRetAddrIsInFunction \"%s\": %p %p %p\n",
74 func_name, func_start_addr, ret_addr, func_start_addr + func_len);
75 CHECK_GE(ret_addr, func_start_addr);
76 CHECK_GE(func_start_addr + func_len, ret_addr);
77 }
78
79
80 static void CheckRetAddrIsInJSFunction(const char* func_name,
81 Address ret_addr,
82 Handle<JSFunction> func) {
83 v8::internal::Code* func_code = func->code();
84 CheckRetAddrIsInFunction(
85 func_name, ret_addr,
86 func_code->instruction_start(),
87 func_code->ExecutableSize());
88 }
89
90
91 // --- T r a c e E x t e n s i o n --- 69 // --- T r a c e E x t e n s i o n ---
92 70
93 class TraceExtension : public v8::Extension { 71 class TraceExtension : public v8::Extension {
94 public: 72 public:
95 TraceExtension() : v8::Extension("v8/trace", kSource) { } 73 TraceExtension() : v8::Extension("v8/trace", kSource) { }
96 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 74 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
97 v8::Handle<String> name); 75 v8::Handle<String> name);
98 static v8::Handle<v8::Value> Trace(const v8::Arguments& args); 76 static v8::Handle<v8::Value> Trace(const v8::Arguments& args);
99 static v8::Handle<v8::Value> JSTrace(const v8::Arguments& args); 77 static v8::Handle<v8::Value> JSTrace(const v8::Arguments& args);
100 static v8::Handle<v8::Value> JSEntrySP(const v8::Arguments& args); 78 static v8::Handle<v8::Value> JSEntrySP(const v8::Arguments& args);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 } 180 }
203 181
204 182
205 static Handle<JSFunction> GetGlobalJSFunction(const char* name) { 183 static Handle<JSFunction> GetGlobalJSFunction(const char* name) {
206 Handle<JSFunction> result(JSFunction::cast( 184 Handle<JSFunction> result(JSFunction::cast(
207 *v8::Utils::OpenHandle(*GetGlobalProperty(name)))); 185 *v8::Utils::OpenHandle(*GetGlobalProperty(name))));
208 return result; 186 return result;
209 } 187 }
210 188
211 189
212 static void CheckRetAddrIsInJSFunction(const char* func_name, 190 static void CheckObjectIsJSFunction(const char* func_name,
213 Address ret_addr) { 191 Address addr) {
214 CheckRetAddrIsInJSFunction(func_name, 192 i::Object* obj = reinterpret_cast<i::Object*>(addr);
215 ret_addr, 193 CHECK(obj->IsJSFunction());
216 GetGlobalJSFunction(func_name)); 194 CHECK(JSFunction::cast(obj)->shared()->name()->IsString());
195 i::SmartPointer<char> found_name =
196 i::String::cast(
197 JSFunction::cast(
198 obj)->shared()->name())->ToCString();
199 CHECK_EQ(func_name, *found_name);
217 } 200 }
218 201
219 202
220 static void SetGlobalProperty(const char* name, Local<Value> value) { 203 static void SetGlobalProperty(const char* name, Local<Value> value) {
221 env->Global()->Set(String::New(name), value); 204 env->Global()->Set(String::New(name), value);
222 } 205 }
223 206
224 207
225 static Handle<v8::internal::String> NewString(const char* s) { 208 static Handle<v8::internal::String> NewString(const char* s) {
226 return i::Factory::NewStringFromAscii(i::CStrVector(s)); 209 return i::Factory::NewStringFromAscii(i::CStrVector(s));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 i::EmbeddedVector<char, 256> trace_call_buf; 248 i::EmbeddedVector<char, 256> trace_call_buf;
266 i::OS::SNPrintF(trace_call_buf, "%s(%%_GetFramePointer());", trace_func_name); 249 i::OS::SNPrintF(trace_call_buf, "%s(%%_GetFramePointer());", trace_func_name);
267 250
268 // Compile the script. 251 // Compile the script.
269 i::CodeGeneratorPatcher patcher; 252 i::CodeGeneratorPatcher patcher;
270 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; 253 bool allow_natives_syntax = i::FLAG_allow_natives_syntax;
271 i::FLAG_allow_natives_syntax = true; 254 i::FLAG_allow_natives_syntax = true;
272 Handle<JSFunction> func = CompileFunction(trace_call_buf.start()); 255 Handle<JSFunction> func = CompileFunction(trace_call_buf.start());
273 CHECK(!func.is_null()); 256 CHECK(!func.is_null());
274 i::FLAG_allow_natives_syntax = allow_natives_syntax; 257 i::FLAG_allow_natives_syntax = allow_natives_syntax;
258 func->shared()->set_name(*NewString(func_name));
275 259
276 #ifdef DEBUG 260 #ifdef DEBUG
277 v8::internal::Code* func_code = func->code(); 261 v8::internal::Code* func_code = func->code();
278 CHECK(func_code->IsCode()); 262 CHECK(func_code->IsCode());
279 func_code->Print(); 263 func_code->Print();
280 #endif 264 #endif
281 265
282 SetGlobalProperty(func_name, v8::ToApi<Value>(func)); 266 SetGlobalProperty(func_name, v8::ToApi<Value>(func));
283 CHECK_EQ(*func, *GetGlobalJSFunction(func_name)); 267 CHECK_EQ(*func, *GetGlobalJSFunction(func_name));
284 } 268 }
(...skipping 21 matching lines...) Expand all
306 CHECK(!result.IsEmpty()); 290 CHECK(!result.IsEmpty());
307 // When stack tracer is invoked, the stack should look as follows: 291 // When stack tracer is invoked, the stack should look as follows:
308 // script [JS] 292 // script [JS]
309 // JSTrace() [JS] 293 // JSTrace() [JS]
310 // JSFuncDoTrace() [JS] [captures EBP value and encodes it as Smi] 294 // JSFuncDoTrace() [JS] [captures EBP value and encodes it as Smi]
311 // trace(EBP encoded as Smi) [native (extension)] 295 // trace(EBP encoded as Smi) [native (extension)]
312 // DoTrace(EBP) [native] 296 // DoTrace(EBP) [native]
313 // StackTracer::Trace 297 // StackTracer::Trace
314 CHECK_GT(sample.frames_count, 1); 298 CHECK_GT(sample.frames_count, 1);
315 // Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace" 299 // Stack tracing will start from the first JS function, i.e. "JSFuncDoTrace"
316 CheckRetAddrIsInJSFunction("JSFuncDoTrace", 300 CheckObjectIsJSFunction("JSFuncDoTrace", sample.stack[0]);
317 sample.stack[0]); 301 CheckObjectIsJSFunction("JSTrace", sample.stack[1]);
318 CheckRetAddrIsInJSFunction("JSTrace",
319 sample.stack[1]);
320 } 302 }
321 303
322 304
323 // This test verifies that stack tracing works when called during 305 // This test verifies that stack tracing works when called during
324 // execution of JS code. However, as calling StackTracer requires 306 // execution of JS code. However, as calling StackTracer requires
325 // entering native code, we can only emulate pure JS by erasing 307 // entering native code, we can only emulate pure JS by erasing
326 // Top::c_entry_fp value. In this case, StackTracer uses passed frame 308 // Top::c_entry_fp value. In this case, StackTracer uses passed frame
327 // pointer value as a starting point for stack walking. 309 // pointer value as a starting point for stack walking.
328 TEST(PureJSStackTrace) { 310 TEST(PureJSStackTrace) {
329 TickSample sample; 311 TickSample sample;
(...skipping 22 matching lines...) Expand all
352 // js_trace(EBP encoded as Smi) [native (extension)] 334 // js_trace(EBP encoded as Smi) [native (extension)]
353 // DoTraceHideCEntryFPAddress(EBP) [native] 335 // DoTraceHideCEntryFPAddress(EBP) [native]
354 // StackTracer::Trace 336 // StackTracer::Trace
355 // 337 //
356 // The last JS function called. It is only visible through 338 // The last JS function called. It is only visible through
357 // sample.function, as its return address is above captured EBP value. 339 // sample.function, as its return address is above captured EBP value.
358 CHECK_EQ(GetGlobalJSFunction("JSFuncDoTrace")->address(), 340 CHECK_EQ(GetGlobalJSFunction("JSFuncDoTrace")->address(),
359 sample.function); 341 sample.function);
360 CHECK_GT(sample.frames_count, 1); 342 CHECK_GT(sample.frames_count, 1);
361 // Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace" 343 // Stack sampling will start from the caller of JSFuncDoTrace, i.e. "JSTrace"
362 CheckRetAddrIsInJSFunction("JSTrace", 344 CheckObjectIsJSFunction("JSTrace", sample.stack[0]);
363 sample.stack[0]); 345 CheckObjectIsJSFunction("OuterJSTrace", sample.stack[1]);
364 CheckRetAddrIsInJSFunction("OuterJSTrace",
365 sample.stack[1]);
366 } 346 }
367 347
368 348
369 static void CFuncDoTrace(byte dummy_parameter) { 349 static void CFuncDoTrace(byte dummy_parameter) {
370 Address fp; 350 Address fp;
371 #ifdef __GNUC__ 351 #ifdef __GNUC__
372 fp = reinterpret_cast<Address>(__builtin_frame_address(0)); 352 fp = reinterpret_cast<Address>(__builtin_frame_address(0));
373 #elif defined _MSC_VER 353 #elif defined _MSC_VER
374 // Approximate a frame pointer address. We compile without base pointers, 354 // Approximate a frame pointer address. We compile without base pointers,
375 // so we can't trust ebp/rbp. 355 // so we can't trust ebp/rbp.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 CHECK_EQ(0, GetJsEntrySp()); 388 CHECK_EQ(0, GetJsEntrySp());
409 CompileRun("a = 1; b = a + 1;"); 389 CompileRun("a = 1; b = a + 1;");
410 CHECK_EQ(0, GetJsEntrySp()); 390 CHECK_EQ(0, GetJsEntrySp());
411 CompileRun("js_entry_sp();"); 391 CompileRun("js_entry_sp();");
412 CHECK_EQ(0, GetJsEntrySp()); 392 CHECK_EQ(0, GetJsEntrySp());
413 CompileRun("js_entry_sp_level2();"); 393 CompileRun("js_entry_sp_level2();");
414 CHECK_EQ(0, GetJsEntrySp()); 394 CHECK_EQ(0, GetJsEntrySp());
415 } 395 }
416 396
417 #endif // ENABLE_LOGGING_AND_PROFILING 397 #endif // ENABLE_LOGGING_AND_PROFILING
OLDNEW
« no previous file with comments | « test/cctest/test-cpu-profiler.cc ('k') | test/cctest/test-profile-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698