public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Mike Gulick <mike.gulick@mathworks.com>
Cc: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [RFC][PATCH] fix gdb segv when objfile can't be opened
Date: Mon, 30 Oct 2017 23:38:00 -0000	[thread overview]
Message-ID: <9ee6ad949b591f29f5205d00ce8527ff@polymtl.ca> (raw)
In-Reply-To: <82a1c23a-37f4-dee5-beae-da95d1cc1c6c@mathworks.com>

On 2017-10-30 18:13, Mike Gulick wrote:
> On 10/27/2017 09:17 PM, Simon Marchi wrote:
>> On 2017-10-23 07:19 PM, Mike Gulick wrote:
>> 
>> ...
>> 
>> Thanks a lot.  Could you also write the corresponding ChangeLog 
>> entries?  See
>> here for details: http://sourceware.org/gdb/wiki/ContributionChecklist
>> Note that we usually put that as part of the commit log, and only move 
>> it
>> to the actual ChangeLog files before pushing to git.  The changes to 
>> the
>> source files will go in gdb/ChangeLog and the changes to the testsuite 
>> in
>> gdb/testsuite/ChangeLog.
>> 
>> You can also put the PR number as part of the ChangeLog (see wiki and
>> previous CL entries for examples).
>> 
> Done.
> 
>> I don't think you have a copyright assignment for GDB yet?  Since this 
>> is
>> more than a few lines, you will need one if you want to contribute 
>> (I'll
>> contact you off-list for that).
>> 
> I'm working on this.  Hopefully it will be sooner rather than later.
> 
>> I noted a a few comments below (mostly minor/formatting stuff, overall 
>> I
>> think this is a good quality submission).
>> ...
>>> 
>>> diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
>>> index cc02740..b33de07 100644
>>> --- a/gdb/gdb_bfd.c
>>> +++ b/gdb/gdb_bfd.c
>>> @@ -702,9 +702,14 @@ gdb_bfd_map_section (asection *sectp, 
>>> bfd_size_type *size)
>>> 
>>>    data = NULL;
>>>    if (!bfd_get_full_section_contents (abfd, sectp, &data))
>>> -    error (_("Can't read data for section '%s' in file '%s'"),
>>> -	   bfd_get_section_name (abfd, sectp),
>>> -	   bfd_get_filename (abfd));
>>> +    {
>>> +      warning (_("Can't read data for section '%s' in file '%s'"),
>>> +	       bfd_get_section_name (abfd, sectp),
>>> +	       bfd_get_filename (abfd));
>>> +      /* Section is invalid -- set size to 0 and return NULL */
>> 
>> Finish the comment with a dot and two spaces.
>> 
> I rewrote the comment to be a full sentence

Ok.

>>> ...
>>> +extern int bar (int);
>>> +
>>> +int foo (int x) {
>>> +  return bar (x);
>>> +}
>> 
>> Unless the purpose of the test is about formatting, we try to follow 
>> GNU
>> style (same as for source code) in tests.  For example, here it would 
>> be:
>> 
>> int
>> foo (int x)
>> {
>>   return bar (x);
>> }
>> 
> I reformatted all of the helper files for the test using 'indent'.

Great, thanks.

>>> ...
>>> +int bar (int y) {
>>> +  return y + 1; /* break here */
>>> +}
>> 
>> Same here.
>> 
>>> ...
>>> +#ifndef VANISH_LIB
>>> +#define VANISH_LIB "./solib-vanish-lib1.so"
>>> +#endif
>> 
>> I think we can remove this, it could only obfuscate a problem
>> if we remove the -DVANISH_LIB in the .exp file.
>> 
> Done.
> 
>>> +
>>> +int main()
>> 
>> Put "int" on its own line.
>> 
>>> +{
>>> +  void *handle;
>>> +  int (*foo)(int);
>>> +  char *error;
>>> +
>>> +  /* Open library */
>>> +  handle = dlopen(VANISH_LIB, RTLD_NOW);
>>> +  if (!handle) {
>>> +    fprintf(stderr, "%s\n", dlerror());
>> 
>> Please make this file follow GNU style as well (space before 
>> parenthesis,
>> curly braces position, etc).
>> 
>>> +    exit(EXIT_FAILURE);
>>> +  }
>>> +
>>> +  /* Clear any existing error */
>>> +  dlerror();
>>> +
>>> +  /* Remove library */
>>> +  if (remove(VANISH_LIB) == -1) {
>> 
>> Can we rename the lib instead of deleting it?  It's always preferable 
>> to keep
>> test artifacts in case we need to inspect them.
>> 
> I updated the test to rename the library instead of removing it.  It
> also now renames it
> back before exiting.  This *should* make the test idempotent, unless
> it fails before it
> is able to rename the .so back to its original name.

The test (the .exp) rebuilds the shared library every time anyway, so 
even if you didn't move it back, it would work fine.

>>> ...
>>> +
>>> +# Library 1
>>> +set lib1name "solib-vanish-lib1"
>>> +set srcfile_lib1 ${srcdir}/${subdir}/${lib1name}.c
>>> +set binfile_lib1 [standard_output_file ${lib1name}.so]
>>> +# I can't make this work for some reason:
>>> +#set lib1_flags [list debug shlib=${binfile_lib2}]
>>> +set lib1_flags [list debug ldflags=-l:${lib2name}.so 
>>> ldflags=-Wl,-rpath=[standard_output_file ""] 
>>> libdir=[standard_output_file ""]]
>> 
>> With
>> 
>>   https://sourceware.org/ml/gdb-patches/2017-10/msg00856.html
>> 
>> the commented out line should work.
>> 
> This did indeed work.  Thank you!
> 
>>> ...
>>> +
>>> +gdb_test "continue" \
>>> +    "Breakpoint .*at .*/${lib2name}.c:${lib2_lineno}.*break here.*" 
>>> \
>>> +    "breakpoint prints location"
>> 
>> I think you could use the "gdb_continue_to_breakpoint" proc.
>> 
> This works as well, so the new patch uses this instead.
> 
> Here's an updated patch which hopefully addresses all of these items.
> 
> ...

Thanks for the update, this LGTM.  Please ping when your hear back about 
your copyright assignment.

Simon

  reply	other threads:[~2017-10-30 23:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-19 14:10 Mike Gulick
2017-10-19 15:59 ` Mike Gulick
2017-10-19 17:54   ` Simon Marchi
2017-10-19 19:39     ` Mike Gulick
2017-10-19 20:10       ` Simon Marchi
2017-10-19 22:13         ` Mike Gulick
2017-10-23 23:19     ` Mike Gulick
2017-10-27 21:11       ` Simon Marchi
2017-10-28  1:19       ` Simon Marchi
2017-10-30 22:14         ` Mike Gulick
2017-10-30 23:38           ` Simon Marchi [this message]
2018-01-07 14:09             ` Simon Marchi
2018-01-08  0:45               ` Mike Gulick
2018-01-08  2:50                 ` Simon Marchi
2018-01-08  2:51                   ` Simon Marchi
2018-01-10 20:33                     ` Mike Gulick
2018-01-12  2:44                       ` Simon Marchi
2018-01-12 15:05                         ` Mike Gulick
2018-01-17 18:01                           ` Simon Marchi
2018-01-18 15:30                             ` Mike Gulick

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=9ee6ad949b591f29f5205d00ce8527ff@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=mike.gulick@mathworks.com \
    --cc=simon.marchi@ericsson.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).