Recent

Author Topic: problem executting tprocess with fpdebug  (Read 5952 times)

calebs

  • Full Member
  • ***
  • Posts: 190
problem executting tprocess with fpdebug
« on: September 02, 2020, 11:09:16 pm »
Hello all!
I've tried to debug a program that uses tprocess to call another executable and with fpdebug always returns
"failed to execute : 50".
Switched to gdb and worked ok.
Is there an option to solve this or is a missing feature?
Thanks
i'll post the code below

Code: Pascal  [Select][+][-]
  1.     ejecutable:=ruta+ejecutablerece;
  2.     prog:=TProcess.CREATE(nil);
  3.     prog.Executable:=ejecutable;
  4.     prog.Parameters.Add('/ult');
  5.     prog.Parameters.Add(tc);
  6.     prog.Parameters.Add(pdv);
  7.     prog.options:=prog.options+[powaitonexit, poUsePipes];
  8.     prog.ShowWindow:=swoMinimize;
  9.     prog.Execute;                                     >> here gives error
  10.     comprob:='-1';                                        
  11.  

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #1 on: September 03, 2020, 01:02:35 am »
I can not reproduce (trunk and 2.0.10).
I used gdb.exe for testing. And that is executed.

But there may be many factors.

That is an "project raised exception....failed to execute"?

Error 50, does not seem to point to it, but could it be that some libraries are missing? or the environment path differs?
Error 50 => "ERROR_NOT_SUPPORTED"

Anything else about the exe, that could depend on environment, permissions or the like?

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: problem executting tprocess with fpdebug
« Reply #2 on: September 03, 2020, 07:52:39 am »
Hello all!
I've tried to debug a program that uses tprocess to call another executable and with fpdebug always returns
"failed to execute : 50".

Same problem for me: Windows 10 64 bit, with Lazarus 2.1.0 r63602 FPC 3.2.0 i386-win32-win32/win64
Same project, with gdb works.

Hi, Mario

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11376
  • FPC developer.
Re: problem executting tprocess with fpdebug
« Reply #3 on: September 03, 2020, 12:51:50 pm »
Sounds like a working dir problem, executing with relative paths, and gdb changing workdir to exe dir, and fpdebug not or so?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #4 on: September 03, 2020, 02:28:35 pm »
FpDebug also set a working dir (as given by the IDE,but that seems to be the correct one / it can be changed in "run params")

But that would affect the app that then calls TProcess. That could lead to an incorrect Path, but then the error would/should be: file not found.

I also just created a new user account on my system, without any admin privileges. But even then, I was able to start a new app with TProcess.

So without any additional info, I cannot do much about this.

calebs

  • Full Member
  • ***
  • Posts: 190
Re: problem executting tprocess with fpdebug
« Reply #5 on: February 25, 2021, 03:53:20 pm »
Hello again, sorry to update this post but i prefer instead open a new one.
I still having problems with spawning process or applications in windows with tprocess.execute.
I 've traced new (useful?) information for debug (i guess).
i have a main program/unit that has on some procedure a tprocess.execute
in the main unit/program the execution worked ok but
i have an external unit that also have a tprocess.execute that calls some other program and there gives the 50 error when using fpdebug.
If i switch to gdb the same application/unit worked as expected with no errors.
it not makes difference if i use dwarf2 or dwarf3.
The problem seems to ocurr when a process.execute is called from other unit.
I home this throw some light at this problem.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #6 on: February 25, 2021, 04:33:29 pm »
Do you have a sample app with source code, which reproduces the issue?

What app do you launch in TProcess? 
Have you tried specifying the full path?
Is the app in question a console app? (then have you tried in Tools > Options > Debugger: "ForceNewConsole" in the property grid?)

Can you use TProcess on   C:\Windows\System32\notepad.exe  ?
Does that work?

Have you tried to run Lazarus as administrator?
(Directly start lazarus.exe / skip startlazarus.exe)

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: problem executting tprocess with fpdebug
« Reply #7 on: February 25, 2021, 04:57:51 pm »
See the attached project.

Works with GDB, it return error 50 with fpdebug

Hi, Mario

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: problem executting tprocess with fpdebug
« Reply #8 on: February 25, 2021, 05:00:07 pm »
If i change executable with 'C:\Windows\System32\notepad.exe' it works also with fpdebug

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #9 on: February 26, 2021, 12:18:36 am »
The path from your sample does not exist on my system.

If I change it, then it works (under fpdebug / 2.0.11 and trunk)
I did compile your code to 64 and 32 bit (but tested both in a 64bit IDE)
=> So if your IDE is 32bit that may still need testing.

Your path: C:\Programmi\Notepad++\notepad++.exe
mine:  C:\Program Files (x86)\Notepad++\notepad++.exe'

Is it possible that you are running into some UAC stuff?
(I may still test with a more restricted User account, but not now, got to many stuff open in my session)



Btw, what happens, if in the IDE, you choose "run without debugging" ?



You could play with
File:   components\fpdebug\fpdbgwinclasses.pas
Line:  650    in TDbgWinProcess.StartInstance

