[Crash-utility] [PATCH V2] extensions: add extend -s option to show all available shared object file
Dave Anderson
anderson at redhat.com
Tue Mar 3 14:49:55 UTC 2020
Thanks Wang -- queued for crash-7.2.9:
https://github.com/crash-utility/crash/commit/5dfbc7aa27392a095b207d31654cec7db94dd810
Dave
----- Original Message -----
> When we load extensions, sometime we do not know the exact name of the shared
> object file.
>
> This patch add -s option for extend cmd to show all available shared object
> file.
>
> for example:
>
> crash> extend -s
> ./trace.so
> /usr/lib64/crash/extensions/dminfo.so
> /usr/lib64/crash/extensions/echo.so
> /usr/lib64/crash/extensions/eppic.so
> /usr/lib64/crash/extensions/snap.so
> /usr/lib64/crash/extensions/trace.so
> ./extensions/dminfo.so
> ./extensions/eppic.so
> ./extensions/echo.so
> ./extensions/snap.so
> ./extensions/trace.so
> crash> extend -s -l
> extend: -l and -s are mutually exclusive
> Usage:
> extend [shared-object ...] | [-u [shared-object ...]] | -s
> Enter "help extend" for details.
> crash> extend -s -u
> extend: -u and -s are mutually exclusive
> Usage:
> extend [shared-object ...] | [-u [shared-object ...]] | -s
> Enter "help extend" for details.
> crash>
>
> Also, this patch update the help for extend command:
> add the search order "5. the ./extensions subdirectory of the current
> directory"
>
> Changes since v1:
> - -s option also check the current working directory
> - fix warning
>
> Signed-off-by: Wang Long <w at laoqinren.net>
> ---
> extensions.c | 75
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> help.c | 4 +++-
> 2 files changed, 74 insertions(+), 5 deletions(-)
>
> diff --git a/extensions.c b/extensions.c
> index 24b91de..d23b1e3 100644
> --- a/extensions.c
> +++ b/extensions.c
> @@ -20,10 +20,13 @@
>
> static int in_extensions_library(char *, char *);
> static char *get_extensions_directory(char *);
> +static void show_all_extensions(void);
> +static void show_extensions(char *);
>
> -#define DUMP_EXTENSIONS (0)
> -#define LOAD_EXTENSION (1)
> -#define UNLOAD_EXTENSION (2)
> +#define DUMP_EXTENSIONS (0)
> +#define LOAD_EXTENSION (1)
> +#define UNLOAD_EXTENSION (2)
> +#define SHOW_ALL_EXTENSIONS (4)
>
> /*
> * Load, unload, or list the extension libaries.
> @@ -36,14 +39,30 @@ cmd_extend(void)
>
> flag = DUMP_EXTENSIONS;
>
> - while ((c = getopt(argcnt, args, "lu")) != EOF) {
> + while ((c = getopt(argcnt, args, "lus")) != EOF) {
> switch(c)
> {
> + case 's':
> + if (flag & UNLOAD_EXTENSION) {
> + error(INFO,
> + "-s and -u are mutually exclusive\n");
> + argerrs++;
> + }else if (flag & LOAD_EXTENSION) {
> + error(INFO,
> + "-s and -l are mutually exclusive\n");
> + argerrs++;
> + } else
> + flag |= SHOW_ALL_EXTENSIONS;
> + break;
> case 'l':
> if (flag & UNLOAD_EXTENSION) {
> error(INFO,
> "-l and -u are mutually exclusive\n");
> argerrs++;
> + } else if (flag & SHOW_ALL_EXTENSIONS) {
> + error(INFO,
> + "-l and -s are mutually exclusive\n");
> + argerrs++;
> } else
> flag |= LOAD_EXTENSION;
> break;
> @@ -53,6 +72,10 @@ cmd_extend(void)
> error(INFO,
> "-u and -l are mutually
> exclusive\n");
> argerrs++;
> + } else if (flag & SHOW_ALL_EXTENSIONS) {
> + error(INFO,
> + "-u and -s are mutually exclusive\n");
> + argerrs++;
> } else
> flag |= UNLOAD_EXTENSION;
> break;
> @@ -100,6 +123,11 @@ cmd_extend(void)
> optind++;
> }
> break;
> +
> + case SHOW_ALL_EXTENSIONS:
> + show_all_extensions();
> + break;
> +
> }
> }
>
> @@ -182,6 +210,45 @@ dump_extension_table(int verbose)
> } while ((ext = ext->prev));
> }
>
> +static void
> +show_extensions(char *dir) {
> + DIR *dirp;
> + struct dirent *dp;
> + char filename[BUFSIZE*2];
> +
> + dirp = opendir(dir);
> + if (!dirp)
> + return;
> +
> + for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
> + sprintf(filename, "%s%s%s", dir,
> + LASTCHAR(dir) == '/' ? "" : "/",
> + dp->d_name);
> +
> + if (!is_shared_object(filename))
> + continue;
> + fprintf(fp, "%s\n", filename);
> + }
> +
> + closedir(dirp);
> +}
> +
> +static void
> +show_all_extensions(void)
> +{
> + char *dir;
> +
> + show_extensions("./");
> +
> + if ((dir = getenv("CRASH_EXTENSIONS")))
> + show_extensions(dir);
> +
> + if (BITS64())
> + show_extensions("/usr/lib64/crash/extensions/");
> +
> + show_extensions("/usr/lib/crash/extensions/");
> + show_extensions("./extensions/");
> +}
>
> /*
> * Load an extension library.
> diff --git a/help.c b/help.c
> index a481850..a0ebe42 100644
> --- a/help.c
> +++ b/help.c
> @@ -2164,13 +2164,14 @@ NULL
> char *help_extend[] = {
> "extend",
> "extend the %s command set",
> -"[shared-object ...] | [-u [shared-object ...]]",
> +"[shared-object ...] | [-u [shared-object ...]] | -s",
> " This command dynamically loads or unloads %s extension shared object",
> " libraries:\n",
> " shared-object load the specified shared object file; more than
> one",
> " one object file may be entered.",
> " -u shared-object unload the specified shared object file; if no file",
> " arguments are specified, unload all objects.",
> +" -s show all available shared object file.",
> "\n If the shared-object filename is not expressed with a fully-qualified",
> " pathname, the following directories will be searched in the order
> shown,",
> " and the first instance of the file that is found will be selected:\n",
> @@ -2178,6 +2179,7 @@ char *help_extend[] = {
> " 2. the directory specified in the CRASH_EXTENSIONS environment
> variable",
> " 3. /usr/lib64/crash/extensions (64-bit architectures)",
> " 4. /usr/lib/crash/extensions",
> +" 5. the ./extensions subdirectory of the current directory",
> "\n If no arguments are entered, the current set of shared object files and
> ",
> " a list of their commands will be displayed. The registered commands",
> " contained in each shared object file will appear automatically in the ",
> --
> 1.8.3.1
>
>
>
>
More information about the Crash-utility
mailing list