* [PATCHv1 2/2] eu-stack: add support for sysroot option
2019-01-20 15:01 [PATCHv1 0/2] specify a sysroot to search when examining a core file Luke Diamand
@ 2019-01-20 15:01 ` Luke Diamand
2019-01-20 15:01 ` [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries Luke Diamand
2019-01-29 13:47 ` [PATCHv1 0/2] specify a sysroot to search when examining a core file Mark Wielaard
2 siblings, 0 replies; 6+ messages in thread
From: Luke Diamand @ 2019-01-20 15:01 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard, Luke Diamand
Use the dwfl_set_sysroot() function to set the sysroot to be
used when analysing a core:
e.g.
$ eu-stack --core core --sysroot /path/to/sysroot -e crashing_prog
Signed-off-by: Luke Diamand <ldiamand@roku.com>
---
src/stack.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/stack.c b/src/stack.c
index c5f347e1..5a58cc1b 100644
--- a/src/stack.c
+++ b/src/stack.c
@@ -73,6 +73,7 @@ static int core_fd = -1;
static Elf *core = NULL;
static const char *exec = NULL;
static char *debuginfo_path = NULL;
+static const char *sysroot = NULL;
static const Dwfl_Callbacks proc_callbacks =
{
@@ -554,6 +555,10 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
show_modules = true;
break;
+ case 'S':
+ sysroot = arg;
+ break;
+
case ARGP_KEY_END:
if (core == NULL && exec != NULL)
argp_error (state,
@@ -587,6 +592,8 @@ parse_opt (int key, char *arg __attribute__ ((unused)),
dwfl = dwfl_begin (&core_callbacks);
if (dwfl == NULL)
error (EXIT_BAD, 0, "dwfl_begin: %s", dwfl_errmsg (-1));
+ if (sysroot)
+ dwfl_set_sysroot(dwfl, sysroot);
if (dwfl_core_file_report (dwfl, core, exec) < 0)
error (EXIT_BAD, 0, "dwfl_core_file_report: %s", dwfl_errmsg (-1));
}
@@ -670,6 +677,8 @@ main (int argc, char **argv)
N_("Show at most MAXFRAMES per thread (default 256, use 0 for unlimited)"), 0 },
{ "list-modules", 'l', NULL, 0,
N_("Show module memory map with build-id, elf and debug files detected"), 0 },
+ { "sysroot", 'S', "sysroot", 0,
+ N_("Set the sysroot to search for libraries referenced from the core file"), 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
--
2.20.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries
2019-01-20 15:01 [PATCHv1 0/2] specify a sysroot to search when examining a core file Luke Diamand
2019-01-20 15:01 ` [PATCHv1 2/2] eu-stack: add support for sysroot option Luke Diamand
@ 2019-01-20 15:01 ` Luke Diamand
2019-01-20 22:08 ` Dmitry V. Levin
2019-01-29 13:47 ` [PATCHv1 0/2] specify a sysroot to search when examining a core file Mark Wielaard
2 siblings, 1 reply; 6+ messages in thread
From: Luke Diamand @ 2019-01-20 15:01 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard, Luke Diamand
When searching the list of modules in a core file, if the core was
generated on a different system to the current one, we need to look
in a sysroot for the various shared objects.
For example, we might be looking at a core file from an ARM system
using elfutils running on an x86 host.
This change adds a new function, dwfl_set_sysroot(), which then
gets used when searching for libraries.
Signed-off-by: Luke Diamand <ldiamand@roku.com>
---
libdw/libdw.map | 7 ++++++-
libdwfl/libdwfl.h | 5 +++++
libdwfl/libdwflP.h | 1 +
libdwfl/link_map.c | 25 +++++++++++++++++++++++--
4 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 55482d58..43a9de2e 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -360,4 +360,9 @@ ELFUTILS_0.173 {
ELFUTILS_0.175 {
global:
dwelf_elf_begin;
-} ELFUTILS_0.173;
\ No newline at end of file
+} ELFUTILS_0.173;
+
+ELFUTILS_0.176 {
+ global:
+ dwfl_set_sysroot;
+} ELFUTILS_0.175;
diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h
index a0c1d357..c11e2f24 100644
--- a/libdwfl/libdwfl.h
+++ b/libdwfl/libdwfl.h
@@ -807,6 +807,11 @@ int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid,
bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation)
__nonnull_attribute__ (1, 2);
+/* Set the sysroot to use when searching for shared libraries. If not
+ specified, search in the system root. */
+void dwfl_set_sysroot (Dwfl *dwfl, const char *sysroot)
+ __nonnull_attribute__ (1);
+
#ifdef __cplusplus
}
#endif
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index 941a8b66..993a0e7c 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -138,6 +138,7 @@ struct Dwfl
int lookup_tail_ndx;
struct Dwfl_User_Core *user_core;
+ const char *sysroot; /* sysroot, or NULL to search standard system paths */
};
#define OFFLINE_REDZONE 0x10000
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 29307c74..0fae680d 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -388,8 +388,21 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
if (name != NULL)
{
/* This code is mostly inlined dwfl_report_elf. */
- // XXX hook for sysroot
- int fd = open (name, O_RDONLY);
+ char *path_name;
+ const char *sysroot = dwfl->sysroot;
+ int rc;
+
+ /* don't look in the sysroot if the path is already inside the sysroot */
+ bool name_in_sysroot = strncmp(name, sysroot, strlen(sysroot)) == 0;
+
+ if (!name_in_sysroot && sysroot)
+ rc = asprintf(&path_name, "%s/%s", sysroot, name);
+ else
+ rc = asprintf(&path_name, "%s", name);
+ if (unlikely(rc == -1))
+ return release_buffer(-1);
+
+ int fd = open (path_name, O_RDONLY);
if (fd >= 0)
{
Elf *elf;
@@ -471,6 +484,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
close (fd);
}
}
+ free(path_name);
}
if (mod != NULL)
@@ -1037,3 +1051,10 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
&integrated_memory_callback, &mcb, r_debug_info);
}
INTDEF (dwfl_link_map_report)
+
+void
+dwfl_set_sysroot (Dwfl *dwfl, const char *sysroot)
+{
+ dwfl->sysroot = sysroot;
+}
+INTDEF (dwfl_set_sysroot)
--
2.20.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCHv1 0/2] specify a sysroot to search when examining a core file
@ 2019-01-20 15:01 Luke Diamand
2019-01-20 15:01 ` [PATCHv1 2/2] eu-stack: add support for sysroot option Luke Diamand
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Luke Diamand @ 2019-01-20 15:01 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard, Luke Diamand
Following on from this discussion:
https://sourceware.org/ml/elfutils-devel/2018-q4/msg00224.html
This patch adds a new API to specify a sysroot, and extends eu-stack to
use it with a new command line option.
I have been experimenting with this on various ARM-based platforms,
currently using a virt-qemu platform built from buildroot.
Luke Diamand (2):
libdwfl: specify optional sysroot to search for shared libraries
eu-stack: add support for sysroot option
libdw/libdw.map | 7 ++++++-
libdwfl/libdwfl.h | 5 +++++
libdwfl/libdwflP.h | 1 +
libdwfl/link_map.c | 25 +++++++++++++++++++++++--
src/stack.c | 9 +++++++++
5 files changed, 44 insertions(+), 3 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries
2019-01-20 15:01 ` [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries Luke Diamand
@ 2019-01-20 22:08 ` Dmitry V. Levin
0 siblings, 0 replies; 6+ messages in thread
From: Dmitry V. Levin @ 2019-01-20 22:08 UTC (permalink / raw)
To: Luke Diamand; +Cc: elfutils-devel, Mark Wielaard
[-- Attachment #1: Type: text/plain, Size: 1156 bytes --]
On Sun, Jan 20, 2019 at 03:00:45PM +0000, Luke Diamand wrote:
> When searching the list of modules in a core file, if the core was
> generated on a different system to the current one, we need to look
> in a sysroot for the various shared objects.
>
> For example, we might be looking at a core file from an ARM system
> using elfutils running on an x86 host.
>
> This change adds a new function, dwfl_set_sysroot(), which then
> gets used when searching for libraries.
[...]
> --- a/libdwfl/link_map.c
> +++ b/libdwfl/link_map.c
> @@ -388,8 +388,21 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
> if (name != NULL)
> {
> /* This code is mostly inlined dwfl_report_elf. */
> - // XXX hook for sysroot
> - int fd = open (name, O_RDONLY);
> + char *path_name;
> + const char *sysroot = dwfl->sysroot;
> + int rc;
> +
> + /* don't look in the sysroot if the path is already inside the sysroot */
> + bool name_in_sysroot = strncmp(name, sysroot, strlen(sysroot)) == 0;
Is sysroot guaranteed to be non-NULL at this point?
If yes, is sysroot guaranteed to end with "/"?
--
ldv
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv1 0/2] specify a sysroot to search when examining a core file
2019-01-20 15:01 [PATCHv1 0/2] specify a sysroot to search when examining a core file Luke Diamand
2019-01-20 15:01 ` [PATCHv1 2/2] eu-stack: add support for sysroot option Luke Diamand
2019-01-20 15:01 ` [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries Luke Diamand
@ 2019-01-29 13:47 ` Mark Wielaard
[not found] ` <BN7PR01MB3953544F2EDA1FB7BF6E9470B0970@BN7PR01MB3953.prod.exchangelabs.com>
2 siblings, 1 reply; 6+ messages in thread
From: Mark Wielaard @ 2019-01-29 13:47 UTC (permalink / raw)
To: Luke Diamand; +Cc: elfutils-devel
Hi Luke,
On Sun, Jan 20, 2019 at 03:00:42PM +0000, Luke Diamand wrote:
> Following on from this discussion:
> https://sourceware.org/ml/elfutils-devel/2018-q4/msg00224.html
>
> This patch adds a new API to specify a sysroot, and extends eu-stack to
> use it with a new command line option.
>
> I have been experimenting with this on various ARM-based platforms,
> currently using a virt-qemu platform built from buildroot.
I like it! Thanks.
Some high level comments, before I review the actual code.
- It currently only works for resolving path names found
in core files. It might make sense to use the same for
other variants of dwfl_report_xxx and maybe add a
dwfl_get_sysroot () to be used inside the find_elf
callback. This can probably be added later though.
- eu-stack uses its own argument parser, but other tools,
like addr2line, use the argp parser dwfl_standard_argp ().
It would be nice to add a --sysroot argument parser there
too that would automatically call dwfl_set_sysroot to
make them handle --sysroot automagically.
- Is there a way to have some small testcase for this?
Cheers,
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCHv1 0/2] specify a sysroot to search when examining a core file
[not found] ` <BN7PR01MB3953544F2EDA1FB7BF6E9470B0970@BN7PR01MB3953.prod.exchangelabs.com>
@ 2019-01-31 15:22 ` Mark Wielaard
0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2019-01-31 15:22 UTC (permalink / raw)
To: Luke Diamand; +Cc: elfutils-devel
Hi Luke,
(BTW. Note that HTML emails will get dropped, you should get a bounce
from the mailinglist.)
On Tue, 2019-01-29 at 19:46 +0000, Luke Diamand wrote:
> Thanks for the comments on the other emails, I'll rework my patch to
> incorporate them.
>
> I've got a small test case I've been using which uses a prebuilt ARM
> and MIPS(!) libc.so (from buildroot) and a core file. But I think in
> theory it ought to be possible to fake something up with a purely
> source code based test. Perhaps create a shared library which dumps
> core, and play around with the rpath?
>
> Is there an existing test case you would suggest that I start from?
>
> I'll have a look.
To test cross arch things it is sometimes just necessary to include
precompiled binaries in the test files (hopefully as small as possible
of course).
For example the tests/run-backtrace-core-<arch>.sh tests include such
pregenerated binaries:
# executable generated by:
#
# gcc -D_GNU_SOURCE -I. -I.. -I../lib -m32 -pthread -static -g \
# -o backtrace.ppc.exec backtrace-child.c
#
# core generated by:
#
# ./backtrace.ppc.exec --gencore
tests/backtrace-subr.sh has some overly complicated code to generate a
core file for the run-backtrace-native-core.sh testcase.
For none-core, running native tests you could look at
tests/run-native-test.sh
All these are slightly fragile though.
Cheers,
Mark
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-01-31 15:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-20 15:01 [PATCHv1 0/2] specify a sysroot to search when examining a core file Luke Diamand
2019-01-20 15:01 ` [PATCHv1 2/2] eu-stack: add support for sysroot option Luke Diamand
2019-01-20 15:01 ` [PATCHv1 1/2] libdwfl: specify optional sysroot to search for shared libraries Luke Diamand
2019-01-20 22:08 ` Dmitry V. Levin
2019-01-29 13:47 ` [PATCHv1 0/2] specify a sysroot to search when examining a core file Mark Wielaard
[not found] ` <BN7PR01MB3953544F2EDA1FB7BF6E9470B0970@BN7PR01MB3953.prod.exchangelabs.com>
2019-01-31 15:22 ` Mark Wielaard
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).