Bug 23738 - c++ string access tapset
Summary: c++ string access tapset
Status: NEW
Alias: None
Product: systemtap
Classification: Unclassified
Component: tapsets (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: William Cohen
Depends on:
Reported: 2018-10-04 15:47 UTC by William Cohen
Modified: 2018-10-18 16:38 UTC (History)
1 user (show)

See Also:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description William Cohen 2018-10-04 15:47:35 UTC
The systemtap example script stap_time.stp needed to access C++ strings provided inside the session variable to get the script name.

$ stap -L "stap.pass*"
stap.pass0 session:long $arg1:long
stap.pass1a session:long $arg1:long
stap.pass1b session:long $arg1:long
stap.pass2 session:long $arg1:long
stap.pass3 session:long $arg1:long
stap.pass4 session:long $arg1:long
stap.pass5 session:long $arg1:long
stap.pass6 session:long $arg1:long

Ended up with some ugly code like the following snippet to implement this:

    len = @cast(session, "struct systemtap_session")->script_file->_M_string_length
    if (len <= 15) {
      script_file = @cast(session, "struct systemtap_session")->script_file->_M_local_buf
    } else {
      script_file = @cast(session, "struct systemtap_session")->script_file->_M_dataplus->_M_p

There should be c++ string tapset like the existing access to traditional C strings user_string() et al.
Comment 1 William Cohen 2018-10-15 18:30:55 UTC
There are differences between f28 and rhel7, so needed something like the following on rhel7 for the code to work.

  // Dig through C++ string private fields to find the systemtap script name
  cmdline_script = @cast(session, "struct systemtap_session")->cmdline_script->_M_dataplus->_M_p
  if (strlen(user_string2(cmdline_script, "<unavailable>"))){
    script = "<cmdline_script>"
  } else {
    script_file = @cast(session, "struct systemtap_session")->script_file->_M_dataplus->_M_p
    script = user_string2(script_file, "<unavailable>")