0

I have written a systemtap script to profile a C++ program. In the systemtap script I want to extract a class member.

Here is the c++ class definition:

class CFldOrder
{
public:
    ByteArray cust_no;
};

class ByteArray
{
public:
    const char* get_value(){return buf;}
private:
    char* buf[255];
};

Here is the code snippet of the systemtap script:

probe process("/trade/ans_bu").statement("*@entrust.cpp:6614")
{
    g_custno = @cast(FldOrder, "CFldOrder")->cust_no->buf
}

When the script is running, it failed at this probe and said "user string copy fault at addr 0x0000075". I guess it means "@cast(FldOrder, "CFldOrder")->cust_no->buf" is not a valid address.

If I debug this program with gdb and break at the position "entrust.cpp:6614", FldOrder.cust_no.buf is displayed correctly.

How can I fix the script?

Matthias
  • 4,481
  • 12
  • 45
  • 84

1 Answers1

0

The problem is probably that your identifier FldOlder is just a script variable, which stap will interpret as an integer with the initialized value of zero. The @cast expression hides pointer arithmetic to get that 0x00000075 address - which is exactly what you'd get in C++ if you printed & ((CFldOlder*)0)->cust_no->buf.

To fix your script, pass @cast a valid pointer. You probably meant the context variable $FldOlder. You may not even need the @cast (which works like C++ reinterpret_cast<>) if the type of the variable is already CFldOlder*.

fche
  • 2,641
  • 20
  • 28