GCC Middle and Back End API Reference
plugin.c File Reference

Data Structures

struct  event_hasher
struct  callback_info
struct  print_options

Functions

static int htab_str_eq ()
static char * get_plugin_base_name ()
void add_new_plugin ()
void parse_plugin_arg_opt ()
static void register_plugin_info ()
int get_named_event_id ()
void register_callback (const char *plugin_name, int event, plugin_callback_func callback, void *user_data)
int unregister_callback ()
int invoke_plugin_callbacks_full ()
static bool try_init_one_plugin ()
static int init_one_plugin (void **slot, void *ARG_UNUSED(info))
void initialize_plugins ()
static int finalize_one_plugin (void **slot, void *ARG_UNUSED(info))
void finalize_plugins ()
static int print_version_one_plugin ()
void print_plugins_versions ()
static int print_help_one_plugin ()
void print_plugins_help ()
bool plugins_active_p ()
DEBUG_FUNCTION void dump_active_plugins ()
DEBUG_FUNCTION void debug_active_plugins ()
void warn_if_plugins ()
void plugins_internal_error_function (diagnostic_context *context, const char *msgid, va_list *ap)
bool plugin_default_version_check (struct plugin_gcc_version *gcc_version, struct plugin_gcc_version *plugin_version)
int get_event_last ()
const char * default_plugin_dir_name ()

Variables

static const char * plugin_event_name_init []
const char ** plugin_event_name = plugin_event_name_init
static hash_table< event_hasherevent_tab
static int event_last = PLUGIN_EVENT_FIRST_DYNAMIC
static int event_horizon = PLUGIN_EVENT_FIRST_DYNAMIC
static htab_t plugin_name_args_tab = NULL
static struct callback_infoplugin_callbacks_init [PLUGIN_EVENT_FIRST_DYNAMIC]
static struct callback_info ** plugin_callbacks = plugin_callbacks_init
bool flag_plugin_added = false
static const char * str_plugin_init_func_name = "plugin_init"
static const char * str_license = "plugin_is_GPL_compatible"

Function Documentation

void add_new_plugin ( )
Create a plugin_name_args object for the given plugin and insert it
   to the hash table. This function is called when
   -fplugin=/path/to/NAME.so or -fplugin=NAME option is processed.   

References plugin_name_args::base_name, default_plugin_dir_name(), error(), fatal_error(), flag_plugin_added, plugin_name_args::full_name, get_plugin_base_name(), htab_str_eq(), and plugin_name_args_tab.

Referenced by handle_common_deferred_options().

DEBUG_FUNCTION void debug_active_plugins ( void  )
Dump active plugins to stderr.   

References dump_active_plugins().

const char* default_plugin_dir_name ( void  )
Retrieve the default plugin directory.  The gcc driver should have passed
   it as -iplugindir <dir> to the cc1 program, and it is queriable through the
   -print-file-name=plugin option to gcc.   

References fatal_error().

Referenced by add_new_plugin().

DEBUG_FUNCTION void dump_active_plugins ( )
Dump to FILE the names and associated events for all the active
   plugins.   

References event_last, callback_info::next, plugin_event_name, callback_info::plugin_name, and plugins_active_p().

Referenced by debug_active_plugins(), and warn_if_plugins().

static int finalize_one_plugin ( void **  slot,
void *  ARG_UNUSEDinfo 
)
static
Release memory used by one plugin.  

Referenced by finalize_plugins().

void finalize_plugins ( void  )
Free memory allocated by the plugin system.  

References finalize_one_plugin(), and plugin_name_args_tab.

Referenced by toplev_main().

int get_event_last ( void  )
Return the current value of event_last, so that plugins which provide
   additional functionality for events for the benefit of high-level plugins
   know how many valid entries plugin_event_name holds.   

References event_last.

static char* get_plugin_base_name ( )
static
Given a plugin's full-path name FULL_NAME, e.g. /pass/to/NAME.so,
   return NAME.   

References plugin_name_args::base_name, strip_off_ending(), and strlen().

Referenced by add_new_plugin().

static int htab_str_eq ( )
static
Helper function for the hash table that compares the base_name of the
   existing entry (S1) with the given string (S2).   

References plugin_name_args::base_name.

Referenced by add_new_plugin().

static int init_one_plugin ( void **  slot,
void *  ARG_UNUSEDinfo 
)
static
Routine to dlopen and initialize one plugin. This function is passed to
   (and called by) the hash table traverse routine. Return 1 for the
   htab_traverse to continue scan, 0 to stop.

   SLOT - slot of the hash table element
   INFO - auxiliary pointer handed to hash table traverse routine
          (unused in this function)   

References plugin_name_args::base_name, plugin_name_args_tab, and try_init_one_plugin().

Referenced by initialize_plugins().

void initialize_plugins ( void  )
Main plugin initialization function.  Called from compile_file() in
   toplev.c.   

References init_one_plugin(), plugin_name_args_tab, timevar_pop(), and timevar_push().

Referenced by toplev_main().

int invoke_plugin_callbacks_full ( )
Invoke all plugin callbacks registered with the specified event,
   called from invoke_plugin_callbacks().   

References event_last, callback_info::func, callback_info::next, PLUGIN_EVENT_FIRST_DYNAMIC, timevar_pop(), timevar_push(), and callback_info::user_data.

Referenced by invoke_plugin_callbacks().

void parse_plugin_arg_opt ( )
Parse the -fplugin-arg-<name>-<key>[=<value>] option and create a
   'plugin_argument' object for the parsed key-value pair. ARG is
   the <name>-<key>[=<value>] part of the option.   

