Date: Sat Jul 18 21:26:33 CEST 2009
User: Allister Beharry
Directory: xdebug
Log Message:
[2.1-dev]
- Added additional lines hash to file hash - prefill and count;
- Added accurate setting of line->count and line->executed.
-
Modified files:
xdebug/xdebug_code_coverage.c (version: 1.53.4.3)
xdebug/xdebug_code_coverage.h (version: 1.13.4.2)
[FILE: /xdebug/xdebug_code_coverage.c]
===================================================================
RCS file: cvstemp,v
retrieving revision 1.53.4.2
retrieving revision 1.53.4.3
diff -u -r1.53.4.2 -r1.53.4.3
--- xdebug/xdebug_code_coverage.c:1.53.4.2 Sat Jul 18 05:26:26 2009 GMT
+++ xdebug/xdebug_code_coverage.c Sat Jul 18 17:26:33 2009 GMT
@@ -50,7 +50,7 @@
void xdebug_coverage_line_dtor(void *data)
{
xdebug_coverage_line *line = (xdebug_coverage_line *) data;
- xdebug_hash_destroy(line->instructions);
+ if (line->instructions != NULL) xdebug_hash_destroy(line->instructions);
/*
if (line->decision) {
xdebug_set_free(line->decision_branch1_set);
@@ -73,6 +73,7 @@
{
xdebug_coverage_file *file = (xdebug_coverage_file *) data;
xdebug_hash_destroy(file->functions);
+ xdebug_hash_destroy(file->lines);
xdfree(file->name);
xdfree(file);
}
@@ -81,12 +82,11 @@
{
xdebug_coverage_file *file;
xdebug_coverage_function *function;
- xdebug_coverage_line *line;
+ xdebug_coverage_line *line, *file_line;
xdebug_coverage_instruction *instruction;
zend_op_array *op_array = execute_data->op_array;
zend_op *base_address = &(op_array->opcodes[0]);
int position = (((long) op) - (long) base_address) / sizeof(zend_op), position_in_line;
- int executed;
char *sline = xdebug_sprintf("%d", op->lineno);
char *sposition = xdebug_sprintf("%d", position), *sposition_in_line;
char *filename = op_array->filename;
@@ -111,12 +111,19 @@
php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: function does not exist in hash.");
return;
}
- /* Check if the line exists in the hash */
+ /* Check if the line exists in the function hash */
if (!xdebug_hash_find(function->lines, sline, strlen(sline), (void *) &line)) {
/*bailout: error*/
- php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: line does not exist in hash.");
+ php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: line does not exist in function hash.");
return;
}
+ /* Check if the line exists in the file hash */
+ if (!xdebug_hash_find(file->lines, sline, strlen(sline), (void *) &file_line)) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: line does not exist in file hash.");
+ return;
+ }
+
position_in_line = position - line->previous_total_instructions;
sposition_in_line = xdebug_sprintf("%d", position_in_line);
/* Check if the instruction already exists in the hash */
@@ -126,13 +133,25 @@
return;
}
fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: counting instruction at position %s, position_in_line %s, in line %s.\n", sposition, sposition_in_line, sline);
- executed = instruction->executed;
instruction->count++;
if (instruction->executed == 0) instruction->executed = 1;
- //instruction->execute_data = execute_data;
- if (line->executed == 0) line->executed = 1;
- if (instruction->position == (line->total_instructions - 1)) line->count++; /*only count the line once when the final instruction executes*/
+ line->instructions_counted++;
+ if (instruction->count > line->count)
+ {
+ line->count = instruction->count;
+ file_line->count = instruction->count;
+ }
+ if (instruction->position == (line->total_instructions - 1)) /*end of instructions for line*/
+ {
+ /*only set the executed flag when the final instruction executes*/
+ if (line->executed == 0)
+ {
+ line->executed = 1;
+ file_line->executed = 1;
+ }
+ line->instructions_counted = 0; /*if at end of line reset the instructions_counted counter*/
+ }
if (xdebug_set_in(function->total_branches_set, position)) { /*Instruction is in a decision branch*/
if (!xdebug_set_in(function->branches_counted_set, position)) /*Only increment branches_counted first time counting instructions*/
{
@@ -150,7 +169,7 @@
{
xdebug_coverage_file *file;
xdebug_coverage_function *function;
- xdebug_coverage_line *line;
+ xdebug_coverage_line *line, *file_line;
xdebug_coverage_instruction *instruction;
xdebug_coverage_decision *decision;
zend_op previous_op;
@@ -162,14 +181,12 @@
zend_op *base_address = &(op_array->opcodes[0]);
int num_known_opcodes = sizeof(op_array) / sizeof(op_array[0]);
/*fprintf(stderr, "XDEBUG_CC: prefill_from_opcode: starting...sline = %s sposition = %s filename = %s \n", sline, xdebug_sprintf("%d", position), filename);*/
-
if (op_array->function_name == NULL)
function_name = "0" ;
else
function_name = op_array->function_name ;
/*fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: setting function name to %s...\n", function_name);*/
-
/* Check if the file already exists in the hash */
if (!xdebug_hash_find(XG(code_coverage), filename, strlen(filename), (void *) &file)) {
@@ -177,13 +194,14 @@
file = xdmalloc(sizeof(xdebug_coverage_file));
file->name = xdstrdup(filename);
file->functions = xdebug_hash_alloc(128, xdebug_coverage_function_dtor);
+ file->lines = xdebug_hash_alloc(128, xdebug_coverage_line_dtor);
file->total_branches = 0;
file->branches_counted = 0;
fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: adding file with filename=%s to hash...\n", filename);
xdebug_hash_add(XG(code_coverage), filename, strlen(filename), file);
}
- /* Check if the function already exists in the hash */
+ /* Check if the function already exists in the code coverage hash */
if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) {
*instructions_prefilled = 0;
function = xdmalloc(sizeof(xdebug_coverage_function));
@@ -203,7 +221,7 @@
xdebug_hash_add(file->functions, function_name, strlen(function_name), function);
}
- /* Check if the line already exists in the hash */
+ /* Check if the line already exists in the function hash */
if (!xdebug_hash_find(function->lines, sline, strlen(sline), (void *) &line)) {
*instructions_prefilled = position;
line = xdmalloc(sizeof(xdebug_coverage_line));
@@ -218,9 +236,27 @@
line->decision = 0;
line->decision_branch1_lineno = 0;
line->decision_branch2_lineno = 0;
- fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding line with lineno=%s and instructions_prefilled=%d to hash...\n", sline, *instructions_prefilled);
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding line with lineno=%s and instructions_prefilled=%d to function hash...\n", sline, *instructions_prefilled);
xdebug_hash_add(function->lines, sline, strlen(sline), line);
}
+ /* Check if the line already exists in the file hash */
+ if (!xdebug_hash_find(file->lines, sline, strlen(sline), (void *) &file_line)) {
+ file_line = xdmalloc(sizeof(xdebug_coverage_line));
+ file_line->count = 0;
+ file_line->executed = 0;
+ file_line->lineno = 0;
+ file_line->dead = 0;
+ file_line->instructions = NULL;
+ file_line->instructions_counted = 0;
+ file_line->total_instructions = 0;
+ file_line->previous_total_instructions = *instructions_prefilled;
+ file_line->decision = 0;
+ file_line->decision_branch1_lineno = 0;
+ file_line->decision_branch2_lineno = 0;
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding line with lineno=%s to file hash...\n", sline);
+ xdebug_hash_add(file->lines, sline, strlen(sline), file_line);
+ }
+
position_in_line = position - *instructions_prefilled;
sposition_in_line = xdebug_sprintf("%d", position_in_line);
@@ -247,7 +283,11 @@
fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding instruction with position=%s dead=%d lineno=%s instructions_prefilled=%d position_in_line=%d to line hash...\n", sposition,instruction->dead, sline, *instructions_prefilled, position_in_line);
xdebug_hash_add(line->instructions, sposition_in_line, strlen(sposition_in_line), instruction);
if (line->lineno == 0) line->lineno = instruction->lineno;
+ if (file_line->lineno == 0) file_line->lineno = instruction->lineno;
line->total_instructions++;
+ file_line->total_instructions++;
+ line->dead = deadcode;
+ file_line->dead = deadcode;
xdfree(sposition_in_line);
/*check if this is a decision*/
@@ -302,13 +342,16 @@
xdebug_set_add(function->total_branches_set, jmp_position2);
function->total_branches += 2;
file->total_branches += 2;
- /*Also add the decision to the instruction and the line in the file*/
+ /*Also add the decision to the instruction and the line in the function and file*/
instruction->decision = 1;
instruction->decision_branch1_position = jmp_position1;
instruction->decision_branch2_position = jmp_position2;
line->decision = 1;
line->decision_branch1_lineno = decision->branch1_lineno;
line->decision_branch2_lineno = decision->branch2_lineno;
+ file_line->decision = 1;
+ file_line->decision_branch1_lineno = decision->branch1_lineno;
+ file_line->decision_branch2_lineno = decision->branch2_lineno;
}
xdfree(sline);
@@ -620,7 +663,7 @@
add_assoc_long(line_zval, "lineno", line->lineno);
add_assoc_long(line_zval, "count", line->count);
add_assoc_long(line_zval, "executed", line->executed);
-
+ add_assoc_long(line_zval, "dead", line->dead);
add_assoc_zval(line_zval, "instructions", instructions);
add_index_zval(retval, line->lineno, line_zval);
[FILE: /xdebug/xdebug_code_coverage.h]
===================================================================
RCS file: cvstemp,v
retrieving revision 1.13.4.1
retrieving revision 1.13.4.2
diff -u -r1.13.4.1 -r1.13.4.2
--- xdebug/xdebug_code_coverage.h:1.13.4.1 Fri Jul 17 04:20:58 2009 GMT
+++ xdebug/xdebug_code_coverage.h Sat Jul 18 17:26:33 2009 GMT
@@ -94,14 +94,17 @@
{
char *name;
xdebug_hash *functions;
+ xdebug_hash *lines;
int total_lines;
int lines_counted;
int total_branches;
int branches_counted;
} xdebug_coverage_file;
-void xdebug_coverage_line_dtor(void *data);
void xdebug_coverage_file_dtor(void *data);
+void xdebug_coverage_function_dtor(void *data);
+void xdebug_coverage_line_dtor(void *data);
+void xdebug_coverage_instruction_dtor(void *data);
static void prefill_from_opcode(char *filename, zend_op_array *op_array, zend_op op, unsigned int position, unsigned int *instructions_prefilled, int deadcode TSRMLS_DC);
void xdebug_count_instruction(zend_op *op, zend_execute_data *execute_data TSRMLS_DC);
Received on Sat Jul 18 2009 - 21:27:02 BST
This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST