public inbox for cygwin-apps@cygwin.com
 help / color / mirror / Atom feed
From: Jon Turney <jon.turney@dronecode.org.uk>
To: Achim Gratz <Stromeko@nexgo.de>
Cc: cygwin-apps@cygwin.com
Subject: Re: [cygport] enabling a replacement for "objdump -d -l"
Date: Mon, 26 Feb 2024 19:29:43 +0000	[thread overview]
Message-ID: <3f1057a0-1dd5-4736-bdf9-14071c1f27b1@dronecode.org.uk> (raw)
In-Reply-To: <87a5nx5z5e.fsf@Gerda.invalid>


Thanks, this is great!

On 18/02/2024 19:51, ASSI via Cygwin-apps wrote:
> 
[...]
> dwarf-parse.-pl

There should be some build system changes which install this file, 
probably in /usr/share/cygport/tools/, which it can then be run from.

> --8<---------------cut here---------------start------------->8---

Please, please make a patch with git format-patch, which I can then just 
apply.

> #!perl -w

Fifty lines of perl with no comments! This is just line noise to me 
unless I spend lots of time staring at it :)

Seriously, this should at least say "I'm running objdump -Wl to dump out 
the .debug_line section containing DWARF XYZ information.

Then maybe some comments about what assumptions it's making about the 
human-readable output it's parsing.

> use common::sense;
> use List::Util qw( sum );
> 
> my $filter = shift @ARGV
>      or die "not enough arguments";
> my $obj = shift @ARGV
>      or die "not enough arguments";
> my @objdump = qw( /usr/bin/objdump -WNl );

cygport goes to some lengths to identify the correct objdump to use when 
cross-building, so it should probably should be used here (passed in as 
an arg?), rather than assuming it's /usr/bin/objdump.

> open my $DWARF, "-|", @objdump, $obj
>      or die "can't invoke objdump\n$!";
> 
> my ( @dirs, @files, %fn, %rn );
> while (<$DWARF>) {
>      if (/^ The Directory Table/../^$/) {
> 	if (/^  \d+/) {
> 	
> 	    my ( $entry, $dir ) = m/^  (\d+)\t.+: (.+)$/;
> 	    $dir = "$dirs[0]/$dir" if ($dir =~ m:\A[^/]:);
> 	    push @dirs, $dir;
> 	}
>      }
>      if (/^ The File Name Table/../^$/) {
> 	if (/^  \d+/) {
> 	    my ( $idx, $fn, undef ) = m/^  \d+\t(\d+)\t.+: (.+)$/;
> 	    $rn{"$dirs[$idx]/$fn"}++;
> 	    push @files, "$dirs[$idx]/$fn";
> 	}
>      }
>      if (my $rc = /^ Line Number Statements/../^  Offset:/) {
> 	$fn{"$files[0]"}++ if ($rc == 1);
> 	$fn{"$files[$1]"}++ if m/ Set File Name to entry (\d+) in the File Name Table/;

What this line is doing is obvious, the rest of this block, not so much.

You might also like to touch on why we bother looking at the line number 
information at all, rather than just producing a (filtered) list of all 
the pathnames mentioned?

> 	@files = () if ($rc =~ m/E0$/);
> 	@dirs  = () if ($rc =~ m/E0$/);
>      }
>      if (/^ No Line Number Statements./../^$/) {
> 	@files = ();
> 	@dirs  = ();
>      }
> }
> foreach my $fn (grep m:^$filter:, sort keys %fn) {
>      say sprintf "%s", $fn;
> }
> say STDERR sprintf "\tLNS: %6d (%6d locations) <=> FNT: %6d ( %6d locations)",
>      0+grep( m:^$filter:, keys %fn ), sum( values %fn ),
>      0+grep( m:^$filter:, keys %rn ), sum( values %rn )
>      if (0);

If you're going to keep this (which you probably should), perhaps it 
should be under some 'if (DEBUG)' conditional.

> 
> close $DWARF
>      or die "failed to close objdump\n$!";
> --8<---------------cut here---------------end--------------->8---
> 
> Integration into cygport is made configurable via a variable to be set
> in .cygportrc for instance in order to easily revert back to the
> original objdump invocation if necessary.  I've been producing packages

DWARF_PARSE should be mentioned in the documentation for cygport.conf

Since the helper script will be installed, it could be made a boolean.

> with that setup for a while now and have not noticed any errors.  In
> principle the new parser actually produces more complete output as there
> can be multiple line number statements and hence source files per
> location, but objdump only lists one of them in the disassembly (at
> least sometimes).  In practise I haven't found a package until now where
> the final list (after filtering) is different.
> 
> --8<---------------cut here---------------start------------->8---
> lib/src_postinst.cygpart: use DWARF_PARSE optionally instead of objdump -dl
> ---
> 
> diff --git a/lib/src_postinst.cygpart b/lib/src_postinst.cygpart
> index f06004e4..3dd6e893 100644
> --- a/lib/src_postinst.cygpart
> +++ b/lib/src_postinst.cygpart
> @@ -1096,7 +1096,12 @@ __prepstrip_one() {
>   	else
>   		dbg="/usr/lib/debug/${exe}.dbg";
>   
> -		lines=$(${objdump} -d -l "${exe}" 2>/dev/null | sed -ne "s|.*\(/usr/src/debug/${PF}/.*\):[0-9]*$|\1|gp" | sort -u | tee -a ${T}/.dbgsrc.out.${oxt} | wc -l);
> +		if defined DWARF_PARSE
> +		then
> +			lines=$(${DWARF_PARSE} /usr/src/debug/${PF}/ "${exe}" | tee -a ${T}/.dbgsrc.out.${oxt} | wc -l);
> +		else
> +			lines=$(${objdump} -d -l "${exe}" 2>/dev/null | sed -ne "s|.*\(/usr/src/debug/${PF}/.*\):[0-9]*$|\1|gp" | sort -u | tee -a ${T}/.dbgsrc.out.${oxt} | wc -l);
> +		fi
>   
>   		# we expect --add-gnu-debuglink to fail if a
>   		# .gnu_debuglink section already exists (e.g. binutils,
> --8<---------------cut here---------------end--------------->8---


  parent reply	other threads:[~2024-02-26 19:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-18 19:51 ASSI
2024-02-20  3:42 ` Marco Atzeri
2024-02-20 18:21   ` ASSI
2024-02-26 19:29 ` Jon Turney [this message]
2024-03-11 19:35   ` ASSI
2024-03-12 17:41     ` Jon Turney
2024-03-12 17:49       ` ASSI
2024-03-12 21:39         ` Brian Inglis

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=3f1057a0-1dd5-4736-bdf9-14071c1f27b1@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=Stromeko@nexgo.de \
    --cc=cygwin-apps@cygwin.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).