libdwfl/argp-std.c: Set offline_next_address for a.out default

Message ID 20250121003809.843793-1-amerey@redhat.com
State Committed
Headers
Series libdwfl/argp-std.c: Set offline_next_address for a.out default |

Commit Message

Aaron Merey Jan. 21, 2025, 12:38 a.m. UTC
  If none of -e, -p or -k is given as a command line option, libdwfl
parse_opt will use '-e a.out' as the default.

When handling -e, parse_opt will set dwfl->offline_next_address
to 0.  However when handling the default '-e a.out',
dwfl->offline_next_address is not set to 0.  This can result in
eu-addr2line failing to correctly output the line information for a
given address.

Fix this by setting dwfl->offline_next_address to 0 when setting up
the default '-e a.out' dwfl.

https://sourceware.org/bugzilla/show_bug.cgi?id=32538

Signed-off-by: Aaron Merey <amerey@redhat.com>
---
 libdwfl/argp-std.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Mark Wielaard Jan. 21, 2025, 2:02 p.m. UTC | #1
Hi Aaron,

On Mon, 2025-01-20 at 19:38 -0500, Aaron Merey wrote:
> If none of -e, -p or -k is given as a command line option, libdwfl
> parse_opt will use '-e a.out' as the default.
> 
> When handling -e, parse_opt will set dwfl->offline_next_address
> to 0.  However when handling the default '-e a.out',
> dwfl->offline_next_address is not set to 0.  This can result in
> eu-addr2line failing to correctly output the line information for a
> given address.
> 
> Fix this by setting dwfl->offline_next_address to 0 when setting up
> the default '-e a.out' dwfl.

Thanks, this makes sense.

> ---
>  libdwfl/argp-std.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
> index 1605fbfe..55e98715 100644
> --- a/libdwfl/argp-std.c
> +++ b/libdwfl/argp-std.c
> @@ -268,6 +268,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
>  	    /* Default if no -e, -p, or -k, is "-e a.out".  */
>  	    arg = "a.out";
>  	    dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
> +
> +	    if (dwfl != NULL)
> +	      dwfl->offline_next_address = 0;
>  	    if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL)
>  	      return fail (dwfl, -1, arg, state);
>  	    opt->dwfl = dwfl;

This is indeed the same as what would happen if the user would provide
"-e a.out" directly.

Which has the following comment:

            /* Start at zero so if there is just one -e foo.so,
               the DSO is shown without address bias.  */
            dwfl->offline_next_address = 0;

Cheers,

Mark
  
Aaron Merey Jan. 21, 2025, 2:23 p.m. UTC | #2
On Tue, Jan 21, 2025 at 9:02 AM Mark Wielaard <mark@klomp.org> wrote:
>
> Hi Aaron,
>
> On Mon, 2025-01-20 at 19:38 -0500, Aaron Merey wrote:
> > If none of -e, -p or -k is given as a command line option, libdwfl
> > parse_opt will use '-e a.out' as the default.
> >
> > When handling -e, parse_opt will set dwfl->offline_next_address
> > to 0.  However when handling the default '-e a.out',
> > dwfl->offline_next_address is not set to 0.  This can result in
> > eu-addr2line failing to correctly output the line information for a
> > given address.
> >
> > Fix this by setting dwfl->offline_next_address to 0 when setting up
> > the default '-e a.out' dwfl.
>
> Thanks, this makes sense.
>
> > ---
> >  libdwfl/argp-std.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
> > index 1605fbfe..55e98715 100644
> > --- a/libdwfl/argp-std.c
> > +++ b/libdwfl/argp-std.c
> > @@ -268,6 +268,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
> >           /* Default if no -e, -p, or -k, is "-e a.out".  */
> >           arg = "a.out";
> >           dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
> > +
> > +         if (dwfl != NULL)
> > +           dwfl->offline_next_address = 0;
> >           if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL)
> >             return fail (dwfl, -1, arg, state);
> >           opt->dwfl = dwfl;
>
> This is indeed the same as what would happen if the user would provide
> "-e a.out" directly.
>
> Which has the following comment:
>
>             /* Start at zero so if there is just one -e foo.so,
>                the DSO is shown without address bias.  */
>             dwfl->offline_next_address = 0;

Thanks Mark, pushed as commit 412ffac6e5a7.

Aaron
  

Patch

diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 1605fbfe..55e98715 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -268,6 +268,9 @@  parse_opt (int key, char *arg, struct argp_state *state)
 	    /* Default if no -e, -p, or -k, is "-e a.out".  */
 	    arg = "a.out";
 	    dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
+
+	    if (dwfl != NULL)
+	      dwfl->offline_next_address = 0;
 	    if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL)
 	      return fail (dwfl, -1, arg, state);
 	    opt->dwfl = dwfl;