PDP-10 / its

Incompatible Timesharing System
Other
834 stars 80 forks source link

Building KLH10 on MacOS Ventura fails #2270

Open oilcan-productions opened 5 months ago

oilcan-productions commented 5 months ago

Logging an issue to keep track of the work here. The build fails really quickly at the start

make clean all EMULATOR=klh10
rm -f -rf out start build/*/stamp
git submodule sync --recursive `dirname tools/pdp6/.gitignore`
Synchronizing submodule url for 'tools/pdp6'
git submodule update --recursive --init `dirname tools/pdp6/.gitignore`
build/stamp.sh build/timestamps.txt
mkdir -p out/klh10/stamp
touch out/klh10/stamp/touch
mkdir -p out/klh10/system
x=`echo 192.168.1.100 | tr . ,`; \
    sed -e "s/%IP%/$x/" \
        -e 's/%NETMASK%/255,255,255,248/' < build/klh10/config.203 > out/klh10/system/config.203
mkdir -p out/klh10
tools/itstar/itstar -cf out/klh10/minsys.tape -C bin/ks10 _ sys
tools/itstar/itstar -rf out/klh10/minsys.tape -C bin/minsys sys
mkdir -p out/klh10
tools/itstar/itstar -cf out/klh10/minsrc.tape -C src midas system sysen1/ddt.1548 syseng/datime.75 syseng/lsrtns.69 syseng/msgs.47 syseng/ntsddt.n79h kshack/nsalv.261 syseng/format.305 syseng/rfn.13 kshack/ksfedr.146 syseng/dump.448 sysnet/netwrk.266
tools/itstar/itstar -rf out/klh10/minsrc.tape -C out/klh10 system
mkdir -p out/klh10
tools/tapeutils/tapewrite -n 2560 out/klh10/salv.tape bin/ks10/boot/ram.262 bin/ks10/boot/salv.rp06
mkdir -p out/klh10
tools/tapeutils/tapewrite -n 2560 out/klh10/dskdmp.tape bin/ks10/boot/ram.262 bin/ks10/boot/dskdmp.rp06
ln -s build/klh10/start 
mkdir -p out/klh10/stamp
sed -e 's/%IP%/192.168.1.100/' \
        -e 's/%GW%/192.168.0.45/' < build/mchn/DB/dskdmp.txt > out/klh10/dskdmp.ini
mkdir -p out/klh10/stamp
touch out/klh10/stamp/pdp10
mkdir -p out/klh10/syshst
sed -e 's/%IP%/192.168.1.100/' \
        -e 's/%HOSTNAME%/DB-ITS.EXAMPLE.COM/' < build/h3text.2018 > out/klh10/syshst/h3text.2018
cat conf/hosts >> out/klh10/syshst/h3text.2018
mkdir -p out/klh10
rm -f -f src/*/*~
tools/itstar/itstar -cf out/klh10/sources.tape -C src syseng sysen1 sysen2 sysen3 sysnet kshack dragon channa _teco_ emacs emacs1 rms klh syshst sra mrc ksc eak gren bawden _mail_ l lisp libdoc comlap lspsrc nilcom rwk chprog rg inquir acount gz sys decsys ecc alan sail kcc kcc_sy c games archy dcp spcwar rwg libmax rat z emaxim rz maxtul aljabr cffk das ell ellen jim jm jpg macrak maxdoc maxsrc mrg munfas paulw reh rlb rlb% share tensor transl wgd zz graphs lmlib pratt quux scheme gsb ejs mudsys draw wl taa tj6 budd sharem ucode rvb kldcp math as imsrc gls demo macsym lmcons dmcg hibou agb gt40 rug maeda ms kle aap common fonts lcf 11logo kmp info aplogo bkph bbn pdp11 chsncp sca music1 moon teach ken lmio1 llogo a2deh chsgtv clib sys3 lmio turnip mits_s rab stan_k bs cstacy kp dcp2 -pics- victor imlac rjl mb bh lars drnil radia gjd maint bolio cent shrdlu vis cbf digest prs jsf decus bsg muds54 hello rrs 2500 minsky danny survey librm3 librm4 klotz atlogo clusys cprog r eb cpm mini nova sits nlogo bee gld mprog2 cfs libmud librm1 librm2 mprog mprog1 mudbug mudsav _batch combat mits_b minits spacy
tools/itstar/itstar -rf out/klh10/sources.tape -C doc info _info_ sysdoc sysnet syshst kshack _teco_ emacs emacs1 c kcc chprog sail draw wl pc tj6 share _glpr_ _xgpr_ inquir mudman system xfont maxout ucode moon acount alan channa fonts games graphs humor kldcp libdoc lisp _mail_ midas quux scheme manual wp chess ms macdoc aplogo _temp_ pdp11 chsncp cbf rug bawden llogo eak clib teach pcnet combat pdl minits mits_s chaos hal -pics- imlac maint cent ksc klh digest prs decus bsg madman hur lmdoc rrs danny netwrk klotz hello clu r mini nova sits jay rjl nlogo mprog2 mudbug cfs hudini
tools/itstar/itstar -rf out/klh10/sources.tape -C bin sys sys1 sys2 emacs _teco_ lisp liblsp alan inquir sail comlap c decsys graphs draw datdrw fonts fonts1 fonts2 games macsym maint _www_ gt40 llogo bawden sysbin -pics- lmman shrdlu imlac pdp10 madman survey rrs clu clucmp rws mini mudsav mudsys libmud librm1 librm2 librm3 librm4 mbprog mprog1 mprog mprog2 mudbug mudtmp _batch
tools/itstar/itstar -rf out/klh10/sources.tape -C out/klh10 syshst
PATH="/Users/mikek/its/tools/klh10/BIN:$PATH" expect -f build/klh10/build.tcl 192.168.1.100 192.168.0.45

ENTERING MAIN BUILD SCRIPT
Wed Jan 24 15:31:10 PST 2024

BUILDING DB ITS

ENTERING BUILD SCRIPT: MARK
Wed Jan 24 15:31:10 PST 2024

spawn ./kn10-ks-its ../mchn/DB/nsalv.ini
KLH10 2.0l (MyITS) built Jan 24 2024 15:24:47
    Copyright © 2002 Kenneth L. Harrenstien -- All Rights Reserved.
This program comes "AS IS" with ABSOLUTELY NO WARRANTY.

Compiled for apple-darwin22.6.0 on x86_64 with word model USEINT
Emulated config:
     CPU: KS10   SYS: ITS   Pager: ITS  APRID: 4097
     Memory: 512 pages of 1024 words  (SHARED)
     Time interval: INTRP   Base: OSGET   Quantums: OSVIRT
     Interval default: 60Hz
     Internal clock: OSINT
     Other: CIRC JPC DEBUG PCCACHE CTYINT IMPINT EVHINT
     Devices: RH11 RPXX(DP) TM03 DZ11 CH11 LHDH(DPIMP)
[MEM: Allocating 512 pages [os_mmcreate: shmget failed for 4194304 bytes - Cannot allocate memory]
private memory, clearing...done]

KLH10# ; Define basic KS10 device config - two RH11s each on its own Unibus
KLH10# 
KLH10# devdef rh0  ub1   rh11   addr=776700 br=6 vec=254
KLH10# devdef rh1  ub3   rh11   addr=772440 br=6 vec=224
KLH10# 
KLH10# ; Provide one disk, one tape in config ITS expects
KLH10# 
KLH10# devdef dsk0 rh0.0 rp     type=rp06 format=dbd9 path=../../out/klh10/rp0.dsk iodly=0
[dp_init: shmget failed - 12]
RPXX subproc init failed!
Final init of device "dsk0" failed!
KLH10# devdef mta0 rh1.0 tm02   fmtr=tm03 type=tu45
KLH10# devdef mta1 rh1.1 tm02   fmtr=tm03 type=tu45
KLH10# devmo mta0 ../../out/klh10/minsys.tape
Mount succeeded.
KLH10# devmo mta1 ../../out/klh10/salv.tape
Mount succeeded.
KLH10# 
KLH10# ; ITS wants a 60Hz clock, allow it.  Need this until defaults OK.
KLH10# set clk_ithzfix=60
   clk_ithzfix: 60.  =>  60.
KLH10# 
KLH10# ; Define IMP for PI on ITS.JOSS.COM
KLH10# devdef imp  ub3   lhdh   addr=767600 br=6 vec=250 ipaddr=199.34.53.51 gwaddr=199.34.53.50
IMP assuming "pcap" interface method since "gwaddr" parameter given
[dp_init: shmget failed - 12]
IMP subproc init failed!
Final init of device "imp" failed!
KLH10# 
KLH10# ; Dummy definitions.  Only one DZ is still (apparently) needed.
KLH10# devdef dz0  ub3   dz11   addr=760010 br=5 vec=340
KLH10# ;devdef dz1  ub3   dz11   addr=760020 br=5 vec=350
KLH10# ;devdef chaos ub3  ch11   addr=764140 br=5 vec=270
KLH10# 
KLH10# ; Define new HOST device hackery
KLH10# ;devdef idler ub3 host addr=777000
KLH10# 
KLH10# load @.nsalv-260-u
Using word format "u36"...
Added 2914 syms to DDT, total 2974
Loaded "@.nsalv-260-u":
Format: ITS-SBLK
Data: 9830, Symwds: 2914, Low: 0, High: 0777266, Startaddress: 0774000
KLH10# [EOF on ../mchn/DB/nsalv.ini]
KLH10# go
Starting KN10 at loc 0774000...

MARK$G'
Format pack on unit #0send: spawn id exp7 not open
    while executing
"send -- $c"
    (procedure "type" line 4)
    invoked from within
"type $r"
    (procedure "respond" line 3)
    invoked from within
"respond "Are you sure you want to format pack on drive" "y""
    (procedure "mark_pack" line 5)
    invoked from within
"mark_pack "0" "0" "foobar""
    (procedure "mark_bootstrap_packs" line 2)
    invoked from within
"mark_bootstrap_packs"
    (file "/Users/mikek/its/build/mark.tcl" line 5)
    invoked from within
"source $build/mark.tcl"
    (file "../build.tcl" line 167)
    invoked from within
