Can I find the relevant code by address? lazarus / 12-Debugger ---------------------------------------------------------------------- jollytall · 2022-01-20 07:24 I have a program running. It was compiled with optimization and no debugger help at all. After running for quite long, it crashed with an Excess Violation and giving a hex address. Is there a way to find where it crashed? I am thinking to recompile again with debug and find the code then. 1. Would the address be the same, or because of the debug information added, it will have different (shifted) addresses, i.e. useless. 2. Even if it is shifted, I can try to compile with debug, run it again and "hope" that once it will crash at the same place. If that happens, how can I find the source line, based on the address? 3. Is there a better way? ---------------------------------------------------------------------- howardpc · 2022-01-20 07:46 Quote from: jollytall on January 20, 2022, 08:24:43 am1. Would the address be the same, or because of the debug information added, it will have different (shifted) addresses, i.e. useless. You can compile with -Xg to ensure that debug information is written to an external debug symbols file. ---------------------------------------------------------------------- bytebites · 2022-01-20 08:56 Compile with optimization and line info. ---------------------------------------------------------------------- Thaddy · 2022-01-20 10:18 Quote from: bytebites on January 20, 2022, 09:56:57 amCompile with optimization and line info. I guess you mean without optimization and with line nfo (-O- -glh)? ---------------------------------------------------------------------- bytebites · 2022-01-20 11:36 Quote from: Thaddy on January 20, 2022, 11:18:44 amQuote from: bytebites on January 20, 2022, 09:56:57 amCompile with optimization and line info. I guess you mean without optimization and with line nfo (-O- -glh)? [/quote -O3 -gl ---------------------------------------------------------------------- Thaddy · 2022-01-20 11:42 nope, glh not gl. or you can do -gl -gh. ---------------------------------------------------------------------- jollytall · 2022-01-20 12:59 Sorry, I am confused: If I understand correctly the external debug file would ensure that the original code is the same as the one without debug info (@howardpc). I do not understand the reference to optimization (@bytebytes and Thaddy). I guess I need the same level of optimization as in the original program, otherwise the addresses will surely be different. And so, if I have the program recompiled with an external debug file, how can I find the code, based on the crash address? ---------------------------------------------------------------------- MarkMLl · 2022-01-20 17:56 Quote from: jollytall on January 20, 2022, 01:59:34 pmIf I understand correctly the external debug file would ensure that the original code is the same as the one without debug info Having a different optimisation level or different runtime checks will guarantee that the new code is not the same as the original one: irrespective of the generation of an external debug file. However having the same optimisation level and runtime checks will not guarantee that the new code is the same as the original: irrespective of the generation of an external debug file. That's where "repeatable builds" comes in. The best thing you can do IMO is to take the current situation as indicative of there being a problem in your code, and to look carefully at whether runtime checks are enabled in all cases (i.e. not turned off halfway through some critical unit and left off). It they're off, then there's a good change that if you recompile with them turned on (plus debugging info and limited optimation) then you'll find your problem within 30 seconds. As me how I know... MarkMLl