2011-12-22 00:17:15 +00:00
|
|
|
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "vm/globals.h"
|
|
|
|
#if defined(TARGET_ARCH_X64)
|
|
|
|
|
|
|
|
#include "vm/debugger.h"
|
|
|
|
|
2012-02-27 22:00:28 +00:00
|
|
|
#include "vm/cpu.h"
|
|
|
|
#include "vm/stub_code.h"
|
|
|
|
|
2011-12-22 00:17:15 +00:00
|
|
|
namespace dart {
|
|
|
|
|
2012-07-03 09:31:44 +00:00
|
|
|
// TODO(hausner): Handle captured variables.
|
2011-12-22 00:17:15 +00:00
|
|
|
RawInstance* ActivationFrame::GetLocalVarValue(intptr_t slot_index) {
|
2012-07-03 09:31:44 +00:00
|
|
|
uword var_address = fp() + slot_index * kWordSize;
|
|
|
|
return reinterpret_cast<RawInstance*>(
|
|
|
|
*reinterpret_cast<uword*>(var_address));
|
2011-12-22 00:17:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-27 22:00:28 +00:00
|
|
|
|
|
|
|
RawInstance* ActivationFrame::GetInstanceCallReceiver(
|
|
|
|
intptr_t num_actual_args) {
|
|
|
|
ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack.
|
|
|
|
// Stack pointer points to last argument that was pushed on the stack.
|
|
|
|
uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize);
|
|
|
|
return reinterpret_cast<RawInstance*>(
|
|
|
|
*reinterpret_cast<uword*>(receiver_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-10 21:06:04 +00:00
|
|
|
RawObject* ActivationFrame::GetClosureObject(intptr_t num_actual_args) {
|
|
|
|
// At a minimum we have the closure object on the stack.
|
|
|
|
ASSERT(num_actual_args > 0);
|
|
|
|
// Stack pointer points to last argument that was pushed on the stack.
|
|
|
|
uword closure_addr = sp() + ((num_actual_args - 1) * kWordSize);
|
|
|
|
return reinterpret_cast<RawObject*>(
|
|
|
|
*reinterpret_cast<uword*>(closure_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-02 18:01:38 +00:00
|
|
|
void CodeBreakpoint::PatchFunctionReturn() {
|
2012-02-27 22:00:28 +00:00
|
|
|
uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13);
|
|
|
|
// movq %rbp,%rsp
|
2012-04-11 18:13:09 +00:00
|
|
|
ASSERT((code[0] == 0x48) && (code[1] == 0x89) && (code[2] == 0xec));
|
2012-02-27 22:00:28 +00:00
|
|
|
ASSERT(code[3] == 0x5d); // popq %rbp
|
|
|
|
ASSERT(code[4] == 0xc3); // ret
|
|
|
|
// Next 8 bytes are nop instructions
|
|
|
|
ASSERT((code[5] == 0x90) && (code[6] == 0x90) &&
|
|
|
|
(code[7] == 0x90) && (code[8] == 0x90) &&
|
|
|
|
(code[9] == 0x90) && (code[10] == 0x90) &&
|
|
|
|
(code[11] == 0x90) && (code[12] == 0x90));
|
|
|
|
// Smash code with call instruction and relative target address.
|
|
|
|
uword stub_addr = StubCode::BreakpointReturnEntryPoint();
|
|
|
|
code[0] = 0x49;
|
|
|
|
code[1] = 0xbb;
|
|
|
|
*reinterpret_cast<uword*>(&code[2]) = stub_addr;
|
|
|
|
code[10] = 0x41;
|
|
|
|
code[11] = 0xff;
|
|
|
|
code[12] = 0xd3;
|
2013-04-23 16:10:22 +00:00
|
|
|
CPU::FlushICache(pc_ - 13, 13);
|
2012-02-27 22:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-02 18:01:38 +00:00
|
|
|
void CodeBreakpoint::RestoreFunctionReturn() {
|
2012-02-27 22:00:28 +00:00
|
|
|
uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13);
|
|
|
|
ASSERT((code[0] == 0x49) && (code[1] == 0xbb));
|
|
|
|
code[0] = 0x48; // movq %rbp,%rsp
|
2012-04-11 18:13:09 +00:00
|
|
|
code[1] = 0x89;
|
|
|
|
code[2] = 0xec;
|
2012-02-27 22:00:28 +00:00
|
|
|
code[3] = 0x5d; // popq %rbp
|
|
|
|
code[4] = 0xc3; // ret
|
|
|
|
code[5] = 0x90; // nop
|
|
|
|
code[6] = 0x90; // nop
|
|
|
|
code[7] = 0x90; // nop
|
|
|
|
code[8] = 0x90; // nop
|
|
|
|
code[9] = 0x90; // nop
|
|
|
|
code[10] = 0x90; // nop
|
|
|
|
code[11] = 0x90; // nop
|
|
|
|
code[12] = 0x90; // nop
|
2013-04-23 16:10:22 +00:00
|
|
|
CPU::FlushICache(pc_ - 13, 13);
|
2012-02-27 22:00:28 +00:00
|
|
|
}
|
|
|
|
|
2011-12-22 00:17:15 +00:00
|
|
|
} // namespace dart
|
|
|
|
|
|
|
|
#endif // defined TARGET_ARCH_X64
|