[Lazarus] debugging a CGI

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
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?

Thank you

Duilio



--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list


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
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
How can I trace the code then?

On Tue, Jan 19, 2021, 22:11 Michael Van Canneyt via lazarus <[hidden email]> 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
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list


On Tue, 19 Jan 2021, duilio foschi via lazarus 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.


>
> On Tue, Jan 19, 2021, 22:11 Michael Van Canneyt via lazarus <
> [hidden email]> 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
>> [hidden email]
>> https://lists.lazarus-ide.org/listinfo/lazarus
>>
>
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
On Tue, 19 Jan 2021 23:31:27 +0100 (CET), Michael Van Canneyt via lazarus
<[hidden email]> 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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list


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
> <[hidden email]> 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.
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
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
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
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 <[hidden email]> 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
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] debugging a CGI

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
On Wed, 20 Jan 2021 11:13:33 +0100 (CET), Michael Van Canneyt via lazarus
<[hidden email]> wrote:

>
>
>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
>> <[hidden email]> 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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus