drmingw icon indicating copy to clipboard operation
drmingw copied to clipboard

Dump also module base addresses in ExcHndl

Open alvinhochun opened this issue 7 years ago • 5 comments

With ASLR enabled in the process, the DLLs are loaded to a random location, so the PC addresses in the stack trace cannot be used directly to assist debugging.

It can be helpful if the base addresses are dumped to the log too.

alvinhochun avatar Nov 08 '16 10:11 alvinhochun

I made a naive attempt at implementing this for my needs:

  1. https://github.com/alvinhochun/drmingw/commit/c741ae1473f8d090293c588e9e5aa9dea126c82d
  2. https://github.com/alvinhochun/drmingw/commit/96a93854ff3864ff27f26b59630f31b334089584
  3. https://github.com/alvinhochun/drmingw/commit/25e5211e95dfa6418cbbb151af0ac3f6786a1480

@jrfonseca What would be your opinion on these changes?

Side note: I tried to use the offset address with the addr2line utility included in mingw-w64. By passing --section=.text to it, I can use the offset address to look up the symbol -- though with a caveat: .text is loaded onto an offset from the module base address, so I ended up having to subtract that amount (I guess it might be from BaseOfCode in the PE header, which seems to always be 0x1000 for mingw-64-built binaries) from the offset address before passing it to addr2line, Does this seem reasonable to you?

alvinhochun avatar Feb 15 '18 17:02 alvinhochun

Sorry, @alvinhochun, I dropped the ball on this.

https://github.com/alvinhochun/drmingw/commit/c741ae1473f8d090293c588e9e5aa9dea126c82d and https://github.com/alvinhochun/drmingw/commit/25e5211e95dfa6418cbbb151af0ac3f6786a1480 look good.

But https://github.com/alvinhochun/drmingw/commit/25e5211e95dfa6418cbbb151af0ac3f6786a1480 introduces GetSymFromAddrWithOffset which doesn't exist in DbgHelp, and I don't think it's necessary. SYMBOL_INFO already has all one needs, IIUC -- offset can be obtained by looking at the Address member. We just need to ensure Address is being filled.

jrfonseca avatar Apr 08 '22 08:04 jrfonseca

Hi! Sorry I didn't make the pull requests properly for this back then. I will rebase the changes and try to incorporate the change your suggested, then make a pull request.

alvinhochun avatar Apr 08 '22 08:04 alvinhochun

But https://github.com/alvinhochun/drmingw/commit/25e5211e95dfa6418cbbb151af0ac3f6786a1480 introduces GetSymFromAddrWithOffset which doesn't exist in DbgHelp, and I don't think it's necessary. SYMBOL_INFO already has all one needs, IIUC -- offset can be obtained by looking at the Address member. We just need to ensure Address is being filled.

There may be a bit of confusion here. GetSymFromAddrWithOffset is a modification of GetSymFromAddr, which I think is an internal function of DrMingw which is not intended to be used externally. Perhaps you may be thinking of SymGetSymFromAddr or SymFromAddr?

The Address field in SYMBOL_INFO refers to the address of the symbol, but what I needed is the out parameter dwDisplacement from the SymFromAddr call to get the offset from the symbol to the current address. I think adding GetSymFromAddrWithOffset is the right way to pass this parameter back to the caller.

Actually, since there is no other caller of GetSymFromAddr I may as well remove it too.

Did I miss anything?

alvinhochun avatar Apr 08 '22 12:04 alvinhochun

You're right. I got confused.

jrfonseca avatar Apr 10 '22 22:04 jrfonseca

Is this fixed already? Looks like the PR got merged.

Robyt3 avatar Oct 04 '22 09:10 Robyt3

Ah, yes. I merged it by end (to cleanup history) so this issue didn't automatically close.

jrfonseca avatar Oct 04 '22 09:10 jrfonseca