There are several possibilities for debugging an OSEck System. For low-level debugging the sysinfo system calls can be utilized for writing debug hooks and error handlers, performing traces, memory profiling, and crash analysis.
hook是一段应用程序,将该应用程序注册到系统,使该应用程序可以在系统级访问在正常情况下无法访问的一些资源,处理一些消息等。hook是debug系统的一种手段。
OSEck guide中对hook的定义:
It is sometimes desirable to write customized routines to change the behavior of, or add functionality to, some of the OSE system calls. This is realized through a number of pre-defined system events (which often but not always map 1:1 to a single system call) for which user defined handlers, so called hooks, can be configured, as described in the OSEck Kernel Reference Manual. Any number of hook functions can be configured for each event, and will be called in the order that they are entered in the configuration file. Hooks exist mainly for debugging and logging purposes,and are not portable from one CPU, or kernel, to another.
OSEck支持应用应用注册以下hook:
alloc_hook,create_pool_hook,create_process_hook,error_hook,debug_hook,kill_pool_hook,kill_proc_hook,receive_hook,reset_pool_hook,restore_hook,send_hook,swap_hook
上述hook将会注册到OSEck的系统级全局变量odo_config(CPU级别的)中,进而提供给系统。
例如,较为常用的swap_hook, 它会在进程切换时被调用,我们可以记录一些进程切换信息,如from,to的进程ID,以及timestamp。这样我们就可以知道不同的进程的切换背景以及进程的执行时间。如果某个进程陷入死循环的话,记录下的该进程的执行时间会很长,这样就有助于我们调查问题了。