Saving state on a context switch
Can anyone think of a way to save and restore an additional cpu state variable during a context switch without modifying the target operating system? Basically I would like to add a variable to the CPUState structure that is saved and restored with the registers.
Any ideas?
Thanks,
Nuri
Quoted 4 lines · eady
Can anyone think of a way to save and restore an additional cpu state variable during a context switch without modifying the target operating system? Basically I would like to add a variable to the CPUState structure that is saved and restored with the registers.
The short answer is that in general you can't.
Processes and contexts are managed by the host OS, and it is responsible for switching state appropriately. Some hardware has features to assist this process, but often not enough to reliably identify a particular process.
To do what you want generally requires intimite knowledge of the appropriate parts of your OS. Some debuggers are capable of doing this. There are patches to add scripting support to GDB for this purpose. I don't have a URL handy, check the gdb mailing lists.
Paul