Sign in Join
Wiki copytemporary

Toro Kernel: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11A dedicated kernel for multi-threading applications
22
33## Introduction
44
55This wiki presents how to debug an application that is built with Toro and executes as a QEMU guest in Windows. This procedure however does not work for applications that are deployed as KVM-QEMU guests. In that case, the built-in gdbstub that is included in QEMU does not work correctly as it is unable to catch breakpoints or do step-by-step execution. To debug an application that is deployed as a KVM-QEMU guest, please follow the tutorial at <https://github.com/torokernel/torokernel/wiki/How-to-Debug-the-Kernel-and-the-Application-in-Toro>.
66
77## On Windows
88
99It's possible to develop Toro Kernel microservices on Windows.
1010
1111### Building
1212
1313- you'll need to have cross-compile linux binary utils
1414
1515
1616those could be acquired from fpcup or fpcupdeluxe (https://github.com/LongDirtyAnimAlf/fpcupdeluxe/releases/download/crosslibs_v1.1/CrossLibsLinuxx64.zip)
1717
1818- you can find a tutorial about how to get a cross-compiler in [1](https://github.com/torokernel/torokernel/wiki/How-to-get-a-Crosscompiler-of-Freepascal-for-a-Windows-host-and-Linux-target)
1919- the project contain "build" utility complication as well. The utility produces an image from the resulting .elf file
2020
2121### Running QEMU
2222
2323- install QEmu for Windows
2424- run the system specifying the built image
2525
26-`qemu-system-x86_64 -hda HelloWorldMicroservice.img`
26+```text
27+qemu-system-x86_64 -hda HelloWorldMicroservice.img
28+```
2729
2830- on start qemu can complain about unknown or raw format of ".img" file.
2931
3032
3133One might find the script files to build the Qemu recognizable image file formats: BuildVHDX.cmd and/or BuildVMDK.cmd
3234
3335#### From Lazarus as Hosting Application
3436
3537Lazarus can be configured to run QEmu as a hosting or launching application. Typically such approach is used for developing libraries, rather than virtual machines. Yet, the approach could be used for the virtual machine as well. While it works, it does introduce some difficulties when debugging is needed.
3638
3739Open *Run-\>Run Parameters...* and specify QEmu as the host application.
3840
3941On the command-line parameters specify *-hda* parameter, that should point to the produced image file.
4042
4143Normally this would be an output file with .img extension.
4244
4345\[\[Image:torokernel_run_params.png\]
4446
4547#### From Lazarus as External Tool
4648
4749Another approach is to launch from IDE QEmu manually as an External Tool.
4850
4951The approach is semi-automatic, yet it's friendly with the remote debugging capabilities (which are covered below)
5052
5153To create an external tool, click *Tools-\>Configure External Tools...*. (if there are some other tools configured you need to click "Add")
5254
5355On the new dialog, the similar information regarding QEmu needs to be provided:
5456
5557- the qemu executable
5658- a parameter -hda specifying the target image file
5759- additional parameters (i.e. network configuration)
5860
5961![](/wiki-images/c/c9/Torokernel_external-tool.png)
6062
6163Once the external tool configuration has been saved. The new section is added under "Tools" menu.
6264
6365The execution can be invoked by either selecting the menu or assigning hot key combinations.
6466
6567## Debugging
6668
6769QEmu provides a built-in support for GDB remote debugging.
6870
6971Remember, the debugging information must be enabled in the Project Options. It's recommended to use the EXTERNAL debug symbol file (-Xg) to keep the executable and the actual file image in a small size.
7072
7173### Manual
7274
7375- run QEmu with enabling gdb (-s) and also requesting the QEmu to halt until getting the "continue" signal from gdb (-S)
7476
75-`qemu-system-x86_64 -s -S -hda HelloWorldMicroservice.img`
77+```text
78+qemu-system-x86_64 -s -S -hda HelloWorldMicroservice.img
79+```
7680
7781
7882The expected result is that Qemu window will halt with the message that "vga" system has not been initialized yet (and doing nothing)
7983
8084-s - configures the default remote GDB mode for the use of TCP socket for port 1234
8185
8286- run the debugger, and provide the previously complied binary file as its gdb target. (The file is needed to load debugging information)
8387
84-`gdb HelloWorldMicroservice`
88+```text
89+gdb HelloWorldMicroservice
90+```
8591
8692- after that run the remote target command
8793
88-`(gdb)> target remote localhost:1234`
94+```text
95+(gdb)> target remote localhost:1234
96+```
8997
9098
9199The command makes gdb connect to the specified address. In which case this would be Qemu running locally at port 1234.
92100
93101- setup the debugging information (i.e. breakpoints, etc)
94102
95103
96104The debugging information in the compiled binary contains the information necessary to work with binary during debugging.
97105
98106Example
99107
100-`(gdb)> b HelloWorldMicroservice.pas:250`
108+```text
109+(gdb)> b HelloWorldMicroservice.pas:250
110+```
101111
102112
103113sets a breakpoint HelloWorldMicroservice at the line that outputs "ToroService: listening on port xxxx ..."
104114
105115- "continue" the process.
106116
107-`(gdb)> continue`
117+```text
118+(gdb)> continue
119+```
108120
109121### From Lazarus IDE
110122
111123It's possible to use Gdb with Lazarus IDE to debug remote applications.
112124
113125The Lazarus IDE handles the debugger in 2 possible ways:
114126
1151271. By default Lazarus attempts to launch the debugger first, and let debugger launch the debugged application.
1161282. For remote debugging the remote application is expected to be launched **outside** of Lazarus IDE project run flow:
117129
118130How to launch the process to be debugged for remte debugging depends on the version of Lazarus:
119131
1201321. for the trunk version of lazarus, see the explanation in the section below on init exec.
1211332. For the released (2.0.x) version of lazarus the method is explained here. This method can of course still be used in trunk.
122134
123135In both cases, the most important thing to remember is to have
124136
125-`-s `\
126-`-S`
137+```text
138+-s
139+-S
140+```
127141
128142parameters added to the Qemu command line. (as described above "-s" configures the network port for GDB, while "-S" makes sure QEmu would wait for the debugger to connect)
129143
130144The "debugger" needs to be configured as following.
131145
132146- type should be set to (gdbserver)
133147- executable should be the same as the Lazarus supplied gdb.exe.
134148- **Debugger_Remote_HostName** should be set to "localhost" (you are running Qemu locally)
135149- **Debugger_Remote_Post** should be set to **1234**. (This is dictated by "-s" parameter passed to QEmu)
136150
137151![](/wiki-images/1/1a/Torokernel_debugger.png)
138152
139153#### Start Qemu As External Tool
140154
141155Run the QEmu via configured "External Tool" (or manually). When ran you should see "Guest has not initialized the display (yet)". That means that Qemu is waiting for the debugger to connect. ![](/wiki-images/5/58/Torokernel_qemu.png)
142156
143157**IMPORTANT** - make sure that "Run Parameters" don't have Host Application or Launch Application configured. If they're configured it will prevent the debugger from loading proper symbol files and will prevent the debugging.
144158
145159Hit "Run" project (F9) in Lazarus IDE.
146160
147161With the gdb connected to the QEmu you should see the services run as they should.
148162
149163Lazarus IDE will allow you to set the breakpoints, inspect variables and callstack as needed.
150164
151165In order to terminate the QEmu process one should either close QEmu window or press "Alt+Ctrl+Q". ![](/wiki-images/5/52/Toro_activedebug.png)
152166
153167#### Using Init Exec of Remote Debugger
154168
155169In Lazarus trunk there's an extension of gdbserver available, that allows to run QEmu automatically.
156170
157171Two additional options were added and should be configured in the following manner:
158172
159173- InitExec_Mode = ieRunCloseOnStop (starts QEmu and closes when the debugging is done)
160174- InitExec_RemoteTarget = the command line that would open up QEmu PRIOR to the debugger trying to connect.
161175
162176![](/wiki-images/7/70/Toro_debug2.png)
163177
164178## See also
165179
166180- <https://github.com/torokernel/torokernel> - source code
167181- <https://torokernel.io> - the official website
168182- <https://www.qemu.org/download/#windows> - QEmu Windows download
169183- <https://github.com/torokernel/torokernel/wiki/How-to-Debug-the-Kernel-and-the-Application-in-Toro> - Debugging of Toro Appliances
170184
171185---
172186*From the Free Pascal wiki, page "Toro Kernel", as it stood on 2021-03-14 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
173187Category: Operating Systems and Platforms
174188Category: Tutorials

Back to history