aboutsummaryrefslogtreecommitdiff
path: root/gdb/infcall.c
diff options
context:
space:
mode:
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-04-23 23:43:24 +0200
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>2019-04-27 13:12:42 +0200
commit136afab8c7d8a8a91dbf38e79be4f9dc4125d552 (patch)
tree2d6f40d947a3fa3a627cf6b7d0b360f4174d10de /gdb/infcall.c
parenta45328b93bdd5399da8a9e56817e445cc2068edd (diff)
downloadgdb-136afab8c7d8a8a91dbf38e79be4f9dc4125d552.zip
gdb-136afab8c7d8a8a91dbf38e79be4f9dc4125d552.tar.gz
gdb-136afab8c7d8a8a91dbf38e79be4f9dc4125d552.tar.bz2
Implement show | set may-call-functions [on|off]
Inferior function calls are powerful but might lead to undesired results such as crashes when calling nested functions (frequently used in particular in Ada). This implements a GDB setting to disable calling inferior functions. Note: the idea is that if/when the 'slash command' patch is pushed, that this setting can be changed e.g. by using the shortcut /c. This is version 2 of the patch. It handles all the received comments, mostly replace 'can-call' by 'may-call', and avoid using 'inferior function call' in factor of 'calling function in the program'. 2019-04-26 Philippe Waroquiers <philippe.waroquiers@skynet.be> gdb/ChangeLog * NEWS: Mention the new set|show may-call-functions. * infcall.c (may_call_functions_p): New variable. (show_may_call_functions_p): New function. (call_function_by_hand_dummy): Throws an error if not may-call-functions. (_initialize_infcall): Call add_setshow_boolean_cmd for may-call-functions. gdb/testsuite/ChangeLog * gdb.base/callexit.exp: Test may-call-functions off. gdb/doc/ChangeLog * gdb.texinfo (Calling): Document the new set|show may-call-functions.
Diffstat (limited to 'gdb/infcall.c')
-rw-r--r--gdb/infcall.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gdb/infcall.c b/gdb/infcall.c
index af60fdc..f99206c 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -55,6 +55,17 @@
asynchronous inferior function call implementation, and that in
turn means restructuring the code so that it is event driven. */
+static int may_call_functions_p = 1;
+static void
+show_may_call_functions_p (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c,
+ const char *value)
+{
+ fprintf_filtered (file,
+ _("Permission to call functions in the program is %s.\n"),
+ value);
+}
+
/* How you should pass arguments to a function depends on whether it
was defined in K&R style or prototype style. If you define a
function using the K&R syntax that takes a `float' argument, then
@@ -708,6 +719,10 @@ call_function_by_hand_dummy (struct value *function,
struct gdb_exception e;
char name_buf[RAW_FUNCTION_ADDRESS_SIZE];
+ if (!may_call_functions_p)
+ error (_("Cannot call functions in the program: "
+ "may-call-functions is off."));
+
if (!target_has_execution)
noprocess ();
@@ -1359,6 +1374,17 @@ When the function is done executing, GDB will silently stop."),
void
_initialize_infcall (void)
{
+ add_setshow_boolean_cmd ("may-call-functions", no_class,
+ &may_call_functions_p, _("\
+Set permission to call functions in the program."), _("\
+Show permission to call functions in the program."), _("\
+When this permission is on, GDB may call functions in the program.\n\
+Otherwise, any sort of attempt to call a function in the program\n\
+will result in an error."),
+ NULL,
+ show_may_call_functions_p,
+ &setlist, &showlist);
+
add_setshow_boolean_cmd ("coerce-float-to-double", class_obscure,
&coerce_float_to_double_p, _("\
Set coercion of floats to doubles when calling functions."), _("\