Oliver Yang ??:
> Brian Xu - Sun Microsystems - Beijing China wrote:
>> Hi,
>>
>> I have a question: how the cmd '::findstack -v' in mdb works?
>>
>> In x32, it is easy to understand, since all the args are on the stack,
>> while for amd64, since the args(<6) are not put on the stack, and those
>> regs used to pass args(rdi, rsi, rdx, rcx, r8, r9) may be reused within
>> the function, so I am curious when backtracing the stack, how to know
>> the value of the args passed to the function's father, grandfather,
>> great grandfather, etc?
> Hi,
>
> In below Eric Schrock's blog, it said it was difficult to get them, 
> since the arguments may
> or may not be pushed on the stack, or they could be lost completely.
>
> http://blogs.sun.com/eschrock/entry/debugging_on_amd64_part_two
>
> It seems to be true in the earlier Nevada build, but in recent Neveda 
> build, ::findstack could
> return the input arguments very well.
Yes. the args are saved now on the stack. It is on the callee's stack 
instead of that on the caller's stack for 32bit.

Here is an example:
[1]> ddi_dma_mem_alloc::dis
ddi_dma_mem_alloc: pushq %rbp
ddi_dma_mem_alloc+1: movq %rsp,%rbp
ddi_dma_mem_alloc+4: subq $0x30,%rsp >>>>>>>>>>>>calculate the quantity 
of the args.
ddi_dma_mem_alloc+8: movq %rdi,-0x8(%rbp)
ddi_dma_mem_alloc+0xc: movq %rsi,-0x10(%rbp)
ddi_dma_mem_alloc+0x10: movq %rdx,-0x18(%rbp)
ddi_dma_mem_alloc+0x14: movq %rcx,-0x20(%rbp)
ddi_dma_mem_alloc+0x18: movq %r8,-0x28(%rbp)
ddi_dma_mem_alloc+0x1c: movq %r9,-0x30(%rbp)
ddi_dma_mem_alloc+0x20: pushq %rbx
ddi_dma_mem_alloc+0x21: pushq %r12
ddi_dma_mem_alloc+0x23: pushq %r13
ddi_dma_mem_alloc+0x25: pushq %r14
ddi_dma_mem_alloc+0x27: pushq %r15
ddi_dma_mem_alloc+0x29: subq $0x38,%rsp >>>>>>>>>>>>>>>>>calculate the 
extra space needed for the local variables on the stack.
ddi_dma_mem_alloc+0x2d: movq %rsi,-0x68(%rbp)
ddi_dma_mem_alloc+0x31: movq %rdx,%r15
ddi_dma_mem_alloc+0x34: movl %ecx,%ebx
ddi_dma_mem_alloc+0x36: movq %r9,%r14
ddi_dma_mem_alloc+0x39: movq 0x20(%rdi),%r12
...

BTW, for SPARC, a FLUSHW instruction can be used to flush register 
windows to the user memory.

Thanks,
Brian

Reply via email to