From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>,
gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table
Date: Thu, 13 May 2021 14:20:03 -0400 [thread overview]
Message-ID: <2d292cdd-1ea4-cea8-522e-4587689fd733@polymtl.ca> (raw)
In-Reply-To: <20210512171655.9463-1-SourabhSingh.Tomar@amd.com>
On 2021-05-12 1:16 p.m., Sourabh Singh Tomar via Gdb-patches wrote:
> Consider following C test case:
> ```
> cat test.c
> int main() {
> int a = OUT;
> }
> ```
> Compiled as:
> `clang -gdwarf-5 -fdebug-macro test.c`
>
> Loading this bin into GDB and trying to access macro info,
> GDB is unable to extract and display macro info correctly.
> ```
> $gdb a.out
> (gdb) start
> (gdb) info macro OUT
> Temporary breakpoint 1 at 0x2016a8: file test.c, line 3.
> Starting program: /home/a.out
> (gdb) info macro OUT
> The symbol `OUT' has no definition as a C/C++ preprocessor macro
> at /home/test.c:-1
> ```
>
> The problems starts when processing file and dir indexes from DWARFv5
> line table. DWARFv5 specifies:
> - The current directory is explicitly present in the
> directories field.
> - The current compilation filename is explicitly present and
> has index 0.
> dir entry 0 contains the absoute path(Not including source
> filename).
absoute -> absolute
You could say that it contains the "compilation directory", typically
the current working directory of the compiler.
> diff --git a/gdb/testsuite/gdb.base/dwarf5-macro.c b/gdb/testsuite/gdb.base/dwarf5-macro.c
> new file mode 100644
> index 00000000000..0a7dc98c620
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/dwarf5-macro.c
> @@ -0,0 +1,3 @@
> +#define HELLO_GDB 1
> +int main() {
> +}
Please add a copyright notice, like in the other .c files.
> diff --git a/gdb/testsuite/gdb.base/dwarf5-macro.exp b/gdb/testsuite/gdb.base/dwarf5-macro.exp
> new file mode 100644
> index 00000000000..cf622cebe32
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/dwarf5-macro.exp
> @@ -0,0 +1,43 @@
> +# Copyright 2020-2021 Free Software Foundation, Inc.
> +
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 3 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
For others in the future to be able to understand why this test exists,
please add a comment here explaining what this test case is about, what
is it specifically meant to check. It would be good to note that for
the bug to reproduce, the source file must be supplied as a relative
path, so that the file_names[0] entry in .debug_line ends up relative
and not absolute. That will help justify why we do a copy below, and
why we pass such an hardcoded path to gdb_compile. This is unusual, so
somebody might be tempted to "clean this up", breaking the purpose of
the test.
> +
> +standard_testfile
> +set additional_flags {debug}
> +file copy -force $srcdir/$subdir/$srcfile [standard_output_file $srcfile]
> +gdb_compile outputs/gdb.base/dwarf5-macro/dwarf5-macro.c $binfile executable {debug}
We typically check for gdb_compile failures, check for examples
elsewhere in the testsuite.
As Tom said, please comment adequatly to explain why we do it this way.
It would perhaps make sense to move this test to gdb.dwarf2? Also, the
name "dwarf5-macro" is a bit broad. If we want to add other tests
related to macro handling in DWARF5, we'll be a bit stuck (we'll have to
rename this one). I would suggest giving it a more specific name, like
dwarf5-macro-relative-path", something like that.
> +
> +get_compiler_info
> +if { [test_compiler_info "gcc-*"] } {
> + set options "additional_flags=-g3"
> +} elseif { [test_compiler_info "clang-*"] } {
> + set options "additional_flags=-gdwarf-5 -fdebug-macro"
> +}
> +
> +if { [prepare_for_testing "failed to prepare" \
prepare_for_testing builds the executable, doesn't it? And it ends up
overwriting the file you compiled above, don't you see that? The test
fails for me because of this, I think.
Simon
next prev parent reply other threads:[~2021-05-13 18:20 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-12 17:16 Sourabh Singh Tomar via Gdb-patches
2021-05-12 17:31 ` Tomar, Sourabh Singh via Gdb-patches
2021-05-13 15:47 ` Tom Tromey
2021-05-13 18:20 ` Simon Marchi via Gdb-patches [this message]
2021-05-14 14:56 ` Keith Seitz via Gdb-patches
2021-05-14 18:21 ` Tomar, Sourabh Singh via Gdb-patches
2021-05-14 18:50 ` Simon Marchi via Gdb-patches
2021-05-14 19:20 ` Tomar, Sourabh Singh via Gdb-patches
2021-05-14 20:56 ` Simon Marchi via Gdb-patches
2021-05-24 11:36 ` Tomar, Sourabh Singh via Gdb-patches
2021-05-24 18:47 ` Keith Seitz via Gdb-patches
2021-06-08 18:48 ` Keith Seitz via Gdb-patches
2021-06-22 17:01 ` [RFC] PING [Re: [PATCH] Fix macro info lookup for binaries containing DWARFv5 line table] Keith Seitz via Gdb-patches
2021-06-22 20:52 ` Simon Marchi via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d292cdd-1ea4-cea8-522e-4587689fd733@polymtl.ca \
--to=gdb-patches@sourceware.org \
--cc=SourabhSingh.Tomar@amd.com \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox