1

I am interested in publishing an application in a release build and storing the debugging symbols (PDBs) but not shipping the PDBs with it. When a custom exception is thrown I want the exception constructor to gather the addresses of the functions on the call stack and place the addresses as part of the exception message. Then looking at those addresses I want to look-up the address when an issue is reported and the error file log is sent. Evey thing I've found has refereed to getting the function name by shipping the debugging symbols as well. How do I just get the address of the function?

JadziaMD
  • 2,690
  • 5
  • 31
  • 42
  • See: http://stackoverflow.com/questions/2528776/windows-c-is-it-possible-to-find-the-line-of-code-where-exception-was-thrown and http://stackoverflow.com/questions/274034/given-a-crash-offset-pdb-and-source-how-can-i-find-the-source-line – Cody Gray - on strike Mar 01 '16 at 14:53
  • Neither of these seem to apply to why I'm specifically asking. I'm interested in the function address being captured by the custom exception type. No dump or a Windows error log. Updated the question to reflect better what I'm asking. – JadziaMD Mar 02 '16 at 08:43
  • 1
    I don't know what you mean by "the custom exception type." When an unhandled exception is thrown, you will get an error message that contains, among other things, the offset of the exception relative to the base address of the application. This will give you the address of the instruction that caused the exception. You can easily trace that to the offending function. Are you instead saying that you want the logic to do this *programmatically*, like when generating an error message in an unhandled exception handler? – Cody Gray - on strike Mar 02 '16 at 08:47
  • Yes, exactly. I would like the function addresses as part of the error message. – JadziaMD Mar 02 '16 at 10:03
  • Cool, yeah that was not clear to me before. I've reopened your question. However, I'd say the best solution would be to use the `__FUNCTION__` macro (or one of its brethren). It expands to the name of the function whose scope it is in, so you would just need to rejigger the exception class constructor so that it takes a pointer to a C-style string and use `__FUNCTION__` at the throw site. – Cody Gray - on strike Mar 02 '16 at 10:06
  • @CodyGray I'm pretty sure he wants to actually capture the function pointers along the call-stack. I think that would require something like `CaptureStackBackTrace` or `RtlUnwind` – PeterT Mar 02 '16 at 10:10
  • You are making your life harder than it needs to be. Simply set up an unhandled exception filter, and write a dump file by calling [MiniDumpWriteDump](https://msdn.microsoft.com/en-us/library/windows/desktop/ms680360.aspx). You can then open the dump file in a debugger. If you rather want to classify your errors, you could use [Windows Error Reporting](https://msdn.microsoft.com/en-us/library/windows/desktop/bb513641.aspx), which automatically puts errors into error buckets based on the callstack. – IInspectable Mar 02 '16 at 14:11

0 Answers0