public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Command Hooks (Post rather than Pre)
@ 2000-08-14 19:37 Steven Johnson
  2000-08-15  0:30 ` Steven Johnson
  0 siblings, 1 reply; 2+ messages in thread
From: Steven Johnson @ 2000-08-14 19:37 UTC (permalink / raw)
  To: gdb

Proposition,

Its possible to have a hook that runs before a command, but it is not yet
possible
to have a hook that runs after a command.

Does anyone other than me think this might be usefull?

I want to use it to introduce some generic load modifications, for example:

I have a target that does not have any RAM to run the application in, It must
be run from flash. So I would have 2 hooks, one before and one after the load.

Hook Before Load:
  Remaps target dram to the position where the program will be loaded.
  Remaps target flash to somewhere out of the way.

Load:
  Transfers program to the target, which gets stored in the dram, (But can not
  be run from there as then i wont have any dram for the program to use :(

Hook After Load:
  Transfers a tiny flash burning stub to the target.
  Executes tiny flash burning stub to erase and burn the flash with the
  contents of dram.
  After executing, remaps the dram and flash back to their proper locations.

This is the exact procedure i want to use, but im sure having hooks that
execute after a command may be a usefull general addition to gdb. 
I propose (and have in fact implemented) the following:

define hookpost-[command]
  ... Any GDB Commands ...
end

define hookpre-[command]       
  ... Any GDB Commands ...
end

the last one is just for symetry, and would be identical to the existing:

define hook-[command]
  ... Any GDB Commands ...
end

Which i have left alone BTW.

Anyway, Im fishing for comments on this before I submit it.

One thing I would like to add is a parameter to the hookpost- defined command,
so that it can be
told if the command it is running after was successful. Im not sure how to
find this out, does
anyone know? Further Im not sure how to actually pass the parameter to the GDB
Command?

What happens currently if a hook calls the command it is hooked to? Do we end
up with recursion that will eventually crash GDB? for example:

define hook-foo
  foo
end

Wouldn't this repeatedly call hook-foo until something overflowed in GDB and
crashed it? Is this worth defending against. My preference would be to have
the command available, but once you were in the hook further hooking was
prevented. So that the above example would execute like this:
gdb> foo

runs hook-foo
  foo
  runs foo
runs foo
ends

instead of:
runs hook-foo
  foo
  runs hook-foo
    foo
    runs hook-foo
      foo
      runs hook-foo
        foo
        runs hook-foo
          ... and so on ...
    

Steven Johnson

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Command Hooks (Post rather than Pre)
  2000-08-14 19:37 Command Hooks (Post rather than Pre) Steven Johnson
@ 2000-08-15  0:30 ` Steven Johnson
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Johnson @ 2000-08-15  0:30 UTC (permalink / raw)
  To: gdb

After some investigation, I can answer one of my own questions :

Does a command recurse if it is called from it's hook?
Answer : Yes.
Do Bad things happen:
Answer : Yes. (Unless one considers a segmentation fault a good thing)

The Patch I have will also prevent this from happening, so that for example,
you can write the following:

define hook-echo
echo PRE HOOK Running\n
end

define hookpost-echo
echo POST HOOK Running\n
end

when you then execute:
gdb>echo hello world\n

you get:
PRE HOOK Running
hello world
POST HOOK Running

This is what my patch will now allow. Anyway as I said, im fishing for
comments on this before I submit it.

Steven Johnson

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-08-15  0:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-14 19:37 Command Hooks (Post rather than Pre) Steven Johnson
2000-08-15  0:30 ` Steven Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).