Recent

Author Topic: Can I find the relevant code by address?  (Read 3518 times)

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Can I find the relevant code by address?
« on: January 20, 2022, 08:24:43 am »
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

  • Hero Member
  • *****
  • Posts: 4144
Re: Can I find the relevant code by address?
« Reply #1 on: January 20, 2022, 08:46:30 am »
1. 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

  • Hero Member
  • *****
  • Posts: 633
Re: Can I find the relevant code by address?
« Reply #2 on: January 20, 2022, 09:56:57 am »
Compile with optimization and line info.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Can I find the relevant code by address?
« Reply #3 on: January 20, 2022, 11:18:44 am »
Compile with optimization and line info.
I guess you mean without optimization and with line nfo (-O- -glh)?
« Last Edit: January 20, 2022, 11:23:16 am by Thaddy »
Specialize a type, not a var.

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Can I find the relevant code by address?
« Reply #4 on: January 20, 2022, 12:36:11 pm »
Compile with optimization and line info.
I guess you mean without optimization and with line nfo (-O- -glh)?
[/quote

-O3 -gl

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: Can I find the relevant code by address?
« Reply #5 on: January 20, 2022, 12:42:09 pm »
nope, glh not gl. or you can do -gl -gh.
Specialize a type, not a var.

jollytall

  • Sr. Member
  • ****
  • Posts: 306
Re: Can I find the relevant code by address?
« Reply #6 on: January 20, 2022, 01:59:34 pm »
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

  • Hero Member
  • *****
  • Posts: 6676
Re: Can I find the relevant code by address?
« Reply #7 on: January 20, 2022, 06:56:01 pm »
If 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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018