Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-01

debugging a CGI

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
I would like to debug a CGI by tracing it in Lazarus IDE as a console application in windows. Is there a way to have the CGI read from standard input at start time?

I recommend to host your webmodule in a http server app, this will make debugging it a lot easier.

Michael.

Reply by email

duilio foschi
to Michael Van Canneyt

How can I trace the code then?

On Tue, Jan 19, 2021, 22:11 Michael Van Canneyt via lazarus <

Show quoted text 21 lines
wrote: On Tue, 19 Jan 2021, duilio foschi via lazarus wrote: > I would like to debug a CGI by tracing it in Lazarus IDE as a console > application in windows. > > Is there a way to have the CGI read from standard input at start time? I recommend to host your webmodule in a http server app, this will make debugging it a lot easier. Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210119/4f1354f5/attachment.html>

Reply by email

Michael Van Canneyt
to duilio foschi
duilio foschi wrote
How can I trace the code then?

It's a normal Lazarus application.
You can just debug the application like any other.

Start a 'HTTP server application' in lazarus, add your web module unit to it and run it. (you may need to add some more units or packages, in essence the same oneas as in your CGI application).

Once done with debugging, you can simply compile the CGI and deploy it.

Michael.

Show quoted text 24 lines
On Tue, Jan 19, 2021, 22:11 Michael Van Canneyt via lazarus < > wrote: > > > On Tue, 19 Jan 2021, duilio foschi via lazarus wrote: > >> I would like to debug a CGI by tracing it in Lazarus IDE as a console >> application in windows. >> >> Is there a way to have the CGI read from standard input at start time? > > I recommend to host your webmodule in a http server app, this will make > debugging it a lot easier. > > Michael. > -- > _______________________________________________ > lazarus mailing list > > https://lists.lazarus-ide.org/listinfo/lazarus >

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote
Start a 'HTTP server application' in lazarus, add your web module unit to it and run it. (you may need to add some more units or packages, in essence the same oneas as in your CGI application).

This is interesting to me too, but when I go to Project/New Project... then the list does *not* contain an entry "HTTP Server Application"

So how exactly do I "start" such project in Lazarus?

I have tested this with Lazarus 2.0.10/Fpc 3.2.0 on Windows 10 but I really need it on a Linux platform (Raspberry Pi).

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 14 lines
On Tue, 19 Jan 2021 23:31:27 +0100 (CET), Michael Van Canneyt via lazarus wrote: > Start a 'HTTP server application' in lazarus, add your web module unit to it > and run it. (you may need to add some more units or packages, in essence the > same oneas as in your CGI application). This is interesting to me too, but when I go to Project/New Project... then the list does *not* contain an entry "HTTP Server Application" So how exactly do I "start" such project in Lazarus? I have tested this with Lazarus 2.0.10/Fpc 3.2.0 on Windows 10 but I really need it on a Linux platform (Raspberry Pi).

Do you have the weblaz package installed ?

The "New project" type for 'HTTP server Application' is only available if you have that package installed.

Michael.

Reply by email

Martin Frb
to duilio foschi: I would like to debug a CGI by tracing it in Lazarus IDE as a console application in…
duilio foschi wrote 5 lines
I would like to debug a CGI by tracing it in Lazarus IDE as a console application in windows. Is there a way to have the CGI read from standard input at start time?

I have not tried this, but you may try to debug it using gdbserver.

Tools > Options > debugger: choose gdbserver  and if required change ip/port 127.0.0.1:1234

Now you can start your app on the console  (I am not sure what commandline gdbserver takes / please double check) DUMMY INSTRUCTION
gdbserver -host ip:port  yourapp

gdbserver will hold your app right at the start.
Your app should be able to read and write to the console from which you started it.
You can then start debugging in the IDE.

Going one step further, if you are real lucky, you can put the above gdbserver line into a script, and actually run it as cgi in a webserver (if the webserver does not timeout/kill it)

Reply by email

duilio foschi
to Martin Frb

I guess I will use conditional compilation.

{$IFDEF WINDOWS} // this means I am debugging the CGI on my PC
  //read from file xxx.json
{$else} // this means the CGI is in production on my linux server
  // read from stdin
{$endif}

Thank you for your help

Duilio

On Wed, Jan 20, 2021 at 1:33 PM Martin Frb via lazarus <

Show quoted text 34 lines
wrote: On 19/01/2021 19:03, duilio foschi via lazarus wrote: > I would like to debug a CGI by tracing it in Lazarus IDE as a console > application in windows. > > Is there a way to have the CGI read from standard input at start time? > I have not tried this, but you may try to debug it using gdbserver. Tools > Options > debugger: choose gdbserver and if required change ip/port 127.0.0.1:1234 Now you can start your app on the console (I am not sure what commandline gdbserver takes / please double check) DUMMY INSTRUCTION gdbserver -host ip:port yourapp gdbserver will hold your app right at the start. Your app should be able to read and write to the console from which you started it. You can then start debugging in the IDE. Going one step further, if you are real lucky, you can put the above gdbserver line into a script, and actually run it as cgi in a webserver (if the webserver does not timeout/kill it) -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210120/283c2915/attachment.html>

Reply by email

Bo Berglund
to Michael Van Canneyt: Do you have the weblaz package installed ? The "New project" type for 'HTTP server…
Michael Van Canneyt wrote 24 lines
On Wed, 20 Jan 2021, Bo Berglund via lazarus wrote: > On Tue, 19 Jan 2021 23:31:27 +0100 (CET), Michael Van Canneyt via lazarus > wrote: > >> Start a 'HTTP server application' in lazarus, add your web module unit to it >> and run it. (you may need to add some more units or packages, in essence the >> same oneas as in your CGI application). > > This is interesting to me too, but when I go to Project/New Project... > then the list does *not* contain an entry "HTTP Server Application" > > So how exactly do I "start" such project in Lazarus? > > I have tested this with Lazarus 2.0.10/Fpc 3.2.0 on Windows 10 but I really need > it on a Linux platform (Raspberry Pi). Do you have the weblaz package installed ? The "New project" type for 'HTTP server Application' is only available if you have that package installed.

Thanks,
that was the problem.
The Weblaz package is deployed with the default installation but not actually installed in the IDE.
When I did that it showed up in the alternatives for a new project! :)

Bo Berglund Developer in Sweden

Reply by email