Bug 6905 - process("a").statement("main@/root/a.c:*") fails by giving error message.
Summary: process("a").statement("main@/root/a.c:*") fails by giving error message.
Status: RESOLVED FIXED
Alias: None
Product: systemtap
Classification: Unclassified
Component: translator (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-19 08:47 UTC by Srinivasa DS
Modified: 2009-09-21 18:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
patch for 6905 (907 bytes, patch)
2008-12-15 09:02 UTC, Wenji Huang
Details | Diff
patch and testcase (1.21 KB, patch)
2009-07-27 02:38 UTC, Wenji Huang
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srinivasa DS 2008-09-19 08:47:10 UTC
Environment: elfutils-0.137, systemtap-20080913 snapshot.

I was developing testcases for uprobes, But any attempt to probe all statements
of a file fails by giving error message.

Consider a .c file /root
=================================
 1 #include<stdlib.h>
  2 int main()
  3 {
  4 int i=0;
  5 i = i + 5;
  6 printf("i value is %d \n", i);
  7 return 0;
  8 }
================================

Execution of below script fails by throwing error message.
./stap -vvvvvv -e 'probe process("/root/a.out").statement("main@/root/ex.c:*") {
printf("%s\n",pp())}'  
================================
SystemTap translator/driver (version 0.7.1/0.131 non-git sources)
Copyright (C) 2005-2008 Red Hat, Inc. and others
This is free software; see the source for copying conditions.
Session arch: x86_64 release: 2.6.18-113.el5
Created temporary directory "/tmp/stap27MWVb"
Searched '/usr/local/share/systemtap/tapset/x86_64/*.stp', found 2
Searched '/usr/local/share/systemtap/tapset/*.stp', found 43
Pass 1: parsed user script and 45 library script(s) in 230usr/10sys/250real ms.
parsed 'main@/root/ex.c:*' -> func 'main', file '/root/ex.c', line 0x7fffd3382624
pattern '/root/a.out' matches module '/root/a.out'
focused on module '/root/a.out = [0x400000-0x600898, bias 0x0] file /root/a.out
ELF machine x86_64 (code 62)
focused on module '/root/a.out'
selected source file '/root/ex.c'
function cache /root/a.out:ex.c size 1
function cache /root/a.out:ex.c hit main
pattern 'main' matches function 'main'
selected function main
function DIE lands on srcfile
probe main@/root/ex.c:3 process=/root/a.out reloc=.absolute section=.text
pc=0x400498
function DIE lands on srcfile
probe main@/root/ex.c:4 process=/root/a.out reloc=.absolute section=.text
pc=0x4004a0
function DIE lands on srcfile
probe main@/root/ex.c:5 process=/root/a.out reloc=.absolute section=.text
pc=0x4004a7
function DIE lands on srcfile
probe main@/root/ex.c:6 process=/root/a.out reloc=.absolute section=.text
pc=0x4004ab
function DIE lands on srcfile
probe main@/root/ex.c:7 process=/root/a.out reloc=.absolute section=.text
pc=0x4004bd
function DIE lands on srcfile
probe main@/root/ex.c:8 process=/root/a.out reloc=.absolute section=.text
pc=0x4004c2
semantic error: libdw failure (dwarf_getsrc_file): no matching address range
dwarf_builder releasing user dwflpp /root/a.out
Pass 2: analyzed script: 6 probe(s), 29 function(s), 0 embed(s), 0 global(s) in
0usr/0sys/7real ms.
Pass 2: analysis failed.  Try again with more '-v' (verbose) options.
Running rm -rf /tmp/stap27MWVb
========================================
Comment 1 Srinivasa DS 2008-09-19 11:16:45 UTC
Passing invalid line number(line number greater than last line of the file) to
dwarf_getsrc_file() is causing the problem.
=================================================================
 void iterate_over_srcfile_lines (char const * srcfile,
                                   int lines[2],
                                   bool need_single_match,
                                   enum line_t line_type,
                                   void (* callback) (const dwarf_line_t& line,
                                                      void * arg),
                                   void *data)
  {
    Dwarf_Line **srcsp = NULL;
    size_t nsrcs = 0;
    dwarf_query * q = static_cast<dwarf_query *>(data);
    int lineno = lines[0];
    auto_free_ref<Dwarf_Line**> free_srcsp(srcsp);

    get_module_dwarf();
    ...........................
    ...........................
    dwarf_assert ("dwarf_getsrc_file",
                      dwarf_getsrc_file (module_dwarf,
                                         srcfile, l, 0,
                                         &srcsp, &nsrcs));
        if (line_type == WILDCARD || line_type == RANGE)
          {
            Dwarf_Addr line_addr;
            dwarf_lineno (srcsp [0], &lineno);
            line_probed = lines_probed.insert(lineno);
            if (lineno != l || line_probed.second == false || nsrcs > 1)
              continue;
            dwarf_lineaddr (srcsp [0], &line_addr);
            if (dwarf_haspc (function, line_addr) != 1)
              break;
          }
=======================================================
Comment 2 Wenji Huang 2008-12-15 09:02:21 UTC
Created attachment 3108 [details]
patch for 6905

Let stap tolerate invalid line and break matching for wildcard and range case.
Meanwhile make stap smart to check line range.
Comment 3 Frank Ch. Eigler 2008-12-16 17:51:49 UTC
The patch looks plausible, but please also submit a test case and results.
Comment 4 Wenji Huang 2008-12-17 02:49:08 UTC
Same C file as above described.
$ gcc -g -o ex ex.c
$ stap -p2 -w -e 'probe
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") {}'  
# probes
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:3") /*
pc=.absolute+0x4004cc */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:4") /*
pc=.absolute+0x4004d4 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:5") /*
pc=.absolute+0x4004db */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:6") /*
pc=.absolute+0x4004df */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:7") /*
pc=.absolute+0x4004f1 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:8") /*
pc=.absolute+0x4004f6 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:*") */

Invalid Range:
$ stap -p2 -w -e 'probe
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c: 1-2") {}'  
semantic error: Starting line number for /home/wjhuang/ex.c : 3
semantic error: no match while resolving probe point
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-2")
semantic error: no probes found
Pass 2: analysis failed.  Try again with another '--vp 01' option.

Excessive Range:
$ stap -p2 -w -e 'probe
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") {}'  
# probes
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:3") /*
pc=.absolute+0x4004cc */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:4") /*
pc=.absolute+0x4004d4 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:5") /*
pc=.absolute+0x4004db */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:6") /*
pc=.absolute+0x4004df */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:7") /*
pc=.absolute+0x4004f1 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:8") /*
pc=.absolute+0x4004f6 */ /* <-
process("/home/wjhuang/ex").statement("main@/home/wjhuang/ex.c:1-20") */
Comment 5 Frank Ch. Eigler 2008-12-18 18:15:03 UTC
Having looked into this area a bit more, it seems like we have
some major cleanup to do.  See also bug #5076, bug #2475, and
even bug #6864.  I'll try to reorganize this area of the code,
which should make your patch moot.  Can you hold on a few weeks?
Comment 6 Wenji Huang 2008-12-19 02:04:28 UTC
np. Like to rebase on new organized code if needed.
Comment 7 Wenji Huang 2009-07-27 02:38:24 UTC
Created attachment 4087 [details]
patch and testcase

The related code has been re-organized, but the problem still exists. The patch

has been rebased and a simple test case is provided.

Example:
$ stap -p2 -e 'probe
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*")
{print("ok")}'
# probes
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:4") /*
pc=.absolute+0x80483c4 */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:5") /*
pc=.absolute+0x80483cd */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:6") /*
pc=.absolute+0x80483d5 */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:7") /*
pc=.absolute+0x80483da */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:8") /*
pc=.absolute+0x80483ee */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:9") /*
pc=.absolute+0x80483f3 */ /* <-
process("/home/wjhuang/a.out").statement("main@/home/wjhuang/test.c:*") */
Comment 8 Wenji Huang 2009-07-28 02:07:44 UTC
commit	1123a74ab28d4ae9f2db0d704ce3981064ed9591
Comment 9 Frank Ch. Eigler 2009-09-21 18:31:49 UTC
committed