References plugin_name_args::argc, plugin_name_args::argv, error(), plugin_argument::key, len, memcpy(), plugin_name_args_tab, and plugin_argument::value.

Referenced by handle_common_deferred_options().

bool plugin_default_version_check ( struct plugin_gcc_version gcc_version,
struct plugin_gcc_version plugin_version 
)
bool plugins_active_p ( void  )
Return true if plugins have been loaded.   

References event_last.

Referenced by dump_active_plugins(), and warn_if_plugins().

void plugins_internal_error_function ( diagnostic_context context,
const char *  msgid,
va_list *  ap 
)
Likewise, as a callback from the diagnostics code.   

References warn_if_plugins().

Referenced by general_init().

static int print_help_one_plugin ( )
static
Print help for one plugin. SLOT is the hash table slot. DATA is the
   argument to htab_traverse_noresize.  

References plugin_name_args::base_name, print_options::file, free(), plugin_name_args::help, and print_options::indent.

Referenced by print_plugins_help().

void print_plugins_help ( )
Print help for each plugin. The output goes to FILE and every line starts
   with INDENT.  

References print_options::file, indent, print_options::indent, plugin_name_args_tab, and print_help_one_plugin().

Referenced by toplev_main().

void print_plugins_versions ( )
Print the version of each plugin.  

References print_options::file, indent, print_options::indent, plugin_name_args_tab, and print_version_one_plugin().

Referenced by print_version().

static int print_version_one_plugin ( )
static
void register_callback ( const char *  plugin_name,
int  event,
plugin_callback_func  callback,
void *  user_data 
)
Called from the plugin's initialization code. Register a single callback.
   This function can be called multiple times.

   PLUGIN_NAME - display name for this plugin
   EVENT       - which event the callback is for
   CALLBACK    - the callback to be called at the event
   USER_DATA   - plugin-provided data    

References error(), event_last, callback_info::func, ggc_register_cache_tab(), ggc_register_root_tab(), callback_info::next, PLUGIN_EVENT_FIRST_DYNAMIC, plugin_event_name, callback_info::plugin_name, register_pass(), register_plugin_info(), and callback_info::user_data.

static void register_plugin_info ( )
static
Register additional plugin information. NAME is the name passed to
   plugin_init. INFO is the information that should be registered.  

References plugin_info::help, plugin_name_args::help, plugin_name_args_tab, plugin_info::version, and plugin_name_args::version.

Referenced by register_callback().

static bool try_init_one_plugin ( )
static
Try to initialize PLUGIN. Return true if successful.  

References error(), fatal_error(), plugin_name_args::full_name, plugin_init(), str_license, and str_plugin_init_func_name.

Referenced by init_one_plugin().

int unregister_callback ( )
Remove a callback for EVENT which has been registered with for a plugin
   PLUGIN_NAME.  Return PLUGEVT_SUCCESS if a matching callback was
   found & removed, PLUGEVT_NO_CALLBACK if the event does not have a matching
   callback, and PLUGEVT_NO_SUCH_EVENT if EVENT is invalid.   

References event_last, callback_info::next, and callback_info::plugin_name.

void warn_if_plugins ( void  )
Give a warning if plugins are present, before an ICE message asking
   to submit a bug report.   

References dump_active_plugins(), fnotice(), and plugins_active_p().

Referenced by plugins_internal_error_function().


Variable Documentation

int event_horizon = PLUGIN_EVENT_FIRST_DYNAMIC
static

Referenced by get_named_event_id().

int event_last = PLUGIN_EVENT_FIRST_DYNAMIC
static
Keep track of the limit of allocated events and space ready for
   allocating events.   

Referenced by dump_active_plugins(), get_event_last(), get_named_event_id(), invoke_plugin_callbacks_full(), plugins_active_p(), register_callback(), and unregister_callback().

hash_table<event_hasher> event_tab
static
A hash table to map event names to the position of the names in the
   plugin_event_name table.   
bool flag_plugin_added = false
For invoke_plugin_callbacks(), see plugin.h.   

Referenced by add_new_plugin(), and invoke_plugin_callbacks().

struct callback_info** plugin_callbacks = plugin_callbacks_init
static
struct callback_info* plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC]
static
An array of lists of 'callback_info' objects indexed by the event id.   
const char** plugin_event_name = plugin_event_name_init
All globals declared here have C linkage to reduce link compatibility
   issues with implementation language choice and mangling.   

Referenced by dump_active_plugins(), get_named_event_id(), and register_callback().

const char* plugin_event_name_init[]
static
Initial value:
{
# define DEFEVENT(NAME) GCC_PLUGIN_STRINGIFY1 (NAME),
# include "plugin.def"
# undef DEFEVENT
}
Event names as strings.  Keep in sync with enum plugin_event.   

Referenced by get_named_event_id().

htab_t plugin_name_args_tab = NULL
static
Hash table for the plugin_name_args objects created during command-line
   parsing.   

Referenced by add_new_plugin(), finalize_plugins(), init_one_plugin(), initialize_plugins(), parse_plugin_arg_opt(), print_plugins_help(), print_plugins_versions(), and register_plugin_info().

const char* str_license = "plugin_is_GPL_compatible"
static
Each plugin should define this symbol to assert that it is
   distributed under a GPL-compatible license.   

Referenced by try_init_one_plugin().

const char* str_plugin_init_func_name = "plugin_init"
static
Each plugin should define an initialization function with exactly
   this name.   

Referenced by try_init_one_plugin().