[Crash-utility] [PATCH] extensions: add extend -s option to show all available shared object file

Dave Anderson anderson at redhat.com
Mon Mar 2 14:54:44 UTC 2020



----- 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.

Hello Wang,

I think this patch is a good idea.  Couple things, though...

Building with "make warn" shows these warnings:

  $ make warn
  ...
  cc -c -g -DX86_64 -DLZO -DSNAPPY -DGDB_7_6  extensions.c -Wall -O2 -Wstrict-prototypes -Wmissing-prototypes -fstack-protector -Wformat-security 
  extensions.c:23:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
   static void show_all_extensions();
   ^
  extensions.c:212:6: warning: no previous prototype for 'show_extensions' [-Wmissing-prototypes]
   void show_extensions(char *dir) {
        ^
  extensions.c: In function 'show_extensions':
  extensions.c:216:6: warning: variable 'found' set but not used [-Wunused-but-set-variable]
    int found;
        ^
  extensions.c: At top level:
  extensions.c:236:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
   show_all_extensions()
   ^
  ...

And secondly, your show_extensions() function doesn't check the
current working directory.  Even though the description below 
only applies when an extension module argument is supplied, it 
makes sense that it should also apply to your -s option:

  $ help extend
  ...
    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:
  
       1. the current working directory
       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
  ... 
  
Thanks,
  Dave



> 
> for example:
> 
> crash> extend -s
> /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"
> 
> Signed-off-by: Wang Long <w at laoqinren.net>
> ---
>  extensions.c | 72
>  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  help.c       |  4 +++-
>  2 files changed, 71 insertions(+), 5 deletions(-)
> 
> diff --git a/extensions.c b/extensions.c
> index 24b91de..bdf9e93 100644
> --- a/extensions.c
> +++ b/extensions.c
> @@ -20,10 +20,12 @@
>  
>  static int in_extensions_library(char *, char *);
>  static char *get_extensions_directory(char *);
> +static void show_all_extensions();
>  
> -#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 +38,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 +71,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 +122,11 @@ cmd_extend(void)
>  			optind++;
>  		}
>  		break;
> +
> +	case SHOW_ALL_EXTENSIONS:
> +		show_all_extensions();
> +		break;
> +
>  	}
>  }
>  
> @@ -182,6 +209,43 @@ dump_extension_table(int verbose)
>  	} while ((ext = ext->prev));
>  }
>  
> +void show_extensions(char *dir) {
> +	DIR *dirp;
> +	struct dirent *dp;
> +	char filename[BUFSIZE*2];
> +	int found;
> +
> +        dirp = opendir(dir);
> +	if (!dirp)
> +		return;
> +
> +        for (found = 0, 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()
> +{
> +	char *dir;
> +
> +	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