[xdebug-dev] xdebug xdebug/xdebug_code_coverage.c Formatted according to PHP coding standard.

From: Allister Beharry <allister.beharry[@]gmail.com>
Date: Wed, 2 Sep 2009 05:29:15 +0200

Date: Wed Sep 2 05:29:15 CEST 2009
User: Allister Beharry
Directory: xdebug

Log Message:
[2.1-dev]
Formatted according to PHP coding standard.
-
Modified files:
           xdebug/xdebug_code_coverage.c (version: 1.53.4.5)

[FILE: /xdebug/xdebug_code_coverage.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.53.4.4
retrieving revision 1.53.4.5
diff -u -r1.53.4.4 -r1.53.4.5
--- xdebug/xdebug_code_coverage.c:1.53.4.4 Mon Jul 20 08:34:39 2009 GMT
+++ xdebug/xdebug_code_coverage.c Wed Sep 02 01:29:14 2009 GMT
@@ -29,360 +29,355 @@
 extern void bytekit_build_basic_blocks(zval *return_value, zend_op_array *ops, long flags TSRMLS_DC);
 extern ZEND_DECLARE_MODULE_GLOBALS(xdebug);
 
-void xdebug_coverage_decision_dtor(void *data)
+void xdebug_coverage_decision_dtor(void *data)
 {
         xdebug_coverage_decision *decision = (xdebug_coverage_decision *) data;
- xdfree(decision);
+ xdfree(decision);
 }
 
-void xdebug_coverage_instruction_dtor(void *data)
+void xdebug_coverage_instruction_dtor(void *data)
 {
         xdebug_coverage_instruction *instruction = (xdebug_coverage_instruction *) data;
- xdfree(instruction->opcode_name);
- /*
- if (instruction->decision) {
- xdebug_set_free(instruction->decision_branch1_set);
- xdebug_set_free(instruction->decision_branch2_set);
- }
- */
- xdfree(instruction);
+ xdfree(instruction->opcode_name);
+ /*
+ if (instruction->decision) {
+ xdebug_set_free(instruction->decision_branch1_set);
+ xdebug_set_free(instruction->decision_branch2_set);
+ }
+ */
+ xdfree(instruction);
 }
 
-void xdebug_coverage_line_dtor(void *data)
+void xdebug_coverage_line_dtor(void *data)
 {
         xdebug_coverage_line *line = (xdebug_coverage_line *) data;
- if (line->instructions != NULL) xdebug_hash_destroy(line->instructions);
- /*
- if (line->decision) {
- xdebug_set_free(line->decision_branch1_set);
- xdebug_set_free(line->decision_branch2_set);
- }
- */
+ if (line->instructions != NULL) xdebug_hash_destroy(line->instructions);
+ /*
+ if (line->decision) {
+ xdebug_set_free(line->decision_branch1_set);
+ xdebug_set_free(line->decision_branch2_set);
+ }
+ */
         xdfree(line);
 }
 
 void xdebug_coverage_function_dtor(void *data)
 {
- xdebug_coverage_function *function = (xdebug_coverage_function *) data;
- xdfree(function->name);
+ xdebug_coverage_function *function = (xdebug_coverage_function *) data;
+ xdfree(function->name);
         xdfree(function->filename);
- xdebug_hash_destroy(function->lines);
- xdebug_hash_destroy(function->decisions);
- xdebug_set_free(function->total_branches_set);
- xdebug_set_free(function->branches_counted_set);
+ xdebug_hash_destroy(function->lines);
+ xdebug_hash_destroy(function->decisions);
+ xdebug_set_free(function->total_branches_set);
+ xdebug_set_free(function->branches_counted_set);
 }
 
-void xdebug_coverage_file_dtor(void *data)
+void xdebug_coverage_file_dtor(void *data)
 {
         xdebug_coverage_file *file = (xdebug_coverage_file *) data;
- xdebug_hash_destroy(file->functions);
- xdebug_hash_destroy(file->lines);
+ xdebug_hash_destroy(file->functions);
+ xdebug_hash_destroy(file->lines);
         xdfree(file->name);
         xdfree(file);
 }
 
 void xdebug_count_instruction(zend_op *op, zend_execute_data *execute_data TSRMLS_DC)
 {
- xdebug_coverage_file *file;
- xdebug_coverage_function *function;
+ xdebug_coverage_file *file;
+ xdebug_coverage_function *function;
         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;
+ xdebug_coverage_instruction *instruction;
+ xdebug_coverage_decision *decision;
+ 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;
         char *sline = xdebug_sprintf("%d", op->lineno);
- char *sposition = xdebug_sprintf("%d", position), *sposition_in_line;
- char *filename = op_array->filename;
- char *function_name;
- fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: starting...sline = %s sposition = %s filename = %s \n", sline, sposition, filename);
- if (op_array->type == ZEND_USER_FUNCTION) {
- if ((op_array->function_name == NULL) || (op_array->function_name == 0))
- function_name = "_main" ;
- else
- function_name = op_array->function_name ;
- fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: setting function name to %s...\n", function_name);
- }
- /*fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: starting...sline = %s sposition = %s filename = %s \n", sline, sposition, filename);*/
- if (!xdebug_hash_find(XG(code_coverage), filename, strlen(filename), (void *) &file)) {
- /*bailout: error*/
- php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: file does not exist in hash.");
- return;
- }
- /* Check if the function exists in the hash */
- if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) {
- /*bailout: error*/
- php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: function does not exist in hash.");
- return;
- }
+ char *sposition = xdebug_sprintf("%d", position), *sposition_in_line;
+ char *filename = op_array->filename;
+ char *function_name;
+ fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: starting...sline = %s sposition = %s filename = %s \n", sline, sposition, filename);
+ if ((op->opcode == ZEND_NOP) || (op->opcode == ZEND_EXT_STMT) || (op->opcode == ZEND_EXT_FCALL_BEGIN) || (op->opcode == ZEND_EXT_FCALL_END) || (op->opcode == ZEND_EXT_NOP) || (op->opcode == ZEND_TICKS)) return;
+ if (op_array->type == ZEND_USER_FUNCTION) {
+ if ((op_array->function_name == NULL) || (op_array->function_name == 0))
+ function_name = "_main" ;
+ else
+ function_name = op_array->function_name ;
+ fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: setting function name to %s...\n", function_name);
+ }
+ /*fprintf(stderr, "XDEBUG_CC: xdebug_count_instruction: starting...sline = %s sposition = %s filename = %s \n", sline, sposition, filename);*/
+ if (!xdebug_hash_find(XG(code_coverage), filename, strlen(filename), (void *) &file)) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: file does not exist in hash.");
+ return;
+ }
+ /* Check if the function exists in the hash */
+ if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, "XDEBUG_CC: xdebug_count_instruction: function does not exist in hash.");
+ return;
+ }
         /* 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 function hash.");
- return;
- }
+ /*bailout: error*/
+ 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 */
- if (!xdebug_hash_find(line->instructions, sposition_in_line, strlen(sposition_in_line), (void *) &instruction)) {
                 /*bailout: error*/
- php_error(E_USER_ERROR, xdebug_sprintf("XDEBUG_CC: xdebug_count_instruction: instruction at position %s, position_in_line %s does not exist in hash."), position, position_in_line);
- 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);
- instruction->count++;
- if (instruction->executed == 0) instruction->executed = 1;
- line->instructions_counted++;
-
- if ((position_in_line == 0) &&
- (
- op->opcode == ZEND_JMP ||
- op->opcode == ZEND_JMPZ ||
- op->opcode == ZEND_JMPNZ ||
- op->opcode == ZEND_JMPZ_EX ||
- op->opcode == ZEND_JMPNZ_EX ||
- op->opcode == ZEND_JMPZNZ
- ));
- else
- {
- 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*/
- {
- function->branches_counted++;
- file->branches_counted++;
- xdebug_set_add(function->branches_counted_set, position);
- }
- }
+ 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 */
+ if (!xdebug_hash_find(line->instructions, sposition_in_line, strlen(sposition_in_line), (void *) &instruction)) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, xdebug_sprintf("XDEBUG_CC: xdebug_count_instruction: instruction at position %s, position_in_line %s does not exist in hash."), position, position_in_line);
+ 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);
+ instruction->count++;
+ if (instruction->executed == 0)
+ instruction->executed = 1;
+ line->instructions_counted++;
+
+ if ((position_in_line == 0) &&
+ (
+ op->opcode == ZEND_JMP ||
+ op->opcode == ZEND_JMPZ ||
+ op->opcode == ZEND_JMPNZ ||
+ op->opcode == ZEND_JMPZ_EX ||
+ op->opcode == ZEND_JMPNZ_EX ||
+ op->opcode == ZEND_JMPZNZ
+ ));
+ else { /*Executes only if the above condition is not satisfied*/
+ 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*/
+ function->branches_counted++;
+ file->branches_counted++;
+ xdebug_set_add(function->branches_counted_set, position);
+ }
+ }
         xdfree(sline);
