0% found this document useful (0 votes)
10 views9 pages

Maxbox Starter146 Debugging

The document provides an overview of debugging techniques using TPSScript and the TPSScriptDebugger component in Pascal Script, emphasizing the importance of debugging in programming. It details the workflow of script execution, including compilation, execution, and debugging support, as well as features like breakpoints, stepping, and variable inspection. Additionally, it discusses the use of the 'sc' command for managing Windows services and includes references for further reading.

Uploaded by

Max Kleiner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Maxbox Starter146 Debugging

The document provides an overview of debugging techniques using TPSScript and the TPSScriptDebugger component in Pascal Script, emphasizing the importance of debugging in programming. It details the workflow of script execution, including compilation, execution, and debugging support, as well as features like breakpoints, stepping, and variable inspection. Additionally, it discusses the use of the 'sc' command for managing Windows services and includes references for further reading.

Uploaded by

Max Kleiner
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

🐞

////////////////////////////////////////////////////////////////////////////

Debugging デバッグ
____________________________________________________________________________
maXbox Starter 146 – Get a Debugger.
1
“Se contentus est sapiens. – Seneca.

Source: 1413_services5jcl_1.pas
1190_Continued_fraction64_python3.12.4debug30.txt

https://sourceforge.net/projects/maxbox5/files/examples/1413_services5jcl
.pas/download

https://sourceforge.net/projects/maxbox5/files/
EKON29/1190_Continued_fraction64_python3.12.4debug30.txt/download

1406_U_Go3_1form2.pas
1413_services5jcl.pas

Every programmer spends a lot of time fixing bugs. Whether it’s a small
typo or a tricky logic error, knowing how to debug efficiently is an
important skill.
But debugging isn’t just about fixing mistakes—it’s also about
understanding what went wrong and learning how to avoid similar problems
in the future.
In maXbox or Delphi we had to connect one event from TPSScript to the
cdebugAfterExecute Event:

object PSScript: TPSScript


CompilerOptions = [icAllowUnit]
OnLine = PSScriptLine
OnCompile = PSScriptCompile
OnExecute = PSScriptExecute
OnAfterExecute = cedebugAfterExecute
OnCompImport = IFPS3ClassesPlugin1CompImport
OnExecImport = IFPS3ClassesPlugin1ExecImport
Plugins = <
item
Plugin = PS3DllPlugin
end>
UsePreProcessor = True
OnNeedFile = PSScriptNeedFile
Left = 392
Top = 136
end

The debug engine (DE) typically sends one of the following events as the
last startup event:

• The entry point event, if attaching to a newly launched program

1 (ep. 9, 13) - Der Weise ist zufrieden mit sich selbst. -

1/9
• The load complete event, if attaching to a program that is already
running.

If the debug session with F8 is to ignore a particular stopping event,


the debug session calls the program's Continue method. If the program was
stepping into, over, or out of a function when it encountered the
stopping condition, then it continues the step.

1406_livedebugger1_Screenshot2025-06-19_093305.png

Debuging and Decompile can be disturbed either by events or method


handlers are in use (e.g. onClose, onDrawcell, onIdle..) or a property
like form.style =[fsBold]. So uncomment this line to debug the code.

If the user elects to step into F7, over F8, or out of a function Ctrl+
F9, the IDE prompts the debug session to call the program's Step method.
The IDE then passes the unit of step (instruction, statement, or line)
and the type of step (whether to step into, over, or out of the
function). When the step is complete, the DE sends a step complete event
to the debug session, which is a stopping event.
If with F8 as step over goes into a loop it works like a live debugger in
the script and you can feel where to code is running!

The program then runs until it encounters a stopping condition, such as


hitting a breakpoint set with F5. In which case, the DE sends a
breakpoint event to the debug session. The breakpoint event is a stopping
event, and the DE again waits for a user response.

2/9
When you set a breakpoint with F5 (you can set more than one) then you
start the debug session with Debug Run till the breakpoint it waits, then
you step further with Debug Run or Ctrl+ F9 like continue. If the debug
session is to ignore a particular stopping event, the debug session calls
the program's Continue method. If the program was stepping into, over, or
out of a function when it encountered the stopping condition, then it
continues the step.

1413_services2_mx5_screenshot.png //1406_1_GoScreenshot2025-06-162815.png

For the advanced setting of the debugger we take a look to the component
TPSScriptDebugger with the corresponding events.

object cedebug: TPSScriptDebugger


CompilerOptions = [icAllowUnit]
OnCompile = PSScriptCompile
OnExecute = cedebugExecute
OnAfterExecute = cedebugAfterExecute
OnCompImport = IFPS3ClassesPlugin1CompImport
OnExecImport = IFPS3ClassesPlugin1ExecImport
Plugins = <
item
Plugin = PS3DllPlugin
end
item
end>
UsePreProcessor = True
OnNeedFile = PSScriptNeedFile

3/9
OnIdle = cedebugIdle
OnLineInfo = cedebugLineInfo
OnBreakpoint = cedebugBreakpoint
Left = 344
Top = 136
end

Also set the breakpoint in a single function works:

function StartServiceByName(const AServer,AServiceName: String):Boolean;


var
ServiceHandle,
SCMHandle: SC_HANDLE;
P: PChar;
begin
P:= nil;
Result:= False;
SCMHandle:= OpenSCManager(PChar(AServer), nil, SC_MANAGER_ALL_ACCESS);
if SCMHandle <> 0 then
try
ServiceHandle:= OpenService(SCMHandle, Pchar(AServiceName),
SERVICE_ALL_ACCESS);
if ServiceHandle <> 0 then
Result:= StartService(ServiceHandle, 0, P);

CloseServiceHandle(ServiceHandle);
finally
CloseServiceHandle(SCMHandle);
end;
end;

We call that from the main:

if StartServiceByName('DESKTOP-BTLKHKF','ALG') then
writ('ALG started...');
writ('stat of ALG '+
itoa(ord(GetServiceStatusByName('DESKTOP-BTLKHKF','ALG'))));
sleep(500)
writ('stat of ALG '+
itoa(ord(GetServiceStatusByName('DESKTOP-BTLKHKF','ALG'))));
//toogle 2___________
//StopServiceByName('DESKTOP-BTLKHKF','ALG');
sleep(500)

Between the two sleeps you can see two different states, namely 2 and 4:

//GetServiceStatusWaitingIfPending(ServiceHandle: SC_HANDLE): DWORD;


