1 // SPDX-License-Identifier: GPL-2.0-or-later 2 #include <subcmd/parse-options.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <objtool/builtin.h> 6 #include <objtool/objtool.h> 7 #include <objtool/klp.h> 8 9 struct subcmd { 10 const char *name; 11 const char *description; 12 int (*fn)(int, const char **); 13 }; 14 15 static struct subcmd subcmds[] = { 16 { "diff", "Generate binary diff of two object files", cmd_klp_diff, }, 17 }; 18 19 static void cmd_klp_usage(void) 20 { 21 fprintf(stderr, "usage: objtool klp <subcommand> [<options>]\n\n"); 22 fprintf(stderr, "Subcommands:\n"); 23 24 for (int i = 0; i < ARRAY_SIZE(subcmds); i++) { 25 struct subcmd *cmd = &subcmds[i]; 26 27 fprintf(stderr, " %s\t%s\n", cmd->name, cmd->description); 28 } 29 30 exit(1); 31 } 32 33 int cmd_klp(int argc, const char **argv) 34 { 35 argc--; 36 argv++; 37 38 if (!argc) 39 cmd_klp_usage(); 40 41 if (argc) { 42 for (int i = 0; i < ARRAY_SIZE(subcmds); i++) { 43 struct subcmd *cmd = &subcmds[i]; 44 45 if (!strcmp(cmd->name, argv[0])) 46 return cmd->fn(argc, argv); 47 } 48 } 49 50 cmd_klp_usage(); 51 return 0; 52 } 53