Forum > Networking and Web Programming
[SOLVED] how to debug a CGI from Lazarus
nomorelogic:
Hi all
I'd like to simulate the invocation of a cgi from Lazarus IDE
this to be able to use the integrated debugger
I already know that a cgi must read from environment variables
this is valid for GET method and here all goes fine
but the content of the POST request (parameter -d in curl) is passed to the cgi using standard input
in Lazarus IDE there is already the possibility to set environment variables (i am referring to the menu: run -> run parameters -> environment)
but I have no idea how to set in the run parameters something equivalent to:
mycgi.pas < input
is there any workaround?
thanks
nomorelogic
Martin_fr:
Unfortunately that is currently not possible. There is already an issue about it: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40458
Well, you could probably us the "GDB Gnu remote debugger (gdbserver)" backend.
Then you have to start your exe outside the IDE, inside the gdbserver tool. And there you probably (not tested) can apply input redirection).
Then start the debugger and it should connect to the gdbserver. (gdbserver will pause your app on start, until the IDE connects)
I am not sure of the exact steps. It is ages ago since I even looked at that.
toby:
what about ?
pgm "`cat cx.txt`"
deal with what is in file cx.txt in the pgm as paramstr 1
Martin_fr:
--- Quote from: toby on December 07, 2023, 10:56:02 pm ---what about ?
pgm "`cat cx.txt`"
deal with what is in file cx.txt in the pgm as paramstr 1
--- End quote ---
That will work in a shell. But if the IDE (the debugger) starts the exe, then shell stuff doesn't happen.
nomorelogic:
--- Quote from: Martin_fr on December 07, 2023, 11:29:31 pm ---
--- Quote from: toby on December 07, 2023, 10:56:02 pm ---what about ?
pgm "`cat cx.txt`"
deal with what is in file cx.txt in the pgm as paramstr 1
--- End quote ---
That will work in a shell. But if the IDE (the debugger) starts the exe, then shell stuff doesn't happen.
--- End quote ---
question:
is it for the same reason that if I use the REQUEST_METHOD environment variable set to GET, the debugger works correctly
whereas if I set it to POST it crashes on the Run statement?
follow example code
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#!/usr/bin/instantfpcprogram TestCgi;{$mode objfpc}{$H+} uses Classes, SysUtils, httpDefs, fpweb, custweb, custcgi, webutil; type TMyCGIHandler = class(TCgiHandler) public procedure HandleRequest(ARequest: Trequest; AResponse: TResponse); override; end; TMyCGIApp = class(TCustomCGIApplication) protected function InitializeWebHandler: TWebHandler; override; end; procedure TMyCGIHandler.HandleRequest(ARequest: Trequest; AResponse: TResponse); procedure AddNV(const N, V: string); begin AResponse.Contents.Add('<TR><TD>' + N + '</TD><TD>' + V + '</TD></TR>'); end; var I, P: integer; N, V: string; begin with AResponse.Contents do begin BeginUpdate; try Add('<HTML><TITLE>FPC CGI Test page</TITLE><BODY>'); Add('<H1>Hello world</H1>'); DumpRequest(ARequest, AResponse.Contents); Add('<H1>CGI environment:</H1>'); Add('<TABLE BORDER="1">'); Add('<TR><TD>Name</TD><TD>Value</TD></TR>'); for I := 1 to GetEnvironmentVariableCount do begin V := GetEnvironmentString(i); P := Pos('=', V); N := Copy(V, 1, P - 1); system.Delete(V, 1, P); AddNV(N, V); end; Add('</TABLE>'); Add('</BODY></HTML>'); finally EndUpdate; end; end; end; function TMyCGIApp.InitializeWebHandler: TWebHandler; begin Result := TMyCgiHandler.Create(self); end; begin with TMyCGIApp.Create(nil) do try Initialize; Run; finally Free; end;end.
Navigation
[0] Message Index
[#] Next page