derickr / vld

BSD 2-Clause "Simplified" License
464 stars 87 forks source link

Recommend to add the parent class info #48

Closed jimmyleeeeee closed 4 years ago

jimmyleeeeee commented 4 years ago

Currently, the class information has been printed one by one. but the relationship is not printed. It is hard to know the relationship between class. I recommend to print the parent class in vld_dump_cle like below: `static int vld_dump_cle (zend_class_entry class_entry TSRMLS_DC) { zend_class_entry ce; zend_bool have_fe = 0; ce = class_entry;

if (ce->type != ZEND_INTERNAL_CLASS) {  
    if (VLD_G(path_dump_file)) {
        fprintf(VLD_G(path_dump_file), "subgraph cluster_class_%s { label=\"class %s\";\n", ZSTRING_VALUE(ce->name), ZSTRING_VALUE(ce->name));
    }

    zend_hash_apply_with_argument(&ce->function_table, (apply_func_arg_t) VLD_WRAP_PHP7(vld_check_fe), (void *)&have_fe TSRMLS_CC);

     if (have_fe) {
        // ============================Added source Begin
        if (ce->parent != NULL) {
            if (ce->ce_flags & ZEND_ACC_RESOLVED_PARENT) {
                vld_printf(stderr, "Parent Class: %s\n", ZSTRING_VALUE(ce->parent->name));
            } else {
                vld_printf(stderr, "Parent Class: %s\n", ZSTRING_VALUE(ce->parent_name));
            }
        }
        // ============================Added source End**
        vld_printf(stderr, "Class %s:\n", ZSTRING_VALUE(ce->name));

        zend_hash_apply_with_arguments(&ce->function_table TSRMLS_CC, (apply_func_args_t) VLD_WRAP_PHP7(vld_dump_fe), 0);
        vld_printf(stderr, "End of class %s.\n\n", ZSTRING_VALUE(ce->name));
    } else {
        vld_printf(stderr, "Class %s: [no user functions]\n", ZSTRING_VALUE(ce->name));
    }

    if (VLD_G(path_dump_file)) {
        fprintf(VLD_G(path_dump_file), "}\n");
    }
}

return ZEND_HASH_APPLY_KEEP;

} ` I am not sure whether the code is OK.

derickr commented 4 years ago

VLD is primarily for dumping opcodes, and it does not try to show all the information about a class. Therefore, I think showing this information is out of scope for VLD.