From: Joel Brobecker <brobecker@adacore.com>
To: Yao Qi <yao@codesourcery.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Don't check PST is NULL in read_symtab
Date: Fri, 11 Jan 2013 15:06:00 -0000 [thread overview]
Message-ID: <20130111150537.GM6143@adacore.com> (raw)
In-Reply-To: <50F025B5.2060203@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1183 bytes --]
> IMO, we don't need an assertion to check PST, because the function is
> used in this way,
>
> (*pst->read_symtab) (objfile, pst);
I am fine without the assertion as well. But if we followed your
argument, we would never need an assertion. For me, assertions
achieve two goals:
1. Clearly document an expectation;
2. Cause a semi-friendly abortion, rather than a mysterious behavior
or crash.
As of today, the way this function is called indeed guarantees that
PST is never NULL. But someone adding a call at a later date might
introduce a bug and cause it to be called with PST == NULL...
> 2013-01-11 Yao Qi <yao@codesourcery.com>
>
> * dwarf2read.c (dwarf2_psymtab_to_symtab): Code indent.
Let's take an example to show you what I meant in my first suggestion.
Attached is a bogus change I made a function in dwarf2read. I added
an "else" around a large block of code. The first patch shows the
actual change, with code reindentation. That's the real patch which
would be checked in eventually - but it's barely readable. So,
to better show the real changes, I also attach the result of
"git diff/show -b", where whitespace-only changes are ignored.
--
Joel
[-- Attachment #2: dwarf2read-actual.diff --]
[-- Type: text/x-diff, Size: 2678 bytes --]
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index e2088f1..d590248 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1918,39 +1918,41 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
if (dwarf2_section_empty_p (info))
return;
+ else
+ {
+ abfd = sectp->owner;
- abfd = sectp->owner;
+ /* If the section has relocations, we must read it ourselves.
+ Otherwise we attach it to the BFD. */
+ if ((sectp->flags & SEC_RELOC) == 0)
+ {
+ const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
- /* If the section has relocations, we must read it ourselves.
- Otherwise we attach it to the BFD. */
- if ((sectp->flags & SEC_RELOC) == 0)
- {
- const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size);
+ /* We have to cast away const here for historical reasons.
+ Fixing dwarf2read to be const-correct would be quite nice. */
+ info->buffer = (gdb_byte *) bytes;
+ return;
+ }
- /* We have to cast away const here for historical reasons.
- Fixing dwarf2read to be const-correct would be quite nice. */
- info->buffer = (gdb_byte *) bytes;
- return;
- }
+ buf = obstack_alloc (&objfile->objfile_obstack, info->size);
+ info->buffer = buf;
- buf = obstack_alloc (&objfile->objfile_obstack, info->size);
- info->buffer = buf;
+ /* When debugging .o files, we may need to apply relocations; see
+ http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
+ We never compress sections in .o files, so we only need to
+ try this when the section is not compressed. */
+ retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
+ if (retbuf != NULL)
+ {
+ info->buffer = retbuf;
+ return;
+ }
- /* When debugging .o files, we may need to apply relocations; see
- http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
- We never compress sections in .o files, so we only need to
- try this when the section is not compressed. */
- retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
- if (retbuf != NULL)
- {
- info->buffer = retbuf;
- return;
+ if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
+ || bfd_bread (buf, info->size, abfd) != info->size)
+ error (_("Dwarf Error: Can't read DWARF data from '%s'"),
+ bfd_get_filename (abfd));
}
-
- if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
- || bfd_bread (buf, info->size, abfd) != info->size)
- error (_("Dwarf Error: Can't read DWARF data from '%s'"),
- bfd_get_filename (abfd));
}
/* A helper function that returns the size of a section in a safe way.
[-- Attachment #3: dwarf2read-spaces_ignored.diff --]
[-- Type: text/x-diff, Size: 733 bytes --]
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index e2088f1..d590248 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1918,7 +1918,8 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
if (dwarf2_section_empty_p (info))
return;
-
+ else
+ {
abfd = sectp->owner;
/* If the section has relocations, we must read it ourselves.
@@ -1951,6 +1952,7 @@ dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info)
|| bfd_bread (buf, info->size, abfd) != info->size)
error (_("Dwarf Error: Can't read DWARF data from '%s'"),
bfd_get_filename (abfd));
+ }
}
/* A helper function that returns the size of a section in a safe way.
next prev parent reply other threads:[~2013-01-11 15:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-11 1:57 Yao Qi
2013-01-11 4:52 ` Joel Brobecker
2013-01-11 14:34 ` Tom Tromey
2013-01-11 14:56 ` Yao Qi
2013-01-11 15:06 ` Tom Tromey
2013-01-14 12:42 ` [committed]: " Yao Qi
2013-01-14 12:44 ` Yao Qi
2013-01-11 14:46 ` Yao Qi
2013-01-11 15:06 ` Joel Brobecker [this message]
2013-01-11 18:02 ` Pedro Alves
2013-01-11 18:44 ` Joel Brobecker
2013-01-14 12:42 ` Yao Qi
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=20130111150537.GM6143@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=yao@codesourcery.com \
/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