From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from re-prd-fep-049.btinternet.com (mailomta32-re.btinternet.com [213.120.69.125]) by sourceware.org (Postfix) with ESMTPS id 4A5BC3858CDB for ; Mon, 26 Feb 2024 19:29:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4A5BC3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=dronecode.org.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4A5BC3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=213.120.69.125 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708975787; cv=none; b=TavtXjwZ1bv2LyHFfNvOApwNV37HQ8JyBaO8yhuG9AfvoE1BP/d3yPPfSZcOVyK6QEnwPtYRc8GleBYl7wm4gnuEHL3ZdM61+6KmcfgUFIFdndoiqENF/0w8q9ALrCPoM0VXbV6PpEETJgTTfIi+tLZKuRWiRrZJ9kf7TP8svBQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708975787; c=relaxed/simple; bh=SVpdREWFKQ3vAkCpfOO9FQHDUz/9j7LfGowcqam8gNg=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=TUYo27PVfcDaLhViA4Nm9oYFe41DpDABZZfKv6BWQSK6vlI8oDVQcCffWmHgOr/5/ctzRXDm+AgrYwyTaH4nj7y7FE85k1k46ftaMVuP2cmOhAUTN2TFKl+drwiZsZb6cB+/WLlQ337VSB9VFf1SBJNtSHT2BOMGEuOThWbcYaA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from re-prd-rgout-003.btmx-prd.synchronoss.net ([10.2.54.6]) by re-prd-fep-049.btinternet.com with ESMTP id <20240226192944.NXGA8012.re-prd-fep-049.btinternet.com@re-prd-rgout-003.btmx-prd.synchronoss.net>; Mon, 26 Feb 2024 19:29:44 +0000 Authentication-Results: btinternet.com; auth=pass (PLAIN) smtp.auth=jonturney@btinternet.com; bimi=skipped X-SNCR-Rigid: 6577B732095FEEE4 X-Originating-IP: [81.153.98.185] X-OWM-Source-IP: 81.153.98.185 X-OWM-Env-Sender: jon.turney@dronecode.org.uk X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvledrgedvgdduvddvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffvfhfhvegjtgfgsehtjeertddtvdejnecuhfhrohhmpeflohhnucfvuhhrnhgvhicuoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqeenucggtffrrghtthgvrhhnpeevvdekgfffteetueehgfdugefgkeevleejudduheevuedtveejfeevvdevvdfgvdenucfkphepkedurdduheefrdelkedrudekheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhephhgvlhhopegludelvddrudeikedruddruddtlegnpdhinhgvthepkedurdduheefrdelkedrudekhedpmhgrihhlfhhrohhmpehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepufhtrhhomhgvkhhosehnvgigghhordguvgdprhgtphhtthhopegthihgfihinhdqrghpphhssegthihgfihinhdrtghomhdprhgvvhfkrfephhhoshhtkeduqdduheefqdelkedqudekhedrrhgrnhhgvgekuddqudehfedrsghttggvnhhtrhgrlhhplhhushdrtghomhdprghuthhhpghushgvrhepjhhonhhtuhhrnhgvhiessghtihhnthgvrhhnvghtrdgtohhmpdhgvghokffrpefiuedpoffvtefjohhstheprhgv qdhprhguqdhrghhouhhtqddttdef X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from [192.168.1.109] (81.153.98.185) by re-prd-rgout-003.btmx-prd.synchronoss.net (authenticated as jonturney@btinternet.com) id 6577B732095FEEE4; Mon, 26 Feb 2024 19:29:44 +0000 Message-ID: <3f1057a0-1dd5-4736-bdf9-14071c1f27b1@dronecode.org.uk> Date: Mon, 26 Feb 2024 19:29:43 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [cygport] enabling a replacement for "objdump -d -l" Content-Language: en-GB To: Achim Gratz References: <87a5nx5z5e.fsf@Gerda.invalid> From: Jon Turney Cc: cygwin-apps@cygwin.com In-Reply-To: <87a5nx5z5e.fsf@Gerda.invalid> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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---