Skip to content

Conversation

jaybosamiya
Copy link
Member

This PR makes a lot of changes.

  • Passes are no longer called using --PASS, but instead must be called using -p PASS. This concludes the discussion Discussion: Change to command line arguments #503.
  • The command line grammar is now a single grammar that contains all the possible arguments. This means that when plugins add command line options, these options propagate to the main bap --help. Note that --PLUGIN-help also works, and lists only arguments specific to that plugin, along with its own manpage.
  • Config is now moved completely out of the Self(). In a future PR, Self() will be completely phased out and plugin developers will no longer have to do the "magic" include Self() anymore.
  • Frontends now use a very similar interface to write command line options as Config, but since they would use Frontend.Config, they are allowed to also set up special commands (similar to the way status and add are commands for git). This allows a lot of versatality for frontends.
  • Frontends are allowed to set up positional arguments as well (such as FILE used in bap).
  • Checks are put in so that plugins cannot mess with frontend, and frontend cannot mess with plugin parameters.
  • Update all of our frontends to the new interface.
  • Allows frontends to set up "post-checks" which basically run after plugins are loaded, but before frontend is made ready. This allows to catch errors for things like --rooter etc very early, even though it depends on the plugins finishing off their registrations.
  • Does pre-processing on the command line arguments (but hidden away internally) so that plugin loading is no longer needed to be handled specifically by the frontend (such as the -l, -L etc. options), but is done in advance, and still works perfectly from the grammar.

Note: Some more minor changes and fixes might need to be done, but I am making this PR so that the review process can start off faster. Also, a refactor of the implemntation of Config needs to be done (for minor cleanups) and would be done in a future PR.

Sorry for the noise but this PR is same as #511 but re-opened since Travis could not detect that PR at all.

This basically ensures that the complete name of argument shows up
everywhere, rather than stripped with plugin name (for example,
`--taint-ptr` shows up now, rather than `--ptr`). This will help when
moving to the one-grammar approach.

This also adds the `is_plugin` boolean which makes checking for plugin
or not simple, and makes sure that things are set up correctly (for
example, at deprecation, for front ends).

WARNING! This breaks help pages (i.e. plugins `--<plugin>-help` no
longer works). This will be fixed in a commit soon.
This basically allows frontends to be written in the exact same way as
plugins while still making sure that the grammar is evaluated correctly
Also improve error handling

type action = Keep | Drop

let filter_option options prefix =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we still need this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the filter_option function exists to get rid of --no-PLUGIN type of arguments. If we remove it, then we'll need to add in --no-taint, --no-propagate-taint, --no-ida, etc (i.e. for every plugin). While this would be an easy change to make, it'd cause further bloat to the man page. Are we sure we want to do this? If so, then I can make that change, and remove this completely.

@ivg
Copy link
Member

ivg commented Jul 14, 2016

Some observed bugs:

  1. bap --list-formats doesn't work as expected:
$ bap --list-formats
Config.error> Required argument FILE is missing
  1. printing format choosing doesn't work any more:
$ bap bin/arm-linux-gnueabi-echo -dbir
  1. Man page for the main frontend doesn't contain sections from manpages of the plugins

@jaybosamiya
Copy link
Member Author

As for --list-formats, it is one of those "command" type of params. Now, my initial assumption was the frontends would not have "command" type of params.. One of the ways of doing this is to make a list plugin, which basically does this instead. In fact, to me, it makes sense as a plugin rather than a front end thing. The change needed for allowing --* based commands which override the required positional arguments is such a massively intrusive change that it'd involve changing parts of the Frontend.Config interface (at least as per my understanding, though you might be able to suggest better).

Printing format choosing - I'm going to have to look into it again. I am unable to reproduce the bug on my system. I'll try getting on a completely clean build soon, to see if that ends up reproducing the bug.

Manpage - didn't we decide not to put it in the main manpage (since the manpage explanations can be seen with --PLUGIN-help?) The change to do this will not be to complicated, but would lead to even more bloat on the frontend manpage.

