-
-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor output modes to use enum (#489) #929
Conversation
librz/analysis/meta.c
Outdated
@@ -237,8 +237,8 @@ RZ_API const char *rz_meta_type_to_string(int type) { | |||
return "# unknown meta # "; | |||
} | |||
|
|||
RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { | |||
rz_return_if_fail(!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL | |||
RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode rad, PJ *pj, bool show_full) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to rename variable too rad
-> mode
. And everywhere else you meet unclear name for the mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed rad
to mode
wherever output modes are involved.
@@ -339,7 +339,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 | |||
break; | |||
case 0: | |||
case 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would remove 0 and 1.
@@ -339,7 +339,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 | |||
break; | |||
case 0: | |||
case 1: | |||
case '*': | |||
case RZ_OUTPUT_MODE_RIZIN: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to define this if it goes into the default switch case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I will remove all the three cases.
case 'j': print_types_json(pdb, pj, tpi_stream->types); return; | ||
case 'r': print_types_format(pdb, tpi_stream->types); return; | ||
case RZ_OUTPUT_MODE_JSON: print_types_json(pdb, pj, tpi_stream->types); return; | ||
case RZ_OUTPUT_MODE_RIZIN: print_types_format(pdb, tpi_stream->types); return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure about this switch. what currently does the 'd
' command?
rz_analysis_var_list_show(core->analysis, fcn, 'r', 0, NULL); | ||
rz_analysis_var_list_show(core->analysis, fcn, 'b', RZ_OUTPUT_MODE_QUIET, NULL); | ||
rz_analysis_var_list_show(core->analysis, fcn, 's', RZ_OUTPUT_MODE_QUIET, NULL); | ||
rz_analysis_var_list_show(core->analysis, fcn, 'r', RZ_OUTPUT_MODE_QUIET, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think this should be RZ_OUTPUT_MODE_STANDARD
@@ -4464,11 +4464,11 @@ RZ_API int rz_core_analysis_search(RzCore *core, ut64 from, ut64 to, ut64 ref, i | |||
op.size = 1; | |||
} | |||
break; | |||
case 'r': | |||
case RZ_OUTPUT_MODE_RIZIN: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure this change is correct. that 'r' is a command, not a mode.
@@ -260,7 +260,7 @@ static RzOutputMode suffix2mode(const char *suffix) { | |||
return argv_modes[i].mode; | |||
} | |||
} | |||
return 0; | |||
return RZ_OUTPUT_MODE_QUIET; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this change either.
@@ -1300,8 +1300,8 @@ static void cmd_debug_modules(RzCore *core, int mode) { // "dmm" | |||
pj_end(pj); | |||
} break; | |||
case ':': | |||
case '*': | |||
if (mode == '*' || (mode == ':' && addr >= map->addr && addr < map->addr_end)) { | |||
case 'RZ_OUTPUT_MODE_RIZIN': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change doesn't make sense. the command requires to be splitted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wargio I am sorry but I haven't understood what you mean by "command should be split". Do you mean I should have a separate case for mode == ':'
? Also, I noticed that I have accidentally put RZ_OUTPUT_MODE_RIZIN
in single quotes. I'll change that as well.
RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, int rad, PJ *pj, bool show_full) { | ||
rz_return_if_fail(!(rad == 'j' && !pj)); // rad == 'j' => pj != NULL | ||
RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 size, RzOutputMode mode, PJ *pj, bool show_full) { | ||
rz_return_if_fail(!(mode == RZ_OUTPUT_MODE_JSON && !pj)); // mode == 'j' => pj != NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also update the commentary or just remove it.
@@ -348,7 +348,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 | |||
if (!s) { | |||
s = strdup(pstr); | |||
} | |||
if (rad) { | |||
if (mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be if (mode)
, code doesn't make sense in JSON mode, for example. Lets just use some specific mode here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XVilka Do you mean I should change it to something more specific like if (mode == RZ_OUTPUT_MODE_STANDARD
)?
@@ -370,7 +370,7 @@ RZ_API void rz_meta_print(RzAnalysis *a, RzAnalysisMetaItem *d, ut64 start, ut64 | |||
free(s); | |||
} break; | |||
case RZ_META_TYPE_STRING: | |||
if (rad) { | |||
if (mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here and below.
@@ -306,7 +306,7 @@ RZ_API int rz_bp_list(RzBreakpoint *bp, int rad) { | |||
pj_ks(pj, "data", rz_str_get(b->data)); | |||
pj_ks(pj, "cond", rz_str_get(b->cond)); | |||
pj_end(pj); | |||
} else if (rad) { | |||
} else if (mode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, better to use a switch instead of if
/else
and use specific modes.
@@ -1216,7 +1216,35 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { | |||
} | |||
break; | |||
case 's': | |||
flag_space_stack_list(core->flags, input[2]); | |||
RzOutputMode mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could extract this in a separate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@XVilka I just wanted to confirm one thing. Should I create an RZ_API
defined function in this file that I can then call in every other file as well?
@@ -1456,7 +1484,35 @@ RZ_IPI int rz_cmd_flag(void *data, const char *input) { | |||
free(s); | |||
} | |||
} else { | |||
rz_flag_list(core->flags, *input, input[0] ? input + 1 : ""); | |||
RzOutputMode mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, will also avoid duplication.
if (input[2] == '.') { // "Cs.." | ||
ut64 size; | ||
RzAnalysisMetaItem *mi = rz_meta_get_at(core->analysis, addr, type, &size); | ||
if (mi) { | ||
rz_meta_print(core->analysis, mi, addr, size, input[3], NULL, false); | ||
switch(input[3]){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
ok, here is what i would do, because this PR is quite messy and big even to comment.
you can open a new PR and reference that one to this. |
if you prefer, we can go function by function, so we can guide you towards the resolution of the issue. |
I agree about step-by-step approach, but instead of one function would do one/two files per PR. This way export from this PR is easy - just use |
i'll close this to discuss on the other PR. |
Your checklist for this pull request
Detailed description
Refactored output modes to use enum.
int mode
andchar mode
patterns in the code have been replaced withRzOutputMode
enum type.Refactoring is still in progress.
Test plan
...
Closing issues
closes #489