Debug output on distributed exe?
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Debug output on distributed exe?
Is there a way to produce debug output on a distributed copy of a PB 5.xx exe file?
I think that should be clear enough, but just in case, what I am looking for is preferably a debugger output window as we get when we compile with the dewbugger. Otherwise. have the debug output go directly to a file. This would be on a distributed exe file compiled using the PB IDE.
I think that should be clear enough, but just in case, what I am looking for is preferably a debugger output window as we get when we compile with the dewbugger. Otherwise. have the debug output go directly to a file. This would be on a distributed exe file compiled using the PB IDE.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.
Re: Debug output on distributed exe?
No, it's not possible as you would need to distribute the PB GUI debugger with it. The easier for you is to do some wrapper around the Debug command to write it to a file if you are in release mode.
Re: Debug output on distributed exe?
Hi Randy,
first and important info: All following solutions need a recreation and distibution of the exe.
First sugestion:
On windows (only) you can use this tool from sysinternals called DebugView......
To send a message you need this
Second suggestion:
I know there are other (smaller/bigger/better) solutions, but this worked for me very well........
Third suggestion: (Win only)
you can use a WM_COPYDATA based Client/Server app combo to do the trick.
first and important info: All following solutions need a recreation and distibution of the exe.
First sugestion:
On windows (only) you can use this tool from sysinternals called DebugView......
To send a message you need this
Code: Select all
;
; Link: https://www.purebasic.fr/english/posting.php?mode=reply&t=85664&sid=f17527e83d31cfbc570e80b1ca62806e
;
; void OutputDebugStringA(
; [in, optional] LPCSTR lpOutputString
; );
;
Macro AppendDebug(Message)
OutputDebugString_(Message)
EndMacro
; acc. to MSDN (never used or tested)
Macro ClearDebug(Message)
OutputDebugString_("DBGVIEWCLEAR")
EndMacro
I know there are other (smaller/bigger/better) solutions, but this worked for me very well........
Code: Select all
; define Logging (log to file)
;
Structure TLogging
File$
bEnabled.i ; #False (0) == disabled (1) == enabled for messages, (2) == <?>
EndStructure
; semiglobal (cannot be used by accident) -- real world app: updates this structure variables via preference file.
;
Define Logging.TLogging
Logging\File$ = "" ; <?>
Logging\bEnabled = 0 ; initially disabled
; write to a defined log file
;
Procedure WriteLogMessageToFile(Message$) ; returns nothing
Shared Logging.TLogging ; semiglobal
Protected FN
Debug "LOGOUT: '" + Message$ + "' ; '" + Logging\File$ + "' " + Logging\bEnabled
If Logging\File$ <> "" And Logging\bEnabled <> #False ; valid filename and enabled logging -> go for it
FN = OpenFile(#PB_Any, Logging\File$, #PB_File_SharedRead|#PB_File_NoBuffering|#PB_UTF8|#PB_File_Append)
If FN <> 0
WriteStringN(FN, FormatDate("%yyyy-%mm-%dd %hh:%ii:%ss", Date()) + " > " + Message$)
CloseFile(FN)
EndIf
EndIf
EndProcedure
; Used Macro, with default info on source code (maybe helpful)
;
Macro LogWrite(Message)
WriteLogMessageToFile(Message + " // File: " + #PB_Compiler_Filename + ", " + #PB_Compiler_Line)
EndMacro
you can use a WM_COPYDATA based Client/Server app combo to do the trick.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Re: Debug output on distributed exe?
Uhhhh. What is a "release mode"? Can't find it in the F1 help >search.
Anyway, looks like it just boils down to workarounds -- No compiler directive or switch I was unaware of so I think the following looks like my preferred workaround:
Code: Select all
; Add this window to top of file:
If OpenWindow(0, 0, 0, 422, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 396, 333)
EndIf
Replace all Debug lines With the following
AddGadgetItem(0, -1, "Desired debug values")
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.
Re: Debug output on distributed exe?
'release mode' means the release which is used by a customer (exe)
Instead of 'Replace all Debug lines With the following' use a Macro
Instead of 'Replace all Debug lines With the following' use a Macro
Re: Debug output on distributed exe?
That's what I thought, but it doesn't work because you can't change the "Debug" command like you can with other commands:infratec wrote: Mon Nov 04, 2024 10:01 pmInstead of 'Replace all Debug lines With the following' use a Macro
Code: Select all
Macro Debug(text) ; Doesn't work.
AddGadgetItem(0, -1, text)
EndMacro
If OpenWindow(0, 0, 0, 422, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 396, 333)
For n=1 To 10
Debug Str(n)
Next
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Re: Debug output on distributed exe?
I don't have any prior experience of macros as I have not used them at all, but your comment sparked my interest Barry.BarryG wrote: Mon Nov 04, 2024 10:32 pm That's what I thought, but it doesn't work because you can't change the "Debug" command like you can with other commands:
It seems to me though, that Debug isn't special in any way, and if you change the name of the macro, it makes the reason clear — it's that in order to match this particular macro (which has a parameter), the brackets must be included, which they are not, so this example won't compile :
Code: Select all
Macro Deb(text)
AddGadgetItem(0, -1, text)
EndMacro
If OpenWindow(0, 0, 0, 422, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 396, 333)
For n=1 To 10
Deb Str(n)
Next
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIfOmitting the brackets after the debug in the for/next loop, fails to match the macro, so you have to include them and then it works perfectly:
Code: Select all
Macro Debug(text)
AddGadgetItem(0, -1, text)
EndMacro
If OpenWindow(0, 0, 0, 422, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 8, 8, 396, 333)
For n=1 To 10
Debug(Str(n)) ; <--- Change to parameter
Next
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIfRe: Debug output on distributed exe?
You should not call it the same, but rather "Trace()" or "MyDebug()" etc.
Re: Debug output on distributed exe?
Randy Walker wrote: Mon Nov 04, 2024 9:28 pm Uhhhh. What is a "release mode"? Can't find it in the F1 help >search.
Well, in my understanding "release mode" is when I use the Menu Item "Create Executable....." and honestly I have never thought in any other direction.
BTW: A fourth suggestion could be the use of network client/server stuff. And surely another workaround, if you want to call it that.
Acc. to the Macro discussion: For me Macro is a smart text replacement. With a lot of cons and pros.
The biggest problem IMHO is the side effects, similar to the use of define in C code.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Re: Debug output on distributed exe?
Not sure exactly who posted the above code but it's a nearly PERFECT solution -- THANKS!!!!PBJim wrote: Tue Nov 05, 2024 4:39 amCode: Select all
Macro Debug(text) AddGadgetItem(0, -1, text) EndMacro If OpenWindow(0, 0, 0, 422, 350, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) EditorGadget(0, 8, 8, 396, 333) For n=1 To 10 Debug(Str(n)) ; <--- Change to parameter Next Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow EndIf
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.
Re: Debug output on distributed exe?
Ah, so I forgot the brackets. 
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Debug output on distributed exe?
Fred wrote: Tue Nov 05, 2024 10:37 am You should not call it the same, but rather "Trace()" or "MyDebug()" etc.
Please don't forget this. It should not be called Debug.
bye,
Daniel
Daniel
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Re: Debug output on distributed exe?
I don't understand the warning. If you're worried my kids will be born naked, It's happened already.
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: Debug output on distributed exe?
Calling macros or procedures like keywords is a huge no-go in programming. It's as if you named your kid like an article or a common verb or place. It makes communication complicated.Randy Walker wrote: Wed Nov 06, 2024 7:48 amI don't understand the warning. If you're worried my kids will be born naked, It's happened already.
Macro Trace ... instead of Macro Debug. And then use Trace(...) instead of Debug(...).
bye,
Daniel
Daniel
-
Randy Walker
- Addict

- Posts: 1109
- Joined: Sun Jul 25, 2004 4:21 pm
- Location: USoA
Re: Debug output on distributed exe?
So this is what I came up with at the top of the file:
Code: Select all
Select MessageRequester("Debug Enabler", "Do you wish to enable Debug Mode?", #MB_YESNO|#MB_ICONQUESTION|#MB_DEFBUTTON2)
Case #IDYES
on =1
Case #IDNO
on =0
EndSelect
Macro trace(text)
If on
AddGadgetItem(0, -1, text)
EndIf
EndMacro
If OpenWindow(0, 30, 30, 422, 350, "Pseudo Debug", #PB_Window_SystemMenu | #PB_Window_Invisible)
EditorGadget(0, 8, 8, 396, 333)
For n=1 To 10
trace(Str(n)) ; <--- Change to parameter
Next
trace("Debug enabled")
If on
HideWindow(0,#False)
EndIf
EndIf
- - - - - - - - - - - - - - - -
Randy
I *never* claimed to be a programmer.
Randy
I *never* claimed to be a programmer.