@ivg
Copy link
Member

ivg commented Jul 25, 2016

One of the ways of doing this is to make a list plugin, which basically does this instead.

One of the reasons why it was made on a frontend side is because, this command must be evaluated only when all plugins are loaded. At the time of adding this option, there were no such mechanism, that why I added this option, that naturally belongs to the print plugin. I think it would be indeed a good idea to move this option to a plugin. We should, however decide, whether it should be a print plugin, e.g., --print-formats. Or a list plugin, that will gather all list options, e.g., --list-formats, --list-passes, etc. An argument against the former, is that formats can be added externally, so the listing operation actually exists on a higher level, then the print plugin. An argument against the latter, is that I don't see a clear mechanism for extending it (especially if we will stick to --list-something format, instead of --list=something,else). Another argument against it, is that we cannot make this interface mandatory, so new plugins may forget to use it, and introduce their own mechanisms.

Printing format choosing - I'm going to have to look into it again. I am unable to reproduce the bug on my system.

It might be because, you have a different order of loading... or you forgot to push some fixes ;)

Manpage - didn't we decide not to put it in the main manpage

Did we? Maybe this indeed would be a good idea. As we still have all possible options (so we satisfy the greppable requirement). And we can get an extended information by querying specific plugin for the help, e.g., --<plugin>-help (that satisfies structural requirement). So, indeed it might be a good idea.

Conflicts:
	src/bap_cmdline_terms.ml
	src/bap_main.ml
	src/bap_mc.ml
@ivg
Copy link
Member

ivg commented Aug 8, 2018

@gitoleg, you're the new owner of this PR, so make sure that it is merged, or at least the necessary parts of it are merged. We still have the configuration system broken, and we need it fixed.

@ivg
Copy link
Member

ivg commented Feb 18, 2019

Let's admit we won't merge it and it anyway bitrotten beyond repair. We will be inspired with this code when we will release BAP 2.0.

@ivg ivg closed this Feb 18, 2019
ivg added a commit to XVilka/bap that referenced this pull request Jun 17, 2020
The master branch is already restricted from pushes so the code can reach the master branch only through a pull requested. We don't want to the same work twice.

Also removes (the commented) windows line, we will return it back, once we will have time for that, see also BinaryAnalysisPlatform#512
ivg added a commit that referenced this pull request Jun 17, 2020
* Try to use GitHub Actions

* Fix LLVM installation for Homebrew

* Disable install for now

* MacOS fixes

* Disable Windows for now

* Fix CI

* fixes CI, build on ubuntu only

* launch unit tests after bap installed

* try set cache home dir via env

* wip

* wip

* Grammar eye-candy.

* Try MacOS again

* switches to a non-alternate llvm, removes the LLVM_CONFIG step

First of all, `/usr/local/opt/llvm/bin/llvm-config`
is llvm-config of LLVM that is shipped with MacOS and which is
stripped from any non-native targets so we can't use it. The
requested llvm@9 is installed at `/usr/local/opt/llvm@9` and is not
symlinked to `/usr/local` because it is keg-only:

```
llvm@9 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have llvm@9 first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm@9/bin:$PATH"' >> /Users/runner/.bash_profile

For compilers to find llvm@9 you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm@9/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm@9/include"
```

llvm@10 aka llvm is also keg-only so it will be installed only into
the cellar. I have to guess whether the llvm-config binary will be
named llvm-config or llvm-config-9, but I bet for the former.

* sets TMPDIR env var to pass tests on mac os

* updates testsuite

* do not run on each push

The master branch is already restricted from pushes so the code can reach the master branch only through a pull requested. We don't want to the same work twice.

Also removes (the commented) windows line, we will return it back, once we will have time for that, see also #512

Co-authored-by: oleg <forown@yandex.ru>
Co-authored-by: ivg <ivg@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants