Recent

Author Topic: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?  (Read 10553 times)

RedOctober

  • Sr. Member
  • ****
  • Posts: 347
F8 is supposed to "skip" over a procedure and go to the next line.  My Laz 1.9 Fpc 3.1.1 likes to keep stepping into the Lazarus units (even when I've pressed F8 not to do that) which is bad enough, but then it keeps going deeper into what looks like Assembler (or some such) and it stops.  Is there an IDE setting for this?

Blaazen

  • Hero Member
  • *****
  • Posts: 2994
  • POKE 54296,15
    • Eye-Candy Controls
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #1 on: January 07, 2018, 03:02:00 am »
Currently there is no setting. I have opened related bugreport some time ago. You can add there a note with request: https://bugs.freepascal.org/view.php?id=27800
Lazarus 2.1.0 r64115 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3886
  • I like bugs.
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #2 on: January 07, 2018, 07:32:02 am »
F8 is supposed to "skip" over a procedure and go to the next line.  My Laz 1.9 Fpc 3.1.1 likes to keep stepping into the Lazarus units (even when I've pressed F8 not to do that) ...
Here F8 works as expected. Manjaro Linux + IDE.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6707
  • Debugger - SynEdit - and more
    • wiki
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #3 on: January 07, 2018, 12:09:24 pm »
This behaviour (where "step over" will end up) is controlled by gdb, so there is not much the IDE can do about it.

Yet, normally this works fine....
Are you sure you use the correct settings? http://wiki.lazarus.freepascal.org/Debugger_Setup
NO Optimization. Also disable inlining.

Check your key-shortcut assignment, that F8 points to "step over".

By default the LCL comes with fpc default debug info type (afaik stabs?), If you use a different one, consider changing it for all packages (all packages that have any debug info).
Some gdb versions dislike "mixed" info.

Maybe try a diff version of gdb?

If "step over" still steps into, check the debug "event log" (alt-ctrl-v), for any messages.
Also check the "breakpoint window" for any breakpoint that you are unaware of (and that may not be shown in the source editor, even though you may think it should)

-------------------
If none of that helps

Supply a reproducible (preferably small) example, together with a logfile, and describe the exact location (unit/line or address) at which it stopped incorrectly after you did a step over.
http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#Log_info_for_debug_session

Also your OS? 32/64bit ? And your GDB version?

Thaddy

  • Hero Member
  • *****
  • Posts: 10570
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #4 on: January 07, 2018, 12:17:58 pm »
F8 is supposed to "skip" over a procedure and go to the next line.  My Laz 1.9 Fpc 3.1.1 likes to keep stepping into the Lazarus units (even when I've pressed F8 not to do that) which is bad enough, but then it keeps going deeper into what looks like Assembler (or some such) and it stops.  Is there an IDE setting for this?
This is only the case if optimizations are off and the debug settings are properly set.

RedOctober

  • Sr. Member
  • ****
  • Posts: 347
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #5 on: January 07, 2018, 04:40:54 pm »
Thank you Martin_fr and Thaddy.  I followed the link given by Martin_fr.  My optimization was set to 1 not 0 like it shd have been.  I did not change anything... the install of fcpdeluxe 1.6 installing Laz 1.9 and Fpc 3.1.1 installed it this way.  I set it to 0 as instructed.  However, I don't know what Martin means when he says "Also disable inlining".  My F8 key mapping is correct.  I'll continue to work on my project and if the problem is cured, 'nuff said.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6707
  • Debugger - SynEdit - and more
    • wiki
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #6 on: January 07, 2018, 05:18:28 pm »
opt 1 vs 0 will not make a diff here.

opt 1 can in a few cases lead to variables still showing an old value, when inspected in the debugger.

----
Inlining is probably not an issue, unless you use a lot of
Code: Pascal  [Select][+][-]
  1. procedure foo; inline;
then use  (IIRC)
Code: Pascal  [Select][+][-]
  1. {$INLINE off}

---
If it happens again see the rest of my comments to gather further info.

RedOctober

  • Sr. Member
  • ****
  • Posts: 347
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #7 on: January 07, 2018, 08:09:12 pm »
Hi Martin_fr.  I've done everything you said, except change gdb.  The "step into Assembler" is still happening.  I'm reduced to setting a break a few lines ahead, then F9-ing up to the break, then going back and examining the variable contents to see what happened. Really annoying, but I can't easily figure out how to stop it.  I'll suffer for now, hopefully this is simplified in the next version(s) of Laz and Fpc.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6707
  • Debugger - SynEdit - and more
    • wiki
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #8 on: January 07, 2018, 09:10:29 pm »
Hi Martin_fr.  I've done everything you said, except change gdb.  The "step into Assembler" is still happening.  I'm reduced to setting a break a few lines ahead, then F9-ing up to the break, then going back and examining the variable contents to see what happened. Really annoying, but I can't easily figure out how to stop it.  I'll suffer for now, hopefully this is simplified in the next version(s) of Laz and Fpc.

With the information provided right now, I can not reproduce it. So it is not likely to be changed.

Try running the logfile, and once it happened write down which line you started at, which line or address you incorrectly ended up. Then attach the logfile here.

Also make a backup of your work at the time it happens for the log. Just in case some parts of the source may be needed.

RedOctober

  • Sr. Member
  • ****
  • Posts: 347
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #9 on: January 07, 2018, 09:50:59 pm »
Does this help Martin_fr?

When clicking F8 step through, I'm always taken to this procedure, at the line shown:
 
procedure TControl.Click;

  function OnClickIsActionExecute: boolean;
  begin
    Result:=false;
    if Action=nil then exit;
    if not Assigned(Action.OnExecute) then exit;
    if not Assigned(FOnClick) then exit;
    Result:=CompareMethods(TMethod(FOnClick),TMethod(Action.OnExecute));
  end;

var
  CallAction: Boolean;
begin
  //DebugLn(['TControl.Click ',DbgSName(Self)]);
  CallAction:=(not (csDesigning in ComponentState)) and (ActionLink <> nil);

  // first call our own OnClick if it differs from Action.OnExecute
  if Assigned(FOnClick)
  and ((not CallAction) or (not OnClickIsActionExecute)) then
    FOnClick(Self);   // <----------------------------------------- F8 Stops here!  Pressing F8 again jumps to the Assembler window.
  // then trigger the Action
  if CallAction then
    ActionLink.Execute(Self);
end;                             


Tools /Options reveals:

GNU debugger(gdb)
C:\ProgramFilesCP\Lazarus_19_fpc_311\fpcbootstrap\gdb\$(TargetCPU)-$(TargetOS)\gdb.exe

See attached log.  Thanks in advance for any help you can provide.



Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6707
  • Debugger - SynEdit - and more
    • wiki
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #10 on: January 08, 2018, 01:20:49 am »
No it does not have all the details.

The log, looks like the "event log".

But
Code: Pascal  [Select][+][-]
  1. lazarus.exe  --debug-log=c:\LOG_FILE.txt  --debug-enable=DBG_CMD_ECHO,DBG_STATE,DBG_DATA_MONITORS,DBGMI_QUEUE_DEBUG,DBGMI_TYPE_INFO
*from the wiki / you need to modify the desktop shortcut to run with those param)

will provide the communication between gdb and the IDE.
gdb actually prints a reason when it stops. An that reason is what I am looking for. It is the next clue.

If you cant do the log. Menu View > debug windows > debug output
Keep it open from the start of your debug, then copy all of it after the error.

There is no guarantee this will reveal anything. But it is the best chance.

-----------------
But anyway looking at what you got.

I can see a lot of threads, and dll being loaded.

Does your app start those threads?
If not, do you use flie open or save dialog (or any other file dialog)?

File dialogs load a lot of 3rd party dll (for shell extension) and that creates threads. And some of them are not behaving with gdb... Though it be strange, because they dont care about stepping or running to breakpoint.

A couple of more things you may try:

1) http://wiki.lazarus.freepascal.org/GDB_Debugger_Tips#On_Windows_Open.2FSave.2FFile_or_System_Dialog_cause_gdb_to_crash
You may not get a crash, but still... try to set DisableLoadSymbolsForLibraries

2) Very low chance, but still
Assuming you compile for 64bit windows, your gdb is at
C:\ProgramFilesCP\Lazarus_19_fpc_311\fpcbootstrap\gdb\x86_64-win64\gdb.exe
If you start a "cmd.exe" (start menu > run), and then run GDB you will see it's version.
If it is below 7.7 then:
https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/
Try GDB 7.7


RedOctober

  • Sr. Member
  • ****
  • Posts: 347
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #11 on: January 08, 2018, 05:46:18 am »
Hi Martin_fr.  Here is what I did:

- Upgraded my gdb to 77, and told Lazarus to use it (in a different folder), instead of the existing one.
- Added the debug params after my desktop shortcut Lazarus startup line. (I changed the folder of LOG_FILE.txt to my own folder)
- Saved my changes, shut down and restarted Lazarus 1.9 from the modified desktop shortcut
- Opened the debug window and ran my .exe with it open.
- At line 1140:
      Pascal:  cdsSvrLstOBJ_GUID.AsString := new_guid;
   it jumped out to the menuitem.inc unit FOnClick line (83)
- A log was produced in the log window, but there was no LOG_FILE.txt  created.
- I shut down my program, copied the log to the attached .txt file.

The "jump out" occurs on many lines, not just the one above.  I just did this one as an example.

I have separated the log into different sections, with a note from me on the very bottom or very top line.


GetMem

  • Hero Member
  • *****
  • Posts: 3782
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #12 on: January 08, 2018, 06:48:32 am »
Download gdb from the following page: http://www.equation.com/servlet/equation.cmd?fa=gdb
In my experience works much better then the one shipped with fpc/lazarus. Make sure you backup the old gdb before test.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6707
  • Debugger - SynEdit - and more
    • wiki
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #13 on: January 08, 2018, 12:59:38 pm »
Ok there seems something wrong with GDB.
But it could also be a problem in how FPC  generates debug info.