- xdfree(sposition);
- xdfree(sposition_in_line);
+ xdfree(sposition);
+ xdfree(sposition_in_line);
 }
 
 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)
 {
- xdebug_coverage_file *file;
- xdebug_coverage_function *function;
- xdebug_coverage_line *line, *file_line;
- xdebug_coverage_instruction *instruction;
- xdebug_coverage_decision *decision;
- zend_op previous_op;
- zval *basic_blocks_file, *basic_blocks_function;
- zval **basic_blocks_file_P;
- int position_in_line;
- unsigned int jmp_position1 = 0, jmp_position2 = 0;
- char *function_name;
- char *sline = xdebug_sprintf("%d", op.lineno);
- char *sposition = xdebug_sprintf("%d", position), *sposition_in_line;
- 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) || (op_array->function_name == 0))
- function_name = "_main" ;
- 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)) {
- /* The file does not exist, so we add it to the hash, and add a functions element to the file */
- 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);
- MAKE_STD_ZVAL(basic_blocks_file);
- array_init(basic_blocks_file);
- add_assoc_zval_ex(XG(code_coverage_basic_blocks), file->name, strlen(file->name) + 1, basic_blocks_file);
+ xdebug_coverage_file *file;
+ xdebug_coverage_function *function;
+ xdebug_coverage_line *line, *file_line;
+ xdebug_coverage_instruction *instruction;
+ xdebug_coverage_decision *decision;
+ zend_op previous_op;
+ zval *basic_blocks_file, *basic_blocks_function;
+ zval **basic_blocks_file_P;
+ int position_in_line;
+ unsigned int jmp_position1 = 0, jmp_position2 = 0;
+ char *function_name;
+ char *sline = xdebug_sprintf("%d", op.lineno);
+ char *sposition = xdebug_sprintf("%d", position), *sposition_in_line;
+ 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) || (op_array->function_name == 0))
+ function_name = "_main" ;
+ 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)) {
+ /* The file does not exist, so we add it to the hash, and add a functions element to the file */
+ 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);
+ MAKE_STD_ZVAL(basic_blocks_file);
+ array_init(basic_blocks_file);
+ add_assoc_zval_ex(XG(code_coverage_basic_blocks), file->name, strlen(file->name) + 1, basic_blocks_file);
          }
 
- /* 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));
- function->name = xdstrdup(function_name);
- function->filename = xdstrdup(filename);
- function->dead = 0;
- function->count = 0;
- function->executed = 0;
- function->lines = xdebug_hash_alloc(128, xdebug_coverage_line_dtor);
- function->total_lines = 0;
- function->lines_counted = 0;
- function->decisions = xdebug_hash_alloc(128, xdebug_coverage_decision_dtor);
- function->total_branches_set = xdebug_set_create(op_array->last);
- function->total_branches = 0;
- function->branches_counted = 0;
- function->branches_counted_set = xdebug_set_create(op_array->last);
- fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: adding function with name=%s to hash...\n", function->name);
- xdebug_hash_add(file->functions, function_name, strlen(function_name), function);
- if (zend_hash_find(HASH_OF(XG(code_coverage_basic_blocks)), file->name, strlen(file->name) + 1, (void **) &basic_blocks_file_P) != SUCCESS) {
- /*bailout: error*/
- php_error(E_USER_ERROR, xdebug_sprintf("XDEBUG_CC: xdebug_prefill_opcode: could not find %s in basic blocks.", file->name));
- return;
- }
- MAKE_STD_ZVAL(basic_blocks_function);
- array_init(basic_blocks_function);
- bytekit_build_basic_blocks(basic_blocks_function, op_array, 0 TSRMLS_CC);
- fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: adding function with name=%s to basic blocks...\n", function->name);
- add_assoc_zval_ex(*basic_blocks_file_P, function->name, strlen(function->name) + 1, basic_blocks_function);
- }
+ /* 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));
+ function->name = xdstrdup(function_name);
+ function->filename = xdstrdup(filename);
+ function->dead = 0;
+ function->count = 0;
+ function->executed = 0;
+ function->lines = xdebug_hash_alloc(128, xdebug_coverage_line_dtor);
+ function->total_lines = 0;
+ function->lines_counted = 0;
+ function->decisions = xdebug_hash_alloc(128, xdebug_coverage_decision_dtor);
+ function->total_branches_set = xdebug_set_create(op_array->last);
+ function->total_branches = 0;
+ function->branches_counted = 0;
+ function->branches_counted_set = xdebug_set_create(op_array->last);
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: adding function with name=%s to hash...\n", function->name);
+ xdebug_hash_add(file->functions, function_name, strlen(function_name), function);
+ if (zend_hash_find(HASH_OF(XG(code_coverage_basic_blocks)), file->name, strlen(file->name) + 1, (void **) &basic_blocks_file_P) != SUCCESS) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, xdebug_sprintf("XDEBUG_CC: xdebug_prefill_opcode: could not find %s in basic blocks.", file->name));
+ return;
+ }
+ MAKE_STD_ZVAL(basic_blocks_function);
+ array_init(basic_blocks_function);
+ bytekit_build_basic_blocks(basic_blocks_function, op_array, 0 TSRMLS_CC);
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: adding function with name=%s to basic blocks...\n", function->name);
+ add_assoc_zval_ex(*basic_blocks_file_P, function->name, strlen(function->name) + 1, basic_blocks_function);
+ }
 
- /* 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));
- line->count = 0;
- line->executed = 0;
- line->lineno = 0;
- line->dead = 0;
- line->instructions_counted = 0;
- line->total_instructions = 0;
- line->previous_total_instructions = *instructions_prefilled;
- line->instructions = xdebug_hash_alloc(16, xdebug_coverage_instruction_dtor); /* can be less if max instructions per line < 8*/
- 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 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);
- }
+ /* 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));
+ line->count = 0;
+ line->executed = 0;
+ line->lineno = 0;
+ line->dead = 0;
+ line->instructions_counted = 0;
+ line->total_instructions = 0;
+ line->previous_total_instructions = *instructions_prefilled;
+ line->instructions = xdebug_hash_alloc(16, xdebug_coverage_instruction_dtor); /* can be less if max instructions per line < 8*/
+ 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 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);
+ position_in_line = position - *instructions_prefilled;
+ sposition_in_line = xdebug_sprintf("%d", position_in_line);
  
