From: Carlo R. <ca...@al...> - 2003-12-19 04:18:08
|
On Fri, Dec 19, 2003 at 04:18:16AM +0000, Philippe Elie wrote: > Carlo I didn't understand your "log the top of stack in sample files", > I don't see how it can work, can you explain it ? When an interrupt occurs, you read the memory contents of (%ebp) in order to know what is the (return) address of the caller - and that is the only thing, currently, that is written to the oprofile (along with the current program counter (pc)). Consider: f3() { } f2() { f3(); } f1() { f2(); } or f3: .LFB2: pushl %ebp .LCFI0: movl %esp, %ebp .LCFI1: popl %ebp ret .LFE2: When an NMI occurs at the moment that you are at .LFB2, then pc points to f3 and (%ebp) points to f1 (this is what causes us to think that f1 calls f3). Same thing when you are at .LCFI0. Therefore, you'd actually need the contents of (%esp) too, "just in case". Then later you can decide to insert that as caller. Now I see that you ALSO need ((%esp+1), because that is what you need when you are at .LCFI0. Perhaps it is possible to do this in the driver though. The driver has to get the stack trace, so it knows exactly how it works on the current target. In the above case (linux x86_32), it could do the following: - If the current pc points to an instruction that disassembles as 'push %ebp', then add an escape sequence that adds the top-of-stack. - If the current pc points to an instruction that disassembles as 'movl %esp, %ebp', then add an escape sequence that adds the content of the stack one deeper (assuming therefore that there was one push since the last call). The profile converter (ie opgprof) can ignore these insertions when they are not inside the prologue of a function. Disadvantage: - driver needs to do two compares and two conditional jumps extra (but we can do branch prediction here: normally the pc will point to other code). - This is architecture dependent, so its gonna be some work to implement. There will also be several ways that an epilogue can look like. Advantage: - because the pc normally points somewhere else, you don't need to add the escape sequences often. - when there is no debug info, you can guess that every inserted escape indeed is inside a prologue and probably still be quite accurate. -- Carlo Wood <ca...@al...> |