Package list debian-goodies / 1af8612
Add a --deb option which generates a metapackage for dbgsym packages Installs the package and its dependencies if --install is given, too. Listed dependencies depend on the --all option. (--all = all dependencies, otherwise just the currently missing ones) Closes: #935567 Axel Beckert 1 year, 5 months ago
7 changed file(s) with 176 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1313 + Add some more comments to the logic of the main routine.
1414 + Add a --all option which outputs all related dbgsym packages, not
1515 just those still missing.
16 + Add a --deb option which generates a metapackage with the dbgsym as
17 dependencies instead of listing them. Recommend equivs and
18 libfile-slurper-perl for that. (Closes: #935567)
1619
1720 -- Axel Beckert <abe@debian.org> Sat, 18 Apr 2020 23:54:38 +0200
1821
1717 curl,
1818 dctrl-tools,
1919 elfutils,
20 equivs,
2021 libipc-system-simple-perl,
22 libfile-slurper-perl,
2123 libfile-which-perl,
2224 man-db,
2325 perl,
7072 dpigs - Show which installed packages occupy the most space
7173 [dctrl-tools]
7274 find-dbgsym-packages
73 - Get list of dbgsym packages from core dump or PID [dctrl-tools,
74 elfutils, libfile-which-perl, libipc-system-simple-perl]
75 - Get list of dbgsym packages from core dump or PID. [dctrl-tools,
76 elfutils, libfile-which-perl, libipc-system-simple-perl,
77 libfile-slurper-perl]
7578 Usage of the --ssh option requires openssh-client.
79 Usage of the --deb option requires equivs.
7680 popbugs - Display a customized release-critical bug list based on
7781 packages you use (using popularity-contest data) [python3,
7882 popularity-contest]
2727 use v5.14;
2828 use IPC::System::Simple qw(capturex $EXITVAL);
2929 use File::Which;
30 use File::Temp qw(tempdir);
31 use File::Slurper qw(read_text write_text);
32 use POSIX qw(strftime);
33 use File::Copy qw(move);
34 use File::Basename qw(fileparse);
3035
3136 $ENV{LC_ALL} = 'C';
3237
3843 my $call_apt = 0;
3944 my $use_ssh = 0;
4045 my $show_all = 0;
46 my $gen_deb = 0;
4147
4248 my %pkgs;
49 my @programs = ();
4350 my @out_of_date_files;
4451 foreach my $arg (@ARGV) {
4552 if ($arg eq '--install') {
4653 $call_apt = 1;
4754 next;
4855 }
56 if ($arg eq '--deb') {
57 die "Package equivs needs to be installed to use the option '--deb'.\n"
58 unless which('equivs-build');
59 $gen_deb = 1;
60 next;
61 }
4962 if ($arg eq '--ssh') {
63 die "Package openssh-client needs to be installed to use the option '--ssh'.\n"
64 unless which('ssh');
5065 $use_ssh = 1;
5166 next;
5267 }
5873 my %build_ids;
5974 if ($arg =~ /^\d+$/) {
6075 %build_ids = get_build_ids_from_pid($arg);
76
77 # Document which file was looked for
78 push(@programs, readlink("/proc/$arg/exe"));
6179 } else {
6280 %build_ids = get_build_ids_from_file($arg);
6381 }
99117 if ($call_apt) {
100118 my @cmd = (qw(apt install --no-install-recommends), @pkgs);
101119
120 # Shall we generate a metapackage and install that one?
121 if ($gen_deb) {
122 my $pkg = gen_pkg(@pkgs);
123 @cmd = (qw(apt install), $pkg);
124 }
125
102126 # Are we root?
103127 unless ($> == 0) {
104128
120144
121145 # Finally execute the command constructed above
122146 exec(@cmd);
147
148 # Shall we just generate a .deb, but not install it?
149 } elsif ($gen_deb) {
150 my $pkg = gen_pkg(@pkgs);
151 my $target = $ENV{TMPDIR} // '/tmp';
152 move($pkg, $target);
153 my $filename = $target.'/'.fileparse($pkg);
154 say "Metapackage has been generated at $filename.";
155 say "Install it like this with root privileges:";
156 say "";
157 say "apt install $filename";
123158
124159 # No options, so just display the list of still needed packages.
125160 } else {
240275 if (is_core_file($filename)) {
241276 return get_build_ids_from_core($filename);
242277 } else {
278 # Document which file was looked for
279 push(@programs, $filename);
280
243281 my @filenames = get_files_from_elf($filename);
244282 my %build_ids;
245283 foreach my $filename (@filenames) {
262300 {
263301 my ($filename) = @_;
264302 my $output = capturex(qw(eu-unstrip --list-only --core), $filename);
303
304 # Document which file was looked for (fifth field in first line)
305 my $program = (split(' ', (split(/\n/, $output))[0]))[4];
306 push(@programs, $program);
265307
266308 return parse_eu_unstrip($output);
267309 }
347389 return;
348390 }
349391
392 sub gen_pkg {
393 my @pkgs = @_;
394 my $tempdir = tempdir( ( $ENV{TMPDIR} ? $ENV{TMPDIR} : '/tmp' ).
395 '/find-dbgsym-packages-equivs_XXXXX',
396 CLEANUP => 1 );
397
398 # Generating the necessary strings for generating the metapackage
399 my %replacements = ();
400
401 $replacements{CALL} = "$0 ".join(' ', @ARGV);
402 $replacements{DATE} = strftime('%a, %d %b %Y %T %z', localtime());
403 $replacements{DEPENDS} = join(', ', @pkgs);
404 $replacements{USER} = getlogin();
405 $replacements{HOST} = `hostname`;
406 $replacements{AOM} = $show_all ? 'all' : 'currently missing';
407
408 chomp($replacements{USER});
409 chomp($replacements{HOST});
410
411 my $dg_version = `dpkg-query -f '\${Version}' -W debian-goodies`;
412 $replacements{DGVERSION} = $dg_version;
413
414 my @now = localtime;
415 my $pkg_version = strftime(
416 '%Y.%m.%dT%H.%M.%S+dg'.$dg_version,
417 localtime()
418 );
419 $replacements{PKGVERSION} = $pkg_version;
420
421 my %programs = map { $_ => 1 } @programs;
422 $replacements{PROGRAMS} = ' * ' .
423 join("\n * ", sort keys %programs);
424
425 $replacements{PACKAGE} = 'dbgsym-pkgs-for-' .
426 join('-',
427 map {
428 s(^.*/)();
429 s/\W//g;
430 s/[-_]//g;
431 lc($_);
432 }
433 sort keys %programs
434 );
435
436 # Replace placeholders with actual data
437 foreach my $file (qw(changelog control readme)) {
438 gen_file_from_template(
439 ( -d './find-dbgsym-packages-templates/' ?
440 './find-dbgsym-packages-templates/' :
441 '/usr/share/debian-goodies/find-dbgsym-packages-templates/' )
442 . $file,
443 "$tempdir/$file",
444 \%replacements
445 );
446 }
447
448 # Generate the .deb
449 chdir($tempdir);
450 #system("head -100 *");
451 my $pkgbuild = capturex(qw(equivs-build control));
452 #system("dpkg-deb --info *.deb");
453
454 my @debs = glob('*.deb');
455 # Sanity check
456 die "$0: BUG: Not exactly one .deb file generated" unless $#debs == 0;
457
458 return $tempdir.'/'.$debs[0];
459 }
460
461 sub gen_file_from_template {
462 my ($input, $output, $replacements) = @_;
463
464 my $text = read_text($input);
465
466 foreach my $key (%$replacements) {
467 $text =~ s/__${key}__/$replacements->{$key}/g;
468 }
469
470 write_text($output, $text);
471 }
472
350473 sub usage
351474 {
352475 print << "EOF";
353476 usage:
354 $0 [--install] [--ssh] [--all] <core file or PID or program> [ ... ]
477 $0 [--install] [--ssh] [--deb] [--all] \
478 <core file or PID or program> [ ... ]
355479
356480 You must already have the correct debug lines in your sources.list and have
357481 executed 'apt-get update'.
0 find-dbgsym-packages (__PKGVERSION__) local; urgency=low
1
2 * Generated by "__CALL__".
3
4 -- find-dbgsym-packages called by <__USER__@__HOST__> __DATE__
5
0 Source: find-dbgsym-packages
1 Section: metapackages
2 Priority: optional
3 Standards-Version: 4.5.0
4 Maintainer: find-dbgsym-packages called by <__USER__@__HOST__>
5
6 Package: __PACKAGE__
7 Version: __PKGVERSION__
8 Depends: __DEPENDS__
9 Architecture: all
10 Changelog: changelog
11 Readme: readme
12 Description: Dependency package for dbgsym packages
13 This package is generated by find-dbgsym-packages from the Debian
14 package debian-goodies (version __DGVERSION__) and depends on __AOM__
15 dbgsym packages required to properly debug the following programms:
16 .
17 __PROGRAMS__
0 This is a local metapackage generated by "__CALL__"
1 called by __USER__ on __HOST__ on __DATE__.
2
3 The version of find-dbgsym-packages is the one from the debian-goodies
4 Debian package at version __DGVERSION__.
55
66 =head1 SYNOPSIS
77
8 B<find-dbgsym-packages> [I<options>] I<executable, core file or PID> [I<executable, library, core file or PID> …]
8 B<find-dbgsym-packages> [B<--install>] [B<--ssh>] [B<--deb>]
9 [B<--all>] I<executable, core file or PID> [I<executable, library,
10 core file or PID> …]
911
1012 =head1 DESCRIPTION
1113
4143 Use C<ssh root@localhost -t> instead of C<sudo> or C<su - -c>. to gain
4244 administrative privileges.
4345
46 =item C<--deb>
47
48 Generate a metapackage which depends on all the still needed debug symbol packages.
49
50 This requires the package C<equivs> to be installed.
51
52 If C<--install> is also given, automatically install the package and
53 all its (missing) dependencies.
54
4455 =item C<--all>
4556
46 Show or install I<all> relevant debug symbol packages, not just those
57 Show or include I<all> relevant debug symbol packages, not just those
4758 still missing.
4859
4960 =back