fpdebug and BackTraceStrFunc show wrong line number on exception lazarus / 12-Debugger ---------------------------------------------------------------------- RolfW · 2023-10-08 09:09 Look at the attached example program and screenshorts. In short: procedure Test2 raises an exception in line 46. 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 Test2;begin  ;   raise Exception.Create('Test');end;  The fpdebug notification shows an exception in line 43. Same result as BackTraceStrFunc. fpdebug jumps to line 43 ("begin") if I "Break" the program exceution. gdb works ok. Tested with Lazarus 3.99 20023-10-08 x86_64_win64-win32/win64. I assume that this is a fpc issue but you may want to have a look at it before publishing a new release. Thank you, Rolf ---------------------------------------------------------------------- Martin_fr · 2023-10-08 09:53 Interesting.... The stack window shows the correct line. The assembler to (in a way)... That is the assembler depends on what the convention is. Currently that is to show the return address, which is one after the call statement (and in this case on the next line). Actually it shows both... The green arrow, at line 46 (which should be selected in the source editor). And the selected line after the call. And that has (at least partially) technical reasons: The callstack only has the return address, after the "call". Intel can't be disassembled in reverse direction (var len asm stmt). Of course in this case the start of the procedure is known, so we get the asm above the return point. But if there is no known start point, then it can't be done. So for the selection, it is "after the call". Since in this case, the line is known from the editor, it is shown (green arrow). And that is interesting, because it is correctly 46. Which mean there are 2 issues. 1) The editor is wrong (bug in the IDE) 2) The asm should be in sync with the editor, but it does not copy the error. (which, yes, it should) (also bug in the IDE) The problem in the Editor is likely in the "cache for line numbers". I.e. the IDE stores where the line number was when you started the debugger => so if you edit while debugging, and lines move, the IDE can still map them to what the debugger gets from the debug info. That mapping is not always exact (but only once the source was edited, because new lines have no info, joined lines can only keep one info, .... ) ---------------------------------------------------------------------- Martin_fr · 2023-10-08 11:34 And it turned out to be some place else.... ---------------------------------------------------------------------- RolfW · 2023-10-08 12:05 A hint: ExecptAddr seems to be ok. I picked up the ExceptAddr shown in BackTraceStrFunc and defined a fpdebug break for this address. The result is as expected: A break in line 46 before the  raise ... statement was executed. ---------------------------------------------------------------------- Martin_fr · 2023-10-08 12:11 I fixed it in the meantime. ---------------------------------------------------------------------- RolfW · 2023-10-11 07:21 Quote from: Martin_fr on October 08, 2023, 02:11:46 pmI fixed it in the meantime. Where can I find the fix? Is it in the main or in the 3.2.2 fixed branch? Thank you, Rolf ---------------------------------------------------------------------- Martin_fr · 2023-10-11 09:43 It is fixed in fpdebug. So it is in the Lazarus git In fixes-3-0: e49d174f1732cffe49f726ceb8c4c7a724e80dff * LazDebuggerFp: Fixed line number for exceptions. in main: bacefb51aeba1be609d807ae38164acfff461b60 ---------------------------------------------------------------------- Martin_fr · 2023-10-11 10:24 And I just found why it was broken in first.... It is now broken when using "raise at" 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   Raise Exception.Create('foo') at get_caller_addr(get_frame), get_caller_frame(get_frame); For example if you have debug info for the RTL, and get a TStringList bounds error. -- EDIT: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/40544 ---------------------------------------------------------------------- RolfW · 2023-10-12 06:13 Quote from: Martin_fr on October 11, 2023, 11:43:50 amIt is fixed in fpdebug. So it is in the Lazarus git In fixes-3-0: e49d174f1732cffe49f726ceb8c4c7a724e80dff * LazDebuggerFp: Fixed line number for exceptions. in main: bacefb51aeba1be609d807ae38164acfff461b60 Does this fix BackTraceStrFunc too? Rolf ---------------------------------------------------------------------- Martin_fr · 2023-10-12 08:14 Quote from: RolfW on October 12, 2023, 08:13:30 amDoes this fix BackTraceStrFunc too? Sorry, I missed that. No that is not changed. (needs someone from the fpc team to look at) ---------------------------------------------------------------------- RolfW · 2023-10-13 06:34 Quote from: Martin_fr on October 12, 2023, 10:14:30 amSorry, I missed that. No that is not changed. (needs someone from the fpc team to look at) Shall I open an issue for BackTraceStrFunc? Rolf ---------------------------------------------------------------------- Martin_fr · 2023-10-13 10:06 I don't know what is indented there. But probably. Also make sure to indicate the debug info you use (most likely Dwarf) (though afaik on Win 32 bit you can still do stabs) And probably your OS too. Note that very likely you will get unexpected resolves. Either for "raise" or "raise at" But that is not due to the BackTraceStrFunc 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   raise Exception.create('abc') at get_caller_addr(get_frame), get_caller_frame(get_frame); The "at" returns the address of the asm instruction after the "call" (and often that is in the next Pascal code line). And, if the BackTraceStrFunc  is fixed, then on any stack dump, for any caller it will report (in some/many cases, but not always) the next line. (well that then may depend on OS, CPU and debug info...) So I don't know if the "bug" is intentional. Currently the BackTraceStrFunc  returns (at least in some cases / not verified) the line before (or is it the line of the address before / which is different, but which may be wanted) This "bug" solves the "address after call instruction" issue. Technically it resolves it in the wrong place (if it is meant as a resolve, which I do not know). Because BackTraceStrFunc  does not know if the address it deals with, comes from a stacktrace, or other place.  Note that this may not apply to all CPU architectures. And OS and debug info type can have an impact, but not sure if they do. ---------------------------------------------------------------------- RolfW · 2023-10-15 17:31 Quote from: Martin_fr on October 13, 2023, 12:06:33 pmI don't know what is indented there. But probably. GetLineInfo reports wrong func/ line values: https://gitlab.com/freepascal.org/fpc/source/-/issues/40471 Rolf