diff --git a/libr/core/canal.c b/libr/core/canal.c index 2b90cc0dffa90..2c895a3d24fbc 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -3008,6 +3008,28 @@ static int RAnalRef_compare_by_addr(const RAnalRef *ref1, const RAnalRef *ref2) return 0; } +static double midbbins(RAnalFunction *fcn) { + int bbins = 0; + RAnalBlock *bb; + RListIter *iter; + r_list_foreach (fcn->bbs, iter, bb) { + bbins += bb->ninstr; + } + return (double)bbins / r_list_length (fcn->bbs); +} + +static int maxbbins(RAnalFunction *fcn) { + int bbins = 0; + RAnalBlock *bb; + RListIter *iter; + r_list_foreach (fcn->bbs, iter, bb) { + if (bb->ninstr > bbins) { + bbins = bb->ninstr; + } + } + return bbins; +} + // Lists function names and their calls (uniqified) static int fcn_print_makestyle(RCore *core, RList *fcns, char mode) { RListIter *fcniter; @@ -3162,7 +3184,14 @@ static int fcn_print_json(RCore *core, RAnalFunction *fcn, bool dorefs, PJ *pj) } pj_kn (pj, "minbound", r_anal_function_min_addr (fcn)); pj_kn (pj, "maxbound", r_anal_function_max_addr (fcn)); - + { + int _maxbbins = maxbbins (fcn); + double _midbbins = midbbins (fcn); + double _ratbbins = _maxbbins / _midbbins; + pj_kn (pj, "maxbbins", _maxbbins); + pj_kd (pj, "midbbins", _midbbins); + pj_kd (pj, "ratbbins", _ratbbins); + } int outdegree = 0; int indegree = 0; if (dorefs) { @@ -3533,6 +3562,11 @@ static int fcn_print_legacy(RCore *core, RAnalFunction *fcn, bool dorefs) { } RVecAnalRef_free (refs); } + int a = maxbbins (fcn); + double b = midbbins (fcn); + r_cons_printf ("\nmaxbbins: %d", a); + r_cons_printf ("\nmidbbins: %.02f", b); + r_cons_printf ("\nratbbins: %.02f", ((double)a / b)); r_cons_printf ("\nnoreturn: %s", r_str_bool (fcn->is_noreturn)); r_cons_printf ("\nin-degree: %d", indegree); r_cons_printf ("\nout-degree: %d", outdegree); @@ -3580,6 +3614,9 @@ static int fcn_list_table(RCore *core, const char *q, int fmt) { RTable *t = r_core_table (core, "fcns"); RTableColumnType *typeString = r_table_type ("string"); RTableColumnType *typeNumber = r_table_type ("number"); +#if 0 && R2_USE_NEW_ABI + RTableColumnType *typeFloat = r_table_type ("float"); +#endif r_table_add_column (t, typeNumber, "addr", 0); r_table_add_column (t, typeNumber, "size", 0); r_table_add_column (t, typeString, "name", 0); @@ -3590,6 +3627,11 @@ static int fcn_list_table(RCore *core, const char *q, int fmt) { r_table_add_column (t, typeNumber, "xref", 0); r_table_add_column (t, typeNumber, "axref", 0); r_table_add_column (t, typeNumber, "calls", 0); +#if 0 && R2_USE_NEW_ABI + r_table_add_column (t, typeFloat, "maxbi", 0); + r_table_add_column (t, typeFloat, "midbi", 0); + r_table_add_column (t, typeFloat, "ratbi", 0); +#endif r_table_add_column (t, typeNumber, "cc", 0); r_table_add_column (t, typeNumber, "file", 0); r_list_foreach (core->anal->fcns, iter, fcn) { @@ -3611,7 +3653,6 @@ static int fcn_list_table(RCore *core, const char *q, int fmt) { xrefs = r_anal_function_get_all_xrefs (fcn); snprintf (axref, sizeof (axref), "%"PFMT64u, xrefs ? RVecAnalRef_length (xrefs) : 0); RVecAnalRef_free (xrefs); - RVecAnalRef *calls = r_core_anal_fcn_get_calls (core, fcn); if (calls) { RVecAnalRef_sort (calls, RAnalRef_compare_by_addr); @@ -3626,7 +3667,19 @@ static int fcn_list_table(RCore *core, const char *q, int fmt) { if (!file) { file = strdup (""); } - r_table_add_row (t, fcnAddr, fcnSize, fcn->name, noret, nbbs, nins, refs, xref, axref, castr, ccstr, file, NULL); +#if 0 && R2_USE_NEW_ABI + double _maxbbins = maxbbins (fcn); + double _midbbins = midbbins (fcn); + double _ratbbins = _maxbbins / _midbbins; + r_table_add_row (t, fcnAddr, fcnSize, fcn->name, noret, nbbs, + nins, refs, xref, axref, castr, + _maxbbins, _midbbins, _ratbbins, + ccstr, file, NULL); +#else + r_table_add_row (t, fcnAddr, fcnSize, fcn->name, noret, nbbs, + nins, refs, xref, axref, castr, + ccstr, file, NULL); +#endif free (file); } if (r_table_query (t, q)) { diff --git a/libr/util/pj.c b/libr/util/pj.c index 6260f8142d263..be97f0500f702 100644 --- a/libr/util/pj.c +++ b/libr/util/pj.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2018-2023 - pancake */ +/* radare - LGPL - Copyright 2018-2024 - pancake */ #include #include @@ -322,7 +322,7 @@ R_API PJ *pj_f(PJ *j, float f) { R_API PJ *pj_d(PJ *j, double d) { r_return_val_if_fail (j, NULL); char numstr[64]; - snprintf (numstr, sizeof (numstr), "%lf", d); + snprintf (numstr, sizeof (numstr), "%.03lf", d); pj_comma (j); pj_raw (j, numstr); return j; diff --git a/test/db/anal/msp430 b/test/db/anal/msp430 index 06323ce73ed08..582fda5e423c3 100644 --- a/test/db/anal/msp430 +++ b/test/db/anal/msp430 @@ -47,6 +47,9 @@ minbound: 0x00004438 maxbound: 0x00004476 is-lineal: true end-bbs: 0 +maxbbins: 9 +midbbins: 3.80 +ratbbins: 2.37 noreturn: false in-degree: 0 out-degree: 6 diff --git a/test/db/anal/x86_64 b/test/db/anal/x86_64 index f326cbf587a87..302d99136c6c7 100644 --- a/test/db/anal/x86_64 +++ b/test/db/anal/x86_64 @@ -2705,6 +2705,9 @@ minbound: 0x00000000 maxbound: 0x00000007 is-lineal: true end-bbs: 0 +maxbbins: 1 +midbbins: 0.50 +ratbbins: 2.00 noreturn: false in-degree: 0 out-degree: 0 @@ -2764,6 +2767,9 @@ minbound: 0x00000000 maxbound: 0x0000000d is-lineal: false end-bbs: 1 +maxbbins: 3 +midbbins: 2.50 +ratbbins: 1.20 noreturn: false in-degree: 0 out-degree: 0 @@ -2839,6 +2845,9 @@ minbound: 0x00000000 maxbound: 0x0000000e is-lineal: false end-bbs: 0 +maxbbins: 3 +midbbins: 2.50 +ratbbins: 1.20 noreturn: false in-degree: 0 out-degree: 0 @@ -2922,6 +2931,9 @@ minbound: 0x00000000 maxbound: 0x0000000e is-lineal: false end-bbs: 0 +maxbbins: 3 +midbbins: 1.67 +ratbbins: 1.80 noreturn: false in-degree: 0 out-degree: 0 @@ -3014,6 +3026,9 @@ minbound: 0x00000000 maxbound: 0x00000013 is-lineal: false end-bbs: 0 +maxbbins: 3 +midbbins: 1.75 +ratbbins: 1.71 noreturn: false in-degree: 0 out-degree: 0 diff --git a/test/db/cmd/cmd_af b/test/db/cmd/cmd_af index c853a2c8ff54d..8862339fdd272 100644 --- a/test/db/cmd/cmd_af +++ b/test/db/cmd/cmd_af @@ -307,6 +307,9 @@ minbound: 0x00001119 maxbound: 0x00001133 is-lineal: true end-bbs: 1 +maxbbins: 8 +midbbins: 8.00 +ratbbins: 1.00 noreturn: false in-degree: 1 out-degree: 0 diff --git a/test/db/cmd/cmd_afb b/test/db/cmd/cmd_afb index b56d4364949ed..1771acd27e5f2 100644 --- a/test/db/cmd/cmd_afb +++ b/test/db/cmd/cmd_afb @@ -7,7 +7,7 @@ afi. afb. EOF EXPECT=<