I dont think it is an issue with how you build fpc (since you use trunk?). I am not aware of any compiler options that would cause this.
It may though be that fpc trunk has not yet known issues in generating debug info.

There is also a small issue in the IDE, though it wouldn't make a difference here. More below.

-------------------------------
Before I go into technical details:

Check in "project options" > Debugging: "Type of debug info".
You might change this to "Dwarf with sets"
You can also try "Dwarf 3" (but that may need an even newer gdb. / try it though, it is fine unless you get "gdb stopped working")

You may also want to change that for the LCL (package options)
Or add -gw  (or -gw3 for dwarf3) to menu: Tools > Configure Build Lazarus: Custom options)


You also may want to try an even newer GDB, but I do not know where to download that for win64.

Alternatively you can build your fpc (the RTL) with -O-1
Maybe gdb will get better results if the code is not optimized.

------------------------------------------------------
The technical bits....

-- Problem 1)

GDB thinks indeed that some code from the unit DB: .AsText and some methods called by this function are new lines in your code and it stops there.
Though FPC did not seem to have inlined them.

So after you hit your breakpoint, when you first press F8,
DB believes that the next line starts in TSTRINGFIELD.SETASSTRING

GDB actually stops in that method.

-- Problem 2)

But the IDE notices that this code does not have debug info. So the IDE tries to find a line on the callstack. In this case this is wrong by the IDE.
The IDE should expose the GDB (or FPC) error at this point.

-- Problem 3)

Because TSTRINGFIELD.SETASSTRING is in the RTL, it is optimized. It does not allow to find the correct caller. (This is a feature / but it does not matter, as there should be no attempt to look up the caller)

So instead of your code (which called SetAsString), the method one further up on the stack is found. This is the code calling "OnClick".

-------------------------
To recap.

After F8 you have the following callstack
1) TSTRINGFIELD.SETASSTRING
2) f_main_MyProject.pas:1140
3) menuitem.inc 83  " OnClick() "

You actually are at 1.
The IDE tries to get 2
But it gets 3, and displays 3

2 will be hidden, even if you display a stacktrace. This is because the RTL is compiled with optimization.
The optimization of the RTL normally would not matter, if not the IDE would try to be too clever....

But even without the IDE trying to be clever, the problem would still be that gdb stopped inside SetAsString.

-------------------------------
On further steps, gdb stopped in various methods in the RTL that are called by SetAsString.
Due to the IDE trying to be too clever, this sometimes shows your code. This explains why some F8 just stay on the same line. GDB stepped to another method, but the IDE finds your line.

I reported the IDE part https://bugs.freepascal.org/view.php?id=32978

======
"optimized" code in the RTL.

Any reference to "optimized" in the above is about fpc compiling some methods without stackframe (i.e. the code does not save the stackpointer as base-stackpointer).
This optimization means that a caller gets hidden on the stack.
It may also interfere with gdb analysing the code. (Though this I have never observed so far)

« Last Edit: January 08, 2018, 01:35:34 pm by Martin_fr »

Pascal

  • Hero Member
  • *****
  • Posts: 914
Re: Is there a way to stop Lazarus F8 debug to NOT step into Assembler?
« Reply #14 on: January 08, 2018, 02:39:48 pm »
For me DB with F8 often stops in fpc_AnsiStr_XXX routines. (win64/x86_64, fpc trunk, laz trunk i386, gdb 7.7.50)
laz trunk x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (2004)

 

TinyPortal © 2005-2018