Code: Pascal  [Select][+][-]
  1.     AProcess.Options:=[poDebugProcess, poNewProcessGroup];

"poDebugProcess" has to be kept. Actually you can try to replace it with poDebugOnlyThisProcess


But you can try removing "poNewProcessGroup", or add others...
Not sure if that makes much of a difference.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #10 on: February 26, 2021, 12:22:05 am »
Same problem for me: Windows 10 64 bit, with Lazarus 2.1.0 r63602 FPC 3.2.0 i386-win32-win32/win64

If I read correct:
=> Your IDE is 64 bit?
=> You have a 32bit cross compiler
=> so your project app maybe is 32bit?

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: problem executting tprocess with fpdebug
« Reply #11 on: February 26, 2021, 08:21:35 am »
Hi,
sorry, you're right, in the Italian version of Windows, "C:\ Programmi" is a link to "C: \ Program Files".
I still tried to put in the path "C:\ Program Files", but I get the same error.

As you suggested, I tried this:
Code: Pascal  [Select][+][-]
  1.     //AProcess.Options:=[poDebugProcess, poNewProcessGroup];
  2.     AProcess.Options:=[poDebugOnlyThisProcess, poNewProcessGroup];
  3.  
After rebuilding the IDE it works !!!

My situation is:
- Windows 64 bit
- Lazarus 2.1.0 r64457 FPC 3.2.0 i386-win32-win32/win64
- Notepad++ 64 bit

Thanks, Mario

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9784
  • Debugger - SynEdit - and more
    • wiki
Re: problem executting tprocess with fpdebug
« Reply #12 on: February 26, 2021, 03:10:31 pm »
Ok, this is a valid solution.  And I will probably change it in the IDE for now. That is, as long as the debugger does not debug processes launched by the debuggee (no plans for that yet).

At the moment, with poDebugProcess, fpdebug is notified on forked processes, and fpdebug releases them into the wild.

Still curious why you run into it.

It would make sense, if your IDE was 32 bits (I have not tested on my end, if it actually triggers it).
With a 32bit IDE, the included fpdebug is of course 32bit too. And a 32bit debugger can not debug a 64bit app. (So the OS would not allow a 64bit process being forked).

But if the IDE is 64 bit.....

Just to be sure that you did not accidentally rebuild the IDE. Please open the Task Manager (ctrl-shift escape on win 10), and when the IDE is running find it in the list (looking at the first tab "processes", not "details"). Make sure neither the IDE (nor its sub entries) have an appendix "(32 bit)"

Btw, by writing those steps down, I noted: I have a 32bit version of notepad++ installed. So that may be a difference there.
Maybe windows already can not tell a 64 bit debugger, that a 32 bit process launches a 64bit exe. After all, to debug 32 bits the 64bit debugger must use a special WOW64 api, which deals with 32 bits only......

Well anyway, we know how to fix it....


https://bugs.freepascal.org/view.php?id=38546
« Last Edit: February 26, 2021, 03:15:59 pm by Martin_fr »

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: problem executting tprocess with fpdebug
« Reply #13 on: February 26, 2021, 03:27:47 pm »
Sorry, I probably expressed myself wrong: my IDE is 32-bit.

calebs

  • Full Member
  • ***
  • Posts: 190
Re: problem executting tprocess with fpdebug
« Reply #14 on: February 26, 2021, 11:57:12 pm »
Hi,
sorry, you're right, in the Italian version of Windows, "C:\ Programmi" is a link to "C: \ Program Files".
I still tried to put in the path "C:\ Program Files", but I get the same error.

As you suggested, I tried this:
Code: Pascal  [Select][+][-]
  1.     //AProcess.Options:=[poDebugProcess, poNewProcessGroup];
  2.     AProcess.Options:=[poDebugOnlyThisProcess, poNewProcessGroup];
  3.  
After rebuilding the IDE it works !!!

My situation is:
- Windows 64 bit
- Lazarus 2.1.0 r64457 FPC 3.2.0 i386-win32-win32/win64
- Notepad++ 64 bit

Thanks, Mario

Hello. I've modified the file you suggest, noadaways the line was 470
Code: Pascal  [Select][+][-]
  1. ...
  2. class function TDbgWinProcess.StartInstance(AFileName: string; AParams, AnEnvironment: TStrings; AWorkingDirectory, AConsoleTty: string;
  3.   AOnLog: TOnLog; ReDirectOutput: boolean): TDbgProcess;
  4. var
  5.   AProcess: TProcessUTF8;
  6. begin
  7.   result := nil;
  8.   AProcess := TProcessUTF8.Create(nil);
  9.   try
  10.     //AProcess.Options:=[poDebugProcess, poNewProcessGroup];    
  11.     AProcess.Options:=[poDebugOnlyThisProcess, poNewProcessGroup];
  12. ...

but it gives me anyway error 50 when i run it.
i've modified that file and went to tools>configure build lazarus>clean & build everything and checked clean all
but it gives me error 50 anyway when process.execute is run from other unit than the main unit.
btw im using lazarus 32 bits on windows 64 bits. All the executables are 32 bits

 

TinyPortal © 2005-2018