jrfonseca / drmingw

Postmortem debugging tools for MinGW.
GNU Lesser General Public License v2.1
279 stars 56 forks source link

Dump also module base addresses in ExcHndl #32

Closed alvinhochun closed 2 years ago

alvinhochun commented 7 years ago

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 commented 6 years ago

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?

jrfonseca commented 2 years ago

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.

alvinhochun commented 2 years ago

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 commented 2 years ago

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?

jrfonseca commented 2 years ago

You're right. I got confused.

Robyt3 commented 2 years ago

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

jrfonseca commented 2 years ago

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