- /* Check if the instruction already exists in the hash */
- if (xdebug_hash_find(line->instructions, sposition_in_line, strlen(sposition_in_line), (void *) &instruction)) {
- /*bailout: error*/
- php_error(E_USER_ERROR, "XDEBUG_CC: prefill_from_opcode: instruction already exists in line hash.");
- return;
- }
- /*Add the instruction to the line*/
- instruction = xdmalloc(sizeof(xdebug_coverage_instruction));
- if (op.opcode < 150)
- instruction->opcode_name = xdstrdup(opcodes[op.opcode].name);
- else instruction->opcode_name = xdstrdup("UNKNOWN");
- instruction->op = op;
- instruction->position = position_in_line;
- instruction->count = 0;
- instruction->dead = deadcode;
- instruction->executed = 0;
- instruction->lineno = op.lineno;
- instruction->decision = 0;
- instruction->decision_branch1_position = 0;
- instruction->decision_branch2_position = 0;
- 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 the instruction already exists in the hash */
+ if (xdebug_hash_find(line->instructions, sposition_in_line, strlen(sposition_in_line), (void *) &instruction)) {
+ /*bailout: error*/
+ php_error(E_USER_ERROR, "XDEBUG_CC: prefill_from_opcode: instruction already exists in line hash.");
+ return;
+ }
+ /*Add the instruction to the line*/
+ instruction = xdmalloc(sizeof(xdebug_coverage_instruction));
+ if (op.opcode < 150)
+ instruction->opcode_name = xdstrdup(opcodes[op.opcode].name);
+ else
+ instruction->opcode_name = xdstrdup("UNKNOWN");
+ instruction->op = op;
+ instruction->position = position_in_line;
+ instruction->count = 0;
+ instruction->dead = deadcode;
+ instruction->executed = 0;
+ instruction->lineno = op.lineno;
+ instruction->decision = 0;
+ instruction->decision_branch1_position = 0;
+ instruction->decision_branch2_position = 0;
+ 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*/
- if (
- op.opcode == ZEND_JMPZ ||
- op.opcode == ZEND_JMPNZ ||
- op.opcode == ZEND_JMPZ_EX ||
- op.opcode == ZEND_JMPNZ_EX ||
- op.opcode == ZEND_JMPZNZ)
- {
- previous_op = op_array->opcodes[position - 1];
- if (previous_op.opcode == ZEND_EXT_STMT) previous_op = op_array->opcodes[position - 2];
- /*if (
- previous_op.opcode == ZEND_IS_SMALLER ||
- previous_op.opcode == ZEND_IS_IDENTICAL ||
- previous_op.opcode == ZEND_IS_NOT_IDENTICAL ||
- previous_op.opcode == ZEND_IS_EQUAL ||
- previous_op.opcode == ZEND_IS_NOT_EQUAL ||
- previous_op.opcode == ZEND_IS_SMALLER)
- */
- if (1) /*Bypass this test for now - assume every JMPZ et.al is a branch*/
- {
- if (op.opcode == ZEND_JMPZ || op.opcode == ZEND_JMPNZ || op.opcode == ZEND_JMPZ_EX || op.opcode == ZEND_JMPNZ_EX)
- {
- jmp_position1 = position + 1;
- #ifdef ZEND_ENGINE_2
- jmp_position2 = ((long) op.op2.u.jmp_addr - (long) base_address) / sizeof(zend_op);
- #else
- jmp_position2 = op.op1.u.opline_num;
- #endif
- }
- else/*ZEND_JMPZNZ*/
- {
- jmp_position1 = op.op2.u.opline_num;
- jmp_position2 = op.extended_value;
- }
- }
- fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: Found decision with position=%s jmp1=%d jmp2=%d.\n", sposition, jmp_position1, jmp_position2);
- /*Create a decision andd add it to the function*/
- decision = xdmalloc(sizeof(xdebug_coverage_decision));
- decision->instruction_position = position;
- decision->lineno = op.lineno;
- decision->branch1_position = jmp_position1;
- decision->branch1_lineno = op_array->opcodes[jmp_position1].lineno;
- decision->branch1_set = xdebug_set_create(op_array->last);
- decision->branch2_position = jmp_position2;
- decision->branch2_lineno = op_array->opcodes[jmp_position2].lineno;
- decision->branch2_set = xdebug_set_create(op_array->last);
- fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding decision with position=%d branch1_position=%d branch2_position=%d to hash...\n", position, jmp_position1, jmp_position2);
- xdebug_hash_add(function->decisions, sposition, strlen(sposition), decision);
- xdebug_set_add(function->total_branches_set, jmp_position1);
- 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 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;
+ /*check if this is a decision*/
+ if (
+ op.opcode == ZEND_JMPZ ||
+ op.opcode == ZEND_JMPNZ ||
+ op.opcode == ZEND_JMPZ_EX ||
+ op.opcode == ZEND_JMPNZ_EX ||
+ op.opcode == ZEND_JMPZNZ
+ ) {
+ previous_op = op_array->opcodes[position - 1];
+ if (previous_op.opcode == ZEND_EXT_STMT) previous_op = op_array->opcodes[position - 2];
+ /*if (
+ previous_op.opcode == ZEND_IS_SMALLER ||
+ previous_op.opcode == ZEND_IS_IDENTICAL ||
+ previous_op.opcode == ZEND_IS_NOT_IDENTICAL ||
+ previous_op.opcode == ZEND_IS_EQUAL ||
+ previous_op.opcode == ZEND_IS_NOT_EQUAL ||
+ previous_op.opcode == ZEND_IS_SMALLER)
+ */
+ if (1) /*Bypass this test for now - assume every JMPZ et.al is a branch*/ {
+ if (op.opcode == ZEND_JMPZ || op.opcode == ZEND_JMPNZ || op.opcode == ZEND_JMPZ_EX || op.opcode == ZEND_JMPNZ_EX) {
+ jmp_position1 = position + 1;
+#ifdef ZEND_ENGINE_2
+ jmp_position2 = ((long) op.op2.u.jmp_addr - (long) base_address) / sizeof(zend_op);
+#else
+ jmp_position2 = op.op1.u.opline_num;
+#endif
+ }
+ else/*ZEND_JMPZNZ*/ {
+ jmp_position1 = op.op2.u.opline_num;
+ jmp_position2 = op.extended_value;
+ }
+ }
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode: Found decision with position=%s jmp1=%d jmp2=%d.\n", sposition, jmp_position1, jmp_position2);
+ /*Create a decision andd add it to the function*/
+ decision = xdmalloc(sizeof(xdebug_coverage_decision));
+ decision->instruction_position = position;
+ decision->lineno = op.lineno;
+ decision->executed = 0;
+ decision->branch1_position = jmp_position1;
+ decision->branch1_lineno = op_array->opcodes[jmp_position1].lineno;
+ decision->branch1_executed = 0;
+ decision->branch1_set = xdebug_set_create(op_array->last);
+ decision->branch2_position = jmp_position2;
+ decision->branch2_lineno = op_array->opcodes[jmp_position2].lineno;
+ decision->branch2_executed = 0;
+ decision->branch2_set = xdebug_set_create(op_array->last);
+ fprintf(stderr, "XDEBUG_CC: xdebug_prefill_opcode adding decision with position=%d branch1_position=%d branch2_position=%d to hash...\n", position, jmp_position1, jmp_position2);
+ xdebug_hash_add(function->decisions, sposition, strlen(sposition), decision);
+ xdebug_set_add(function->total_branches_set, jmp_position1);
+ 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 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;
   }
@@ -542,7 +537,6 @@
 #endif
 
         /* Run dead code analysis if requested */
-
         if (XG(code_coverage_dead_code_analysis) && opa->done_pass_two) {
                 set = xdebug_set_create(opa->last);
                 xdebug_analyse_branch(opa, 0, set);
@@ -551,7 +545,7 @@
         /* The normal loop then finally */
         for (i = 0; i < opa->last; i++) {
                 zend_op opcode = opa->opcodes[i];
- fprintf(stderr, "XDEBUG_CC: prefill_from_oparray: calling prefill_from_opcode for opcode %d.\n", i);
+ fprintf(stderr, "XDEBUG_CC: prefill_from_oparray: calling prefill_from_opcode for opcode %d.\n", i);
                 prefill_from_opcode(fn, opa, opcode, i, &j, set ? !xdebug_set_in(set, i) : 0 TSRMLS_CC);
         }
 
@@ -581,9 +575,7 @@
 {
         char *new_filename;
         zend_class_entry *ce;
-
         ce = *class_entry;
-
         new_filename = va_arg(args, char*);
         if (ce->type == ZEND_USER_CLASS) {
                 if (!(ce->ce_flags & ZEND_XDEBUG_VISITED)) {
@@ -660,6 +652,28 @@
         }
 }
 
+static void add_decision(void *ret, xdebug_hash_element *e)
+{
+ xdebug_coverage_decision *decision = (xdebug_coverage_decision*) e->ptr;
+ zval *retval = (zval*) ret;
+ zval *decision_zval;
+
+ TSRMLS_FETCH();
+ MAKE_STD_ZVAL(decision_zval);
+ array_init(decision_zval);
+
+ add_assoc_long(decision_zval, "lineno", decision->lineno);
+ add_assoc_long(decision_zval, "instruction position", decision->instruction_position);
+ add_assoc_long(decision_zval, "executed", decision->executed);
+ add_assoc_long(decision_zval, "branch1_lineno", decision->branch1_lineno);
+ add_assoc_long(decision_zval, "branch1_position", decision->branch1_position);
+ /*add_assoc_long(decision_zval, "branch1_executed", decision->branch1_executed);*/
+ add_assoc_long(decision_zval, "branch2_lineno", decision->branch2_lineno);
+ add_assoc_long(decision_zval, "branch2_position", decision->branch2_position);
+ /*add_assoc_long(decision_zval, "branch2_executed", decision->branch2_executed);*/
+ add_index_zval(retval, decision->lineno, decision_zval);
+}
+
 static void add_instruction(void *ret, xdebug_hash_element *e)
 {
  xdebug_coverage_instruction *instruction = (xdebug_coverage_instruction*) e->ptr;
@@ -716,20 +730,24 @@
  
  if (XG(code_coverage_line_coverage_ex) || XG(code_coverage_dump_instructions)) add_index_zval(retval, line->lineno, line_zval);
 }
-
+
 static void add_cc_function(void *ret, xdebug_hash_element *e)
 {
  xdebug_coverage_function *function = (xdebug_coverage_function*) e->ptr;
  zval *retval = (zval*) ret;
  zval *lines;
+ zval *decisions;
  zval *function_zval;
  zval **file_P;
  zval **basic_blocks_function_P;
  HashTable *target_hash;
+ HashTable *target_hash2;
 
  TSRMLS_FETCH();
  MAKE_STD_ZVAL(lines);
  array_init(lines);
+ MAKE_STD_ZVAL(decisions);
+ array_init(decisions);
  MAKE_STD_ZVAL(function_zval);
  array_init(function_zval);
 
@@ -744,7 +762,12 @@
  //if (XG(code_coverage_branch_coverage)) add_assoc_zval_ex(function_zval, "basic blocks", strlen("basic blocks") + 1, XG(code_coverage_basic_blocks));
  if (XG(code_coverage_branch_coverage))
  {
- add_assoc_long(function_zval, "total_branches", function->total_branches);
+ xdebug_hash_apply(function->decisions, (void *) decisions, add_decision);
+ /* Sort on linenumber */
+ target_hash2 = HASH_OF(decisions);
+ zend_hash_sort(target_hash2, zend_qsort, xdebug_lineno_cmp, 0 TSRMLS_CC);
+ add_assoc_zval_ex(function_zval, "decisions", strlen("decisions") + 1, decisions);
+ add_assoc_long(function_zval, "total_branches", function->total_branches);
   add_assoc_long(function_zval, "branches_counted", function->branches_counted);
   if (zend_hash_find(HASH_OF(XG(code_coverage_basic_blocks)), function->filename, strlen(function->filename) + 1, (void **) &file_P) != SUCCESS)
   {
@@ -786,13 +809,6 @@
         if (XG(code_coverage_branch_coverage))
         {
    add_assoc_zval_ex(file_zval, "functions", strlen("functions") + 1, functions);
- if (zend_hash_find(HASH_OF(XG(code_coverage_basic_blocks)), file->name, strlen(file->name) + 1, (void **) &file_basic_blocks_P) != SUCCESS)
- {
- /*bailout: error*/
- php_error(E_USER_ERROR, xdebug_sprintf("XDEBUG_CC: add_file: could not find file %s in basic blocks hash.", file->name));
- return;
- }
- add_assoc_zval_ex(file_zval, "basic blocks", strlen("basic blocks") + 1, *file_basic_blocks_P);
    add_assoc_zval_ex(retval, file->name, strlen(file->name) + 1, file_zval);
         }
         else
Received on Wed Sep 02 2009 - 05:37:58 BST

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST