* Re: [RFA] Avoid recursivly defined user functions.
@ 2002-04-13 10:04 Eli Zaretskii
0 siblings, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2002-04-13 10:04 UTC (permalink / raw)
To: dhoward
Cc: fnasser, msnyder, schwab, Hilfinger, drow,
gdb-patches@sources.redhat.com
> Date: Sat, 13 Apr 2002 09:33:57 -0700 (PDT)
> From: Don Howard <dhoward@redhat.com>
>
> How's this?
Perfect, thanks!
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [RFA] Avoid recursivly defined user functions.
@ 2002-04-11 19:23 Eli Zaretskii
0 siblings, 0 replies; 21+ messages in thread
From: Eli Zaretskii @ 2002-04-11 19:23 UTC (permalink / raw)
To: dhoward; +Cc: Hilfinger, drow, schwab, msnyder, gdb-patches@sources.redhat.com
> Date: Thu, 11 Apr 2002 10:55:26 -0700 (PDT)
> From: Don Howard <dhoward@redhat.com>
>
> 2002-04-11 Don Howard <dhoward@redhat.com>
>
> * cli/cli-cmds.c (init_cli_cmds): Add new user settable value:
> max_user_call_depth.
Please add the documentation for this variable. (A short notice in
NEWS is probably also a good idea.)
Thanks.
^ permalink raw reply [flat|nested] 21+ messages in thread* [RFA] Avoid recursivly defined user functions.
@ 2002-04-03 14:09 Don Howard
2002-04-03 14:36 ` Paul Hilfinger
0 siblings, 1 reply; 21+ messages in thread
From: Don Howard @ 2002-04-03 14:09 UTC (permalink / raw)
To: gdb-patches
Executing a recursively defined user function results in a core-dump from
gdb:
(gdb) define foo
Type commands for definition of "foo".
End with a line saying just "end".
>foo
>end
(gdb) foo
Segmentation fault (core dumped)
The following patch catches recursive user function definitions and
disallowes them:
2002-04-03 Don Howard <dhoward@redhat.com>
* cli/cli-script.c (define_command): Avoid recursivly defined user
commands.
Index: cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.11
diff -p -u -w -r1.11 cli-script.c
--- cli-script.c 2002/03/17 19:53:39 1.11
+++ cli-script.c 2002/04/03 22:07:36
@@ -1099,6 +1099,13 @@ define_command (char *comname, int from_
sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
cmds = read_command_lines (tmpbuf, from_tty);
+ {
+ struct command_line *c;
+ for (c=cmds; c; c=c->next)
+ if (strcmp (c->line, comname) == 0)
+ error ("Recursive user command definitions are not supported.");
+ }
+
if (c && c->class == class_user)
free_command_lines (&c->user_commands);
--
dhoward@redhat.com
gdb engineering
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [RFA] Avoid recursivly defined user functions. 2002-04-03 14:09 Don Howard @ 2002-04-03 14:36 ` Paul Hilfinger 2002-04-03 15:53 ` Michael Snyder 0 siblings, 1 reply; 21+ messages in thread From: Paul Hilfinger @ 2002-04-03 14:36 UTC (permalink / raw) To: Don Howard; +Cc: gdb-patches > Executing a recursively defined user function results in a core-dump from > gdb: ... > The following patch catches recursive user function definitions and > disallowes them: Is the segmentation fault the result of stack overflow? If so, I point out that there is an 'if' statement, so recursive commands are not necessarily wrong, are they? P. Hilfinger ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-03 14:36 ` Paul Hilfinger @ 2002-04-03 15:53 ` Michael Snyder 2002-04-04 3:17 ` Andreas Schwab 0 siblings, 1 reply; 21+ messages in thread From: Michael Snyder @ 2002-04-03 15:53 UTC (permalink / raw) To: Hilfinger; +Cc: Don Howard, gdb-patches Paul Hilfinger wrote: > > > Executing a recursively defined user function results in a core-dump from > > gdb: > > ... > > > The following patch catches recursive user function definitions and > > disallowes them: > > Is the segmentation fault the result of stack overflow? Yes it is. > If so, I > point out that there is an 'if' statement, so recursive commands are > not necessarily wrong, are they? No they're not. So it's a judgement call. Is it more important to allow recursive macros, or to prevent GDB from dumping core? We're basically running an interpreter here... I guess one thing we could do would be to impose an arbitrary (possibly user-settable) stack depth limit. That's more work, of course... Michael ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-03 15:53 ` Michael Snyder @ 2002-04-04 3:17 ` Andreas Schwab 2002-04-09 14:01 ` Don Howard 0 siblings, 1 reply; 21+ messages in thread From: Andreas Schwab @ 2002-04-04 3:17 UTC (permalink / raw) To: Michael Snyder; +Cc: Hilfinger, Don Howard, gdb-patches Michael Snyder <msnyder@redhat.com> writes: |> Paul Hilfinger wrote: |> > |> > > Executing a recursively defined user function results in a core-dump from |> > > gdb: |> > |> > ... |> > |> > > The following patch catches recursive user function definitions and |> > > disallowes them: |> > |> > Is the segmentation fault the result of stack overflow? |> |> Yes it is. |> |> > If so, I |> > point out that there is an 'if' statement, so recursive commands are |> > not necessarily wrong, are they? |> |> No they're not. So it's a judgement call. Is it more important |> to allow recursive macros, or to prevent GDB from dumping core? |> We're basically running an interpreter here... |> |> I guess one thing we could do would be to impose an arbitrary |> (possibly user-settable) stack depth limit. That's more work, |> of course... The simple minded check in Don's patch won't catch many cases of infinite recursion anyway (mutual recursion, command invocation with arguments). Andreas. -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-04 3:17 ` Andreas Schwab @ 2002-04-09 14:01 ` Don Howard 2002-04-09 14:05 ` Daniel Jacobowitz 2002-04-09 14:20 ` Andreas Schwab 0 siblings, 2 replies; 21+ messages in thread From: Don Howard @ 2002-04-09 14:01 UTC (permalink / raw) To: Andreas Schwab; +Cc: Michael Snyder, Hilfinger, gdb-patches On Thu, 4 Apr 2002, Andreas Schwab wrote: > Michael Snyder <msnyder@redhat.com> writes: > > |> Paul Hilfinger wrote: > |> > > |> > > Executing a recursively defined user function results in a core-dump from > |> > > gdb: > |> > > |> > ... > |> > > |> > > The following patch catches recursive user function definitions and > |> > > disallowes them: > |> > > |> > Is the segmentation fault the result of stack overflow? > |> > |> Yes it is. > |> > |> > If so, I > |> > point out that there is an 'if' statement, so recursive commands are > |> > not necessarily wrong, are they? > |> > |> No they're not. So it's a judgement call. Is it more important > |> to allow recursive macros, or to prevent GDB from dumping core? > |> We're basically running an interpreter here... > |> > |> I guess one thing we could do would be to impose an arbitrary > |> (possibly user-settable) stack depth limit. That's more work, > |> of course... > > The simple minded check in Don's patch won't catch many cases of infinite > recursion anyway (mutual recursion, command invocation with arguments). > I think I can detect mutual recursion by walking through the body of each user-defined command (recursivly). This amounts to static recursion detection. I think I could track simple recursion depth at runtime. I don't see how to track mutual recursion depth at runtime. Maybe do the static recursion detection and recursivly flag user-defined commands in the body? Can you explain what you mean by "command invocation with arguments"? -- dhoward@redhat.com gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-09 14:01 ` Don Howard @ 2002-04-09 14:05 ` Daniel Jacobowitz 2002-04-09 14:09 ` Paul Hilfinger 2002-04-09 14:20 ` Andreas Schwab 1 sibling, 1 reply; 21+ messages in thread From: Daniel Jacobowitz @ 2002-04-09 14:05 UTC (permalink / raw) To: Don Howard; +Cc: Andreas Schwab, Michael Snyder, Hilfinger, gdb-patches On Tue, Apr 09, 2002 at 02:01:13PM -0700, Don Howard wrote: > I think I can detect mutual recursion by walking through the body of each > user-defined command (recursivly). This amounts to static recursion > detection. > > I think I could track simple recursion depth at runtime. > > I don't see how to track mutual recursion depth at runtime. Maybe do the > static recursion detection and recursivly flag user-defined commands in > the body? How about something even simpler - track user command depth at runtime? Set an absurd limit, like 1024 deep, if we can handle that in a normal-sized stack limit. Then complain if we hit it at runtime. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-09 14:05 ` Daniel Jacobowitz @ 2002-04-09 14:09 ` Paul Hilfinger 2002-04-09 14:18 ` Don Howard 0 siblings, 1 reply; 21+ messages in thread From: Paul Hilfinger @ 2002-04-09 14:09 UTC (permalink / raw) To: Daniel Jacobowitz; +Cc: Don Howard, Andreas Schwab, Michael Snyder, gdb-patches > How about something even simpler - track user command depth at runtime? > Set an absurd limit, like 1024 deep, if we can handle that in a > normal-sized stack limit. Then complain if we hit it at runtime. I completely agree with this. After all, if you were willing to contemplate outlawing recursion altogether, you certainly won't LOSE anything by Daniel's approach, and you gain everything you wanted in the first place---to avoid crashing GDB. Paul ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-09 14:09 ` Paul Hilfinger @ 2002-04-09 14:18 ` Don Howard 2002-04-11 10:56 ` Don Howard 0 siblings, 1 reply; 21+ messages in thread From: Don Howard @ 2002-04-09 14:18 UTC (permalink / raw) To: Hilfinger; +Cc: Daniel Jacobowitz, Andreas Schwab, Michael Snyder, gdb-patches On Tue, 9 Apr 2002, Paul Hilfinger wrote: > > > How about something even simpler - track user command depth at runtime? > > Set an absurd limit, like 1024 deep, if we can handle that in a > > normal-sized stack limit. Then complain if we hit it at runtime. > > I completely agree with this. After all, if you were willing to > contemplate outlawing recursion altogether, you certainly won't LOSE > anything by Daniel's approach, and you gain everything you wanted in > the first place---to avoid crashing GDB. > > Paul > I like this approach, also. -- dhoward@redhat.com gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-09 14:18 ` Don Howard @ 2002-04-11 10:56 ` Don Howard 2002-04-11 12:08 ` Daniel Jacobowitz ` (3 more replies) 0 siblings, 4 replies; 21+ messages in thread From: Don Howard @ 2002-04-11 10:56 UTC (permalink / raw) To: Hilfinger; +Cc: Daniel Jacobowitz, Andreas Schwab, Michael Snyder, gdb-patches On Tue, 9 Apr 2002, Don Howard wrote: > On Tue, 9 Apr 2002, Paul Hilfinger wrote: > > > > > > How about something even simpler - track user command depth at runtime? > > > Set an absurd limit, like 1024 deep, if we can handle that in a > > > normal-sized stack limit. Then complain if we hit it at runtime. > > > > I completely agree with this. After all, if you were willing to > > contemplate outlawing recursion altogether, you certainly won't LOSE > > anything by Daniel's approach, and you gain everything you wanted in > > the first place---to avoid crashing GDB. > > > > Paul > > > > > I like this approach, also. > 2002-04-11 Don Howard <dhoward@redhat.com> * cli/cli-cmds.c (init_cli_cmds): Add new user settable value: max_user_call_depth. (init_cmd_lists): Initialize the new value; * cli/cli-script.c (execute_user_command): Limit the call depth of user defined commands. This avoids a core-dump when user commands are infinitly recursive. Index: cli/cli-cmds.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v retrieving revision 1.18 diff -p -u -w -r1.18 cli-cmds.c --- cli/cli-cmds.c 28 Mar 2002 01:35:56 -0000 1.18 +++ cli/cli-cmds.c 11 Apr 2002 17:30:58 -0000 @@ -80,6 +80,9 @@ static void shell_escape (char *, int); void apropos_command (char *, int); \f +/* Limit the call depth of user-defined commands */ +int max_user_call_depth; + /* Define all cmd_list_elements. */ /* Chain containing all defined commands. */ @@ -606,6 +609,8 @@ show_debug (char *args, int from_tty) void init_cmd_lists (void) { + max_user_call_depth = 1024; + cmdlist = NULL; infolist = NULL; enablelist = NULL; @@ -823,4 +828,11 @@ With no arguments, run an inferior shell Argument is the name of the user defined command.\n\ With no argument, show definitions of all user defined commands.", &showlist); add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); + + add_show_from_set ( + add_set_cmd ("max_user_call_depth", no_class, var_integer, + (char *) &max_user_call_depth, + "Set the max call depth for user-defined commands.\n", + &setlist), + &showlist); } Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.11 diff -p -u -w -r1.11 cli-script.c --- cli/cli-script.c 17 Mar 2002 19:53:39 -0000 1.11 +++ cli/cli-script.c 11 Apr 2002 17:30:59 -0000 @@ -247,6 +247,15 @@ execute_cmd_post_hook (struct cmd_list_e } /* Execute the command in CMD. */ +void +do_restore_user_call_depth (void * call_depth) +{ + int * depth = call_depth; + /* We will be returning_to_top_level() at this point, so we want to + reset our depth. */ + (*depth) = 0; +} + void execute_user_command (struct cmd_list_element *c, char *args) @@ -254,6 +263,8 @@ execute_user_command (struct cmd_list_el register struct command_line *cmdlines; struct cleanup *old_chain; enum command_control_type ret; + static int user_call_depth = 0; + extern int max_user_call_depth; old_chain = setup_user_args (args); @@ -262,6 +273,11 @@ execute_user_command (struct cmd_list_el /* Null command */ return; + if (user_call_depth++ > max_user_call_depth) + error ("Max user call depth exceeded -- command aborted\n"); + + old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth); + /* Set the instream to 0, indicating execution of a user-defined function. */ old_chain = make_cleanup (do_restore_instream_cleanup, instream); @@ -277,6 +293,8 @@ execute_user_command (struct cmd_list_el cmdlines = cmdlines->next; } do_cleanups (old_chain); + + user_call_depth--; } enum command_control_type -- dhoward@redhat.com gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-11 10:56 ` Don Howard @ 2002-04-11 12:08 ` Daniel Jacobowitz 2002-04-11 12:41 ` Eli Zaretskii ` (2 subsequent siblings) 3 siblings, 0 replies; 21+ messages in thread From: Daniel Jacobowitz @ 2002-04-11 12:08 UTC (permalink / raw) To: gdb-patches On Thu, Apr 11, 2002 at 10:55:26AM -0700, Don Howard wrote: > On Tue, 9 Apr 2002, Don Howard wrote: > > > On Tue, 9 Apr 2002, Paul Hilfinger wrote: > > > > > > > > > How about something even simpler - track user command depth at runtime? > > > > Set an absurd limit, like 1024 deep, if we can handle that in a > > > > normal-sized stack limit. Then complain if we hit it at runtime. > > > > > > I completely agree with this. After all, if you were willing to > > > contemplate outlawing recursion altogether, you certainly won't LOSE > > > anything by Daniel's approach, and you gain everything you wanted in > > > the first place---to avoid crashing GDB. > > > > > > Paul > > > > > > > > > I like this approach, also. > > > > > 2002-04-11 Don Howard <dhoward@redhat.com> > > * cli/cli-cmds.c (init_cli_cmds): Add new user settable value: > max_user_call_depth. > (init_cmd_lists): Initialize the new value; > * cli/cli-script.c (execute_user_command): Limit the call depth of > user defined commands. This avoids a core-dump when user commands > are infinitly recursive. Well, I like it. -- Daniel Jacobowitz Carnegie Mellon University MontaVista Software Debian GNU/Linux Developer ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-11 10:56 ` Don Howard 2002-04-11 12:08 ` Daniel Jacobowitz @ 2002-04-11 12:41 ` Eli Zaretskii 2002-04-11 13:55 ` Michael Snyder 2002-04-12 4:08 ` Andreas Schwab 3 siblings, 0 replies; 21+ messages in thread From: Eli Zaretskii @ 2002-04-11 12:41 UTC (permalink / raw) To: dhoward; +Cc: Hilfinger, drow, schwab, msnyder, gdb-patches > Date: Thu, 11 Apr 2002 10:55:26 -0700 (PDT) > From: Don Howard <dhoward@redhat.com> > > 2002-04-11 Don Howard <dhoward@redhat.com> > > * cli/cli-cmds.c (init_cli_cmds): Add new user settable value: > max_user_call_depth. > (init_cmd_lists): Initialize the new value; > * cli/cli-script.c (execute_user_command): Limit the call depth of > user defined commands. This avoids a core-dump when user commands > are infinitly recursive. Please add the documentation for this variable. (A short notice in NEWS is probably also a good idea.) Thanks. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-11 10:56 ` Don Howard 2002-04-11 12:08 ` Daniel Jacobowitz 2002-04-11 12:41 ` Eli Zaretskii @ 2002-04-11 13:55 ` Michael Snyder 2002-04-12 4:08 ` Andreas Schwab 3 siblings, 0 replies; 21+ messages in thread From: Michael Snyder @ 2002-04-11 13:55 UTC (permalink / raw) To: Don Howard; +Cc: Hilfinger, Daniel Jacobowitz, Andreas Schwab, gdb-patches Don Howard wrote: > > On Tue, 9 Apr 2002, Don Howard wrote: > > > On Tue, 9 Apr 2002, Paul Hilfinger wrote: > > > > > > > > > How about something even simpler - track user command depth at runtime? > > > > Set an absurd limit, like 1024 deep, if we can handle that in a > > > > normal-sized stack limit. Then complain if we hit it at runtime. > > > > > > I completely agree with this. After all, if you were willing to > > > contemplate outlawing recursion altogether, you certainly won't LOSE > > > anything by Daniel's approach, and you gain everything you wanted in > > > the first place---to avoid crashing GDB. > > > > > > Paul > > > > > > > > > I like this approach, also. So do I. ;-) > > > > 2002-04-11 Don Howard <dhoward@redhat.com> > > * cli/cli-cmds.c (init_cli_cmds): Add new user settable value: > max_user_call_depth. > (init_cmd_lists): Initialize the new value; > * cli/cli-script.c (execute_user_command): Limit the call depth of > user defined commands. This avoids a core-dump when user commands > are infinitly recursive. > > Index: cli/cli-cmds.c > =================================================================== > RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v > retrieving revision 1.18 > diff -p -u -w -r1.18 cli-cmds.c > --- cli/cli-cmds.c 28 Mar 2002 01:35:56 -0000 1.18 > +++ cli/cli-cmds.c 11 Apr 2002 17:30:58 -0000 > @@ -80,6 +80,9 @@ static void shell_escape (char *, int); > > void apropos_command (char *, int); > > +/* Limit the call depth of user-defined commands */ > +int max_user_call_depth; > + > /* Define all cmd_list_elements. */ > > /* Chain containing all defined commands. */ > @@ -606,6 +609,8 @@ show_debug (char *args, int from_tty) > void > init_cmd_lists (void) > { > + max_user_call_depth = 1024; > + > cmdlist = NULL; > infolist = NULL; > enablelist = NULL; > @@ -823,4 +828,11 @@ With no arguments, run an inferior shell > Argument is the name of the user defined command.\n\ > With no argument, show definitions of all user defined commands.", &showlist); > add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); > + > + add_show_from_set ( > + add_set_cmd ("max_user_call_depth", no_class, var_integer, > + (char *) &max_user_call_depth, > + "Set the max call depth for user-defined commands.\n", > + &setlist), > + &showlist); > } > Index: cli/cli-script.c > =================================================================== > RCS file: /cvs/src/src/gdb/cli/cli-script.c,v > retrieving revision 1.11 > diff -p -u -w -r1.11 cli-script.c > --- cli/cli-script.c 17 Mar 2002 19:53:39 -0000 1.11 > +++ cli/cli-script.c 11 Apr 2002 17:30:59 -0000 > @@ -247,6 +247,15 @@ execute_cmd_post_hook (struct cmd_list_e > } > > /* Execute the command in CMD. */ > +void > +do_restore_user_call_depth (void * call_depth) > +{ > + int * depth = call_depth; > + /* We will be returning_to_top_level() at this point, so we want to > + reset our depth. */ > + (*depth) = 0; > +} > + > > void > execute_user_command (struct cmd_list_element *c, char *args) > @@ -254,6 +263,8 @@ execute_user_command (struct cmd_list_el > register struct command_line *cmdlines; > struct cleanup *old_chain; > enum command_control_type ret; > + static int user_call_depth = 0; > + extern int max_user_call_depth; > > old_chain = setup_user_args (args); > > @@ -262,6 +273,11 @@ execute_user_command (struct cmd_list_el > /* Null command */ > return; > > + if (user_call_depth++ > max_user_call_depth) > + error ("Max user call depth exceeded -- command aborted\n"); > + > + old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth); > + > /* Set the instream to 0, indicating execution of a > user-defined function. */ > old_chain = make_cleanup (do_restore_instream_cleanup, instream); > @@ -277,6 +293,8 @@ execute_user_command (struct cmd_list_el > cmdlines = cmdlines->next; > } > do_cleanups (old_chain); > + > + user_call_depth--; > } > > enum command_control_type > > -- > dhoward@redhat.com > gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-11 10:56 ` Don Howard ` (2 preceding siblings ...) 2002-04-11 13:55 ` Michael Snyder @ 2002-04-12 4:08 ` Andreas Schwab 2002-04-12 11:28 ` Michael Snyder 3 siblings, 1 reply; 21+ messages in thread From: Andreas Schwab @ 2002-04-12 4:08 UTC (permalink / raw) To: Don Howard; +Cc: Hilfinger, Daniel Jacobowitz, Michael Snyder, gdb-patches Don Howard <dhoward@redhat.com> writes: |> + |> + add_show_from_set ( |> + add_set_cmd ("max_user_call_depth", no_class, var_integer, I think this should use hyphens instead of underscores. Andreas. -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-12 4:08 ` Andreas Schwab @ 2002-04-12 11:28 ` Michael Snyder 2002-04-12 12:07 ` Fernando Nasser 0 siblings, 1 reply; 21+ messages in thread From: Michael Snyder @ 2002-04-12 11:28 UTC (permalink / raw) To: Andreas Schwab; +Cc: Don Howard, Hilfinger, Daniel Jacobowitz, gdb-patches Andreas Schwab wrote: > > Don Howard <dhoward@redhat.com> writes: > > |> + > |> + add_show_from_set ( > |> + add_set_cmd ("max_user_call_depth", no_class, var_integer, > > I think this should use hyphens instead of underscores. Yeah, that's sort of the unwritten convention. Other than that, I like it. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-12 11:28 ` Michael Snyder @ 2002-04-12 12:07 ` Fernando Nasser 2002-04-12 15:32 ` Don Howard 0 siblings, 1 reply; 21+ messages in thread From: Fernando Nasser @ 2002-04-12 12:07 UTC (permalink / raw) To: Michael Snyder Cc: Andreas Schwab, Don Howard, Hilfinger, Daniel Jacobowitz, gdb-patches Michael Snyder wrote: > > Andreas Schwab wrote: > > > > Don Howard <dhoward@redhat.com> writes: > > > > |> + > > |> + add_show_from_set ( > > |> + add_set_cmd ("max_user_call_depth", no_class, var_integer, > > > > I think this should use hyphens instead of underscores. > > Yeah, that's sort of the unwritten convention. > Other than that, I like it. So do I. It is approved conditional to this fix and the documentation. (No need to resubmit -- just post the final version committed) -- Fernando Nasser Red Hat Canada Ltd. E-Mail: fnasser@redhat.com 2323 Yonge Street, Suite #300 Toronto, Ontario M4P 2C9 ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-12 12:07 ` Fernando Nasser @ 2002-04-12 15:32 ` Don Howard 2002-04-13 1:44 ` Eli Zaretskii 0 siblings, 1 reply; 21+ messages in thread From: Don Howard @ 2002-04-12 15:32 UTC (permalink / raw) To: Fernando Nasser Cc: Michael Snyder, Andreas Schwab, Hilfinger, Daniel Jacobowitz, gdb-patches On Fri, 12 Apr 2002, Fernando Nasser wrote: > Michael Snyder wrote: > > > > Andreas Schwab wrote: > > > > > > Don Howard <dhoward@redhat.com> writes: > > > > > > |> + > > > |> + add_show_from_set ( > > > |> + add_set_cmd ("max_user_call_depth", no_class, var_integer, > > > > > > I think this should use hyphens instead of underscores. > > > > Yeah, that's sort of the unwritten convention. > > Other than that, I like it. > > So do I. It is approved conditional to this fix and the documentation. > > (No need to resubmit -- just post the final version committed) > Thanks. I've comitted the following: Index: ChangeLog =================================================================== RCS file: /cvs/src/src/gdb/ChangeLog,v retrieving revision 1.2423 diff -p -u -w -r1.2423 ChangeLog --- ChangeLog 12 Apr 2002 18:18:56 -0000 1.2423 +++ ChangeLog 12 Apr 2002 20:40:55 -0000 @@ -1,3 +1,12 @@ +2002-04-12 Don Howard <dhoward@redhat.com> + + * cli/cli-cmds.c (init_cli_cmds): Add new user settable value: + max_user_call_depth. + (init_cmd_lists): Initialize the new value; + * cli/cli-script.c (execute_user_command): Limit the call depth of + user defined commands. This avoids a core-dump when user commands + are infinitly recursive. + 2002-04-12 Andrew Cagney <cagney@redhat.com> * defs.h (read_relative_register_raw_bytes): Delete declaration. Index: NEWS =================================================================== RCS file: /cvs/src/src/gdb/NEWS,v retrieving revision 1.61 diff -p -u -w -r1.61 NEWS --- NEWS 31 Mar 2002 17:53:00 -0000 1.61 +++ NEWS 12 Apr 2002 20:41:05 -0000 @@ -3,6 +3,11 @@ *** Changes since GDB 5.2: +* New command "set max-user-call-depth <nnn>" + +This command allows the user to limit the call depth of user-defined +commands. The default is 1024. + * Changes in FreeBSD/i386 native debugging. Support for the "generate-core-file" has been added. Index: cli/cli-cmds.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-cmds.c,v retrieving revision 1.18 diff -p -u -w -r1.18 cli-cmds.c --- cli/cli-cmds.c 28 Mar 2002 01:35:56 -0000 1.18 +++ cli/cli-cmds.c 12 Apr 2002 20:41:07 -0000 @@ -80,6 +80,9 @@ static void shell_escape (char *, int); void apropos_command (char *, int); \f +/* Limit the call depth of user-defined commands */ +int max_user_call_depth; + /* Define all cmd_list_elements. */ /* Chain containing all defined commands. */ @@ -606,6 +609,8 @@ show_debug (char *args, int from_tty) void init_cmd_lists (void) { + max_user_call_depth = 1024; + cmdlist = NULL; infolist = NULL; enablelist = NULL; @@ -823,4 +828,11 @@ With no arguments, run an inferior shell Argument is the name of the user defined command.\n\ With no argument, show definitions of all user defined commands.", &showlist); add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); + + add_show_from_set ( + add_set_cmd ("max-user-call-depth", no_class, var_integer, + (char *) &max_user_call_depth, + "Set the max call depth for user-defined commands.\n", + &setlist), + &showlist); } Index: cli/cli-script.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-script.c,v retrieving revision 1.11 diff -p -u -w -r1.11 cli-script.c --- cli/cli-script.c 17 Mar 2002 19:53:39 -0000 1.11 +++ cli/cli-script.c 12 Apr 2002 20:41:10 -0000 @@ -247,6 +247,15 @@ execute_cmd_post_hook (struct cmd_list_e } /* Execute the command in CMD. */ +void +do_restore_user_call_depth (void * call_depth) +{ + int * depth = call_depth; + /* We will be returning_to_top_level() at this point, so we want to + reset our depth. */ + (*depth) = 0; +} + void execute_user_command (struct cmd_list_element *c, char *args) @@ -254,6 +263,8 @@ execute_user_command (struct cmd_list_el register struct command_line *cmdlines; struct cleanup *old_chain; enum command_control_type ret; + static int user_call_depth = 0; + extern int max_user_call_depth; old_chain = setup_user_args (args); @@ -262,6 +273,11 @@ execute_user_command (struct cmd_list_el /* Null command */ return; + if (++user_call_depth > max_user_call_depth) + error ("Max user call depth exceeded -- command aborted\n"); + + old_chain = make_cleanup (do_restore_user_call_depth, &user_call_depth); + /* Set the instream to 0, indicating execution of a user-defined function. */ old_chain = make_cleanup (do_restore_instream_cleanup, instream); @@ -277,6 +293,8 @@ execute_user_command (struct cmd_list_el cmdlines = cmdlines->next; } do_cleanups (old_chain); + + user_call_depth--; } enum command_control_type Index: doc/gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.95 diff -p -u -w -r1.95 gdb.texinfo --- doc/gdb.texinfo 7 Apr 2002 19:09:58 -0000 1.95 +++ doc/gdb.texinfo 12 Apr 2002 20:41:42 -0000 @@ -12781,6 +12781,13 @@ Display the @value{GDBN} commands used t not its documentation). If no @var{commandname} is given, display the definitions for all user-defined commands. +@kindex show max-user-call-depth +@kindex set max-user-call-depth +@item show max-user-call-depth +@item set max-user-call-depth +The value of @code{max-user-call-depth} controls how many levels deep a +user-defined call chain can go. Default is 1024. + @end table When user-defined commands are executed, the -- dhoward@redhat.com gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-12 15:32 ` Don Howard @ 2002-04-13 1:44 ` Eli Zaretskii 2002-04-13 9:33 ` Don Howard 0 siblings, 1 reply; 21+ messages in thread From: Eli Zaretskii @ 2002-04-13 1:44 UTC (permalink / raw) To: dhoward; +Cc: fnasser, msnyder, schwab, Hilfinger, drow, gdb-patches > Date: Fri, 12 Apr 2002 15:31:30 -0700 (PDT) > From: Don Howard <dhoward@redhat.com> > > +@kindex show max-user-call-depth > +@kindex set max-user-call-depth > +@item show max-user-call-depth > +@item set max-user-call-depth The second @item should be @itemx. In general, all the @item's but the first one should be @itemx when they all pertain to the same entry in the @table (or in @itemize list). This is so the produced text looks like this: [previous text] show max-user-call-depth set max-user-call-depth The value of `max-user-call-depth' controls how many... instead of this: [previous text] show max-user-call-depth set max-user-call-depth The value of `max-user-call-depth' controls how many... where the extra line between the two @item's makes the first one look as if the following text doesn't apply to it. > +The value of @code{max-user-call-depth} controls how many levels deep a > +user-defined call chain can go. Perhaps this text is a bit more clear: The value of @code{max-user-call-depth} controls how many recursion levels are allowed in user-defined commands before GDB suspects an infinite recursion and aborts the command. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-13 1:44 ` Eli Zaretskii @ 2002-04-13 9:33 ` Don Howard 0 siblings, 0 replies; 21+ messages in thread From: Don Howard @ 2002-04-13 9:33 UTC (permalink / raw) To: Eli Zaretskii; +Cc: fnasser, msnyder, schwab, Hilfinger, drow, gdb-patches How's this? 2002-04-13 Don Howard <dhoward@redhat.com> From Eli Zaretskii <eliz@is.elta.co.il> * gdb.texinfo (show max-user-call-depth): Correct formatting. Provide a better explaination of this feature. Index: gdb.texinfo =================================================================== RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v retrieving revision 1.96 diff -p -u -w -r1.96 gdb.texinfo --- gdb.texinfo 12 Apr 2002 22:31:23 -0000 1.96 +++ gdb.texinfo 13 Apr 2002 16:30:18 -0000 @@ -12784,9 +12784,10 @@ definitions for all user-defined command @kindex show max-user-call-depth @kindex set max-user-call-depth @item show max-user-call-depth -@item set max-user-call-depth -The value of @code{max-user-call-depth} controls how many levels deep a -user-defined call chain can go. Default is 1024. +@itemx set max-user-call-depth +The value of @code{max-user-call-depth} controls how many recursion +levels are allowed in user-defined commands before GDB suspects an +infinite recursion and aborts the command. @end table On Sat, 13 Apr 2002, Eli Zaretskii wrote: > > Date: Fri, 12 Apr 2002 15:31:30 -0700 (PDT) > > From: Don Howard <dhoward@redhat.com> > > > > +@kindex show max-user-call-depth > > +@kindex set max-user-call-depth > > +@item show max-user-call-depth > > +@item set max-user-call-depth > > The second @item should be @itemx. In general, all the @item's but > the first one should be @itemx when they all pertain to the same entry > in the @table (or in @itemize list). This is so the produced text > looks like this: > > [previous text] > > show max-user-call-depth > set max-user-call-depth > The value of `max-user-call-depth' controls how many... > > instead of this: > > [previous text] > > show max-user-call-depth > > set max-user-call-depth > The value of `max-user-call-depth' controls how many... > > where the extra line between the two @item's makes the first one look > as if the following text doesn't apply to it. > > > +The value of @code{max-user-call-depth} controls how many levels deep a > > +user-defined call chain can go. > > Perhaps this text is a bit more clear: > > The value of @code{max-user-call-depth} controls how many recursion > levels are allowed in user-defined commands before GDB suspects an > infinite recursion and aborts the command. > -- dhoward@redhat.com gdb engineering ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [RFA] Avoid recursivly defined user functions. 2002-04-09 14:01 ` Don Howard 2002-04-09 14:05 ` Daniel Jacobowitz @ 2002-04-09 14:20 ` Andreas Schwab 1 sibling, 0 replies; 21+ messages in thread From: Andreas Schwab @ 2002-04-09 14:20 UTC (permalink / raw) To: Don Howard; +Cc: Michael Snyder, Hilfinger, gdb-patches Don Howard <dhoward@redhat.com> writes: |> Can you explain what you mean by "command invocation with arguments"? You can pass arguments even to a user defined command (referenced in the body with $argN), but your check compares the whole line with the command name, so if you pass any arguments to a recursive invocation you'll miss it. Andreas. -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2002-04-13 17:04 UTC | newest] Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-04-13 10:04 [RFA] Avoid recursivly defined user functions Eli Zaretskii -- strict thread matches above, loose matches on Subject: below -- 2002-04-11 19:23 Eli Zaretskii 2002-04-03 14:09 Don Howard 2002-04-03 14:36 ` Paul Hilfinger 2002-04-03 15:53 ` Michael Snyder 2002-04-04 3:17 ` Andreas Schwab 2002-04-09 14:01 ` Don Howard 2002-04-09 14:05 ` Daniel Jacobowitz 2002-04-09 14:09 ` Paul Hilfinger 2002-04-09 14:18 ` Don Howard 2002-04-11 10:56 ` Don Howard 2002-04-11 12:08 ` Daniel Jacobowitz 2002-04-11 12:41 ` Eli Zaretskii 2002-04-11 13:55 ` Michael Snyder 2002-04-12 4:08 ` Andreas Schwab 2002-04-12 11:28 ` Michael Snyder 2002-04-12 12:07 ` Fernando Nasser 2002-04-12 15:32 ` Don Howard 2002-04-13 1:44 ` Eli Zaretskii 2002-04-13 9:33 ` Don Howard 2002-04-09 14:20 ` Andreas Schwab
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox