Recent

Author Topic: Step by step  (Read 6937 times)

katfo

  • New Member
  • *
  • Posts: 39
Step by step
« on: October 04, 2016, 08:28:47 pm »
Hello. How do I run my code step by step so that it doesn’t jump for example to wincontrol.inc or other such files which are part of Lazarus. I am only interested in finding errors in my own code. Thank you

Bart

  • Hero Member
  • *****
  • Posts: 5706
    • Bart en Mariska's Webstek
Re: Step by step
« Reply #1 on: October 04, 2016, 09:51:35 pm »
F8?

katfo

  • New Member
  • *
  • Posts: 39
Re: Step by step
« Reply #2 on: October 05, 2016, 09:24:11 am »
Yes I know F8. Here is a picture when I have pushed F8 repeatedly. My code is in file e_pas.pas which is marked with an arrow. As you can see Lazarus goes in this process through several windows and even the assembler has popped out. My code works OK without errors. There is only one tiny logical error which I try to pinpoint.  I don’t want to know what happens in these other files, I presume that they are correct.

Thaddy

  • Hero Member
  • *****
  • Posts: 18792
  • Glad to be alive.
Re: Step by step
« Reply #3 on: October 05, 2016, 09:35:18 am »
F8 wil execute a whole block, e.g. when a procedure is called. F7 will step through line by line if that is what you want.
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

katfo

  • New Member
  • *
  • Posts: 39
Re: Step by step
« Reply #4 on: October 05, 2016, 10:03:18 am »
F7 doesn’t help, the situation is the same. I wrote previously about an image showing my debugging. It can be seen when I am logged in but when I logout, the image disappears. How should I do that it remains visible?

Thaddy

  • Hero Member
  • *****
  • Posts: 18792
  • Glad to be alive.
Re: Step by step
« Reply #5 on: October 05, 2016, 10:26:36 am »
You can't. Attachments are only visible when you are logged in.
If you build all libraries without debug info both F8 and F7 work a bit like you want. Same goes for Delphi, btw.
« Last Edit: October 05, 2016, 10:28:27 am by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Step by step
« Reply #6 on: October 05, 2016, 10:44:30 am »
How did you start your debugging process?
Did you set a breakpoint somewhere in your own code after which you used F8?

If so... could you show us the code where you jump into LCL code when pressing F8?
(also explain the steps you took to get where you are in your picture)

Pressing F8 should never get you to where you are now (because it's "Step over").

When in your code set a breakpoint and let the program run. When at the breakpoint (press F5 to clear the breakpoint) and you can press F8 to execute the complete line or press F7 to enter any function. So only use F7 for your own functions. Even if you press F7 for your own function you could end up in LCL-code because parameters (like stringconversion) could throw you into LCL. In that case keep pressing F8 until your back in your own code.

Try debugging some simple examples and try to get the hang of the debugging steps.
If something doesn't work ask here again with the code-example you're using so we can explain the steps.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: Step by step
« Reply #7 on: October 05, 2016, 02:33:08 pm »
If I have a code line like:  EditEndDir.Text:=FloatToStr(bearing);  I put breakpoints before & after this line & click 'Run' to resume to the 2nd breakpoint. If there's no place for the 2nd breakpoint I add a line such as x:=0; i.e something that doesn't affect the debug.

However, yesterday out of interest I decided to 'Step Into' this line of code & was absolutely amazed at how much effort the 'Authors of Free Pascal Lazarus' had gone to just to implementing this single function 'for us', FOR FREE! I must have clicked 'Step Into' at least a 100 times to get to the next procedure! It really opened my eyes to the respect this team deserves.
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: Step by step
« Reply #8 on: October 05, 2016, 02:46:38 pm »
If I have a code line like:  EditEndDir.Text:=FloatToStr(bearing);  I put breakpoints before & after this line & click 'Run' to resume to the 2nd breakpoint. If there's no place for the 2nd breakpoint I add a line such as x:=0; i.e something that doesn't affect the debug.
You can also place a breakpoint on that line (hint: F5 is setting/clearing a breakpoint) and run the program. It will stop ON that single line. Pressing F8 will execute the whole line. Pressing F7 will go into the function FloatToStr(). After using F7 once you need to be very careful when to use it again. If you keep pressing F7 it will enter each function it encounters... and that's a lot very, very deep. So you need to press F8 sometimes to just jump over if you don't have any interest in investigating that function further.

(So you don't need to put an extra line like X:=0 to go to that line. Just F8 over the first line is sufficient.)

Quote
However, yesterday out of interest I decided to 'Step Into' this line of code & was absolutely amazed at how much effort the 'Authors of Free Pascal Lazarus' had gone to just to implementing this single function 'for us', FOR FREE! I must have clicked 'Step Into' at least a 100 times to get to the next procedure! It really opened my eyes to the respect this team deserves.
Yeah... stepping through all the code can be overwhelming. And especially due to the cross-compiling possibility it goes deeper and deeper :)

I do find the debugger somewhat lacking (less useful than the one in Delphi) especially when wanting to find out current values. It's fine for simple variables but for objects it get a lot less useful. For example hoovering over the DecimalSeparator of FormatSettings.DecimalSeparator gets you an error. Hoovering over FormatSettings gets you the complete record which can run off your screen. And sometimes properties of objects aren't even displayed.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12205
  • Debugger - SynEdit - and more
    • wiki
Re: Step by step
« Reply #9 on: October 05, 2016, 02:49:15 pm »
First of all: Make sure you compile with the correct settings: http://wiki.lazarus.freepascal.org/Debugger_Setup#Project_Options

2nd, If you use F7 (step into your own code's subprocedure) and the line looks like
Code: Pascal  [Select][+][-]
  1. MyProc(edit1.text)
This will unfortunately go through edit1.text().
You can change the options of the LCL package, and recompile it without debug info.
But that will not help in all cases.

3rd: If you get an Exception
The reason for the exception may well be in your code:
Code: Pascal  [Select][+][-]
  1. Page1.free;
  2. Page1.doSomething();
2nd line will crash. But the crash will (very likely) happen deep down in doSomething, or methods called by that.
If that is the LCL, with debug info, the debugger stops there, if not you most likely get the assembler.
You can look at the stacktrace, and see the code that called it

----------------------
In your case it seems to stop in WindProc.
That is possible yet something else, and even harder to find. You may have done something wrong one place, but the error happens much later in un-related code. So the stack may not help either.

It is possible that you called someComponent.Free inside an event (an event of that component, or one of its children.

Code: Pascal  [Select][+][-]
  1. procedure MyInfoForm.Button2Click(SEnder:TObjet);
  2. begin
  3.   MyInfoForm.Free;
  4. end;
  5.  
That destroys the button too. But you are in an event of the button.
After the "end" above, the program will be in code that belongs to the button, but the button is no longer, and then it will crash.

You can hide the form, but you must defer destroying it.
Code: Pascal  [Select][+][-]
  1. MyInfoForm.Hide;
  2. Application.ReleaseComponent(MyInfoForm);)

 

TinyPortal © 2005-2018