"source ../build.tcl"
    (file "build/klh10/build.tcl" line 71)
make: *** [out/klh10/rp0.dsk] Error 1
oilcan-productions commented 4 months ago

When I go and step through the mark.tcl script manually by running ./kn10-ks-its ../mchn/DB/nsalv.ini from the build/klh10 directory.
I get this error on the first question. Which seems to be the same fault during make it is just not bubbled up.

Format pack on unit #0zsh: segmentation fault  sudo ./kn10-ks-its ../mchn/DB/nsalv.ini
larsbrinkhoff commented 4 months ago

@eswenson1, are you running KLH10 on a Mac? If so, anything to add here with regards to your success or lack thereof?

eswenson1 commented 4 months ago

I'm not currently. Let me try to build and run.

Update: I did just try to do a make clean EMULATOR=klh10 && make EMULATOR=klh10 download and while KLH10 built, the download target resulted in this:

...
ln -s build/klh10/start
mkdir -p out/klh10/stamp
sed -e 's/%IP%/192.168.1.100/' \
        -e 's/%GW%/192.168.0.45/' < build/mchn/DB/dskdmp.txt > out/klh10/dskdmp.ini
mkdir -p out/klh10/stamp
touch out/klh10/stamp/pdp10
wget http://hactrn.kostersitz.com/images/klh10.tgz
--2024-02-16 08:22:32--  http://hactrn.kostersitz.com/images/klh10.tgz
Resolving hactrn.kostersitz.com (hactrn.kostersitz.com)... 31.22.4.235
Connecting to hactrn.kostersitz.com (hactrn.kostersitz.com)|31.22.4.235|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141598464 (135M) [application/x-tar]
Saving to: ‘klh10.tgz’

klh10.tgz                        100%[==========================================================>] 135.04M  4.33MB/s    in 34s

2024-02-16 08:23:07 (3.99 MB/s) - ‘klh10.tgz’ saved [141598464/141598464]

tar xzf klh10.tgz
klh10/output.tape: truncated gzip input
tar: Error exit delayed from previous errors.
make: *** [download] Error 1

I tried repeatedly downloading klh10.tgz from hactrn.kostersitz.com, and each time, while the download appears to work perfectly fine, the .tgz has errors extracting. Perhaps it was not properly uploaded the last time?

I'll try a full build, which, of course, is needed to test out this ticket. I was just curious to try the download thing since I haven't ever before.

eswenson1 commented 4 months ago

I'm failing in the same way as previously described:

ENTERING MAIN BUILD SCRIPT
Fri Feb 16 08:29:08 PST 2024

BUILDING DB ITS

ENTERING BUILD SCRIPT: MARK
Fri Feb 16 08:29:08 PST 2024

spawn ./kn10-ks-its ../mchn/DB/nsalv.ini
KLH10 2.0l (MyITS) built Feb 16 2024 08:22:27
    Copyright © 2002 Kenneth L. Harrenstien -- All Rights Reserved.
This program comes "AS IS" with ABSOLUTELY NO WARRANTY.

Compiled for apple-darwin23.2.0 on arm with word model USEINT
Emulated config:
     CPU: KS10   SYS: ITS   Pager: ITS  APRID: 4097
     Memory: 512 pages of 1024 words  (SHARED)
     Time interval: INTRP   Base: OSGET   Quantums: OSVIRT
     Interval default: 60Hz
     Internal clock: OSINT
     Other: CIRC JPC DEBUG PCCACHE CTYINT IMPINT EVHINT
     Devices: RH11 RPXX(DP) TM03 DZ11 CH11 LHDH(DPIMP)
[MEM: Allocating 512 pages shared memory, clearing...done]

KLH10# ; Define basic KS10 device config - two RH11s each on its own Unibus
KLH10#
KLH10# devdef rh0  ub1   rh11   addr=776700 br=6 vec=254
KLH10# devdef rh1  ub3   rh11   addr=772440 br=6 vec=224
KLH10#
KLH10# ; Provide one disk, one tape in config ITS expects
KLH10#
KLH10# devdef dsk0 rh0.0 rp     type=rp06 format=dbd9 path=../../out/klh10/rp0.dsk iodly=0
[dp_init: shmget failed - 12]
RPXX subproc init failed!
Final init of device "dsk0" failed!
KLH10# devdef mta0 rh1.0 tm02   fmtr=tm03 type=tu45
KLH10# devdef mta1 rh1.1 tm02   fmtr=tm03 type=tu45
KLH10# devmo mta0 ../../out/klh10/minsys.tape
Mount succeeded.
KLH10# devmo mta1 ../../out/klh10/salv.tape
Mount succeeded.
KLH10#
KLH10# ; ITS wants a 60Hz clock, allow it.  Need this until defaults OK.
KLH10# set clk_ithzfix=60
   clk_ithzfix: 60.  =>  60.
KLH10#
KLH10# ; Define IMP for PI on ITS.JOSS.COM
KLH10# devdef imp  ub3   lhdh   addr=767600 br=6 vec=250 ipaddr=199.34.53.51 gwaddr=199.34.53.50
IMP assuming "pcap" interface method since "gwaddr" parameter given
[dp_init: shmget failed - 12]
IMP subproc init failed!
Final init of device "imp" failed!
KLH10#
KLH10# ; Dummy definitions.  Only one DZ is still (apparently) needed.
KLH10# devdef dz0  ub3   dz11   addr=760010 br=5 vec=340
KLH10# ;devdef dz1  ub3   dz11   addr=760020 br=5 vec=350
KLH10# ;devdef chaos ub3  ch11   addr=764140 br=5 vec=270
KLH10#
KLH10# ; Define new HOST device hackery
KLH10# ;devdef idler ub3 host addr=777000
KLH10#
KLH10# load @.nsalv-260-u
Using word format "u36"...
Added 2914 syms to DDT, total 2974
Loaded "@.nsalv-260-u":
Format: ITS-SBLK
Data: 9830, Symwds: 2914, Low: 0, High: 0777266, Startaddress: 0774000
KLH10# [EOF on ../mchn/DB/nsalv.ini]
KLH10# go
Starting KN10 at loc 0774000...

MARK$G'
Format pack on unit #0send: spawn id exp7 not open
    while executing
"send -- $c"
    (procedure "type" line 4)
    invoked from within
"type $r"
    (procedure "respond" line 3)
    invoked from within
"respond "Are you sure you want to format pack on drive" "y""
    (procedure "mark_pack" line 5)
    invoked from within
"mark_pack "0" "0" "foobar""
    (procedure "mark_bootstrap_packs" line 2)
    invoked from within
"mark_bootstrap_packs"
    (file "/Users/eswenson/ITS/ws/its/build/mark.tcl" line 5)
    invoked from within
"source $build/mark.tcl"
    (file "../build.tcl" line 167)
    invoked from within
"source ../build.tcl"
    (file "build/klh10/build.tcl" line 71)
make: *** [out/klh10/rp0.dsk] Error 1
➜  its git:(master) ✗
eswenson1 commented 4 months ago

I manually tried to start KLH10 (in the right directory with the right command-line parameters), and got this:

KLH10# load @.ddt-u
Using word format "u36"...
Added 1610 syms to DDT, total 1670
Loaded "@.ddt-u":
Format: ITS-SBLK
Data: 1947, Symwds: 1617, Low: 0772702, High: 0777266, Startaddress: 0774000
Assembled by ALAN on 1989-05-31 05:00:25 from file "AI:SYSTEM;DDT 68"
KLH10# load dskdmp.216bin
Using word format "u36"...
Added 1272 syms to DDT, total 2942
Loaded "dskdmp.216bin":
Format: ITS-SBLK
Data: 954, Symwds: 1279, Low: 04000, High: 07774, Startaddress: 04000
Assembled by KLH on 1992-07-20 04:70:12 from file "NX:SYSTEM;DSKDMP 216"
KLH10# [EOF on ../../out/klh10/dskdmp.ini]
KLH10# go
Starting KN10 at loc 04000...

It hung at this point. So either there is something wrong with the files loaded into KLH10 (e.g. dskdmp.216bin or @.ddt-u), which I doubt, or the built KLH10 doesn't work any more when built on mac. I'll see if I can find an old klh10 I've built and run to see if it does better.

oilcan-productions commented 4 months ago

When I start my full build manually with this ./kn10-ks-its ../mchn/DB/nsalv.ini it starts up fine but then crashes when I type the 0 at the format pack # prompt. It looks like yours started at loc 04000 whereas mine starts at 0774000

eswenson1 commented 4 months ago

Is it normal to get this error on startup of kn10-ks-its? I don't recall seeing it before.

KLH10 2.0l (MyITS) built Feb 16 2024 08:22:27
    Copyright � 2002 Kenneth L. Harrenstien -- All Rights Reserved.
This program comes "AS IS" with ABSOLUTELY NO WARRANTY.

Compiled for apple-darwin23.2.0 on arm with word model USEINT
Emulated config:
     CPU: KS10   SYS: ITS   Pager: ITS  APRID: 4097
     Memory: 512 pages of 1024 words  (SHARED)
     Time interval: INTRP   Base: OSGET   Quantums: OSVIRT
     Interval default: 60Hz
     Internal clock: OSINT
     Other: CIRC JPC DEBUG PCCACHE CTYINT IMPINT EVHINT
     Devices: RH11 RPXX(DP) TM03 DZ11 CH11 LHDH(DPIMP)
[MEM: Allocating 512 pages [os_mmcreate: shmget failed for 4194304 bytes - Cannot allocate memory]
private memory, clearing...done]

KLH10# quit

I wonder if this is the cause?

eswenson1 commented 4 months ago

I'm getting the same issue as you are:

➜  klh10 git:(master) ✗ ./kn10-ks-its ../mchn/DB/nsalv.ini
KLH10 2.0l (MyITS) built Feb 16 2024 08:22:27
    Copyright � 2002 Kenneth L. Harrenstien -- All Rights Reserved.
This program comes "AS IS" with ABSOLUTELY NO WARRANTY.

Compiled for apple-darwin23.2.0 on arm with word model USEINT
Emulated config:
     CPU: KS10   SYS: ITS   Pager: ITS  APRID: 4097
     Memory: 512 pages of 1024 words  (SHARED)
     Time interval: INTRP   Base: OSGET   Quantums: OSVIRT
     Interval default: 60Hz
     Internal clock: OSINT
     Other: CIRC JPC DEBUG PCCACHE CTYINT IMPINT EVHINT
     Devices: RH11 RPXX(DP) TM03 DZ11 CH11 LHDH(DPIMP)
[MEM: Allocating 512 pages [os_mmcreate: shmget failed for 4194304 bytes - Cannot allocate memory]
private memory, clearing...done]

KLH10# ; Define basic KS10 device config - two RH11s each on its own Unibus
KLH10#
KLH10# devdef rh0  ub1   rh11   addr=776700 br=6 vec=254
KLH10# devdef rh1  ub3   rh11   addr=772440 br=6 vec=224
KLH10#
KLH10# ; Provide one disk, one tape in config ITS expects
KLH10#
KLH10# devdef dsk0 rh0.0 rp     type=rp06 format=dbd9 path=../../out/klh10/rp0.dsk iodly=0
[dp_init: shmget failed - 12]
RPXX subproc init failed!
Final init of device "dsk0" failed!
KLH10# devdef mta0 rh1.0 tm02   fmtr=tm03 type=tu45
KLH10# devdef mta1 rh1.1 tm02   fmtr=tm03 type=tu45
KLH10# devmo mta0 ../../out/klh10/minsys.tape
Mount succeeded.
KLH10# devmo mta1 ../../out/klh10/salv.tape
Mount succeeded.
KLH10#
KLH10# ; ITS wants a 60Hz clock, allow it.  Need this until defaults OK.
KLH10# set clk_ithzfix=60
   clk_ithzfix: 60.  =>  60.
KLH10#
KLH10# ; Define IMP for PI on ITS.JOSS.COM
KLH10# devdef imp  ub3   lhdh   addr=767600 br=6 vec=250 ipaddr=199.34.53.51 gwaddr=199.34.53.50
IMP assuming "pcap" interface method since "gwaddr" parameter given
[dp_init: shmget failed - 12]
IMP subproc init failed!
Final init of device "imp" failed!
KLH10#
KLH10# ; Dummy definitions.  Only one DZ is still (apparently) needed.
KLH10# devdef dz0  ub3   dz11   addr=760010 br=5 vec=340
KLH10# ;devdef dz1  ub3   dz11   addr=760020 br=5 vec=350
KLH10# ;devdef chaos ub3  ch11   addr=764140 br=5 vec=270
KLH10#
KLH10# ; Define new HOST device hackery
KLH10# ;devdef idler ub3 host addr=777000
KLH10#
KLH10# load @.nsalv-260-u
Using word format "u36"...
Added 2914 syms to DDT, total 2974
Loaded "@.nsalv-260-u":
Format: ITS-SBLK
Data: 9830, Symwds: 2914, Low: 0, High: 0777266, Startaddress: 0774000
KLH10# [EOF on ../mchn/DB/nsalv.ini]
KLH10# go
Starting KN10 at loc 0774000...

FOO$J?   MARK$G'
Format pack on unit #0[1]    61311 segmentation fault  ./kn10-ks-its ../mchn/DB/nsalv.ini
                                                                                         %
➜  klh10 git:(master) ✗

I suspect the inability to allocate memory (first error message on kn10-ks-its startup) is the cause.

oilcan-productions commented 4 months ago

I guess that would be a problem.

oilcan-productions commented 4 months ago

I am wondering if this has to do with the new memory protection features in MacOS. For example I had to codesign gdb to actually use it to get it to run and start debugging

eswenson1 commented 4 months ago

I dunno. I had to codesign gdb way before this problem started happening.

oilcan-productions commented 4 months ago

Found this in the klh10 install.txt

KERNEL CONFIGURATION
====================

    Installation on most UNIX platforms is straightforward except
for two special requirements of the KLH10 emulator, which sometimes
require kernel reconfiguration.

    [A] Shared memory; MANDATORY if running any device sub-processes.
    The so-called SYSV "shm" system calls must be available, and
    ideally should allow shared segments of up to 32MB for a KL10,
    4MB for a KS10.  The configuration examples below assume a KL10
    since it doesn't hurt even if a KS10 is all you will ever run.

    If this support is lacking, you will get a warning similar to
    the following:
        [os_mmcreate: shmget failed for 33554432 bytes - Invalid argument]
    which is not necessarily fatal, but less efficient.

maybe this is a red herring?

oilcan-productions commented 4 months ago

The code for this lives in ./tools/klh10/src/osdsup.c line 1633 in mine. From where it calls it in '/Users/mikek/its-klh/tools/klh10/src/klh10.c' the process tries shared memory first and then moves on the private memory if that fails. the message seems like a red herring as it is deemed a warning that no shared memory is available. Maybe I'll update the message text to say WARNING :)

eswenson1 commented 4 months ago

For some reason, I cannot run my old version of kn10-ks-its under gdb. So I'm unable to debug. I get this:

gdb ./kn10-ks-its
GNU gdb (GDB) 14.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin22.6.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./kn10-ks-its...
(gdb) run nsalv.ini
Starting program: /Users/eswenson/its/ws/its/build/klh10/kn10-ks-its nsalv.ini
[New Thread 0x2203 of process 90662]

.
mark^[g

I'm hung after the [New Thread...] message from gdb. I never see any messages from kn10-ks-its. The "mark^[g" was a silly/vain attempt to see if it had started without messages and NSALV was waiting for input (it wasn't).

eswenson1 commented 4 months ago

I wonder if shared memory settings need to get updated. This is what I have:

sysctl -a | grep sysv.shm
kern.sysv.shmmax: 4194304
kern.sysv.shmmin: 1
kern.sysv.shmmni: 32
kern.sysv.shmseg: 8
kern.sysv.shmall: 1024
eswenson1 commented 4 months ago

I increased kern.sysv.shmmax to double that amount and I still get a failure. But the value emitted in the error message is still 4194304. I wonder if I have to reboot the system after changing the value? I thought you could simply do sudo sysctl -w kern.sysv.shmmax=xxxxx to change the value until the next reboot? When I run sysctl kern.sysv.shmmax to confirm my setting, I get back:

kern.sysv.shmmax: 8388608

So my change appears to take effect. Not sure why kn10-ks-is asking for 4194304. Can you tell from the code what it wants?

eswenson1 commented 4 months ago

It does look like kn10-ks-its is only wanting 4M, so the 4194304 value is what it is asking for. My "shmmax" value is double that, so the shmget call should succeed. Not sure why it isn't. Googling.....

oilcan-productions commented 4 months ago

I found that once it crashes in the terminal window I have to start a new terminal session for the emulator to get to the prompt again. Something in that terminal session gets borked after the crash

eswenson1 commented 4 months ago

Can you use gdb to determine what the error code from the shmget failure is? That might provide a clue.

eswenson1 commented 4 months ago

For me, creating a new shell doesn't fix my inability to run kn10-ks-its under gdb. I never get to see any output from kn10-ks-its after gdb reports that a new thread is created.

eswenson1 commented 4 months ago

I may have to rebuild my kn10-ks-its (good idea anyway). I was able to attach to my kn10-ks-its process from gdb after it was started and see this:

➜  ~ gdb -p 92014
GNU gdb (GDB) 14.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin22.6.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 92014
[New Thread 0x2803 of process 92014]

warning: Error calling thread_get_state for GP registers for thread 0x2803

warning: Mach error at "../../gdb/i386-darwin-nat.c:132" in function "fetch_registers": (os/kern) invalid argument (0x4)
Reading symbols from /Users/eswenson/its/ws/its/build/klh10/kn10-ks-its...

warning: unhandled dyld version (17)
0x0000000109697bcd in ?? ()
(gdb)

I'll rebuild and retry.

oilcan-productions commented 4 months ago

the memsiz is calculated in klh10.c memsiz = (size_t)PAG_SIZE * PAG_MAXPHYSPGS * sizeof(w10_t);

oilcan-productions commented 4 months ago

this is what I get in gdb

Attaching to process 33823
[New Thread 0x1703 of process 33823]

warning: Error calling thread_get_state for GP registers for thread 0x1703

warning: Mach error at "../../gdb/i386-darwin-nat.c:132" in function "fetch_registers": (os/kern) invalid argument (0x4)
Reading symbols from /Users/mikek/its-klh/build/klh10/kn10-ks-its...

warning: unhandled dyld version (17)
0x00007ff80e490e52 in ?? ()
(gdb) cont
Continuing.
[Inferior 1 (process 33823) exited normally]
(gdb) 
oilcan-productions commented 4 months ago

Need to do a CONTINUE in GDB after attaching so it takes the input on the emulator side.

eswenson1 commented 4 months ago

Yeah, I did. I got:

(gdb) cont
Continuing.
[Inferior 1 (process 7648) exited normally]
(gdb)

and in the gdb session:

MARK$G'
Format pack on unit #0[1]    7648 segmentation fault  ./kn10-ks-its ../mchn/DB/nsalv.ini

So no help.

oilcan-productions commented 4 months ago

At least we are both seeing the same.

oilcan-productions commented 4 months ago

I do not think it has to do with the amount of memory the emulator tries to allocate I changed it to just try 50% of the allocation. No change in behavior.

eswenson1 commented 4 months ago

What is the error code you’re getting from shmget?

oilcan-productions commented 4 months ago

The thing is I am not getting any error from shmget.

eswenson1 commented 4 months ago

Are you getting a null pointer back? What is the value of errno?

oilcan-productions commented 4 months ago

Yes it is a null pointer. errno=11

eswenson1 commented 4 months ago

Geez. That’s EAGAIN, or Resource Temporarily Unavailable. Not very helpful. Also I don’t see any hits on this errno with shmget.

oilcan-productions commented 4 months ago

It is the last error gdb sees after the emulator exits. I have also tried to set a break point at the function but that crashed gdb :S

eswenson1 commented 4 months ago

The KLH10 code should check for a null pointer and “handle” it somehow (possibly exiting gracefully after getting and displaying ERRNO). What does it do now? Try a regular local alloc? Is it doing that and fumbling the handling? Or is it getting an error from malloc (or whatever) too?

