dtrace的使用

之前利用dtrace脚本检测用户进程的函数调用,一直说找不到函数符号,现在突然反应过来,C++

的符号不是函数名,而是一个畸形的名称:

libcommon.so                                                                               

#include <iostream>
#include "common.hpp"

class commonImpl : public common {
public:
  virtual void sayHello(void) {
    std::cout << "sayHello" << std::endl;
  }

  ~commonImpl(void) throw();

};

commonImpl::~commonImpl(void) throw() {
}

common::~common(void) throw() {

}

common & common::instance(void) {
  static commonImpl s_commonImpl;
  return s_commonImpl;
}


test_main:

#include <iostream>
#include "common.hpp"

void callme(void) {

  while (true) {

    common & comm = common::instance();
    comm.sayHello();
    sleep(10);
  }
}

int main() {

  callme();
  return 0;
}





dtrace.d 脚本


#!/usr/sbin/dtrace -s
#pragma D option quiet
pid$target:libcommon:_ZN10commonImpl8sayHelloEv:entry
{
        printf("dump:%-15s: %8x\n", probefunc, arg0);
}

pid$target:::entry,
pid$target:::return
{
     printf("pid %s\n", probefunc);
}


执行结果:

dump:_ZN10commonImpl8sayHelloEv: fef81718

你可能感兴趣的:(c,脚本)