Commit 7e9fc63d authored by yangguo@chromium.org's avatar yangguo@chromium.org

Reorder full code for while loops to better reflect statement positions.

R=jkummerow@chromium.org
BUG=v8:2047
LOG=N

Review URL: https://codereview.chromium.org/353823002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22013 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0bf430c1
...@@ -854,11 +854,6 @@ void FullCodeGenerator::SetExpressionPosition(Expression* expr) { ...@@ -854,11 +854,6 @@ void FullCodeGenerator::SetExpressionPosition(Expression* expr) {
} }
void FullCodeGenerator::SetStatementPosition(int pos) {
CodeGenerator::RecordPositions(masm_, pos);
}
void FullCodeGenerator::SetSourcePosition(int pos) { void FullCodeGenerator::SetSourcePosition(int pos) {
if (pos != RelocInfo::kNoPosition) { if (pos != RelocInfo::kNoPosition) {
masm_->positions_recorder()->RecordPosition(pos); masm_->positions_recorder()->RecordPosition(pos);
...@@ -1283,31 +1278,28 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { ...@@ -1283,31 +1278,28 @@ void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) { void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
Comment cmnt(masm_, "[ WhileStatement"); Comment cmnt(masm_, "[ WhileStatement");
Label test, body; Label loop, body;
Iteration loop_statement(this, stmt); Iteration loop_statement(this, stmt);
increment_loop_depth(); increment_loop_depth();
// Emit the test at the bottom of the loop. __ bind(&loop);
__ jmp(&test);
SetExpressionPosition(stmt->cond());
VisitForControl(stmt->cond(),
&body,
loop_statement.break_label(),
&body);
PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS); PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
__ bind(&body); __ bind(&body);
Visit(stmt->body()); Visit(stmt->body());
// Emit the statement position here as this is where the while
// statement code starts.
__ bind(loop_statement.continue_label()); __ bind(loop_statement.continue_label());
SetStatementPosition(stmt);
// Check stack before looping. // Check stack before looping.
EmitBackEdgeBookkeeping(stmt, &body); EmitBackEdgeBookkeeping(stmt, &loop);
__ jmp(&loop);
__ bind(&test);
VisitForControl(stmt->cond(),
&body,
loop_statement.break_label(),
loop_statement.break_label());
PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS); PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
__ bind(loop_statement.break_label()); __ bind(loop_statement.break_label());
......
...@@ -562,7 +562,6 @@ class FullCodeGenerator: public AstVisitor { ...@@ -562,7 +562,6 @@ class FullCodeGenerator: public AstVisitor {
void SetReturnPosition(FunctionLiteral* fun); void SetReturnPosition(FunctionLiteral* fun);
void SetStatementPosition(Statement* stmt); void SetStatementPosition(Statement* stmt);
void SetExpressionPosition(Expression* expr); void SetExpressionPosition(Expression* expr);
void SetStatementPosition(int pos);
void SetSourcePosition(int pos); void SetSourcePosition(int pos);
// Non-local control flow support. // Non-local control flow support.
......
...@@ -3193,19 +3193,26 @@ TEST(DebugStepWhile) { ...@@ -3193,19 +3193,26 @@ TEST(DebugStepWhile) {
v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo"); v8::Local<v8::Function> foo = CompileFunction(&env, src, "foo");
SetBreakPoint(foo, 8); // "var a = 0;" SetBreakPoint(foo, 8); // "var a = 0;"
// Looping 0 times. We still should break at the while-condition once.
step_action = StepIn;
break_point_hit_count = 0;
v8::Handle<v8::Value> argv_0[argc] = { v8::Number::New(isolate, 0) };
foo->Call(env->Global(), argc, argv_0);
CHECK_EQ(3, break_point_hit_count);
// Looping 10 times. // Looping 10 times.
step_action = StepIn; step_action = StepIn;
break_point_hit_count = 0; break_point_hit_count = 0;
v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) }; v8::Handle<v8::Value> argv_10[argc] = { v8::Number::New(isolate, 10) };
foo->Call(env->Global(), argc, argv_10); foo->Call(env->Global(), argc, argv_10);
CHECK_EQ(22, break_point_hit_count); CHECK_EQ(23, break_point_hit_count);
// Looping 100 times. // Looping 100 times.
step_action = StepIn; step_action = StepIn;
break_point_hit_count = 0; break_point_hit_count = 0;
v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) }; v8::Handle<v8::Value> argv_100[argc] = { v8::Number::New(isolate, 100) };
foo->Call(env->Global(), argc, argv_100); foo->Call(env->Global(), argc, argv_100);
CHECK_EQ(202, break_point_hit_count); CHECK_EQ(203, break_point_hit_count);
// Get rid of the debug event listener. // Get rid of the debug event listener.
v8::Debug::SetDebugEventListener(NULL); v8::Debug::SetDebugEventListener(NULL);
...@@ -5123,10 +5130,7 @@ static void ThreadedMessageHandler(const v8::Debug::Message& message) { ...@@ -5123,10 +5130,7 @@ static void ThreadedMessageHandler(const v8::Debug::Message& message) {
if (IsBreakEventMessage(print_buffer)) { if (IsBreakEventMessage(print_buffer)) {
// Check that we are inside the while loop. // Check that we are inside the while loop.
int source_line = GetSourceLineFromBreakEventMessage(print_buffer); int source_line = GetSourceLineFromBreakEventMessage(print_buffer);
// TODO(2047): This should really be 8 <= source_line <= 13; but we CHECK(8 <= source_line && source_line <= 13);
// currently have an off-by-one error when calculating the source
// position corresponding to the program counter at the debug break.
CHECK(7 <= source_line && source_line <= 13);
threaded_debugging_barriers.barrier_2.Wait(); threaded_debugging_barriers.barrier_2.Wait();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment