Re: accessing per-cpu variables from gdb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Robin,

Thanks a lot for your message. :) I guess that would work.

I have another question regarding accessing per-cpu variable, this
might be a bit off-topic.

About the current macro, here is the assembly listing for
current->total_link_count (as an example):

In x86_64:

nopl   0x0(%rax,%rax,1)
mov    %gs:0xb000,%rax
movl   $0x0,0x4cc(%rax)

Where 0xb000 is the offset of the per-cpu variable
'per_cpu__current_task' and 0x4cc is 'total_link_count' element within
the task_struct.

I'm wondering how this works because the value in the 'gs' register is
actually 0, So how does the look up of the per-cpu variable
current_task work in the above code?

Thanks,
-Joel

On Tue, Jan 26, 2010 at 12:43 PM, Robin Randhawa
<robin.randhawa@xxxxxxxxx> wrote:
> 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



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux