如何查看使用DTrace调用堆栈

如何查看使用DTrace调用堆栈

本文介绍了如何查看使用DTrace调用堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何查看调用堆栈,返回值和下面的简单程序的参数,是的DTrace

  / **繁琐code ** / #包括LT&;&stdio.h中GT; INT
 美孚(INT *一,为int * B)
 {
     * A = * B;
     * B = 4;
     返回0;
 } INT
 主要(无效)
 {
     诠释A,B;
     一个= 1;
     B = 2;
     富(安培;一,和b);
     的printf(价值一:%D,B值数:%d \\ n,A,B);
     返回0;
 }


解决方案

首先,这里的脚本:

  PID $目标:: foo的:进入
{
    USTACK();    自>为arg0 =为arg0;
    自> ARG1 = ARG1;    的printf(为arg0 = 0X%X \\ n,自>为arg0);
    的printf(*为arg0 =%d个\\ N,*(INT *)COPYIN(自>为arg0,4));    的printf(ARG1 = 0X%X \\ n,自> ARG1);
    的printf(* ARG1 =%d个\\ N,*(INT *)COPYIN(自> ARG1,4));
}PID $目标:: foo的:回归
{
    USTACK();
    的printf(为arg0 = 0X%X \\ n,自>为arg0);
    的printf(*为arg0 =%d个\\ N,*(INT *)COPYIN(自>为arg0,4));    的printf(ARG1 = 0X%X \\ n,自> ARG1);
    的printf(* ARG1 =%d个\\ N,*(INT *)COPYIN(自> ARG1,4));    的printf(返回=%d个\\ N,ARG1);
}

如何工作的。 USTACK()打印用户进程的堆栈。

在一个函数入口,ARGN是第N个参数的功能。由于参数是
指针,你需要你之前使用COPYIN()中的实际数据复制取消对它的引用。

有关的函数返回时,你不再有访问函数的参数。所以,你救
的参数以供以后使用。

最后,函数返回,您可以访问与函数的返回值
ARG1。

How to view call stack, return value and arguments of the simply program below, with dtrace

 /** Trival code **/

 #include <stdio.h>

 int
 foo (int *a, int *b)
 {
     *a = *b;
     *b = 4;
     return 0;
 }

 int
 main (void)
 {
     int a, b;
     a = 1;
     b = 2;
     foo (&a, &b);
     printf ("Value a: %d, Value b: %d\n", a, b);
     return 0;
 }
解决方案

First off, here's the script:

pid$target::foo:entry
{
    ustack();

    self->arg0 = arg0;
    self->arg1 = arg1;

    printf("arg0 = 0x%x\n", self->arg0);
    printf("*arg0 = %d\n", *(int *)copyin(self->arg0, 4));

    printf("arg1 = 0x%x\n", self->arg1);
    printf("*arg1 = %d\n", *(int *)copyin(self->arg1, 4));
}

pid$target::foo:return
{
    ustack();
    printf("arg0 = 0x%x\n", self->arg0);
    printf("*arg0 = %d\n", *(int *)copyin(self->arg0, 4));

    printf("arg1 = 0x%x\n", self->arg1);
    printf("*arg1 = %d\n", *(int *)copyin(self->arg1, 4));

    printf("return = %d\n", arg1);
}

How this works. ustack() prints the stack of the user process.

In an function entry, argN is the Nth argument to the function. Since the arguments arepointers, you need to use copyin() to copy in the actual data before you dereference it.

For a function return, you no longer have access to the function arguments. So you savethe parameters for later use.

Finally, for a function return, you can access the value returned by the function witharg1.

这篇关于如何查看使用DTrace调用堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:29