public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Sangamesh Mallayya" <sangamesh.swamy@in.ibm.com>
To: "Ulrich Weigand" <uweigand@de.ibm.com>
Cc: gdb-patches@sourceware.org
Subject: Re: set sysroot command on AIX has no effect.
Date: Sat, 08 Oct 2016 13:15:00 -0000	[thread overview]
Message-ID: <OF848F0736.112F16BD-ON65258046.00477D54-65258046.0048C0EC@notes.na.collabserv.com> (raw)
In-Reply-To: <20161007193107.9C39210C1FE@oc8523832656.ibm.com>

Hi Ulrich,

> 
> > Calling solib_find returning a prefixed sysroot path and the 
duplication
> > can be avoided as you suggested.
> > But calling solib_bfd_fopen after this is causing the assertion to 
fail on
> > NULL path as solib_bfd_fopen doing xfree of pathname at the end.
> 
> Well, of course, you have to check for NULL.  What I'm suggesting is to
> use something along the lines of:
> 
>   found_pathname = solib_find (filename, &found_file);
>   if (found_pathname == NULL)
>     // error handling
>   archive_bfd = solib_bfd_fopen (found_pathname, found_file);
> 

Yes, i did try these steps. But this won't set the sysroot path as we 
intend to.
The final object filename we want is the one returned from solib_find, 
which is a sysroot prefixed pathname.
After solib_bfd_fopen call we can't refer to found_pathname as it's been 
freed in solib_bfd_fopen at the end, and assertion failure later.

