Find program counter of process in kernel
Asked Answered
M

0

4

I'm trying to track the value of the PC of a particular process within the kernel.
To do this, I looked at the kernel source and figured out that the pc is being stored inside task_struct->stack and that to make sense of the stack, I need to type cast it into struct thread_info *.
Therefore, in in gdb, I set a breakpoint b scheduler_tick (called every 10ms). However, when I printed out p/x ((struct thread_info *)curr->stack)->cpu_context.pc, I received the value as $4 = 0x804d19d8.

I expected the PC to be below 0x80000000 given that addresses above 0x80000000 are configured to be kernel-space in my kernel. Upon looking at the objdump output of the kernel, I see that the pc was pointing to __schedule.

Isn't the PC supposed to be pointing to user-space instructions for a process that I started from user-space?
My understanding was that, when an interrupt is triggered, the register state is saved, the interrupt is serviced, and then the register state is restored so the program continues as though 'nothing' happened.

Marandamarasca answered 25/9, 2014 at 5:5 Comment(2)
See how ptrace does it, github.com/torvalds/linux/blob/master/arch/arm/kernel/ptrace.cTheorbo
There are multiple PC values. The one you are looking at is the kernel PC. The userspace one is in struct task_struct *task. Using Auslen's link, task_pt_regs((struct thread_info *)(curr)->task)->uregs[ARM_pc] should get it.Apocarp

© 2022 - 2024 — McMap. All rights reserved.