This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Command Hooks (Post rather than Pre)


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]