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: Mon, 10 Oct 2016 12:11:00 -0000 [thread overview]
Message-ID: <OF715ED758.00DC97FD-ON65258048.00413E8B-65258048.0042F442@notes.na.collabserv.com> (raw)
In-Reply-To: <20161008143755.10ABE10BEE3@oc8523832656.ibm.com>
Hi Ulrich,
> Sangamesh Mallayya wrote:
>
> >> 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.
>
> Well, if you want to reuse the found_pathname, you'll just have to
> duplicate it (there's already a call to xstrdup later in the function,
> you may have to move it earlier).
>
> >> > + 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.
>
> My point was, the code as shown above does *not* pass the path returned
> from solib_find to gdb_bfd_open! The path returned from solib_find is
> assigned to "pathname" (overriding the value pathname that was input to
> the function), but then gdb_bfd_open is still called with "filename".
>
> >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);" ?
>
> Agreed (see above). However, note that this will *not* contain the
> object name in parentheses. For example, if you initially get a
> pathname of:
> /usr/lib/libc.a(shr.o)
> Then you separate out the filename into:
> /usr/lib/libc.a
> Then you pass this to solib_find and get a full name including sysroot:
> /path/to/sysroot/usr/lib/libc.a
> But what you probably want to use as name in the final solib object is:
> /path/to/sysroot/usr/lib/libc.a(shr.o)
>
> My point was that in order to get this, you'll have to append the
> "(shr.o)" back on to the result you got from solib_find.
>
> >The only problem i think if we use solib_find without using
> >solib_bfd_fopen is found_file descriptor.
> >Let me know your view.
>
> Please do use the pair of solib_find / solib_bfd_fopen; they were
> designed to be used with each other, that's why they have the
> interface they do.
Thanks a lot for the detailed explanation and guidance.
Here is the change i have it right now which takes care of.
1) calling solib_find and then solib_bfd_fopen.
2) Appending parenthesized member name.
Let me know your view on this.
--- ./gdb/solib-aix.c_orig 2016-10-04 03:22:01.000000000 -0500
+++ ./gdb/solib-aix.c 2016-10-10 06:23:32.000000000 -0500
@@ -648,6 +648,8 @@
char *member_name;
bfd *archive_bfd, *object_bfd;
struct cleanup *cleanup;
+ int found_file, found_path_len;
+ char *found_pathname, *found_pathname1;
if (pathname[path_len - 1] != ')')
return solib_bfd_open (pathname);
@@ -669,12 +671,24 @@
member_name = xstrprintf ("%.*s", path_len - filename_len - 2, sep +
1);
make_cleanup (xfree, member_name);
- archive_bfd = gdb_bfd_open (filename, gnutarget, -1);
+ /* Calling solib_find makes certain that sysroot path is set properly
+ if program has a dependency on .a archive and sysroot is set via
+ set sysroot command */
+ found_pathname = solib_find (filename, &found_file);
+ if (found_pathname == NULL)
+ perror_with_name (pathname);
+ found_pathname1 = xstrdup (found_pathname);
+ found_path_len = strlen (found_pathname1) + strlen (sep);
+ /* Reserve a space for appending parenthesized member name to
filename,
+ as path returned from solib_find is just a filename */
+ found_pathname1 = xrealloc (found_pathname1, found_path_len);
+ archive_bfd = solib_bfd_fopen (found_pathname, found_file);
if (archive_bfd == NULL)
{
warning (_("Could not open `%s' as an executable file: %s"),
filename, bfd_errmsg (bfd_get_error ()));
do_cleanups (cleanup);
+ xfree (found_pathname1);
return NULL;
}
@@ -681,6 +695,7 @@
if (bfd_check_format (archive_bfd, bfd_object))
{
do_cleanups (cleanup);
+ xfree (found_pathname1);
return archive_bfd;
}
@@ -690,6 +705,7 @@
filename, bfd_errmsg (bfd_get_error ()));
gdb_bfd_unref (archive_bfd);
do_cleanups (cleanup);
+ xfree (found_pathname1);
return NULL;
}
@@ -711,6 +727,7 @@
warning (_("\"%s\": member \"%s\" missing."), filename,
member_name);
gdb_bfd_unref (archive_bfd);
do_cleanups (cleanup);
+ xfree (found_pathname1);
return NULL;
}
@@ -721,6 +738,7 @@
gdb_bfd_unref (archive_bfd);
gdb_bfd_unref (object_bfd);
do_cleanups (cleanup);
+ xfree (found_pathname1);
return NULL;
}
@@ -729,7 +747,8 @@
synthetic name. Otherwise, we would only be displaying the name
of the archive member object. */
xfree (bfd_get_filename (object_bfd));
- object_bfd->filename = xstrdup (pathname);
+ strcat (found_pathname1, sep);
+ object_bfd->filename = found_pathname1;
gdb_bfd_unref (archive_bfd);
do_cleanups (cleanup);
next prev parent reply other threads:[~2016-10-10 12:11 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
2016-10-08 14:38 ` Ulrich Weigand
2016-10-10 12:11 ` Sangamesh Mallayya [this message]
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=OF715ED758.00DC97FD-ON65258048.00413E8B-65258048.0042F442@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