Skip to content
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

[Enhancement] Better 'cqsearch.exe' output results #92

Open
pidgeon777 opened this issue Oct 28, 2021 · 3 comments
Open

[Enhancement] Better 'cqsearch.exe' output results #92

pidgeon777 opened this issue Oct 28, 2021 · 3 comments

Comments

@pidgeon777
Copy link

Let consider this command:

cqsearch.exe -s "C:\Work\Test\CodeQuery.db" -p8 -t func_name -f -u

We are searching for all the func_name function calls in the code.

This would be the output:

func_name        C:\Work\Test\main.c:16628     func_name(REG_CHB,&num_bytes);
func_name        C:\Work\Test\main.c:16941     err = func_name(read_reg,&temp);
func_name        C:\Work\Test\utils.c:31   err = func_name(0xD1000A00 , cpu_version);
func_name        C:\Work\Test\utils.c:781  func_name(REG_CHA,value);
func_name        C:\Work\Test\utils.c:783  func_name(REG_CHB,value);

My proposal, and I hope it will be considered, is to replace the first column of the results (consisting in the name of the searched function), with the function name where the call occurs.

Thus, something as follows would be achieved:

main          C:\Work\Test\main.c:16628     func_name(REG_CHB,&num_bytes);
func_b        C:\Work\Test\main.c:16941     err = func_name(read_reg,&temp);
func_b        C:\Work\Test\utils.c:31   err = func_name(0xD1000A00 , cpu_version);
func_c        C:\Work\Test\utils.c:781  func_name(REG_CHA,value);
func_d        C:\Work\Test\utils.c:783  func_name(REG_CHB,value);

This improved output could be applied by adding a new command line switch to the cqsearch.exe executable so that a user could decide if to enable it or not.

Moreover, when searching for symbol occurrences with cqsearch.exe, the possible values for the n switch are:

 1: Symbol (default)                       -> V
 2: Function or macro definition           -> ?
 3: Class or struct                        -> ?
 4: Files including this file              -> X
 5: Full file path                         -> X
 6: Functions calling this function        -> X
 7: Functions called by this function      -> X
 8: Calls of this function or macro        -> V
 9: Members and methods of this class      -> ?
10: Class which owns this member or method -> ?
11: Children of this class (inheritance)   -> ?
12: Parent of this class (inheritance)     -> ?
13: Functions or macros inside this file   -> X

My proposal is to enhance the output for the types marked with V. With the ? symbol I marked the kinds for which I'm not sure the new output format should be applied. Finally, X marks those types for which, in my opinion, the new output format would not make sense.

What do you think, @ruben2020?

@ruben2020
Copy link
Owner

ruben2020 commented Nov 2, 2021

Hi @pidgeon777
It's a bit hard because existing plugins for vim and visual studio code depend on the current output format of cqsearch CLI.
Do you have any use cases for this, from cqsearch CLI?
i think you can get the same information from CodeQuery GUI.

@ruben2020
Copy link
Owner

ruben2020 commented Nov 2, 2021

@pidgeon777
The first column is not redundant. If you do a non-exact search for "button", it will also show "clickbutton", "smallbutton", "buttonclick" and so on.

@pidgeon777
Copy link
Author

Hi @ruben2020

It's a bit hard because existing plugins for vim and visual studio code depend on the current output format of cqsearch CLI.

I think it could be easily solved by adding a further option argument to cqsearch. For example:

-F : Show the function name where the searched symbol/function call occurs.

By doing so, my proposed "enhanced" output format would be enabled only when specifying that switch, leaving the default cqsearch behaviour untouched.

Do you have any use cases for this, from cqsearch CLI?

Yes, cqsearch is very useful for example to look for symbol references or function calls.

Anyway, by also displaying the function where the symbol is referenced and applying some further filtering (for example with grep), it would be very easy to detect:

  • Functions where a symbol is read.
  • Functions where a symbol is written.
  • Functions where a function is called (also doable with Graph mode, but textual through CLI is more powerful under certain circumstances).

For example, one could want to verify that a variable is read or written only in one function, and not in more of them.

Or check in which functions, and how many times, a function is called.

With my proposed output, it would be much easier to check for that, for example.

Finally, with CodeQuery GUI you are limited to the GUI itself.

With cqsearch output results being pure text could be further processed with interesting results.

The first column is not redundant. If you do a non-exact search for "button", it will also show "clickbutton", "smallbutton", "buttonclick" and so on.

My fault. If then, a new column could be added and resulting in this new output:

<Symbol Name>       <Function where it occurs>      <File:line>     <Line Text>

Where <Symbol Name> could be partial or exact.

Again, all of this could be enabled by specifying the -F switch, for example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants