Author Topic: Compiling a PM sample with GCC (2023)  (Read 141622 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #165 on: June 10, 2023, 12:17:13 am »
Hi

I removed some of the warnings, and I think the sample is running as expected showing some listbox (I hope).
https://github.com/OS2World/DEV-SAMPLES-C-PM-ListBox2

I have these warnings that I need help to remove.
Code: [Select]
gcc -Wall -Zomf -c -O2 ListBox.c -o ListBox.obj
In file included from C:/usr/include/os2.h:39,
                 from ListBox.c:64:
ListBox.c: In function 'UpdateScrollBars':
ListBox.c:448:30: warning: operation on 'plbw->iVertScroll' may be undefined [-Wsequence-point]
  448 |           (plbw->iVertScroll = plbw->cVertScroll = 0) :
      |           ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ListBox.c:472:27: warning: operation on 'plbw->iHorzScroll' may be undefined [-Wsequence-point]
  472 |        (plbw->iHorzScroll = plbw->iHorzScroll = 0) :
      |        ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ListBox.c: In function 'ListBoxWndProc':
ListBox.c:2553:11: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
 2553 |        if ( ((flStyle = WinQueryWindowULong(hWnd, QWL_STYLE)) & 0x0000ffffUL) != (plbw->flStyle & 0x0000ffffUL) )
      |           ^

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #166 on: June 11, 2023, 04:44:47 am »
Hi Again

These little animate samples compiled fine with gcc.
- https://github.com/OS2World/DEV-SAMPLES-C-PM-Animate

Also this "Select Font" window sample.
- https://github.com/OS2World/DEV-SAMPLE-C-PM-Font

Also this long listbox sample.
- https://github.com/OS2World/DEV-SAMPLES-C-PM-HugeLB

Regards
« Last Edit: June 11, 2023, 06:26:38 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #167 on: June 12, 2023, 03:44:49 am »
Hello

I tried this one,
https://github.com/OS2World/DEV-SAMPLES-C-PM-ShowBPM

It compiles but I get this error on POPUPLOG.

Quote

06-11-2023  20:38:56  SYS3175  PID 06ab  TID 0001  Slot 0083
C:\DEV\4TRYING\DEV-SAMPLES-PM-SHOWBPM\SHOWBMP.EXE
c0000005
1fd2bb49
P1=00000002  P2=00032000  P3=XXXXXXXX  P4=XXXXXXXX 
EAX=fffffff2  EBX=00031d90  ECX=3fffff65  EDX=0000000b
ESI=1b36ca3d  EDI=00031ffd 
DS=0053  DSACC=d0f3  DSLIM=9fffffff 
ES=0053  ESACC=d0f3  ESLIM=9fffffff 
FS=150b  FSACC=00f3  FSLIM=00000030
GS=0000  GSACC=****  GSLIM=********
CS:EIP=005b:1fd2bb49  CSACC=d0df  CSLIM=9fffffff
SS:ESP=0053:00031cf4  SSACC=d0f3  SSLIM=9fffffff
EBP=00031d50  FLG=00010a07

PMMERGE.DLL 0004:0015bb49


Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5211
  • Karma: +119/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #168 on: June 12, 2023, 07:47:09 am »
Looking at the trp, I think this change you made is wrong,
Code: [Select]
@@ -76,8 +76,8 @@

         if (pErr->offBinaryData)       // Return code provided
           {
-            SELECTOROF (pRetCode) = SELECTOROF (pErr);
-            OFFSETOF (pRetCode) = pErr->offBinaryData;
+            pRetCode = pErr ;
+            pRetCode = pErr->offBinaryData;
             rc = *pRetCode;            // Save return code
           }
       }

For the macros, os2def.h says,
Code: [Select]
   /* Extract selector or offset from far pointer */
   /* Warning:the selectorof macro should not be used*/
   /* for 32 bit objects                             */
   #define SELECTOROF(ptr)     ((((ULONG)(ptr))>>13)|7)
   #define OFFSETOF(p)         (((PUSHORT)&(p))[0])
#endif  /* !INCL_SAADEFS */

What the correct fix is, I don't have any idea. I assume the original was 16 bit
To create an informative trp, remove the def file from the link line and add -g to all the CFLAGS and LDFLAGS

Edit: The change was to UTILITY.C
« Last Edit: June 12, 2023, 07:49:20 am by Dave Yeo »

Lars

  • Hero Member
  • *****
  • Posts: 1376
  • Karma: +70/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #169 on: June 12, 2023, 07:55:00 am »
I have not looked into the source code so I don't know what is already 32-bit flat pointer and what is still segmented, but try:

pRetcode = (PUSHORT)((PUCHAR)pErr + pErr->offBinaryData);
« Last Edit: June 12, 2023, 07:58:53 am by Lars »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5211
  • Karma: +119/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #170 on: June 12, 2023, 08:11:16 am »
I have not looked into the source code so I don't know what is already 32-bit flat pointer and what is still segmented, but try:

pRetCode = (PUSHORT)((PUCHAR)pErr + pErr->offBinaryData);

Gets rid of the sigsegv but crashes with an error beep. Putting the def back results in the same sys3175 in popuplog.
Perhaps my guess was wrong or incomplete

Lars

  • Hero Member
  • *****
  • Posts: 1376
  • Karma: +70/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #171 on: June 12, 2023, 09:13:39 am »
That's not surprising as szFormat is not initialized which likely leads to a chrash in sprintf, all USHORTs should be converted to ULONGs and possibly some other minor probs.

Lars

  • Hero Member
  • *****
  • Posts: 1376
  • Karma: +70/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #172 on: June 12, 2023, 09:17:04 am »
Correction: szFormat is initialized dynamically via a resource (ridiculous). But because USHORTs are in use, the format string will likely not match the passed variables size. Therefore: convert the USHORT stuff to ULONG (rc and the like).

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #173 on: June 12, 2023, 07:21:08 pm »
Hi

Sorry, I found a different issue with SHOWBPM that was confusing me. The "make clean" was not deleting the UTILITY.OBJ, and I was using an old one, that why I didn't get any warning/errors there, since it was linking the old one.

I will check on that and improve it replacing the SHORT for LONG and see what happens.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5211
  • Karma: +119/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #174 on: June 12, 2023, 09:17:58 pm »
Here it is still crashing. Thinking about removing the def, the program no longer is a PM program. Forget how to morph a program, "exehdr /PMTYPE:PM showbmp.exe" does turn it back to a PM program.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #175 on: June 12, 2023, 10:57:47 pm »
Hi Again

This the far I can get with the SHOWBMP sample. I tried to remove the warnings I can, changed the SHORT for LONG.

It compiles, but it crashes on run.

Here is the POPUPLOG
Code: [Select]
06-12-2023  15:55:19  SYS3175  PID 0195  TID 0001  Slot 007d
C:\DEV\3NOSHOW\DEV-SAMPLES-PM-SHOWBPM\SHOWBMP.EXE
c0000005
1fd2bb49
P1=00000002  P2=00032000  P3=XXXXXXXX  P4=XXXXXXXX 
EAX=fffffff2  EBX=00031d90  ECX=3fffff65  EDX=0000000b
ESI=1b33ca3d  EDI=00031ffd 
DS=0053  DSACC=d0f3  DSLIM=9fffffff 
ES=0053  ESACC=d0f3  ESLIM=9fffffff 
FS=150b  FSACC=00f3  FSLIM=00000030
GS=0000  GSACC=****  GSLIM=********
CS:EIP=005b:1fd2bb49  CSACC=d0df  CSLIM=9fffffff
SS:ESP=0053:00031cf4  SSACC=d0f3  SSLIM=9fffffff
EBP=00031d50  FLG=00010a07

If you can suggest me something to make it run, it can be nice, otherwise if it is too much trouble and old, maybe it is time to move on.

Regards


Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #176 on: June 14, 2023, 06:03:03 pm »
Hello

Now I'm trying this BeeHive demo with gcc.
https://github.com/OS2World/DEV-SAMPLES-IBM_Dev_Toolkit_Samples/tree/b61beeafb1baec2d2ab3ff46ca90c0eb4d576986/samples/mm/BEEHIVE

It compiles, I removed some warnings, but the program crash on start without any popplog message.
I even tried, compiling before fixing the warnings and it didn't start also.

Dave, what is the trick to see the error?  is that something specific the program should have to generate the .trp?

Regards
« Last Edit: June 14, 2023, 06:08:53 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5211
  • Karma: +119/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #177 on: June 15, 2023, 12:58:41 am »
I tried running it in the debugger, seems that it tries to set up DIVE the way that other program did, which silently fails while seeming to succeed, then it cleanly exits.
Perhaps someone more knowledgeable can look at it, but I think it needs some rewriting to properly use DIVE in Warp
Previously I removed the def and got a trp, but not this time and really removing the def might need the program to morph to PM.
For getting the debug data, could just add -g to CFLAGS and LDFLAGS. I changed the makefile like so
Code: [Select]
--- makefile.orig       2023-06-14 15:22:06.000000000 -0700
+++ makefile    2023-06-14 15:47:28.000000000 -0700
@@ -4,23 +4,27 @@
 #  Compile::Resource Compiler
 #  Compile::GNU C
 #  Make: make
+
+CFLAGS=-Wall -Zomf -O2 -c
+DEBUGFLAGS=-g
+
 all : beehive.exe

 beehive.exe : beehive.obj animate.obj blitgen.obj pcxload.obj beehive.def beehi
ve.res
-       gcc -Zomf -L. -lmmpm2 beehive.obj animate.obj blitgen.obj pcxload.obj beehive.def beehive.res -o beehive.exe
+       gcc $(DEBUGFLAGS) -Zomf -L. -lmmpm2 beehive.obj animate.obj blitgen.obj
pcxload.obj beehive.def beehive.res -o beehive.exe
        wrc beehive.res

 beehive.obj : beehive.c beehive.h
-       gcc -Wall -Zomf -c -O2 beehive.c -o beehive.obj
+       gcc $(CFLAGS) $(DEBUGFLAGS) beehive.c -o beehive.obj

 animate.obj : animate.c
-       gcc -Wall -Zomf -c -O2 animate.c -o animate.obj
+       gcc $(CFLAGS) $(DEBUGFLAGS) animate.c -o animate.obj

 blitgen.obj : blitgen.c
-       gcc -Wall -Zomf -c -O2 blitgen.c -o blitgen.obj
+       gcc $(CFLAGS) $(DEBUGFLAGS) blitgen.c -o blitgen.obj

 pcxload.obj : pcxload.c
-       gcc -Wall -Zomf -c -O2 pcxload.c -o pcxload.obj
+       gcc $(CFLAGS) $(DEBUGFLAGS) pcxload.c -o pcxload.obj

 beehive.res : beehive.rc
        wrc -r beehive.rc

Usually the DEBUGFLAGS line can be commented out. This way it is easy to change the CFLAGS as well by passing CFLAGS/DEBUGFLAGS on the command line.
Code: [Select]
make 'DEBUGFLAGS=-Zmap -g' 2>&1 | tee make.out
In compile cmd gives a map file and debug data for example.

Edit: looking further, it does seem to load DIVE, though the code actually uses DosLoadModule to load GAMESRVR, which isn't on my system, yet the map file shows DIVE being used
« Last Edit: June 15, 2023, 02:38:05 am by Dave Yeo »

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5115
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #178 on: June 15, 2023, 03:18:37 am »
Hi Dave
Edit: looking further, it does seem to load DIVE, though the code actually uses DosLoadModule to load GAMESRVR, which isn't on my system, yet the map file shows DIVE being used
The only thing that I found is that GAMESRVR is not longer available, seems that was embedded to DIVE since Warp 4.

DosLoadModule has two version the old 1.x and the newer one, but it seems to be called like the newer one. 

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5211
  • Karma: +119/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #179 on: June 15, 2023, 04:47:59 am »
Searching the os2tk45 toolkit, it is in samples\mm\fsdive as well as samples\mm\dll. dive.dll seems to pipe to it as well.
The "Help-Using Your Toolkit" (uselkt.inf) inf refers to it in the description of the FSDIVE Sample program.