// Copyright 2011 the V8 project authors. All rights reserved. // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // * Neither the name of Google Inc. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Tests of profiler-related functions from log.h #include <stdlib.h> #include "include/v8-function.h" #include "src/api/api-inl.h" #include "src/base/strings.h" #include "src/execution/frames.h" #include "src/execution/isolate.h" #include "src/execution/vm-state-inl.h" #include "src/objects/objects-inl.h" #include "src/profiler/tick-sample.h" #include "test/cctest/cctest.h" #include "test/cctest/trace-extension.h" namespace v8 { namespace internal { static bool IsAddressWithinFuncCode(Tagged<JSFunction> function, Isolate* isolate, void* addr) { … } static bool IsAddressWithinFuncCode(v8::Local<v8::Context> context, Isolate* isolate, const char* func_name, void* addr) { … } // This C++ function is called as a constructor, to grab the frame pointer // from the calling function. When this function runs, the stack contains // a C_Entry frame and a Construct frame above the calling function's frame. static void construct_call(const v8::FunctionCallbackInfo<v8::Value>& info) { … } // Use the API to create a JSFunction object that calls the above C++ function. void CreateFramePointerGrabberConstructor(v8::Local<v8::Context> context, const char* constructor_name) { … } // Creates a global function named 'func_name' that calls the tracing // function 'trace_func_name' with an actual EBP register value, // encoded as one or two Smis. static void CreateTraceCallerFunction(v8::Local<v8::Context> context, const char* func_name, const char* trace_func_name) { … } // This test verifies that stack tracing works when called during // execution of a native function called from JS code. In this case, // TickSample::Trace uses Isolate::c_entry_fp as a starting point for stack // walking. TEST(CFromJSStackTrace) { … } // This test verifies that stack tracing works when called during // execution of JS code. However, as calling TickSample::Trace requires // entering native code, we can only emulate pure JS by erasing // Isolate::c_entry_fp value. In this case, TickSample::Trace uses passed frame // pointer value as a starting point for stack walking. TEST(PureJSStackTrace) { … } static void CFuncDoTrace(uint8_t dummy_param) { … } static int CFunc(int depth) { … } // This test verifies that stack tracing doesn't crash when called on // pure native code. TickSample::Trace only unrolls JS code, so we can't // get any meaningful info here. TEST(PureCStackTrace) { … } TEST(JsEntrySp) { … } } // namespace internal } // namespace v8