oilcan-productions commented 4 months ago

it jumps to a regular malloc which seems to succeed as it is not erroring out and the emulator completes loading. That is why I think the shared memory thing is "just a warning"

/* MEM_INIT - Allocate & initialize PDP10 memory.
**  Perhaps move this to pag_init?
*/
static void
mem_init(void)
{
    size_t memsiz;
    char *ptr;

    /* Determine amount of phys mem to get */
    memsiz = ((size_t)PAG_SIZE * PAG_MAXPHYSPGS * sizeof(w10_t))/2;

    /* Always attempt to get shared memory first.  If that fails
    ** (either because OS can't do it, or KLH10 was compiled without
    ** support), then go for private memory.
    */
    fprintf(stdout, "[MEM: Allocating %ld pages ", (long)PAG_MAXPHYSPGS);
    if (os_mmcreate(memsiz, &cpu.mm_physegid, &ptr)) {
    cpu.mm_shared = TRUE;
    fprintf(stdout, "shared memory, clearing...");
    } else {
    /* Failed - routine already barfed about it, if OS failure. */
    cpu.mm_shared = FALSE;
    fprintf(stdout, "shared memory unavailable. Will use private memory instead.");

    /* Allocate private KN10 memory */
    cpu.mm_physegid = 0;

    if (!(ptr = malloc(memsiz))) {
        syserr(errno, "MEM: cannot malloc KN10 physical memory!\n");
    }
    fprintf(stdout, "private memory, clearing...");
    }

    cpu.physmem = (vmptr_t)ptr;

    /* To avoid unpleasant surprises to code that expects unused bits
    ** of w10_t words to be zero, we clear it all to begin with.
    */
    memset(ptr, 0, memsiz);     /* Clear it all out */
    fprintf(stdout, "done]\n");
}
eswenson1 commented 4 months ago

In that case, why are we getting the segmentation fault? Can you step in gdb from after the successful local memory allocation to see where we reference through a bad pointer?

ams commented 4 months ago

2024-02-16 08:23:07 (3.99 MB/s) - ‘klh10.tgz’ saved [141598464/141598464]

We should put this file in a different spot, downloading like that will break at some point ...

~/its $ tar tvf ./klh10.tgz
drwxr-xr-x  0 runner docker      0 Feb 12 13:51 klh10/
-rw-r--r--  0 runner docker 177776640 Feb 12 13:56 klh10/rp0.dsk
-rw-r--r--  0 runner docker     66780 Feb 12 13:50 klh10/ndskdmp.tape
-rw-r--r--  0 runner docker    113004 Feb 12 13:50 klh10/nnsalv.tape
-rw-r--r--  0 runner docker     64212 Feb 12 12:04 klh10/dskdmp.tape
-rw-r--r--  0 runner docker   6873628 Feb 12 12:07 klh10/reboot.tape
-rw-r--r--  0 runner docker    799724 Feb 12 12:04 klh10/minsys.tape
-rw-r--r--  0 runner docker   5014306 Feb 12 12:04 klh10/minsrc.tape
drwxr-xr-x  0 runner docker         0 Feb 12 12:03 klh10/check/
-rw-r--r--  0 runner docker         0 Feb 12 12:03 klh10/check/src.diff
-rw-r--r--  0 runner docker         0 Feb 12 12:03 klh10/check/bin.diff
-rw-r--r--  0 runner docker       534 Feb 12 12:03 klh10/check/doc2
-rw-r--r--  0 runner docker       534 Feb 12 12:03 klh10/check/doc1
-rw-r--r--  0 runner docker         0 Feb 12 12:03 klh10/check/doc.diff
-rw-r--r--  0 runner docker       328 Feb 12 12:03 klh10/check/bin2
-rw-r--r--  0 runner docker       328 Feb 12 12:03 klh10/check/bin1
-rw-r--r--  0 runner docker      1069 Feb 12 12:03 klh10/check/src2
-rw-r--r--  0 runner docker      1069 Feb 12 12:03 klh10/check/src1
drwxr-xr-x  0 runner docker         0 Feb 12 12:04 klh10/system/
-rw-r--r--  0 runner docker     40515 Feb 12 12:04 klh10/system/config.203
-rw-r--r--  0 runner docker      1095 Feb 12 12:05 klh10/dskdmp.ini
-rw-r--r--  0 runner docker  88684464 Feb 12 12:05 klh10/sources.tape
-rw-r--r--  0 runner docker 137158394 Feb 12 13:53 klh10/output.tape
tar: Truncated input file (needed 137158656 bytes, only 0 available)
tar: Error exit delayed from previous errors.
ams commented 4 months ago

Might be worth trying that other debugger (lldb ...); Apple is known for making life complicated. Can someone write up a short reproducible case (like for dumb people). Then I can take a look.

eswenson1 commented 4 months ago

We should put this file in a different spot, downloading like that will break at some point ...

Why do you say that? Why would a different spot impact whether the contents are corrupt or not?

larsbrinkhoff commented 4 months ago

It's true enough that if you do a second "make download" the new file will be e.g. klh10.tar.gz.1 which is wrong.

eswenson1 commented 4 months ago

