【问题标题】:systemtap userspace function tracingsystemtap 用户空间函数跟踪
【发布时间】:2016-02-13 21:42:48
【问题描述】:

我有一个简单的 c++ 程序

main.cpp

#include <iostream>
using namespace std;

int addition (int a, int b)
{
  int r;
  r=a+b;
  return r;
}

int main ()
{
  int z;
  z = addition (5,3);
  cout << "The result is " << z;
}

我想为此生成函数跟踪 - 打印函数名称及其输入输出和返回类型

我的 systemtap 脚本:para-callgraph.stp

#! /usr/bin/env stap

function trace(entry_p, extra) {
  %( $# > 1 %? if (tid() in trace) %)
  printf("%s%s%s %s\n",
         thread_indent (entry_p),
         (entry_p>0?"->":"<-"),
         probefunc (),
         extra)
}


probe $1.call   { trace(1, $$parms)  }
probe $1.return { trace(-1, $$return) }

我的 C++ Exec 被调用:a (编译为 g++ -g main.cpp)

Command I run 
stap para-callgraph.stp 'process("a").function("*")' -c "./a > /dev/null"

 0 a(15119):->_GLOBAL__I__Z8additionii 
    27 a(15119): ->__static_initialization_and_destruction_0 __initialize_p=0x0 __priority=0x0
   168 a(15119): <-__static_initialization_and_destruction_0 
   174 a(15119):<-_GLOBAL__I__Z8additionii 
     0 a(15119):->main 
    18 a(15119): ->addition a=0x0 b=0x400895
    30 a(15119): <-addition return=0x8
   106 a(15119):<-main return=0x0

这里 ->addition a=0x0 b=0x400895 :它的地址而不是实际值,即我想要的 5、3。

How to modify my stap script?

【问题讨论】:

  • 您使用的是什么版本的 G++/SystemTap?你的代码对我来说很好。请注意,SystemTap 依赖 GCC 提供的 DWARF 信息来显示变量,并且 GCC >5.0 版本已将 DWARF 切换到版本 4。
  • 你能给我 Centos 7 (3.10.0-229.14.1.el7.x86_64) Systemtap 翻译器/驱动程序 (版本 2.6/0.160, rpm 2.6-10.el7_1) gcc 的 DWARF 的链接吗(GCC) 4.8.3 20140911 (红帽 4.8.3-9)

标签: function arguments trace systemtap


【解决方案1】:

这似乎是一个 systemtap 错误。它应该打印 b 的值,而不是它的地址。请将其报告给systemtap@sourceware.org 邮件列表(包含编译器/等版本和其他信息,如man error::reporting 中所述。

至于更改脚本,$$parms 部分是局部变量被转换为漂亮打印字符串的地方。可以改成...

trace(1, $$parms . (@defined($foobar) ? (" foobar=".$foobar$) : ""))

foobar=XYZ 附加到跟踪记录,只要参数foobar 可用。要解决有问题的 systemtap 错误,您可以尝试

trace(1, $$parms . (@defined($b) ? (" *b=".user_int($b)) : ""))

取消引用 b 变量,就像它是 int * 一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-23
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    相关资源
    最近更新 更多