This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: Patch to command hook
Eli Zaretskii wrote:
>
> > Date: Thu, 17 Aug 2000 12:04:27 +1000
> > From: Steven Johnson <sbjohnson@ozemail.com.au>
> >
> > 4. Updated gdb.texinfo section on hooks to document "hookpost-"
> > and "hookpre-".
>
> Thanks for working on this.
>
Your Welcome.
> The patches to gdb.texinfo are approved, provided that the following
> comments are taken care of:
>
> > + A @emph{hook} may also be defined which is run after the command you
>
> When introducing a new term, please use @dfn{}, not @emph{}.
>
> > + executed. Whenever you run the command @samp{foo}, if the user-defined
>
OK, I just copied @emph{hook} from the existing documentation of hooks. should
it also be @defn{hook} ?
> Please leave two spaces after a period that ends a sentence. This
> produces a much nicer results in the printed manual, and also makes
> Emacs sentence-related commands DTRT.
>
OK.
> Please also provide index entries for the hooks. I suggest these:
>
> @cindex pre-command hooks
> @cindex post-command hooks
> @findex hookpre
> @findex hookpost
>
OK.
> > + #define MAX_TMPBUF 128
> [snip]
> > ! char tmpbuf[MAX_TMPBUF];
> [snip]
> > + strncpy(tmpbuf,HOOK_PRE_STRING,MAX_TMPBUF);
> > + strncat(tmpbuf,comname+HOOK_LEN,MAX_TMPBUF-HOOK_PRE_LEN);
>
> Why the arbitrary limitation on the length of the hook name? Is the
> user-defined command name length limited in GDB? If so, MAX_TMPBUF
> should be that limitation + sizeof("hookpost"). If there's no limit
> on the length of a user-defined command, then I think the hooks should
> not be limited, either.
>
It was already in the function, I just made it into a #define, instead of a
hard coded 128 as it was before. I didn't give it much more thought but I will
look into it.
> > + strncpy(tmpbuf,HOOK_STRING,MAX_TMPBUF);
> > + strncat(tmpbuf,comname+HOOK_PRE_LEN,MAX_TMPBUF-HOOK_LEN);
> > +
> > + tem2 = &tmpbuf[0];
> > +
> > + oldc = lookup_cmd (&tem2, cmdlist, "", -1, 1);
> > +
> > + if (oldc && STREQ (tmpbuf, oldc->name))
> > + {
> > + error ("Can not define \"%s\"! \"%s\" has already been defined.",
> > + comname, oldc->name);
>
> Hmm... So how does one redefine or undefine a hook for a command?
> I'm probably missing something, but what?
Yes, this is the best I could come up with. I could find no way un un-defining
a command once it was defined. So, "hook-" and "hookpre-" are both seperate
commands, they are also mutually exclusive, so I made it that once you had
defined one or the other then you couldn't define the other. Ideally, I would
like it to come up with a warning, give you the option of not defining, or of
undefining the previous command. Maybe I just shouldn't of added "hookpre-"?
The other concern I had was when a script gets an error, how is the command
unrolled. I know it doesn't execute the hooked command, but the call to the
hook doesn't return anything (obvious) so how is it that execution terminates?
Steven.