]> sourceware.org Git - systemtap.git/commitdiff
PR20423: improve 'struct {...} being accessed instead of member' message
authorFrank Ch. Eigler <fche@redhat.com>
Sun, 31 Jul 2016 17:57:32 +0000 (13:57 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Sun, 31 Jul 2016 17:57:32 +0000 (13:57 -0400)
Esp. for anonymous structures, this message was not very helpful.
The new message is much more complete:

semantic error: 'struct {...}' (include/linux/types.h:175) is being accessed instead of a member such as '->counter': operator '->' at <input>:1:81
        source: probe kernel.function("dput") { println( @cast($dentry->d_inode, "struct inode")->i_count) }
                                                                                                ^

dwflpp.cxx

index 22c4f95ca4d7f0b57effdeb7c9092384a056fa57..f245d1290cb04a83a6928dfcab496b85ea5ea54d 100644 (file)
@@ -3680,8 +3680,37 @@ dwflpp::translate_final_fetch_or_store (struct obstack *pool,
     case DW_TAG_structure_type:
     case DW_TAG_class_type:
     case DW_TAG_union_type:
-      throw SEMANTIC_ERROR (_F("'%s' is being accessed instead of a member",
-                               dwarf_type_name(typedie).c_str()), e->tok);
+      {
+        string type_name = dwarf_type_name(typedie);
+        string decl_file = dwarf_decl_file(typedie) ?: "";
+        int decl_line = 0;
+        (void) dwarf_decl_line(typedie, &decl_line);
+        string decl_source;
+        // PR20423: assemble an error message at least as informative
+        // as bad-member message in translate_components()
+        if (decl_file[0] && decl_line > 0)
+          decl_source = " (" + decl_file + ":" + lex_cast(decl_line) + ")";
+        string a_member; 
+        try
+          {
+            set<string> members;
+            set<string> dupes;
+            get_members (typedie, members, dupes);
+            if (members.begin() != members.end())
+              {
+                a_member = " such as '->" + (*members.begin()) + "'";
+              }
+          }
+        catch (...)
+          {
+            // leave a_member empty
+          }
+        throw SEMANTIC_ERROR (_F("'%s'%s is being accessed instead of a member%s",
+                                 type_name.c_str(),
+                                 decl_source.c_str(),
+                                 a_member.c_str()),
+                              e->components[e->components.size()-1].tok);
+      }
       break;
 
     case DW_TAG_base_type:
This page took 0.031729 seconds and 5 git commands to generate.