> where the code currently does:
> 
>   archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
>   if (archive_bfd == NULL)
>     // error handling
>
> 
> > +   pathname = solib_find (filename, &found_file);
> > +   if (pathname == NULL)
> > +       perror_with_name (filename);
> >     archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
> >     if (archive_bfd == NULL)
> >       {
> 
> This has a number of problems:
> - you still use gdb_bfd_open with filename, which means it still won't
>   find the file  (I assume you meant to use pathname?)

pathname we get is something like "/usr/lib/libc.a(shr.o)", Offcourse 
their is no such file with this pathname in the system.
So we set a filename as "/usr/lib/libc.a" after separating member name 
from actual file and gdb_bfd_open does find the file and return it's bfd.
Here if we pass the path returned from solib_find to gdb_bfd_open instead 
of filename then no issue is seen.

filename is a malloc'ed string which will be freed up when do_cleanups is 
called before existing from solib_aix_bfd_open.


> - if solib_find actually finds the file, "found_file" is an open file
>   descriptor, which the code now leaks

I too was bit reluctant about found_file use after solib_find, but wanted 
to have your view.

> - actually, the pathname string now also leaks
> - and finally, at the bottom:
>   object_bfd->filename = xstrdup (pathname);
>   you now miss the object file name (in parentheses), so
>   "info sharedlibrary" will no longer show it
> 
> Most of those should be fixed when using the approach above.

pathname string we need to assign to object filename is the one which is 
returned from solib_find which gives us sysroot path.
We aren't modifying actual pathname which we got from solib_map_sections, 
just reusing the pathname variable locally, so as to assign that to object 
filename.
I confirmed this with debugging gdb and pasted the output of gdb session 
below.

I think, better we use found_pathname variable to store returned value 
from solib_find instead of using existing pathname variable to avoid 
confusion.
And may assign object filename as "object_bfd->filename = xstrdup 
(found_pathname);" ?

The only problem i think if we use solib_find without using 
solib_bfd_fopen is found_file descriptor.
Let me know your view.

output of gdb session before call to solib_aix_bfd_open & after return 
from solib_aix_bfd_open
----------------------------------------------------------------------------------------------

Breakpoint 3, _ZL18solib_map_sectionsP7so_list (so=0x1102d8bd0) at 
solib.c:547
547       abfd = ops->bfd_open (filename);
(top-gdb) p *so
$7 = {next = 0x1102d9030, lm_info = 0x1102ca310, 
  so_original_name = "/usr/lib/libc.a(shr.o)", '\000' <repeats 489 times>, 

  so_name = "/usr/lib/libc.a(shr.o)", '\000' <repeats 489 times>, pspace = 
0x11025be70, 
  abfd = 0x0, symbols_loaded = 0 '�', objfile = 0x0, sections = 0x0, 
sections_end = 0x0, 
  addr_low = 0, addr_high = 0}
(top-gdb) p filename
$8 = 0x110273b70 "/usr/lib/libc.a(shr.o)"
(top-gdb) n
548       do_cleanups (old_chain);
(top-gdb) p *so
$9 = {next = 0x1102d9030, lm_info = 0x1102ca310, 
  so_original_name = "/usr/lib/libc.a(shr.o)", '\000' <repeats 489 times>, 

  so_name = "/usr/lib/libc.a(shr.o)", '\000' <repeats 489 times>, pspace = 
0x11025be70, 
  abfd = 0x0, symbols_loaded = 0 '�', objfile = 0x0, sections = 0x0, 
sections_end = 0x0, 
  addr_low = 0, addr_high = 0}
(top-gdb) p filename
$10 = 0x110273b70 "/usr/lib/libc.a(shr.o)"
(top-gdb) 

Thanks,
-Sangamesh




From:   "Ulrich Weigand" <uweigand@de.ibm.com>
To:     Sangamesh Mallayya/India/IBM@IBMIN
Cc:     gdb-patches@sourceware.org
Date:   10/08/2016 01:01 AM
Subject:        Re: set sysroot command on AIX has no effect.



Sangamesh Mallaya wrote:

> Calling solib_find returning a prefixed sysroot path and the duplication
> can be avoided as you suggested.
> But calling solib_bfd_fopen after this is causing the assertion to fail 
on
> NULL path as solib_bfd_fopen doing xfree of pathname at the end.

Well, of course, you have to check for NULL.  What I'm suggesting is to
use something along the lines of:

  found_pathname = solib_find (filename, &found_file);
  if (found_pathname == NULL)
    // error handling
  archive_bfd = solib_bfd_fopen (found_pathname, found_file);

where the code currently does:

  archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
  if (archive_bfd == NULL)
    // error handling


> +   pathname = solib_find (filename, &found_file);
> +   if (pathname == NULL)
> +       perror_with_name (filename);
>     archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
>     if (archive_bfd == NULL)
>       {

This has a number of problems:
- you still use gdb_bfd_open with filename, which means it still won't
  find the file  (I assume you meant to use pathname?)
- if solib_find actually finds the file, "found_file" is an open file
  descriptor, which the code now leaks
- actually, the pathname string now also leaks
- and finally, at the bottom:
  object_bfd->filename = xstrdup (pathname);
  you now miss the object file name (in parentheses), so
  "info sharedlibrary" will no longer show it

Most of those should be fixed when using the approach above.

Bye,
Ulrich

-- 
  Dr. Ulrich Weigand
  GNU/Linux compilers and toolchain
  Ulrich.Weigand@de.ibm.com




  reply	other threads:[~2016-10-08 13:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-13  9:05 Sangamesh Mallayya
2016-09-29 15:33 ` Ulrich Weigand
2016-09-30 14:15   ` Sangamesh Mallayya
2016-09-30 14:38     ` Ulrich Weigand
2016-10-04 13:19       ` Sangamesh Mallayya
2016-10-07 19:31         ` Ulrich Weigand
2016-10-08 13:15           ` Sangamesh Mallayya [this message]
2016-10-08 14:38             ` Ulrich Weigand
2016-10-10 12:11               ` Sangamesh Mallayya
2016-10-10 16:29                 ` Ulrich Weigand
2016-10-11  7:17                   ` Ulrich Weigand
2016-10-13 13:42                     ` Sangamesh Mallayya
2016-10-13 14:03                       ` Ulrich Weigand
2016-10-13 17:44                         ` Sangamesh Mallayya
2016-10-14 13:13                           ` Ulrich Weigand
     [not found] <OFBAE0EEF6.511F8BA2-ON6525802D.00305F69-6525802D.0031DA2D@LocalDomain>
2016-09-27 11:39 ` Sangamesh Mallayya

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=OF848F0736.112F16BD-ON65258046.00477D54-65258046.0048C0EC@notes.na.collabserv.com \
    --to=sangamesh.swamy@in.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=uweigand@de.ibm.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).