Skip to content

Commit eb045fc

Browse files
committed
better support --ftrace
1 parent dd05f67 commit eb045fc

File tree

2 files changed

+61
-24
lines changed

2 files changed

+61
-24
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ v0.3.0 2023-01-XX
1111
Updated Cosmopolitan source
1212
Update Perl source
1313
Added dbg config: gdb not working for me, YYMV
14+
Better support --ftrace by outputting .com.dbg instead of elf
1415
Updated docs with new info.
1516

1617
v0.2.1 2022-12-03

lib/Perl/Dist/APPerl.pm

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -694,21 +694,21 @@ my %defconfig = (
694694
cosmo_id => '9c5a7795add7add5a214afce27d896084e0861c5',
695695
dest => 'perl-small-vista.com',
696696
},
697-
'full' => { desc => 'moving target: full', base => 'v5.36.0-full-v0.1.0', perl_id => '45c18985158e73ccd50b82a59117bec67b199f20', cosmo_id => 'eb69a42863ef602a951249b801ceed5f74cbb11c', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
698-
'full-vista' => { desc => 'moving target: full for vista', base => 'v5.36.0-full-v0.1.0-vista', perl_id => '45c18985158e73ccd50b82a59117bec67b199f20', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
699-
'small' => { desc => 'moving target: small', base => 'v5.36.0-small-v0.1.0', perl_id => '45c18985158e73ccd50b82a59117bec67b199f20', cosmo_id => 'eb69a42863ef602a951249b801ceed5f74cbb11c', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
700-
'small-vista' => { desc => 'moving target: small for vista', base => 'v5.36.0-small-v0.1.0-vista', perl_id => '45c18985158e73ccd50b82a59117bec67b199f20', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
697+
'full' => { desc => 'moving target: full', base => 'v5.36.0-full-v0.1.0', perl_id => 'ca87f329eeb075c0fe7ac803eb933f36af45a69b', cosmo_id => 'eb69a42863ef602a951249b801ceed5f74cbb11c', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
698+
'full-vista' => { desc => 'moving target: full for vista', base => 'v5.36.0-full-v0.1.0-vista', perl_id => 'ca87f329eeb075c0fe7ac803eb933f36af45a69b', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
699+
'small' => { desc => 'moving target: small', base => 'v5.36.0-small-v0.1.0', perl_id => 'ca87f329eeb075c0fe7ac803eb933f36af45a69b', cosmo_id => 'eb69a42863ef602a951249b801ceed5f74cbb11c', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
700+
'small-vista' => { desc => 'moving target: small for vista', base => 'v5.36.0-small-v0.1.0-vista', perl_id => 'ca87f329eeb075c0fe7ac803eb933f36af45a69b', '+perl_extra_flags' => ['-Dprivlib=/zip/lib/perl5', '-Darchlib=/zip/lib/perl5/x86_64-cosmo', '-Dsitelib=/zip/lib/perl5/site_perl', '-Dsitearch=/zip/lib/perl5/site_perl/x86_64-cosmo']},
701701
# development configs
702702
'dbg' => { base => 'full', perl_extra_flags => ['-Doptimize=-g3 -gdwarf-4', '-de'], cosmo_mode => 'dbg', cosmo_id => '52f1db7220935cfcf2c8e583678f5ccc4b5bbacd'},
703703
dontuse_threads => {
704704
desc => "not recommended, threaded build is buggy",
705-
base => 'v5.36.0-full-v0.1.0',
705+
base => 'full',
706706
perl_extra_flags => ['-Doptimize=-Os', '-Dusethreads', '-de'],
707707
perl_id => 'cosmo-apperl'
708708
},
709709
perl_cosmo_dev => {
710710
desc => "For developing cosmo platform perl without apperl additions",
711-
base => 'v5.36.0-full-v0.1.0',
711+
base => 'full',
712712
perl_id => 'cosmo'
713713
},
714714
perl_cosmo_dev_on_vista => {
@@ -718,7 +718,7 @@ my %defconfig = (
718718
},
719719
perl_apperl_dev => {
720720
desc => "For developing apperl",
721-
base => 'v5.36.0-full-v0.1.0',
721+
base => 'full',
722722
perl_id => 'cosmo-apperl'
723723
}
724724
}
@@ -899,7 +899,7 @@ sub Set {
899899
chdir($SiteConfig->{perl_repo}) or die "Failed to enter perl repo";
900900
print "make veryclean\n";
901901
system("make", "veryclean");
902-
foreach my $todelete ('miniperl.com', 'perl.com', 'miniperl.elf', 'perl.elf') {
902+
foreach my $todelete ('miniperl.com', 'perl.com', 'miniperl.elf', 'miniperl.com.dbg', 'perl.elf', 'perl.com.dbg') {
903903
print "rm $todelete\n";
904904
unlink($todelete) || $!{ENOENT} or die "failed to delete $todelete";
905905
}
@@ -1061,13 +1061,22 @@ sub Build {
10611061
}
10621062

10631063
# pack
1064-
my $APPNAME = basename($PERL_APE);
1065-
my $APPPATH = "$TEMPDIR/$APPNAME";
1064+
my $APPPATH = "$TEMPDIR/".basename($PERL_APE);
10661065
my $packAPE = sub {
1067-
print "cp $PERL_APE $APPPATH\n";
1068-
copy($PERL_APE, $APPPATH) or die "copy failed: $!";
1069-
print "chmod 755 $APPPATH\n";
1070-
chmod(0755, $APPPATH) or die $!;
1066+
my $copyexe = sub {
1067+
my ($srcpath, $destpath) = @_;
1068+
print "cp $srcpath $destpath\n";
1069+
copy($srcpath, $destpath) or die "copy failed: $!";
1070+
print "chmod 755 $destpath\n";
1071+
chmod(0755, $destpath) or die $!;
1072+
};
1073+
$copyexe->($PERL_APE, $APPPATH);
1074+
my $srcdbg = "$PERL_APE.dbg";
1075+
if(! -f $srcdbg) {
1076+
$srcdbg = $PERL_APE;
1077+
$srcdbg =~ s/com$/elf/;
1078+
}
1079+
$copyexe->($srcdbg, "$APPPATH.dbg");
10711080
if((! exists $UserProjectConfig->{nobuild_perl_bin}) || scalar(keys %{$itemconfig->{zip_extra_files}})) {
10721081
print "cd $ZIP_ROOT\n";
10731082
chdir($ZIP_ROOT) or die "failed to enter ziproot";
@@ -1076,7 +1085,6 @@ sub Build {
10761085
};
10771086
$packAPE->();
10781087

1079-
10801088
# install modules
10811089
if(exists $itemconfig->{install_modules}) {
10821090
my $perlman1 = "$TEMPDIR$proxyConfig{installman1dir}";
@@ -1085,7 +1093,7 @@ sub Build {
10851093
my $perllib = "$TEMPDIR$proxyConfig{installprivlib}";
10861094
my $perlarchlib = "$TEMPDIR$proxyConfig{installarchlib}";
10871095
my $mmopt = sub {
1088-
my @mmopt = ("PERL_LIB=$perllib", "PERL_ARCHLIB=$perlarchlib", "MAP_TARGET=perl.elf",
1096+
my @mmopt = ("PERL_LIB=$perllib", "PERL_ARCHLIB=$perlarchlib", "MAP_TARGET=perl.com.dbg",
10891097
"INSTALLDIRS=perl",
10901098
"INSTALLARCHLIB=$perlarchlib",
10911099
"INSTALLPRIVLIB=$perllib",
@@ -1151,8 +1159,8 @@ sub Build {
11511159
# install into the src tree
11521160
_command_or_die('make', 'install');
11531161
# build a new perl binary, convert to APE, and repack zip
1154-
_command_or_die('make', 'perl.elf');
1155-
_command_or_die(dirname($proxyConfig{cc})."/x86_64-linux-musl-objcopy", '-S', '-O', 'binary', 'perl.elf', 'perl.com');
1162+
_command_or_die('make', 'perl.com.dbg');
1163+
_command_or_die(dirname($proxyConfig{cc})."/x86_64-linux-musl-objcopy", '-S', '-O', 'binary', 'perl.com.dbg', 'perl.com');
11561164
$PERL_APE = abs_path('./perl.com');
11571165
}
11581166
else {
@@ -1178,16 +1186,24 @@ sub Build {
11781186
close($fh);
11791187
}
11801188

1181-
print "mv $APPPATH $OUTPUTDIR/perl.com\n";
1182-
move($APPPATH, "$OUTPUTDIR/perl.com") or die "move failed: $!";
1189+
foreach my $file ('perl.com', 'perl.com.dbg') {
1190+
my $srcpath = "$TEMPDIR/$file";
1191+
my $destpath = "$OUTPUTDIR/$file";
1192+
print "mv $srcpath $destpath\n";
1193+
move($srcpath, $destpath) or die "move failed: $!";
1194+
}
11831195

11841196
# copy to user specified location
11851197
if(exists $itemconfig->{dest}) {
11861198
print "cd ".START_WD."\n";
11871199
chdir(START_WD) or die "Failed to restore cwd";
1188-
my @args = ("$UserProjectConfig->{apperl_output}/$CurAPPerlName/perl.com", $itemconfig->{dest});
1189-
print 'cp '.join(' ', @args)."\n";
1190-
cp(@args) or die "copy failed: $!";
1200+
foreach my $srcfile ('perl.com', 'perl.com.dbg') {
1201+
my $destfile = $itemconfig->{dest};
1202+
$destfile .= '.dbg' if ($srcfile =~ /dbg$/);
1203+
my @args = ("$UserProjectConfig->{apperl_output}/$CurAPPerlName/$srcfile", $destfile);
1204+
print 'cp '.join(' ', @args)."\n";
1205+
cp(@args) or die "copy failed: $!";
1206+
}
11911207
}
11921208
}
11931209

@@ -1847,7 +1863,7 @@ to be able to build and install them into your APPerl. It supports
18471863
folder paths and paths to tarballs such as the one's directly
18481864
downloaded from CPAN.
18491865
1850-
For example to install L<Geo::Calc:XS>, download its tarball from CPAN
1866+
For example to install B<Geo::Calc:XS>, download its tarball from CPAN
18511867
and add to to my_src_build_config in apperl-project.json:
18521868
18531869
"install_modules" : ["Geo-Calc-XS-0.33.tar.gz"]
@@ -1937,6 +1953,26 @@ Build and test it.
19371953
apperlm build
19381954
./helloext.com
19391955
1956+
=head1 DEBUGGING
1957+
1958+
APPerl binaries as with other Actually Portable Executables built with
1959+
the Cosmopolitan Libc have some nice debug features:
1960+
1961+
Syscall logging can be performed just by running with C<--strace> as
1962+
the first argument:
1963+
1964+
./perl.com --strace /zip/bin/perldoc perlcosmo
1965+
1966+
Function call logging can be performed if you have the accompanying
1967+
C<.com.dbg> file in the same directory as your APPerl binary:
1968+
1969+
./perl.com --ftrace /zip/bin/perldoc perlcosmo
1970+
1971+
In theory, it should be possible to use C<gdb> with APPerl binaries,
1972+
but the author has had great difficulty getting this to work. The
1973+
C<dbg> APPerl config is available to build Cosmopolitan with C<MODE=dbg>
1974+
and Perl with C<-Doptimize=-g3 -gdwarf-4>.
1975+
19401976
=head1 SUPPORT AND DOCUMENTATION
19411977
19421978
APPerl web page: L<https://computoid.com/APPerl/>

0 commit comments

Comments
 (0)