* [patch] Correct `gcc -D' macros get ignored (PR 9873)
@ 2009-02-20 0:20 Jan Kratochvil
[not found] ` <20090228071514.GA25299@adacore.com>
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2009-02-20 0:20 UTC (permalink / raw)
To: gdb-patches
Hi,
http://sourceware.org/bugzilla/show_bug.cgi?id=9873
There is a GCC patch to fix DWARF macros defined from gcc command line
http://sourceware.org/bugzilla/attachment.cgi?id=3753&action=view
but current GDB starts to ignore such macros. Thus the GDB HEAD acceptance is
a prerequisite for the GCC HEAD change.
Command line macros should be defined _before_ first DW_MACINFO_start_file:
Regression tested on x86_64-unknown-linux-gnu.
current GCC:
Contents of the .debug_macinfo section:
DW_MACINFO_start_file - lineno: 0 filenum: 1
DW_MACINFO_define - lineno : 0 macro : __STDC__ 1
DW_MACINFO_define - lineno : 0 macro : __STDC_HOSTED__ 1
patched GCC:
Contents of the .debug_macinfo section:
DW_MACINFO_define - lineno : 0 macro : __STDC__ 1
DW_MACINFO_define - lineno : 0 macro : __STDC_HOSTED__ 1
http://dwarf.freestandards.org/Dwarf3.pdf
6.3.3 Macinfo Entries for Command Line Options
[..]
All such DW_MACINFO_define and DW_MACINFO_undef entries representing
compilation options should appear before the first DW_MACINFO_start_file entry
for that compilation unit and should encode the value 0 in their line number
operands.
current GCC + current GDB:
patched GCC + patched GDB:
(gdb) info macro __STDC__
Defined at ../.././gdb/testsuite/gdb.base/macscp1.c:0
#define __STDC__ 1
patched GCC + current GDB:
During symbol reading, debug info gives macro definition outside of any file: __STDC__ 1.
During symbol reading, debug info gives macro definition outside of any file: __STDC_HOSTED__ 1.
(gdb) info macro __STDC__
The symbol `__STDC__' has no definition as a C/C++ preprocessor macro
at gdb.base/macscp1.c:102
current GCC + patched GDB:
During symbol reading, debug info gives in-file macro definition with zero line 0: __STDC__ 1.
During symbol reading, debug info gives in-file macro definition with zero line 0: __STDC_HOSTED__ 1.
(gdb) info macro __STDC__
Defined at ../.././gdb/testsuite/gdb.base/macscp1.c:0
#define __STDC__ 1
Thanks,
Jan
gdb/
2009-02-19 Jan Kratochvil <jan.kratochvil@redhat.com>
PR gdb/9873:
* dwarf2read.c (dwarf_decode_macros): New variable `at_commandline'.
Move the variable `macinfo_type' out of the loop. Create a new
processing pass before the current one to pre-create `current_file'.
New complaint on misplaced zero/non-zero definitions/includes.
Skip first DW_MACINFO_start_file with `at_commandline' set.
gdb/testsuite/
2009-02-19 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/macscp.exp: New option `-DFROM_COMMANDLINE'. New workaround
of a ccache bug.
(info_macro): Suffix the filename for command line macros.
(info macro FROM_COMMANDLINE after `list main'): New test.
--- gdb/dwarf2read.c 12 Feb 2009 09:15:06 -0000 1.295
+++ gdb/dwarf2read.c 19 Feb 2009 21:05:11 -0000
@@ -9963,6 +9963,17 @@ dwarf_decode_macros (struct line_header
{
gdb_byte *mac_ptr, *mac_end;
struct macro_source_file *current_file = 0;
+ enum dwarf_macinfo_record_type macinfo_type;
+
+ /* Flag is in use by the second pass and determines if GDB is still before
+ first DW_MACINFO_start_file. If true GDB is still reading the definitions
+ from command line. First DW_MACINFO_start_file will need to be ignored as
+ it was already executed to create CURRENT_FILE for the main source holding
+ also the command line definitions. On first met DW_MACINFO_start_file
+ this flag is reset to normally execute all the remaining
+ DW_MACINFO_start_file macinfos. */
+
+ int at_commandline;
if (dwarf2_per_objfile->macinfo_buffer == NULL)
{
@@ -9970,19 +9981,24 @@ dwarf_decode_macros (struct line_header
return;
}
+ /* Start the first pass to find ahead the main source file name. GDB has to
+ create CURRENT_FILE where to place the macros given to the compiler
+ from the command line. Such command line macros are present before first
+ DW_MACINFO_start_file but still those macros are associated to the
+ compilation unit. The compilation unit GDB identifies by its main source
+ file name. */
+
mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
mac_end = dwarf2_per_objfile->macinfo_buffer
+ dwarf2_per_objfile->macinfo_size;
- for (;;)
+ do
{
- enum dwarf_macinfo_record_type macinfo_type;
-
/* Do we at least have room for a macinfo type byte? */
if (mac_ptr >= mac_end)
{
dwarf2_macros_too_long_complaint ();
- return;
+ break;
}
macinfo_type = read_1_byte (abfd, mac_ptr);
@@ -9993,7 +10009,81 @@ dwarf_decode_macros (struct line_header
/* A zero macinfo type indicates the end of the macro
information. */
case 0:
- return;
+ break;
+
+ case DW_MACINFO_define:
+ case DW_MACINFO_undef:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ case DW_MACINFO_start_file:
+ {
+ unsigned int bytes_read;
+ int line, file;
+
+ line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+
+ current_file = macro_start_file (file, line, current_file, comp_dir,
+ lh, cu->objfile);
+ }
+ break;
+
+ case DW_MACINFO_end_file:
+ /* No data to skip by MAC_PTR. */
+ break;
+
+ case DW_MACINFO_vendor_ext:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ default:
+ break;
+ }
+ } while (macinfo_type != 0 && current_file == NULL);
+
+ /* Here is the second pass to read in the macros starting from the ones
+ defined at the command line. */
+
+ mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
+ at_commandline = 1;
+
+ do
+ {
+ /* Do we at least have room for a macinfo type byte? */
+ if (mac_ptr >= mac_end)
+ {
+ /* Complaint is in the first pass above. */
+ break;
+ }
+
+ macinfo_type = read_1_byte (abfd, mac_ptr);
+ mac_ptr++;
+
+ switch (macinfo_type)
+ {
+ /* A zero macinfo type indicates the end of the macro
+ information. */
+ case 0:
+ break;
case DW_MACINFO_define:
case DW_MACINFO_undef:
@@ -10008,19 +10098,31 @@ dwarf_decode_macros (struct line_header
mac_ptr += bytes_read;
if (! current_file)
+ {
+ /* DWARF violation as no main source is present. */
+ complaint (&symfile_complaints,
+ _("debug info with no main source gives macro %s "
+ "on line %d: %s"),
+ macinfo_type ==
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other", line, body);
+ break;
+ }
+ if (at_commandline != (line == 0))
complaint (&symfile_complaints,
- _("debug info gives macro %s outside of any file: %s"),
+ _("debug info gives %s macro %s with %s line %d: %s"),
+ at_commandline ? _("command-line") : _("in-file"),
macinfo_type ==
- DW_MACINFO_define ? "definition" : macinfo_type ==
- DW_MACINFO_undef ? "undefinition" :
- "something-or-other", body);
- else
- {
- if (macinfo_type == DW_MACINFO_define)
- parse_macro_definition (current_file, line, body);
- else if (macinfo_type == DW_MACINFO_undef)
- macro_undef (current_file, line, body);
- }
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other",
+ line == 0 ? _("zero") : _("non-zero"), line, body);
+
+ if (macinfo_type == DW_MACINFO_define)
+ parse_macro_definition (current_file, line, body);
+ else if (macinfo_type == DW_MACINFO_undef)
+ macro_undef (current_file, line, body);
}
break;
@@ -10034,9 +10136,22 @@ dwarf_decode_macros (struct line_header
file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
- current_file = macro_start_file (file, line,
- current_file, comp_dir,
- lh, cu->objfile);
+ if (at_commandline != (line == 0))
+ complaint (&symfile_complaints,
+ _("debug info gives source %d included "
+ "from %s at %s line %d"),
+ file, at_commandline ? _("command-line") : _("file"),
+ line == 0 ? _("zero") : _("non-zero"), line);
+
+ if (at_commandline)
+ {
+ /* This DW_MACINFO_start_file was executed in the pass one. */
+ at_commandline = 0;
+ }
+ else
+ current_file = macro_start_file (file, line,
+ current_file, comp_dir,
+ lh, cu->objfile);
}
break;
@@ -10090,7 +10205,7 @@ dwarf_decode_macros (struct line_header
}
break;
}
- }
+ } while (macinfo_type != 0);
}
/* Check if the attribute's form is a DW_FORM_block*
--- gdb/testsuite/gdb.base/macscp.exp 18 Feb 2009 22:24:37 -0000 1.20
+++ gdb/testsuite/gdb.base/macscp.exp 19 Feb 2009 21:05:11 -0000
@@ -26,13 +26,21 @@ set testfile "macscp"
set objfile ${objdir}/${subdir}/${testfile}.o
set binfile ${objdir}/${subdir}/${testfile}
-set options { debug }
+set options { debug additional_flags=-DFROM_COMMANDLINE=ARG}
get_compiler_info ${binfile}
if [test_compiler_info gcc*] {
lappend options additional_flags=-g3
}
+# Workaround ccache making lineno non-zero for command-line definitions.
+if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
+ set result [catch "exec which gcc" output]
+ if {$result == 0 && [string first "/ccache/" $output] >= -1} {
+ lappend options "compiler=/usr/bin/gcc"
+ }
+}
+
# Generate the intermediate object file. This is required by Darwin to
# have access to the .debug_macinfo section.
if {[gdb_compile "${srcdir}/${subdir}/macscp1.c" "${objfile}" \
@@ -79,11 +87,15 @@ proc info_macro {macro} {
if {$debug_me} {exp_internal 1}
gdb_expect {
- -re "Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
+ -re "Defined at \[^\r\n\]*(${filepat}):(${decimal})\[\r\n\]" {
# `location' and `definition' should be empty when we see
# this message.
if {[llength $location] == 0 && [llength $definition] == 0} {
set location $expect_out(1,string)
+ # Definitions from gcc command-line get suffixed by the lineno.
+ if {$expect_out(2,string) == "0" } {
+ set location "$location:$expect_out(2,string)"
+ }
exp_continue
} else {
# Exit this expect loop, with a result indicating failure.
@@ -198,6 +210,8 @@ proc list_and_check_macro {func macro ex
}
+list_and_check_macro main FROM_COMMANDLINE "macscp1.c:0 ARG"
+
if {[list_and_check_macro main WHERE {macscp1.c {before macscp1_3}}]} {
return 0
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] Correct `gcc -D' macros get ignored (PR 9873)
[not found] ` <20090228100225.GA15788@host0.dyn.jankratochvil.net>
@ 2009-03-03 0:54 ` Joel Brobecker
2009-03-09 0:57 ` Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2009-03-03 0:54 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> * Just some text like "command-line" would be hiding a DWARF-contained
> information from the user - each macro command-line macro is still
> associated with a compilation unit (CU). In this context I find the Base
> Source (see below) file name as the appropriate identifier of this CU.
Sounds like a good argument in favor of keeping the name of the base
file in that macro data, indeed. As a result, I also agree with you
that introducing a special file for command-line macro definitions
is excessive.
Regarding whether or not we should print line "0" or "command-line",
in the absence of further comments from other contributors, I suggest
we follow your approach of keeping this as is - but with some extra
documentation just to make it clear what the zero means. The
documentation patch can be proposed separately from this patch, since
it would document the existing behavior.
> Partially I think this workaround may be more appropriate as
> distribution/vendor specific one so it may be dropped if you think so.
I don't think we should change which compiler is being used, particulary
if we can't determine whether the compiler has the problem or not...
Usually, what we do is add setup_xfail's. Perhaps other maintainers
with more experience will have a different opinion?
Now, back to your original patch. I don't like the code semi-duplication,
but I don't see any better way of doing this either, so...
| + /* Flag is in use by the second pass and determines if GDB is still before
| + first DW_MACINFO_start_file. If true GDB is still reading the definitions
| + from command line. First DW_MACINFO_start_file will need to be ignored as
| + it was already executed to create CURRENT_FILE for the main source holding
| + also the command line definitions. On first met DW_MACINFO_start_file
| + this flag is reset to normally execute all the remaining
| + DW_MACINFO_start_file macinfos. */
| + int at_commandline;
I suggest placing this comment a little later, where we actually start
using it (just at the start of the second pass). We can leave this flag
here, of course.
| + /* Start the first pass to find ahead the main source file name. GDB has to
| + create CURRENT_FILE where to place the macros given to the compiler
| + from the command line. Such command line macros are present before first
| + DW_MACINFO_start_file but still those macros are associated to the
| + compilation unit. The compilation unit GDB identifies by its main source
| + file name. */
I suggest a different wording. That's just a suggestion, trying to follow
the style that I am used to seeing in the GDB sources, not gospel. Use it
if you think it helps:
/* First pass: Find the name of the base filename.
This filename is needed in order to process all macros whose
definition (or undefinition) comes from the command line.
These macros are defined before the first DW_MACINFO_start_file
entry, and yet still need to be associated to base file.
To determine the base file name, we scan the macro definitions
until we reach the first DW_MACINFO_start_file entry. We then
initialize CURRENT_FILE accordingly so that any macro definition
found before the first DW_MACINFO_start_file can still be
associated to the base file. */
| + /* Here is the second pass to read in the macros starting from the ones
| + defined at the command line. */
Another suggestion, that refers to the suggestion I was making about
the comment for variable at_command_line....
/* Second pass: Process all entries.
Use the AT_COMMAND_LINE flag to determine whether we are still
processing command-line macro definitions/undefinitions. This
flag is unset when we reach the first DW_MACINFO_start_file entry. */
| + do
| + {
| + /* Do we at least have room for a macinfo type byte? */
| + if (mac_ptr >= mac_end)
| + {
| + /* Complaint is in the first pass above. */
| + break;
| + }
Unfortunately, I'm not sure about the fact that the complaint has
already been logged during the first pass. The first pass stops
the scanning as soon as we have found our base file.
I suggest you move the complaint back here, and then replace
the complaint in the first pass by a comment explaining that
a complaint will be logged during the second pass.
| + if (at_commandline != (line == 0))
This is a little too smart for my aging brain :-). I'd rather have
a clearer expression:
if (line == 0 && !at_commandline)
| + if (at_commandline != (line == 0))
Same here.
| +# Workaround ccache making lineno non-zero for command-line definitions.
| +if {[find_gcc] == "gcc" && [file executable "/usr/bin/gcc"]} {
| + set result [catch "exec which gcc" output]
| + if {$result == 0 && [string first "/ccache/" $output] >= -1} {
| + lappend options "compiler=/usr/bin/gcc"
| + }
| +}
For now, my vote is to hold off on this change, and let the user
change his path if ccache is not to be used.
| gdb_expect {
| - -re "Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
| + -re "Defined at \[^\r\n\]*(${filepat}):(${decimal})\[\r\n\]" {
| # `location' and `definition' should be empty when we see
| # this message.
| if {[llength $location] == 0 && [llength $definition] == 0} {
| set location $expect_out(1,string)
| + # Definitions from gcc command-line get suffixed by the lineno.
| + if {$expect_out(2,string) == "0" } {
| + set location "$location:$expect_out(2,string)"
| + }
Can you update the function documentation, please? Something like:
If a macro was defined at the command-line level, ":0" will be
appended at the end of the filename where this macro is defined.
You may dump the comment that you added here, if you'd like.
--
Joel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] Correct `gcc -D' macros get ignored (PR 9873)
2009-03-03 0:54 ` Joel Brobecker
@ 2009-03-09 0:57 ` Jan Kratochvil
2009-03-09 18:41 ` Joel Brobecker
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kratochvil @ 2009-03-09 0:57 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Tue, 03 Mar 2009 01:54:30 +0100, Joel Brobecker wrote:
> /* First pass: Find the name of the base filename.
> This filename is needed in order to process all macros whose
> definition (or undefinition) comes from the command line.
> These macros are defined before the first DW_MACINFO_start_file
> entry, and yet still need to be associated to base file.
>
> To determine the base file name, we scan the macro definitions
> until we reach the first DW_MACINFO_start_file entry. We then
> initialize CURRENT_FILE accordingly so that any macro definition
> found before the first DW_MACINFO_start_file can still be
> associated to the base file. */
Sure I find your text better although its first line does not follow the GNU
Coding Style directive `[...] please write complete sentences [...]'.
Used your text.
> | + do
> | + {
> | + /* Do we at least have room for a macinfo type byte? */
> | + if (mac_ptr >= mac_end)
> | + {
> | + /* Complaint is in the first pass above. */
> | + break;
> | + }
>
> Unfortunately, I'm not sure about the fact that the complaint has
> already been logged during the first pass. The first pass stops
> the scanning as soon as we have found our base file.
Thanks for the catch, fixed.
> | + if (at_commandline != (line == 0))
>
> This is a little too smart for my aging brain :-). I'd rather have
> a clearer expression:
>
> if (line == 0 && !at_commandline)
OK although it was catching both inconsistencies so it has to be written as
if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
> | gdb_expect {
> | - -re "Defined at \[^\r\n\]*(${filepat}):${decimal}\[\r\n\]" {
> | + -re "Defined at \[^\r\n\]*(${filepat}):(${decimal})\[\r\n\]" {
> | # `location' and `definition' should be empty when we see
> | # this message.
> | if {[llength $location] == 0 && [llength $definition] == 0} {
> | set location $expect_out(1,string)
> | + # Definitions from gcc command-line get suffixed by the lineno.
> | + if {$expect_out(2,string) == "0" } {
> | + set location "$location:$expect_out(2,string)"
> | + }
>
> Can you update the function documentation, please? Something like:
>
> If a macro was defined at the command-line level, ":0" will be
> appended at the end of the filename where this macro is defined.
>
> You may dump the comment that you added here, if you'd like.
As I moved the testcase part to:
http://sourceware.org/ml/gdb-patches/2009-03/msg00104.html
and changed the format of the command-line defined macros rather used now
a simple `gdb_test' call and this `proc info_macro' change was thus dropped.
Thanks,
Jan
gdb/
2009-03-09 Jan Kratochvil <jan.kratochvil@redhat.com>
PR gdb/9873:
* dwarf2read.c (dwarf_decode_macros): New variable `at_commandline'.
Move the variable `macinfo_type' out of the loop. Create a new
processing pass before the current one to pre-create `current_file'.
New complaint on misplaced zero/non-zero definitions/includes.
Skip first DW_MACINFO_start_file with `at_commandline' set.
--- gdb/dwarf2read.c 12 Feb 2009 09:15:06 -0000 1.295
+++ gdb/dwarf2read.c 9 Mar 2009 00:52:01 -0000
@@ -9963,6 +9963,8 @@ dwarf_decode_macros (struct line_header
{
gdb_byte *mac_ptr, *mac_end;
struct macro_source_file *current_file = 0;
+ enum dwarf_macinfo_record_type macinfo_type;
+ int at_commandline;
if (dwarf2_per_objfile->macinfo_buffer == NULL)
{
@@ -9970,19 +9972,29 @@ dwarf_decode_macros (struct line_header
return;
}
+ /* First pass: Find the name of the base filename.
+ This filename is needed in order to process all macros whose definition
+ (or undefinition) comes from the command line. These macros are defined
+ before the first DW_MACINFO_start_file entry, and yet still need to be
+ associated to base file.
+
+ To determine the base file name, we scan the macro definitions until we
+ reach the first DW_MACINFO_start_file entry. We then initialize
+ CURRENT_FILE accordingly so that any macro definition found before the
+ first DW_MACINFO_start_file can still be associated to the base file. */
+
mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
mac_end = dwarf2_per_objfile->macinfo_buffer
+ dwarf2_per_objfile->macinfo_size;
- for (;;)
+ do
{
- enum dwarf_macinfo_record_type macinfo_type;
-
/* Do we at least have room for a macinfo type byte? */
if (mac_ptr >= mac_end)
{
- dwarf2_macros_too_long_complaint ();
- return;
+ /* Complaint is printed during the second pass as GDB will probably
+ stop the first pass earlier upon finding DW_MACINFO_start_file. */
+ break;
}
macinfo_type = read_1_byte (abfd, mac_ptr);
@@ -9993,7 +10005,92 @@ dwarf_decode_macros (struct line_header
/* A zero macinfo type indicates the end of the macro
information. */
case 0:
- return;
+ break;
+
+ case DW_MACINFO_define:
+ case DW_MACINFO_undef:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ case DW_MACINFO_start_file:
+ {
+ unsigned int bytes_read;
+ int line, file;
+
+ line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+
+ current_file = macro_start_file (file, line, current_file, comp_dir,
+ lh, cu->objfile);
+ }
+ break;
+
+ case DW_MACINFO_end_file:
+ /* No data to skip by MAC_PTR. */
+ break;
+
+ case DW_MACINFO_vendor_ext:
+ /* Only skip the data by MAC_PTR. */
+ {
+ unsigned int bytes_read;
+
+ read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ read_string (abfd, mac_ptr, &bytes_read);
+ mac_ptr += bytes_read;
+ }
+ break;
+
+ default:
+ break;
+ }
+ } while (macinfo_type != 0 && current_file == NULL);
+
+ /* Second pass: Process all entries.
+
+ Use the AT_COMMAND_LINE flag to determine whether we are still processing
+ command-line macro definitions/undefinitions. This flag is unset when we
+ reach the first DW_MACINFO_start_file entry. */
+
+ mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset;
+
+ /* Determines if GDB is still before first DW_MACINFO_start_file. If true
+ GDB is still reading the definitions from command line. First
+ DW_MACINFO_start_file will need to be ignored as it was already executed
+ to create CURRENT_FILE for the main source holding also the command line
+ definitions. On first met DW_MACINFO_start_file this flag is reset to
+ normally execute all the remaining DW_MACINFO_start_file macinfos. */
+
+ at_commandline = 1;
+
+ do
+ {
+ /* Do we at least have room for a macinfo type byte? */
+ if (mac_ptr >= mac_end)
+ {
+ dwarf2_macros_too_long_complaint ();
+ break;
+ }
+
+ macinfo_type = read_1_byte (abfd, mac_ptr);
+ mac_ptr++;
+
+ switch (macinfo_type)
+ {
+ /* A zero macinfo type indicates the end of the macro
+ information. */
+ case 0:
+ break;
case DW_MACINFO_define:
case DW_MACINFO_undef:
@@ -10008,19 +10105,31 @@ dwarf_decode_macros (struct line_header
mac_ptr += bytes_read;
if (! current_file)
+ {
+ /* DWARF violation as no main source is present. */
+ complaint (&symfile_complaints,
+ _("debug info with no main source gives macro %s "
+ "on line %d: %s"),
+ macinfo_type ==
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other", line, body);
+ break;
+ }
+ if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
complaint (&symfile_complaints,
- _("debug info gives macro %s outside of any file: %s"),
+ _("debug info gives %s macro %s with %s line %d: %s"),
+ at_commandline ? _("command-line") : _("in-file"),
macinfo_type ==
- DW_MACINFO_define ? "definition" : macinfo_type ==
- DW_MACINFO_undef ? "undefinition" :
- "something-or-other", body);
- else
- {
- if (macinfo_type == DW_MACINFO_define)
- parse_macro_definition (current_file, line, body);
- else if (macinfo_type == DW_MACINFO_undef)
- macro_undef (current_file, line, body);
- }
+ DW_MACINFO_define ? _("definition") : macinfo_type ==
+ DW_MACINFO_undef ? _("undefinition") :
+ "something-or-other",
+ line == 0 ? _("zero") : _("non-zero"), line, body);
+
+ if (macinfo_type == DW_MACINFO_define)
+ parse_macro_definition (current_file, line, body);
+ else if (macinfo_type == DW_MACINFO_undef)
+ macro_undef (current_file, line, body);
}
break;
@@ -10034,9 +10143,22 @@ dwarf_decode_macros (struct line_header
file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read);
mac_ptr += bytes_read;
- current_file = macro_start_file (file, line,
- current_file, comp_dir,
- lh, cu->objfile);
+ if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
+ complaint (&symfile_complaints,
+ _("debug info gives source %d included "
+ "from %s at %s line %d"),
+ file, at_commandline ? _("command-line") : _("file"),
+ line == 0 ? _("zero") : _("non-zero"), line);
+
+ if (at_commandline)
+ {
+ /* This DW_MACINFO_start_file was executed in the pass one. */
+ at_commandline = 0;
+ }
+ else
+ current_file = macro_start_file (file, line,
+ current_file, comp_dir,
+ lh, cu->objfile);
}
break;
@@ -10090,7 +10212,7 @@ dwarf_decode_macros (struct line_header
}
break;
}
- }
+ } while (macinfo_type != 0);
}
/* Check if the attribute's form is a DW_FORM_block*
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] Correct `gcc -D' macros get ignored (PR 9873)
2009-03-09 0:57 ` Jan Kratochvil
@ 2009-03-09 18:41 ` Joel Brobecker
2009-03-09 18:56 ` Jan Kratochvil
0 siblings, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2009-03-09 18:41 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
> 2009-03-09 Jan Kratochvil <jan.kratochvil@redhat.com>
>
> PR gdb/9873:
> * dwarf2read.c (dwarf_decode_macros): New variable `at_commandline'.
> Move the variable `macinfo_type' out of the loop. Create a new
> processing pass before the current one to pre-create `current_file'.
> New complaint on misplaced zero/non-zero definitions/includes.
> Skip first DW_MACINFO_start_file with `at_commandline' set.
This is OK, with one tiny typo (and I'm probably the one responsible
for it).
> Sure I find your text better although its first line does not follow the GNU
> Coding Style directive `[...] please write complete sentences [...]'.
> Used your text.
Are you refering to the "First pass:"? I think it's OK.
> OK although it was catching both inconsistencies so it has to be written as
>
> if ((line == 0 && !at_commandline) || (line != 0 && at_commandline))
Right!
> + associated to base file.
^^^ "the" base file...
Cheers,
--
Joel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch] Correct `gcc -D' macros get ignored (PR 9873)
2009-03-09 18:41 ` Joel Brobecker
@ 2009-03-09 18:56 ` Jan Kratochvil
0 siblings, 0 replies; 5+ messages in thread
From: Jan Kratochvil @ 2009-03-09 18:56 UTC (permalink / raw)
To: Joel Brobecker; +Cc: gdb-patches
On Mon, 09 Mar 2009 19:41:38 +0100, Joel Brobecker wrote:
> > Sure I find your text better although its first line does not follow the GNU
> > Coding Style directive `[...] please write complete sentences [...]'.
> > Used your text.
>
> Are you refering to the "First pass:"? I think it's OK.
Yes; OK.
Checked-in: http://sourceware.org/ml/gdb-cvs/2009-03/msg00041.html
A testcase (to verify it still works wrt current gcc) is left for review in:
[patch] Better display command-line macros + doc addon
http://sourceware.org/ml/gdb-patches/2009-03/msg00104.html
Thanks for the review,
Jan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-03-09 18:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-20 0:20 [patch] Correct `gcc -D' macros get ignored (PR 9873) Jan Kratochvil
[not found] ` <20090228071514.GA25299@adacore.com>
[not found] ` <20090228100225.GA15788@host0.dyn.jankratochvil.net>
2009-03-03 0:54 ` Joel Brobecker
2009-03-09 0:57 ` Jan Kratochvil
2009-03-09 18:41 ` Joel Brobecker
2009-03-09 18:56 ` Jan Kratochvil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox