Hi Joel. On Tue, Jan 26, 2010 at 03:23:03AM +0530, Joel Fernandes wrote: > I am having some trouble accessing 'current' to get the currently > executing task in kgdb (x86_64). > > As current is a macro, I can't expand it in kgdb, so instead I'm > trying to access the variable per_cpu__current_task inorder to get the > task_struct for the currently executing task. But the memory address > of this variable is 0xb000 (which kgdb cannot access) so I'm guessing > each CPU has an offset stored somewhere to which if I add 0xb000 would > give me the actual address of per_cpu__current_task for that CPU? Any > idea where I could find this per-cpu offset? > > I'm thinking of having a function return current and call that from > gdb but that's extra code and is ugly. > Is there an easier way to access 'current' from the debugger? The thread_info structure, which contains a pointer to the 'current' task_struct, lies at the bottom of the kernel mode stack and can be accessed by performing some simple math on the kernel mode stack pointer. Here's a snippet from arch/x86/include/asm/thread_info.h which you can use to learn more: static inline struct thread_info *current_thread_info(void) { return (struct thread_info *) (current_stack_pointer & ~(THREAD_SIZE - 1)); } You can wrap this operation into a GDB script and use that to access current. The following snippet is for an x86 setup but you should be able to derive something useful. define show_current set $thread_info = $sp &0xffffe000 printf "$current=0x%08lX\n", (((struct thread_info *)($current))->task) end GDB should allow you to hook this function in a way that it is "refreshed" on every break which is needed but you'll need to figure that out using the GDB manuals. Cheers, Robin -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