{(ssUnknown, // Just fill the value 0
ssStopped, // SERVICE_STOPPED
ssStartPending, // SERVICE_START_PENDING
ssStopPending, // SERVICE_STOP_PENDING
ssRunning, // SERVICE_RUNNING
ssContinuePending, // SERVICE_CONTINUE_PENDING
ssPausePending, // SERVICE_PAUSE_PENDING
ssPaused); // SERVICE_PAUSED }

So it changes from ssStartPending 2 to ssRunning 4, on methods see first


screenshot above.

4/9
Besides using the previous methods, if you need more control in a
debugger way you can use WMI. With Win32_Service class you have access to
all information of the services installed on the machine and you can has
access to methods: Start, Stop, Pause, Resume, Interrogate, Create,
Delete, Change, ChangeStartMode…

1406_livedebugger2_Screenshot2025-06-19_093052.png
1413_services_mx5_screenshot.png

How TPSScriptDebugger Works in Pascal Script


TPSScriptDebugger is a component in RemObjects Pascal Script designed to
provide debugging capabilities for scripts executed within your Delphi,
maXbox or C++Builder applications. While the search results do not
provide a direct, detailed breakdown of TPSScriptDebugger, the general
workflow of debugging in Pascal Script and the integration of debugging
support can be inferred from the available information and standard usage
patterns of the library.

General Workflow of Pascal Script Execution


• Script Compilation: Scripts are first compiled using the
TPSPascalCompiler class. The script is parsed and converted into
bytecode, and any compiler messages (errors or warnings) are
collected during this stage 1.

5/9
• Script Execution: The compiled bytecode is then executed by the
TPSExec class. If runtime errors occur, they are captured and
reported, typically using methods like PSErrorToString to convert
error codes to readable messages12.

Debugging Support
• Debugger Integration: TPSScriptDebugger works by hooking into the
script execution process. It allows you to:
• Set breakpoints in your script code.
• Step through script execution line by line.
• Inspect and modify variable values at runtime.
• Monitor the call stack and execution flow.
• Usage Pattern:
• You typically associate a TPSScriptDebugger instance with your
TPSScript or TPSExec instance.
• The debugger listens for execution events (such as line
changes or exceptions) and provides callbacks or events that
your host application can use to update the UI (e.g.,
highlighting the current line, showing variable values).
• When a breakpoint is hit, execution is paused, and control is
returned to the host application, allowing inspection and step
operations.
• Implementation Details:
• TPSScriptDebugger interacts closely with the script engine,
receiving notifications about instruction pointer changes,
exceptions, and variable state.
• The component exposes methods and events for common debugging
actions: continue, step over, step into, step out, and stop.
• It maintains a mapping between script source lines and
bytecode instructions, enabling accurate breakpoints and
stepping.

Example Usage
While the search results do not include a full code example for
TPSScriptDebugger, the general approach is as follows (pseudocode):
text
var Script: TPSScript;
Debugger: TPSScriptDebugger;
begin
Script := TPSScript.Create(nil);
Debugger := TPSScriptDebugger.Create(nil);
Script.Debugger := Debugger;
// Load and compile script
// Set breakpoints via Debugger.Breakpoints.Add(lineNumber)
// Start execution; Debugger events will handle breakpoints and
stepping
end;

6/9
Key Features
• Breakpoints: Set and remove breakpoints at specific source lines.
• Stepping: Step into, over, or out of script code.
• Variable Inspection: View and modify script variables during paused
execution.
• Call Stack: Inspect the current call stack to understand the
execution context.

Summary Table: TPSScriptDebugger Capabilities


Feature Description
Breakpoints Pause execution at specific script lines
Stepping Step into, over, or out of code
Variable Inspection View/modify script variables during debugging
Call Stack Inspect current function/procedure call stack
Exception Handling Catch and report script exceptions

References
• For a general overview of Pascal Script compilation and exe: 12
• For integration and debugging capabilities: 12
If you need more detailed, code-level documentation for
TPSScriptDebugger, consulting the official RemObjects Pascal Script
documentation or the source code itself is recommended, as community
resources often provide only high-level overviews12.
1.https://lawrencebarsanti.wordpress.com/2009/11/28/introduction-to-
pascal-script/
2.https://wiki.freepascal.org/Pascal_Script_Examples
3.https://talk.remobjects.com/t/pascal-script-set-var-question/10074
4.https://stackoverflow.com/questions/17101532/loading-pre-compiled-
script-in-remobjects-pascal-script-delphi
5.https://doc.tmssoftware.com/biz/scripter/scripter-user-guide.pdf
6.https://doc.tmssoftware.com/biz/scripter/guide/scripter.html
7.https://www.pascalgamedevelopment.com/showthread.php?32620-
Scripting-with-remote-debugger
8.https://www.youtube.com/watch?v=9dnGDI8qHsY

A last and interesting call concerns the shell with a kind of debug. If
you are familiar with the console just do an external console call from
the script:

ShellExecute(0, nil, 'cmd.exe', 'sc config "the service name"


start=disabled', nil, SW_HIDE);
ShellExecute(0, nil, 'cmd.exe', 'sc config "the service name"
start=auto', nil, SW_HIDE);

RunDosInMemo('cmd.exe /C sc config "ALG" start= disabled',Memo2);


>>> [SC] ChangeServiceConfig SUCCESS
RunDosInMemo('cmd.exe /C sc query "ALG"',Memo2);

7/9
The sc config command is a powerful tool in Windows that allows you to
modify the configuration of a service. This command can change various
parameters of a service, such as its start type, error control, binary
path, dependencies, and more. It is particularly useful for system
administrators who need to manage services on local or remote machines.

Another Appendix Page

In September, Brian Kleiner represented Switzerland in the 17th Korea


Prime Minister Cup (KPMC), in Gwangju. There were players from 53
countries present, with 6 rounds over three days of play. The organi-
sation from the hosts was excellent from start to finish, the late summer
weather was ideal, and a good spirit reigned throughout.

MaxMatrix Time/Space:
The multiplication of past x future is a vector with the function:= known
= f(changeable) [y=f(x)] as distance over time, so distance is a function
of time: d=f(t).

8/9
Conclusion
While the search results do not mention TPSScriptDebugger specifically,
standard script debuggers—including those for Pascal Script—share core
features that facilitate tracing the execution flow of scripts. These
features, as seen in various script debuggers, typically include:

Breakpoints: Allow you to pause script execution at specific lines, so


you can examine the state of the script and its variables at critical
points. Step Over, Step Into, Step Out: These commands let you control
execution line by line:

Step Over: Executes the current line and moves to the next, skipping over
function calls.
Step Into: Dives into the details of a function call, allowing you to
trace execution inside called functions or procedures.
Step Out: Runs the rest of the current function and pauses execution when
control returns to the caller.

The sc config command is a powerful tool in Windows that allows you to


modify the configuration of a service.

Script:

https://sourceforge.net/projects/maxbox5/files/examples/
1413_services5jcl_1.pas/download

References:

Advanced Debugging API

🐞
How to use the command 'sc' (with examples)

圍棋.
Doc and Tool: maXbox5 - Manage Files at SourceForge.net

Max Kleiner 19/06/2025

Digitally signed by

maXbox4exe maXbox4exe
Date: 2025.06.19 15:29:08
+02'00'
9/9

You might also like