It appears that inlined_subroutine dwarf records are not always generated for inlined functions, and when they are generated the formal_parameter records of the inlined_subroutine do not always have location records. I have prepared 6 files (2 per case) demonstrating 3 different minimal cases. In each case, the .i file is the input and the .dump file is the result of running eu-readelf --debug-dump a.out. The three cases are: - formal-parameter-but-no-location: this has an inlined_subroutine record with no location attribute on the formal_parameter. the missing attribute should appear around line 77 of the dump. - no-inlined-subroutine-record: this shows that inlined_subroutines are not always generated. the missing record should appear around line 54 of the dump. - constant-formal-parameter-with-location.dump: this has a record in the form I would expect to see in the previous 2 cases: lines 65-77 of the dump show both the inlined_subroutine and formal_parameter with a location attribute. Please let me know if you need more details.
Created attachment 9577 [details] case 1, preprocessed file
Created attachment 9578 [details] case 1, debug info dump
Created attachment 9579 [details] case 2, preprocessed file
Created attachment 9580 [details] case 2, debug info dump
Created attachment 9581 [details] case 3, preprocessed file
Created attachment 9582 [details] case 3, debug info dump
I should also point out that the compile flags for these cases were always "-finline -O2 -g"; I'm not sure how best to tell gcc to enable function-inlining (and nothing else), so this might be a mistake on my part. The cases are small enough that you can retry them on other flags and experiment.
A lot of these are all because we optimize stuff away. like the no-inlined-subroutine is because we just get "return 11;". Others look like they are fixed in 4.1.0.
If you compile with -dA you will get readable DWARF2 debug info in the .s file. Case 1: There is no location info for the parameter x because it has been optimized away. Change the variable x in main to y to avoid ambiguity, compile with -fdump-tree-all, and look at the t27 and t29 dumps. In the t27 dump, the variable x is there and assigned to. In the t29 dump, the variable x is there, but no longer assigned to. Since it is no longer assigned to, we never allocate space for it, and hence no location attribute can be emitted. t29 is the copyrename dump file. If I compile with -fno-tree-copyrename, then I do get a location attribute for the parameter x in the inlined copy of foo. I don't think there is any bug here, but if there is, it would be in the tree copyrename pass, because there is no longer any useful parameter x when it is done. Case 2: Similar situation. The tree-ssa optimizers optimize away all trace of the inline foo function. By the time we get to the end of tree-ssa, all we have left is return 11. If you look in the .00.expand RTL dump, there are no line number notes or basic block notes associated with the inline foo. Since there is no inline foo, the debug output routines can't do anything here. I tried all of the -fno-tree-* options, but that doesn't help. This is apparently something that can't be turned off. If we really want debug info in this case, then the tree optimizers need to be modified to preserve lexical blocks and variables that originated in inlined functions. Not clear if this is desirable. Case 3: The difference here is that the tree optimizers are not able to completely optimize away the for loop in the inline function. Since we still have lines of code from the inline function, and stores to the parameter x, when the tree-ssa optimizers are done, we get the debug info you expect. Summary, these problems are all issues with tree optimizers destroying info when optimizing. Case 1 probably can't be fixed without hurting optimization, and hence is probably not feasible to fix it. A partial fix to Case 2 may be feasible, as the tree optimizers can perhaps be taught to keep the lexical block needed to represent the inline function foo. However, as in case 1, there will be no location attribute for x though, and this can't be fixed without disabling optimizations. Case 3 is the good example, there is nothing broken here.
(In reply to comment #9) > Case 1: > There is no location info for the parameter x because it has been optimized > away. Change the variable x in main to y to avoid ambiguity, compile with > -fdump-tree-all, and look at the t27 and t29 dumps. In the t27 dump, the > variable x is there and assigned to. In the t29 dump, the variable x is there, > but no longer assigned to. Since it is no longer assigned to, we never > allocate space for it, and hence no location attribute can be emitted. t29 is > the copyrename dump file. If I compile with -fno-tree-copyrename, then I do > get a location attribute for the parameter x in the inlined copy of foo. I > don't think there is any bug here, but if there is, it would be in the tree > copyrename pass, because there is no longer any useful parameter x when it is > done. For the record, I encountered this problem today also (formals with no location information). Not a single argument had a location. Adding -fno-tree-copyrename fixed one (of about seven). In this case the variables are all used, mostly in non-trivial ways. My testcase was eval.c from GDB; the function evaluate_struct_tuple is inlined and debugging into it is quite hard. I'm working on improving this in GDB, but I can't improve where the compiler gives me nothing to work with. We already know that there are many similar problems in the tree optimizers; I'm just adding a data point.
Every inlined function starts with copying of argument initializers into the formal arguments. This makes such copies too suitable for SSA coalescing. It appears to me that it would be desirable to arrange for coalescing to somehow preserve information as to which variables have been coalesced, such that we can emit debug info for all coalesced variables, not just one of them. It sounds like a lot of work, though.
Case 2 was filed as PR 29792 and was declared invalid. Though we get currently: .uleb128 0x2 # (DIE (0x25) DW_TAG_subprogram) .ascii "foo\0" # DW_AT_name .byte 0x1 # DW_AT_decl_file (no-inlined-instance-record.c) .byte 0x2 # DW_AT_decl_line .byte 0x1 # DW_AT_prototyped .long 0x40 # DW_AT_type .byte 0x3 # DW_AT_inline .long 0x40 # DW_AT_sibling .uleb128 0x3 # (DIE (0x36) DW_TAG_formal_parameter) .ascii "x\0" # DW_AT_name .byte 0x1 # DW_AT_decl_file (no-inlined-instance-record.c) .byte 0x1 # DW_AT_decl_line .long 0x40 # DW_AT_type .byte 0x0 # end of children of DIE 0x25 Case 1, is also too hard to fix as it would make us lose a lot of optimizations. Really what GCC is producing is the best debugging you can get for these functions.
> Case 1, is also too hard to fix as it would make us lose a lot of > optimizations. If aoliva is correct in comment# 11, then some information is being lost that could be retained with some additional effort. That would make this bug other than invalid - at best a wontfix.
(In reply to comment #13) > If aoliva is correct in comment# 11, then some information is being lost > that could be retained with some additional effort. That would make this > bug other than invalid - at best a wontfix. Lets look at this again. A simplified testcase without inlining: int main () { int x1 = 3; { int x = x1; int i = 0; for (i = 0; i < x; ++i) x += i; return x; } } This is basically the same as case 1 (though a constant instead of a call to rand()), now do we want not to prop x1 into x? I say we always do want that because otherwise we get an extra assignment. Plus this issue is not a regression at all because the RTL level does the same.
(In reply to comment #14) > This is basically the same as case 1 (though a constant instead of a call to > rand()), now do we want not to prop x1 into x? I say we always do want that > because otherwise we get an extra assignment. I believe the idea was to emit extra DWARF for that copy-propagation, so as to treat the destination as a location-list-level alias of the source. The idea was not to inhibit the copy, just to "document it", if that is sensible & feasible. > Plus this issue is not a regression at all because the RTL level does the same. (Did someone say it was?)
Subject: Bug number PR 23551 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-05/msg00703.html
Subject: Bug 23551 Author: aoliva Date: Fri Jul 6 08:38:40 2007 New Revision: 126402 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126402 Log: PR debug/23551 * tree-ssa-copyrename.c (copy_rename_partition_coalesce): Disregard DECL_FROM_INLINE. Modified: trunk/gcc/ChangeLog trunk/gcc/tree-ssa-copyrename.c
Subject: Bug 23551 Author: aoliva Date: Mon Jul 9 19:24:23 2007 New Revision: 126492 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126492 Log: Revert: 2007-07-06 Alexandre Oliva <aoliva@redhat.com> PR debug/23551 * tree-ssa-copyrename.c (copy_rename_partition_coalesce): Disregard DECL_FROM_INLINE. Modified: trunk/gcc/ChangeLog trunk/gcc/tree-ssa-copyrename.c
I have one further case that may be worth adding to this ticket which relates to the order of formal paramters emitted for an inlined subroutine in debug info. GCC currently emits formal parameter DIEs for an inlined subroutine in reverse order to the function's parameters. The DWARF spec is slightly unclear in this area but does indicate that formal parameters must appear in the same order as listed in the function prototype in both abstract and concrete instances. One potential fix would be to change setup_one_parameter in tree-inline.c to append each new VAR_DECL to the vars list instead of prepend them. There may however be a more elegant approach by modifying the dwarf engine to detect and re-order VAR_DECLs that relate to formal paramters and emit them in the correct order. If this would be best as a separate ticket then I will open one.
(In reply to Matthew Fortune from comment #19) > I have one further case that may be worth adding to this ticket which > relates to the order of formal paramters emitted for an inlined subroutine > in debug info. > > GCC currently emits formal parameter DIEs for an inlined subroutine in > reverse order to the function's parameters. The DWARF spec is slightly > unclear in this area but does indicate that formal parameters must appear in > the same order as listed in the function prototype in both abstract and > concrete instances. > > One potential fix would be to change setup_one_parameter in tree-inline.c to > append each new VAR_DECL to the vars list instead of prepend them. There may > however be a more elegant approach by modifying the dwarf engine to detect > and re-order VAR_DECLs that relate to formal paramters and emit them in the > correct order. > > If this would be best as a separate ticket then I will open one. If a separate ticket would let us close this one, then yes, please open one.
There is PR103047 for that now.