User`s guide

VxWorks
BSP Developer’s Guide, 6.0
68
void (*myHwInit2Hook)(void); /* declare a hook routine */
...
void sysHwInit2 (void)
{
if (myHwInit2Hook != NULL) /* and conditionally call it */
{
myHwInit2Hook();
return;
}
... /* default code */
}
Adding hooks allows you to replace the routine from the debugger dynamically.
For example, to override the behavior of sysHwInit2( ) above, create a new version
of it called myHwInit2( ) in a module called myLib.o, and then type the following:
(gdb) load myLib.o
(gdb) set myHwInit2Hook = myHwInit2
(gdb) break myHwInit2
(gdb) continue
However, if you start the agent before the kernel, you must start the agent after the
call to sysHwInit( ). Therefore, you cannot override sysHwInit( ). Alternatively,
you can add additional hardware initialization code that is called before the kernel
is started. In this case, you add a hook right before the call to kernelInit( ).
As an alternative to hooks, you can call routines from the debugger by using GDB’s
call procedure. For example:
(gdb) call myHwInit2
The advantage of using hooks instead of the call mechanism is that:
Hooks let you avoid executing the original code.
Hooks are much faster than the call mechanism.
If your board has an “abort” or “halt” button, consider connecting a debugging
routine to the abort interrupt. Then you can set a breakpoint on your interrupt
handler from the debugger. This provides a way for you to gain control of the
system if it appears to fail. In this case, it is best to have the abort switch tied to a
non-maskable interrupt (NMI).
!
WARNING: Only fatal interrupts such as “abort” can be connected to an NMI. If a
device interrupt is connected to an NMI, the kernel does work properly.