public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Athira Rajeev <atrajeev@in.ibm.com>
To: systemtap@sourceware.org
Cc: suzuki@in.ibm.com, srikar@linux.vnet.ibm.com
Subject: [PATCH] systemtap: Fix parsing of literals in SDT_V3 operand for s390x and ia64
Date: Wed, 03 Oct 2012 14:24:00 -0000	[thread overview]
Message-ID: <20121003071222.1901.62858.stgit@localhost.localdomain> (raw)

systemtap fails to parse literal arguments of the format 'N' ( for example in s390x and ia64 )
The regular expression to match literals is defined in function "visit_target_symbol_arg" as below:

^[i\\$#][-]?[0-9][0-9]*$

In other architectures,
x86_64 - It is of the form $N, which has $ before the literal.
powerpc - It is of the form iN which has i before the literal.

This fails in s390x where literal is of the form 'N' which doesnt have leading $ or i.

This can be reproduced using simple test code and stap script as below:
This test is for SDT_USE_VARIADIC where STAP_PROBEV macro is used.

========================
cat sdt_va_args.c
#define SDT_USE_VARIADIC
#include "sys/sdt.h"

int main()
{
    STAP_PROBEV(test, mark_z);
    STAP_PROBEV(test, mark_a, 10);
    return 0;
}

========================
cat sdt.stp
probe process(@1).mark("mark_z")
{
  printf("_\n");
}

probe process(@1).mark("mark_a")
{
  printf("%d\n", $arg1);
}

========================

Running with stap,

stap sdt.stp sdt_va_args.exe -c ./sdt_va_args.exe
WARNING: Can't parse SDT_V3 operand '10': identifier '$arg1' at sdt.stp:8:18
 source:   printf("%d\n", $arg1);
                          ^
semantic error: unable to find local 'arg1' near pc 0x8000050a  in  main sdt_va_args.c (): identifier '$arg1' at :8:18
        source:   printf("%d\n", $arg1);
                                 ^
Pass 2: analysis failed.  Try again with another '--vp 01' option.

Taking the objdump,

objdump -s -j .note.stapsdt ./sdt_va_args.exe

./sdt_va_args.exe:     file format elf64-s390

Contents of section .note.stapsdt:
 0000 00000008 00000025 00000003 73746170  .......%....stap
 0010 73647400 00000000 80000506 00000000  sdt.............
 0020 80000638 00000000 00000000 74657374  ...8........test
 0030 006d6172 6b5f7a00 00000000 00000008  .mark_z.........
 0040 0000002a 00000003 73746170 73647400  ...*....stapsdt.
 0050 00000000 8000050a 00000000 80000638  ...............8
 0060 00000000 00000000 74657374 006d6172  ........test.mar
 0070 6b5f6100 2d344031 30000000           k_a.-4@10...

Where the argument is of the format "-4@10"

Here stap fails to parse argument of this format ( when it is passed as value directly ).

Below patch in tapsets.cxx fixes this issue:
Here the regex is changed to match literals of form 'N'
Also changed the way it extracts the value as s390x arg format doesnt have leading $, i or # before literal.
This could happen in ia64 also as it has the same format. I have tested this in s390x only.

Signed-off-by: Athira Rajeev <atrajeev@in.ibm.com>
---

 tapsets.cxx |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/tapsets.cxx b/tapsets.cxx
index 71a4ad8..bdba7f3 100644
--- a/tapsets.cxx
+++ b/tapsets.cxx
@@ -5451,11 +5451,17 @@ sdt_uprobe_var_expanding_visitor::visit_target_symbol_arg (target_symbol *e)
       // anyway.  With -mregnames, we could, if gcc somehow
       // communicated to us the presence of that option, but alas it
       // doesn't.  http://gcc.gnu.org/PR44995.
-      rc = regexp_match (asmarg, "^[i\\$#][-]?[0-9][0-9]*$", matches);
+      rc = regexp_match (asmarg, "^[i\\$#]?[-]?[0-9][0-9]*$", matches);
       if (! rc)
         {
-	  string sn = matches[0].substr(1);
+	  int k=0;
 	  int64_t n;
+	  string sn;
+	  const char *tmp = matches[0].c_str();
+	  if ( tmp[k] == 'i' || tmp[k] == '$' || tmp[k] == '#')
+		k++;
+	  sn = matches[0].substr(k);
+
 	  try
 	    {
 	      // We have to pay attention to the size & sign, as gcc sometimes

             reply	other threads:[~2012-10-03 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-03 14:24 Athira Rajeev [this message]
2012-10-09 15:37 ` Frank Ch. Eigler
2012-10-11 10:57   ` Suzuki K. Poulose
2012-10-12 16:07     ` Frank Ch. Eigler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121003071222.1901.62858.stgit@localhost.localdomain \
    --to=atrajeev@in.ibm.com \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=suzuki@in.ibm.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).