From mboxrd@z Thu Jan 1 00:00:00 1970 From: Fernando Nasser To: gdb@sources.redhat.com Subject: RFC: gdbglobals.[ch] Date: Tue, 12 Dec 2000 11:49:00 -0000 Message-id: <3A368138.A7360C4A@cygnus.com> X-SW-Source: 2000-12/msg00071.html I guess you are all aware of the problem we currently have with variables being needed somewhere else and then becoming globals (or spinning off global accessor functions). This is hitting the user interfaces as they have facilities to set/show some of these variables (see, for instance, the inferior_args case). As per Andrew's request, I have wrote down a proposal based on a private conversation we had so that we can see what people think about it. Here it is: GDB GLOBALS =========== GDB "globals" allow gdblib information to be shared with other GDB components, like the user interfaces or script languages. It provides a standard way to access and share data. Data will be registered by the provider and will have a symbolic "name" so that other components interested in accessing it can use this name to request access symbolically. It will also have a "type", which will be (initially) one of: enum var_types { /* "on" or "off". *VAR is an integer which is nonzero for on, zero for off. */ var_boolean, /* "on" / "true" / "enable" or "off" / "false" / "disable" or "auto. *VAR is an ``enum cmd_auto_boolean''. NOTE: In general a custom show command will need to be implemented - one that for "auto" prints both the "auto" and the current auto-selected value. */ var_auto_boolean, /* Unsigned Integer. *VAR is an unsigned int. The user can type 0 to mean "unlimited", which is stored in *VAR as UINT_MAX. */ var_uinteger, /* Like var_uinteger but signed. *VAR is an int. The user can type 0 to mean "unlimited", which is stored in *VAR as INT_MAX. */ var_integer, /* String which the user enters with escapes (e.g. the user types \n and it is a real newline in the stored string). *VAR is a malloc'd string, or NULL if the string is empty. */ var_string, /* String which stores what the user types verbatim. *VAR is a malloc'd string, or NULL if the string is empty. */ var_string_noescape, /* String which stores a filename. *VAR is a malloc'd string, or NULL if the string is empty. */ var_filename, /* ZeroableInteger. *VAR is an int. Like Unsigned Integer except that zero really means zero. */ var_zinteger, /* Enumerated type. Can only have one of the specified values. *VAR is a char pointer to the name of the element that we find. */ var_enum }; The libgdb module registering the global will provide the name, type and address of the data. It can also provide (optionally) a call back routine to be invoked if the data is changed. A handle is returned. The GDB component trying to access the data will request it by name and provide a call back routine (optional) to be invoked when the data changes. It will receive, on success, a handle to be used when invoking the accessor routines. Accessor routines will be provided to set or get the data. Data shall only be accessed through these functions, so proper notification is given to registered consumers. Tentative API: /* Register a global and optionally a callback. */ extern gdb_global_handle gdb_global_register (char *name, enum var_types type, char *addr, const char *enumlist[], gdb_global_callback_ftype notify_me); /* Get handle to access a global and optionally register callback. */ extern gdb_global_handle gdb_global_request (char *name, enum var_types type, gdb_global_callback_ftype notify_me); /* Obtain the current value of a global. */ extern gdb_global_rc gdb_global_get_value (gdb_global_handle global, char **cur_val); /* Obtain all possible values for a var_enum global. Returns pointer to the NULL-terminated list of pointers to the values. */ extern gdb_global_rc gdb_global_get_enum_values (gdb_global_handle global, char **values[]); /* Set a new value in a global and notify consumers. */ extern gdb_global_rc gdb_global_set_value (, char *new_val); /* Replace the global value with a new implementation. Notify consumers. */ extern gdb_global_rc gdb_global_replace (gdb_global_handle global, char *new_addr, const char *enumlist[]); /* Obtain the name, type and current value of a global given the handle. */ extern gdb_global_rc gdb_global_info (gdb_global_handle global, char *name, enum var_types type, char **cur_val); /* Obtain a list of all globals that match a regular expression, with name, type and current value. Returns malloc'ed NULL-terminated list of handles. */ extern gdb_global_rc gdb_global_list (struct re_pattern_buffer *regex, gdb_global_handle **list); /* Callback function type. */ typedef void (gdb_global_callback_ftype) (gdb_global_handle global, gdb_global_handle new_handle); -- Fernando Nasser Red Hat - Toronto E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9