Yes. That’s true. But why is the file corrupt?

eswenson1 commented 4 months ago

Might be worth trying that other debugger (lldb ...); Apple is known for making life complicated. Can someone write up a short reproducible case (like for dumb people). Then I can take a look.

Well, to reproduce, get an Intel Mac and make sure it is running Ventura or Sonoma. Pull the ITS GitHub tree and attempt a make EMULATOR=klh10. It will get a segmentation fault when expect hands the salvager a “0” to format pack 0.

The same failure occurs on an M(1 2 3) Mac, but gdb won’t run on these.

ams commented 4 months ago

We should put this file in a different spot, downloading like that will break at some point ...

Why do you say that? Why would a different spot impact whether the contents are corrupt or not?

What I mean is that it should be put into the git repo, or some other such place where there is some verification / CRC of the file in question. Randomly downloading it over the network, with no means of looking at when the file was modified, or if there are other versions is suboptimal to say the least.

ams commented 4 months ago

The same failure occurs on an M(1 2 3) Mac, but gdb won’t run on these.

Yes it will.

How do you attach GDB to the klh10 process? The notes above do not work (e.g., there is no such ini file ..)

eswenson1 commented 4 months ago

Since when will gdb run on M* processors? I did a “brew install gdb” on my M2 Mac and Ingot a message that gdb can only run on x68_64 architecture machines.

You attach gdb to a process by running:

gdb -p <pid-of-process>

What INI are you referring to? I didn’t mention an INI. Just try to build a freshly-pulled GitHub.com/pdp-10/its repo with:

make EMULATOR=klh10
eswenson1 commented 4 months ago

What I mean is that it should be put into the git repo, or some other such place where there is some verification / CRC of the file in question.

I don’t think git is the answer here. These disk image files are huge and git isn’t really for huge binary files.

We should upload them (during the build) along with a digest of the image. We should download them with a fixed name (no .1) — deleting any filename that matches the filename first — so that we will unarchive the intended file. The download should check the digest before proceeding with the contents of the archive.

ams commented 4 months ago

(gdb) run nsalv.ini

@eswenson1 that ini file that you mentioned up thread. Attaching to a PID will not work in this case, since the process segfault.

I'm short on time, I can probably figure out what is going on but not enough to setup exactly what you are doing so I need help with that -- i.e. what exactly are you running and how since nothing from up thread has been reproducible.

ams commented 4 months ago

What I mean is that it should be put into the git repo, or some other such place where there is some verification / CRC of the file in question.

I don’t think git is the answer here. These disk image files are huge and git isn’t really for huge binary files.

We should upload them (during the build) along with a digest of the image. We should download them with a fixed name (no .1) — deleting any filename that matches the filename first — so that we will unarchive the intended file. The download should check the digest before proceeding with the contents of the archive.

Exact solution is debatable, a separate git repository with these things might be worth it. A digest of some sort too .. but I think depending on this "magical website on the network" to "magically work" isn't the solution.

Or if this is part of some make target, document that -- maybe that is even done. I don't know ... AFAIC right now this is all broken beyond repair.

ams commented 4 months ago
~/its/build/klh10 $ lldb kn10-ks-its ../mchn/DB/nsalv.ini
[...]
(lldb) run
[...]
Process 5363 launched: '/Users/ams/its/build/klh10/kn10-ks-its' (arm64)
[...]
KLH10# [EOF on ../mchn/DB/nsalv.ini]
KLH10# go
Starting KN10 at loc 0774000...

When running under lldb there seems to be no segfault, hitting C-c we get:

Process 5363 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
    frame #0: 0x0000000100023d38 kn10-ks-its`i_popj(op=179, ac=1, e=0) at injrst.c:687:9 [opt]
   684      register w10_t pcw, w;
   685      register vaddr_t sloc;
   686  
-> 687      w = ac_get(ac);
                ^
   688  
   689  #if KLH10_EXTADR
   690      /* Determine if stack pointer is local or global */
Target 0: (kn10-ks-its) stopped.
warning: kn10-ks-its was compiled with optimization - stepping may behave oddly; variables may not be available.

Which seems correct. Similarly if just run directly:

~/its/build/klh10 [1] $ ./kn10-ks-its ../mchn/DB/nsalv.ini
[...]
KLH10# go
Starting KN10 at loc 0774000...

So something or someone is not telling the whole truth, probably the expect script doing more stuff -- what exactly is being feed?

eswenson1 commented 4 months ago

(gdb) run nsalv.ini

@eswenson1 that ini file that you mentioned up thread. Attaching to a PID will not work in this case, since the process segfault.

I'm short on time, I can probably figure out what is going on but not enough to setup exactly what you are doing so I need help with that -- i.e. what exactly are you running and how since nothing from up thread has been reproducible.

Sorry. I thought you were referring to how to simply reproduce the issue and connect with gdb after the fact. And yes, you’re right the segfault will make the attach-after-start route not be possible.

So if you pull the tree, attempt a build, let it segfault, and THEN do this:

  1. cd to build/klh10
  2. Run gdb kn10-is-its
  3. At the gdb prompt run ../../build/mchn/DB/nsalv.ini

you should be able to trap the segfault.