generating core dump in linux lazarus / 62-General ---------------------------------------------------------------------- Чебурашка · 2024-03-07 10:19 Working under linux debian 12. I have this two softwares 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 program project1; uses  SysUtils;var  n, d: Integer;begin  n := 20;  d := 0;  Writeln(Format('%f', [n/d]));end. and Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i #include #include  int main(int argc, char** argv) {     int n = 20;    int d = 0;        printf("%f", n/d);        return 0;}  I set ulimit -c unlimited to enable coredumps. Also I have kernel.core_pattern = core. When I exec the pascal one I get no core and this message Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i An unhandled exception occurred at $0000000000401105:EDivByZero: Division by zero  $0000000000401105  main,  line 10 of project1.lpr  When I exec the C one I get the core and the following message Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Floating point exception (core dumped)  Is it possible to obtain the coredump also in pascal? I need to debug a much bigger fpc application that crashes randomly. ---------------------------------------------------------------------- Darie · 2024-03-07 10:37 What about infinite recursion? ---------------------------------------------------------------------- Red_prig · 2024-03-07 10:38 try it https://wiki.freepascal.org/SetExceptionMask ---------------------------------------------------------------------- Чебурашка · 2024-03-07 10:49 Quote from: Red_prig on March 07, 2024, 11:38:44 amtry it https://wiki.freepascal.org/SetExceptionMask Thanks. But if the exception is another (this program with a division by zero was just an example), let's say an access violation (SIGSEGV) the same problem arises, that is in C i get the core dumps, in fpc I don't. Is there a compilation switch or directive to change this? ---------------------------------------------------------------------- Red_prig · 2024-03-07 10:57 I think not, since core dump is a system call and as I understand it, Pascal does not use it when crashing, you can probably try to override this behavior ---------------------------------------------------------------------- MarkMLl · 2024-03-07 11:08 Quote from: Red_prig on March 07, 2024, 11:57:10 amI think not, since core dump is a system call and as I understand it, Pascal does not use it when crashing, you can probably try to override this behavior ...in which case looking for discussions relating to a custom global exception handler might be useful. MarkMLl ---------------------------------------------------------------------- Чебурашка · 2024-03-07 11:25 Quote from: MarkMLl on March 07, 2024, 12:08:38 pmQuote from: Red_prig on March 07, 2024, 11:57:10 amI think not, since core dump is a system call and as I understand it, Pascal does not use it when crashing, you can probably try to override this behavior ...in which case looking for discussions relating to a custom global exception handler might be useful. MarkMLl I don't find a way to disable the exception handling, like in the simple program above, instead of trapping anything, it should simply crash. ---------------------------------------------------------------------- Thaddy · 2024-03-07 11:34 If you run your program under GDB you can have a core dump. I have to look up the options, long time since I used it. [edit] This is chatGPT, but is a correct answer, it is close to how I remember it: Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Certainly! When debugging a program using GDB (GNU Debugger) on Linux, you can generate and analyze a core dump. Here’s how you can do it: Enable Core Dumps:First, check the maximum core dump size using:ulimit -c If the result is zero (meaning no core dump will be produced), set the limit to the maximum:ulimit -c unlimited Now, core dumps will be generated and placed in the location specified by /proc/sys/kernel/core_pattern.Generating a Core Dump:When your program crashes, it generates a core dump file (usually named core.pid, where pid is the process ID).You can use the generate-core-file command within GDB to create a core dump of a running process:gdb -p (gdb) generate-core-file  Analyzing the Core Dump:Load the core dump file along with the binary (executable) using GDB:gdb  For example:gdb ./my_program core.pid Once inside the GDB prompt, you can use various commands:bt (backtrace): Shows the stack trace at the time of the crash.info locals: Displays values of local variables.info registers: Shows values of CPU registers.frame X: Changes to stack frame X.up and down: Navigate within the call stack.Remember that when using the core file, you don’t need to pass arguments; GDB already captures the state of the program during the crash. Happy debugging! 🐞🔍123Don't forget to set ulimit -c 0 after debugging. ---------------------------------------------------------------------- MarkMLl · 2024-03-07 11:57 Quoteulimit -c unlimited Now, core dumps will be generated and placed in the location specified by /proc/sys/kernel/core_pattern. He's already said that he's done this, and that the problem is peculiar to an FPC (apparently, FPC + Lazarus) program. I'm pretty sure I used to set global exception handlers on Delphi programs which were effective and have set handlers on FPC threads to good effect, but don't know whether I've set an ultimate handler for an FPC/Lazarus app. MarkMLl ---------------------------------------------------------------------- Thaddy · 2024-03-07 12:06 Well, set the global exception handlers to nil? That would be ExceptClsProc := nil; ExceptObjProc := nil; and ExceptProc := nil; This must be done after the sysutils unit is loaded, because that will set these three. You have to unset them later than sysutils is loaded. (That is IF you use sysutils. Either direct or indirect) ---------------------------------------------------------------------- Чебурашка · 2024-03-07 12:37 Quote from: Thaddy on March 07, 2024, 01:06:11 pmWell, set the global exception handlers to nil? That would be ExceptClsProc := nil; ExceptObjProc := nil; and ExceptProc := nil; This must be done after the sysutils unit is loaded, because that will set these three. You have to unset them later than sysutils is loaded. (That is IF you use sysutils. Either direct or indirect) Thaddy rules. 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 program project1; uses  SysUtils;var  n, d: Integer;  r:Double;    Procedure AExceptClsProc(Obj : TObject; Addr : CodePointer; FrameCount:Longint; Frame: PCodePointer);  begin    raise Exception.Create('AExceptClsProc');  end;  Procedure AExceptObjProc(Obj : TObject; Addr : CodePointer; FrameCount:Longint; Frame: PCodePointer);  begin    raise Exception.Create('AExceptObjProc');  end;  Procedure AExceptProc(Obj : TObject; Addr : CodePointer; FrameCount:Longint; Frame: PCodePointer);  begin    raise Exception.Create('AExceptProc');  end;  begin  SysUtils.Now; // Forcing SysUtils to be accessed (Thanks to Thaddy)    ExceptClsProc := @AExceptClsProc;   ExceptObjProc := @AExceptObjProc;   ExceptProc := @AExceptProc;    n := 20;  d := 0;  r := n/d;end.  Result: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [13:42:02] mep@mep-development:~/tmp/2024-03-07-coredump$ ./project1 Segmentation fault (core dumped)  For info setting the three handlers to nil in the program above doesn't solve the problem, as executions sticks to the Runtime error messages. Now I need to see what the coredump contains... ---------------------------------------------------------------------- MarkMLl · 2024-03-07 12:57 Quote from: Чебурашка on March 07, 2024, 01:37:01 pmQuote from: Thaddy on March 07, 2024, 01:06:11 pmWell, set the global exception handlers to nil? That would be ExceptClsProc := nil; ExceptObjProc := nil; and ExceptProc := nil; This must be done after the sysutils unit is loaded, because that will set these three. You have to unset them later than sysutils is loaded. (That is IF you use sysutils. Either direct or indirect) Thaddy rules. Looks about right. However I think the important thing is going to be the import order in the uses statement, since sysutils isn't load-on- demand your sysutils.Now() won't have any useful effect. MarkMLl ---------------------------------------------------------------------- Чебурашка · 2024-03-07 13:26 Quote from: Чебурашка on March 07, 2024, 01:37:01 pmNow I need to see what the coredump contains... Setting ExceptProc to nil doesn't work. Setting to custom and doing nothing inside doesn't work. Setting to custom and raising exception generates a segmentation fault (core dumped), but it is not because to the original exception, but is because stack runs out (infinite recursion like someone said before). ---------------------------------------------------------------------- MarkMLl · 2024-03-07 13:29 Quote from: Чебурашка on March 07, 2024, 02:26:27 pmSetting ExceptProc to nil doesn't work. Setting to custom and doing nothing inside doesn't work. Setting to custom and raising exception generates a segmentation fault (core dumped), but it is not because to the original exception, but is because stack runs out (infinite recursion like someone said before). Yes, but we were assuming that you noticed Red_prig's suggestion that generating a coredump required a system call. MarkMLl ---------------------------------------------------------------------- Чебурашка · 2024-03-07 13:31 Quote from: MarkMLl on March 07, 2024, 02:29:22 pmYes, but we were assuming that you noticed Red_prig's suggestion that generating a coredump required a system call. Ops sorry, thank you