diff mbox

Add 'force-dwarf-lexical-blocks' command line option

Message ID 53D65490.7000601@codesourcery.com
State New
Headers show

Commit Message

Herman, Andrei July 28, 2014, 1:48 p.m. UTC
Please find attached the fixed patch files for this change:
	1. Add command line option -fforce-dwarf-lexical-blocks.
	2. Support flag_force_dwarf_blocks in C.
	3. Support flag_force_dwarf_blocks in C++.

Attached also are the proposed ChangeLog additions, named according to 
the directory each one belongs to.

All check-c and check-c++ tests have been run for unix target, with and 
without the new option.
The only test that failed with the -fforce-dwarf-lexical-blocks set and 
passed without this flag was:
FAIL: gcc.dg/debug/dwarf2/inline2.c scan-assembler-times \\(DIE 
\\([^\n]*\\) DW_TAG_lexical_block 6
as expected.

Best regards,
Andrei Herman
Mentor Graphics Corporation
Israel branch


On 6/20/2014 12:09 AM, Joseph S. Myers wrote:
> On Sun, 1 Jun 2014, Herman, Andrei wrote:
>
>> +  /* The -fforce-dwarf-lexical-blocks option is only relevant when debug
>> +     info is in DWARF4 format */
>> +  if (flag_force_dwarf_blocks) {
>
> Watch coding style: the opening '{' always goes on the next line.
>
>> +fforce-dwarf-lexical-blocks
>> +C C++ Var(flag_force_dwarf_blocks)
>> +Force generation of lexical blocks in dwarf output
>
> I don't see a good reason for this not to be supported for ObjC and ObjC++
> as well.  Say DWARF, not dwarf.
>
>> +@item -fforce-dwarf-lexical-blocks
>> +Produce debug information (a DW_TAG_lexical_block) for every function
>> +body, loop body, switch body, case statement, if-then and if-else statement,
>> +even if the body is a single statement.  Likewise, a lexical block will be
>> +emitted for the first label of a statement.  This block ends at the end of the
>> +current lexical scope, or when a break, continue, goto or return statement is
>> +encountered at the same lexical scope level.  This option is usefull for
>> +coverage tools that utilize the dwarf debug information.
>> +This option only applies to C/C++ code and is available when using DWARF
>> +Version 4 or higher.
>
> Use @code{} markup for keywords (if, else, break, continue, goto, return).
> "useful" not "usefull".  "DWARF" not "dwarf".
>
>> +/* Create a block_loc struct for a statement list created on behalf of
>> +   flag_force_dwarf_blocks.  We use this for label or forced c99 scopes.  */
>> +
>> +void
>> +push_block_info (tree block, location_t loc, bool is_label)
>> +{
>> +  if (TREE_CODE(block) != STATEMENT_LIST)
>
> Watch coding style: space before '(' in function and macro calls (and
> similar calls such as sizeof) (many places in this patch, not just this
> one).
>
>> +tree
>> +pop_block_info (location_t &loc)
>
> It's not documented in codingconventions.html, but I think it's preferred
> to avoid returning values through reference arguments (see e.g.
> <https://gcc.gnu.org/ml/gcc-patches/2013-11/msg00198.html>).
>
>> +{
>> +  block_loc  tl = NULL;
>
> Excess space between "block_loc" and "tl".
>
>> @@ -4679,7 +4712,7 @@ c_parser_compound_statement_nostart (c_parser *parser)
>>     expressions being rejected later.  */
>>
>> static void
>> -c_parser_label (c_parser *parser)
>> +c_parser_label (c_parser *parser, bool prev_label)
>
> You're adding a new argument - you need to update the comment above this
> function to explain the semantics of this argument.
>
> In general, make sure that new functions have comments above them that
> explain the semantics of the arguments (by name) and any return value.
>
>> +/* If current scope is a label scope, pop it from block info stack
>> +   and close it's compound statement.  */
>
> "its" not "it's".
>
From 113007fbf8de51f14f77ba9e652abbcc45c8316a Mon Sep 17 00:00:00 2001
From: Andrei Herman <Andrei_Herman@codesourcery.com>
Date: Sun, 27 Jul 2014 15:47:05 +0300
Subject: [PATCH 1/3] 	Add command line option -fforce-dwarf-lexical-blocks.

	* gcc/c-family/c.opt: Add -fforce-dwarf-lexical-blocks flag.
	* gcc/c-family/c-opts.c (c_common_post_options): Limit its use
	to DWARF4.
	* gcc/doc/invoke.texi: Document the new option.

Signed-off-by: Andrei Herman <Andrei_Herman@codesourcery.com>
---
 gcc/c-family/c-opts.c | 15 +++++++++++++++
 gcc/c-family/c.opt    |  4 ++++
 gcc/doc/invoke.texi   | 12 ++++++++++++
 3 files changed, 31 insertions(+)

Comments

Joseph Myers Aug. 14, 2014, 9:14 p.m. UTC | #1
On Mon, 28 Jul 2014, Herman, Andrei wrote:

> Please find attached the fixed patch files for this change:
> 	1. Add command line option -fforce-dwarf-lexical-blocks.
> 	2. Support flag_force_dwarf_blocks in C.

The front-end parts of these patches are OK with the changes indicated 
below if the non-front-end parts are approved.

> +  /* The -fforce-dwarf-lexical-blocks option is only relevant when debug
> +     info is in DWARF4 format.  */
> +  if (flag_force_dwarf_blocks)
> +    {
> +      if (write_symbols != DWARF2_DEBUG)
> +        flag_force_dwarf_blocks = 0;
> +      if (write_symbols == DWARF2_DEBUG && dwarf_version < 4)
> +        {
> +          inform (input_location,
> +                  "-fforce-dwarf-lexical-blocks is only supported with "
> +                  "DWARF4 debug format");
> +          flag_force_dwarf_blocks = 0;
> +        }
> +    }

If it's deliberate not to give the diagnostic for write_symbols != 
DWARF2_DEBUG, please add a comment explaining why the diagnostic is not 
given in that case.

> +fforce-dwarf-lexical-blocks
> +C C++ Var(flag_force_dwarf_blocks)
> +Force generation of lexical blocks in DWARF output

As previously noted, should also be enabled for ObjC and ObjC++ unless 
there is a clear reason not to do so.

> +/* Information about a statement list created for a label (is_label=true)
> +   or for a forced c99 scope.  The -fforce-dwarf-lexical-blocks will

"The -fforce-dwarf-lexical-blocks option".
diff mbox

Patch

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 29e9a35..058a344 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -936,6 +936,21 @@  c_common_post_options (const char **pfilename)
 #endif
     }
 
+  /* The -fforce-dwarf-lexical-blocks option is only relevant when debug
+     info is in DWARF4 format.  */
+  if (flag_force_dwarf_blocks)
+    {
+      if (write_symbols != DWARF2_DEBUG)
+        flag_force_dwarf_blocks = 0;
+      if (write_symbols == DWARF2_DEBUG && dwarf_version < 4)
+        {
+          inform (input_location,
+                  "-fforce-dwarf-lexical-blocks is only supported with "
+                  "DWARF4 debug format");
+          flag_force_dwarf_blocks = 0;
+        }
+    }
+
   if (flag_preprocess_only)
     {
       /* Open the output now.  We must do so even if flag_no_output is
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index c586e65..c3e6cc2 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -960,6 +960,10 @@  ffor-scope
 C++ ObjC++ Var(flag_new_for_scope) Init(1)
 Scope of for-init-statement variables is local to the loop
 
+fforce-dwarf-lexical-blocks
+C C++ Var(flag_force_dwarf_blocks)
+Force generation of lexical blocks in DWARF output
+
 ffreestanding
 C ObjC C++ ObjC++
 Do not assume that standard C libraries and \"main\" exist
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 9475594..56f0a6e 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -333,6 +333,7 @@  Objective-C and Objective-C++ Dialects}.
 -feliminate-unused-debug-symbols -femit-class-debug-always @gol
 -fenable-@var{kind}-@var{pass} @gol
 -fenable-@var{kind}-@var{pass}=@var{range-list} @gol
+-fforce-dwarf-lexical-blocks @gol
 -fdebug-types-section -fmem-report-wpa @gol
 -fmem-report -fpre-ipa-mem-report -fpost-ipa-mem-report -fprofile-arcs @gol
 -fopt-info @gol
@@ -5200,6 +5201,17 @@  normally emits debugging information for classes because using this
 option increases the size of debugging information by as much as a
 factor of two.
 
+@item -fforce-dwarf-lexical-blocks
+Produce debug information (a DW_TAG_lexical_block) for every function
+body, loop body, @code{switch} body, @code{case} statement, @code{if} and
+@code{else} statement, even if the body is a single statement.  Likewise, a
+lexical block will be emitted for the first label of a statement.  This block
+ends at the end of the current lexical scope, or when a @code{break},
+@code{continue}, @code{goto} or @code{return} statement is encountered at the
+same lexical scope level.  This option is useful for coverage tools that
+utilize the DWARF debug information.  This option only applies to C/C++ code
+and is available when using DWARF Version 4 or higher.
+
 @item -fdebug-types-section
 @opindex fdebug-types-section
 @opindex fno-debug-types-section