]> sourceware.org Git - systemtap.git/commitdiff
PR4166: Allow array-like indexing on pointers
authorJosh Stone <jistone@redhat.com>
Wed, 15 Jul 2009 00:57:16 +0000 (17:57 -0700)
committerJosh Stone <jistone@redhat.com>
Wed, 15 Jul 2009 00:57:16 +0000 (17:57 -0700)
* dwflpp.cxx (dwflpp::translate_components): let pointers get treated
  the same as arrays, and add a final DIE dereference for array access.
* loc2c.c (c_translate_array): tolerate pointer types
* testsuite/systemtap.base/pointer_array.*: new test

dwflpp.cxx
loc2c.c
testsuite/systemtap.base/pointer_array.exp [new file with mode: 0644]
testsuite/systemtap.base/pointer_array.stp [new file with mode: 0644]

index 8fa31c6ac518b33f96def5fd722499e7c723fd7b..3f30e3a8e5d8f0e5a27348f32ca3ee28baadfafb 100644 (file)
@@ -1684,13 +1684,10 @@ dwflpp::translate_components(struct obstack *pool,
           break;
 
         case DW_TAG_pointer_type:
-          if (e->components[i].first == target_symbol::comp_literal_array_index)
-            throw semantic_error ("cannot index pointer", e->tok);
-          // XXX: of course, we should support this the same way C does,
-          // by explicit pointer arithmetic etc.  PR4166.
-
           c_translate_pointer (pool, 1, 0 /* PR9768*/, die, tail);
-          break;
+          if (e->components[i].first != target_symbol::comp_literal_array_index)
+            break;
+          /* else fall through as an array access */
 
         case DW_TAG_array_type:
           if (e->components[i].first == target_symbol::comp_literal_array_index)
@@ -1772,6 +1769,11 @@ dwflpp::translate_components(struct obstack *pool,
       if (dwarf_attr_integrate (die, DW_AT_type, attr_mem) == NULL)
         throw semantic_error ("cannot get type of field: " + string(dwarf_errmsg (-1)), e->tok);
     }
+
+  /* For an array index, we need to dereference the final DIE */
+  if (e->components.back().first == target_symbol::comp_literal_array_index)
+    die = dwarf_formref_die (attr_mem, die_mem);
+
   return die;
 }
 
diff --git a/loc2c.c b/loc2c.c
index 5f4e449546ad8717b2ae584b9541d0575c84efdd..1543463243c7154b9badf94861c3ac1b2026f0bf 100644 (file)
--- a/loc2c.c
+++ b/loc2c.c
@@ -1745,7 +1745,8 @@ c_translate_array (struct obstack *pool, int indent,
                   Dwarf_Die *typedie, struct location **input,
                   const char *idx, Dwarf_Word const_idx)
 {
-  assert (dwarf_tag (typedie) == DW_TAG_array_type);
+  assert (dwarf_tag (typedie) == DW_TAG_array_type ||
+          dwarf_tag (typedie) == DW_TAG_pointer_type);
 
   ++indent;
 
diff --git a/testsuite/systemtap.base/pointer_array.exp b/testsuite/systemtap.base/pointer_array.exp
new file mode 100644 (file)
index 0000000..0e3af21
--- /dev/null
@@ -0,0 +1,13 @@
+set test "pointer_array"
+set ::result_string {/bin/true
+/
+b
+i
+n
+/
+t
+r
+u
+e
+0}
+stap_run2 $srcdir/$subdir/$test.stp -c/bin/true
diff --git a/testsuite/systemtap.base/pointer_array.stp b/testsuite/systemtap.base/pointer_array.stp
new file mode 100644 (file)
index 0000000..1d15ebf
--- /dev/null
@@ -0,0 +1,16 @@
+probe syscall.execve
+{
+    if (pid() == target()) {
+        println(user_string($argv[0]))
+        printf("%c\n", $argv[0][0])
+        printf("%c\n", $argv[0][1])
+        printf("%c\n", $argv[0][2])
+        printf("%c\n", $argv[0][3])
+        printf("%c\n", $argv[0][4])
+        printf("%c\n", $argv[0][5])
+        printf("%c\n", $argv[0][6])
+        printf("%c\n", $argv[0][7])
+        printf("%c\n", $argv[0][8])
+        println($argv[0][9])
+    }
+}
This page took 0.039 seconds and 5 git commands to generate.