dtrace -c './main' -n 'pid$target:main::entry' -n 'pid$target:main::return'
このようにして、実行時に呼び出されるすべての関数を出力に含めることができ、関数の入力時と戻り時に起動します。
私が調べているコードは次のとおりです。
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
class Polygon {
protected:
int width, height;
public:
void set_values (int a, int b)
{ width=a; height=b; }
virtual int area ()
{ return 0; }
};
class Rectangle: public Polygon {
public:
int area()
{
foo();
return width*height;
}
void foo(){}
};
class Triangle: public Polygon {
public:
int area()
{
foo();
return width*height/2;
}
void foo(){}
};
int main () {
//initialize random seed
srand(time(NULL));
if(rand() % 2)
{
Rectangle rect;
Polygon * ppoly = ▭
ppoly->set_values (4,5);
ppoly->area();
}
else
{
Triangle trgl;
Polygon * ppoly = &trgl;
ppoly->set_values (4,5);
ppoly->area();
}
return 0;
}
そして、私が得るdtrace出力はこれです:
CPU ID FUNCTION:NAME
3 109401 main:entry
3 109404 Triangle::Triangle():entry
3 109405 Polygon::Polygon():entry
3 109415 Polygon::Polygon():return
3 109414 Triangle::Triangle():return
3 109403 Polygon::set_values(int, int):entry
3 109413 Polygon::set_values(int, int):return
3 109406 Triangle::area():entry
3 109407 Triangle::foo():entry
3 109417 Triangle::foo():return
3 109416 Triangle::area():return
3 109411 main:return
今、私はそれを Python スクリプトで解析し、呼び出しツリーの xml を作成しようとしています