F4 - Run to cursor lazarus / 12-Debugger ---------------------------------------------------------------------- BLL · 2016-06-25 09:42 Hi, Can anyone help? I have come to lazarus from CBuilder. One of the debugging options I find very useful is the run to cursor, but it is always greyed out and therefore not available. Why please? Brian ---------------------------------------------------------------------- rvk · 2016-06-25 10:12 Yeah, that's also something I needed to get used to. F4 only works within the procedure you are at that moment. It doesn't work like in Delphi. The workaround is... you go to the place where you want to go. But you don't press F4 but F5 and press F9 (run). F5 sets a breakpoint. When the program breaks you directly press F5 again and the breakpoint is released. It would be neat if Lazarus could implement that F5, F9 & F5 under the F4 button (But for now you can do it that way) ---------------------------------------------------------------------- BLL · 2016-06-25 16:48 Hi, Thanks for the info. If it's that badly implemented, F4 shouldn't be there! I also don't understand why compile, make and build are on the Run menu! If you are going to run a programme, it must be built first! In CBuilder, these items were on the Project menu, which, I think, makes much more sense. You build a project and then you run it! Brian ---------------------------------------------------------------------- Martin_fr · 2016-06-25 18:42 It is not badly implemented, it implements a different function. It is "step to cursor" http://bugs.freepascal.org/view.php?id=21958#c59370 ---------------------------------------------------------------------- rvk · 2016-06-25 18:53 Quote from: Martin_fr on June 25, 2016, 08:42:13 pmIt is not badly implemented, it implements a different function. It is "step to cursor" Well, it doesn't say "Step to Cursor (F4)" but it says "Run to Cursor (F4)". And because the naming in Delphi is exactly the same it confuses the hell out of people just beginning with Lazarus Luckily I learned quit quickly to use the F5 for breakpoint but seeing that different function uses the same name and even the same function key as Delphi, I can understand the confusion. ---------------------------------------------------------------------- BLL · 2016-06-25 19:34 I don't follow your logic! Run to cursor means run the program until it reaches the point where you have put the cursor. Of course you can set a breakpoint, but surely, the whole idea of F4 was to be quicker. Otherwise, you need 2 steps - 1 set breakpoint, 2 run program! CBuilder had it right, lazarus, in my opinion does not! ---------------------------------------------------------------------- Martin_fr · 2016-06-25 20:30 Yes, it is currently wrongly named. Lazarus does not have "run to cursor" at all. It has a different function. "step to cursor" can be useful too. So the function itself is not wrong, or bad, it is just a different one. Both needs to be done: - fix the name - implement "run to c" ---------------------------------------------------------------------- duzenko · 2019-08-30 10:14 Nice to know that it's 2019 and still no Run to Cursor ---------------------------------------------------------------------- RuudB · 2020-04-19 12:41 It does work, but..... not the first time. The very first time you have to use the F5/F9 combination and then you can use F4. But I wonder as well why it cannot be used the first time. ---------------------------------------------------------------------- Martin_fr · 2020-04-19 12:56 Because it is a "step over" variant. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Foo(i : integer);begin  if i > 10 then exit  DoBefore(1);  DoFoo(i+1);  DoAfter;end; Say you are on "DoBefore" and i = 1. You want [1] to "Step over to cursor" to "DoAfter". Then the line DoAfter is executed with i = 3,4,5 to 10. But "Step over" does not "step in" => so you should expect to stop at "DoAfter" when i=1, and only then. I.e. you only stop at the target line, if you reach the target line in the very same stack-frame in which you started. - Any hit of the line, while in a deeper stack frame is skipped - Exiting the current stack frame, will enter pause (break) This is what gdb provides under that name. That is were the idea came from. If you have not started the app yet, then all code is in "deeper stack frames", and can not be reached by "step over to cursor" You want a completely new command. (a reasonable one, yes) But no one had yet time to implement it. As for me (I do a lot of the work on the debugger), I simple have tons of other todo items, that are all at a higher priority. [1] Well, you do want something else, but this is what it is designed for at current ---------------------------------------------------------------------- duzenko · 2022-01-09 10:01 Happy 2022 everyone I can see F4 run to cursor in the menu but it's greyed out unless the app already runs and is paused in debugger? ---------------------------------------------------------------------- Martin_fr · 2022-01-09 10:11 Quote from: duzenko on January 09, 2022, 11:01:11 amHappy 2022 everyone Just the right topic for some brighter outlook. Because Quote from: duzenko on August 30, 2019, 12:14:30 pmNice to know that it's 2019 and still no Run to Cursor 2022 and we do have "Run to Cursor". At least when using FpDebug. (IIRC, not yet ported to the gdb/lldb based debuggers) Mind: - This is a new command, you need to change your keyboard mapping, if you want that with F4.   The default for F4 is still "Step to cursor", with the old behaviour. - FpDebug only stops on lines with code (blue dots). "Run to cursor" to any other line, will never reach that line (nor will it stop at the next / but that will be added in future) - This may only work, once the app has been started with F9. (not sure, if it can be used to launch the app, and run to line...). So maybe not perfect, but one step at a time. https://wiki.lazarus.freepascal.org/Debugger_Status ---------------------------------------------------------------------- duzenko · 2022-01-09 10:24 Exciting! How do I remap F4 to that new menu item? Can't see the key settings in UI anywhere ---------------------------------------------------------------------- duzenko · 2022-01-09 10:30 Found in Tools Options Editor Key mappings Now we're talking ---------------------------------------------------------------------- Martin_fr · 2022-01-09 10:42 Menu: Tools > Options >> Editor > "Key Mappings" Filter for "run". The entry is in the section "Run menu commands", it is called "Run to cursor" (just below the entry "Step over to cursor"). Double click the entry, assign a key. If you assign "F4" it will ask if you want to remove it from the existing command. And I just checked. In FpDebug, it can be used to launch the app. So you can place the cursor somewhere in your code (e.g., Button1Pressed), and press "F4". And if that line is not empty (i.e. if it gets a blue dot, after launch), then the debugger will stop there. Of course, if you hit a breakpoint, or your app gets paused in the debugger for other reasons, then the "F4" location is no longer a target. But you can of course go to this line again, and use "F4" again. I also checked the gdb based debugger. And "Run to cursor" works too. ---------------------------------------------------------------------- duzenko · 2023-08-26 08:02 Sorry for necroposting, but can we please get one menu item for both debugger backends (in the sake of general sanity) I'm sure there's a mighty hero somewhere who can add an if/then clause in the right place of the source code? ---------------------------------------------------------------------- Martin_fr · 2023-08-26 09:08 Quote from: duzenko on August 26, 2023, 10:02:17 amSorry for necroposting, but can we please get one menu item for both debugger backends (in the sake of general sanity) I'm sure there's a mighty hero somewhere who can add an if/then clause in the right place of the source code? "both debugger backends" There are 3 main variants: FpDebug, Gdb, Lldb - and then variants thereof.... https://wiki.freepascal.org/Debugger_Status#Available_Debuggers "get one menu item" There are 2 different commands. They perform a different action. (And iirc FpDebug and GDB support both commands.) "Run to cursor" "Step over to cursor" "Run to cursor" => Works like - breakpoint at cursor - run(F9) "Step over to cursor" => Works like - While -    not AtCursor() -    or -    HasSteppedOut - do  Step Over(F8) "Step over to cursor" means you must be able to reach the location at cursor, without leaving the current function. (But you will not stop at it, inside a recursive call) "Run to cursor" will stop inside a recursive call And this is why both commands are important. - If I am in a function, that has recursion, I may need "Step over to cursor". - But if I want to run to just any location then I need "Run to cursor" If you want to start the debugger, and stop at some location, then you need "Run to cursor" - because you aren't inside a function (as the app is not yet running), and so "Step over to cursor" can not work. ---- All this is independent of the Debugger Backend. As indicated, some backends support both commands. At the time this thread was created, it may have been the case that any backend supported only one (or none) of those 2 commands. But that is no longer the case. ---------------------------------------------------------------------- Martin_fr · 2023-08-26 09:14 And, yes: Documentation is needed. There is some mention here: https://wiki.freepascal.org/Debugger_Status#Execution_Control_.28Run.2 C_Step.2C_....29 There is complete absence here: https://wiki.freepascal.org/Main_menu#Run Not sure about other mentions.... Currently waiting for a contributor who wants to help bringing the Documentation up to date. ---------------------------------------------------------------------- duzenko · 2023-08-29 09:05 Thanks, I see the reasoning behind the current implementation BUT it also makes Lazarus an odd duck in the world of IDE's where there is exactly one Run to cursor and it's always the same keyboard shortcut I don't argue the usefulness of step over to cursor but what I suggest is to make this compatible in UX with at least one other popular IDE, i.e. Delphi So have F4 to do what it does in Delphi/FPIDE/etc and add a special kbd shortcut to the other one so that we don't have to reset the keymappings after each installation/config reset ---------------------------------------------------------------------- Martin_fr · 2023-08-30 08:02 The problem with changing existing keymappings is that people are used to the current layout. I.e. everyone who has not (recently) switched for Delphi - but used Lazarus for a while - is used to the existing keymap. I don't know how many other keymap diffs we have from Delphi, and maybe a "Delphi like" keymap would be useful. There is currently an issue on the bugtracker about a VisualStudio like keymap. Also an argument about it being build in, or something to download and "import" (using the import button). Maybe get in contact there / Maybe create a feature request, and refer the other issue. Afaik someone from the team is looking at the VS-map issue, so maybe they can look at helping with a Delphi like keymap too. This may even go further than just the keymap. Afaik we have many other settings, that have Lazarus defaults. So there may be interest in having a complete preset, for those options.... But that would probably require some one to contribute it. I also recall, that an simplified vs advanced option has been suggested in the past. But on one had ever had the time to do anything about it. As a workaround, if you have more than one install of Lazarus, you can copy the EditorOptions.xml file from one config dir to another. But of course that is at best a workaround.