0

I saw a very good way to get the symbol name from the following post.

Win32 - Backtrace from C code

But what about getting the file name and line number. I tried to use the SymGetLineFromAddr64 but could not get this debug information.

Community
  • 1
  • 1
Imran
  • 103
  • 1
  • 1
  • 9

1 Answers1

3

If you couldn't get this debug information, and your code was correct, then the problem could be with the options. You need SYMOPT_LOAD_LINES to have this information loaded:

SymSetOptions(SYMOPT_LOAD_LINES);

Then, supposing you are using the code from the link you provided, it would be like this:

DWORD  dwDisplacement;
IMAGEHLP_LINE64 line;

SymGetLineFromAddr64(process, (DWORD64)stack[i], &dwDisplacement, &line);

Now you can access these line members (from the IMAGEHLP_LINE64 structure):

DWORD   LineNumber;
PTSTR   FileName;
Toribio
  • 3,963
  • 3
  • 34
  • 48
  • Thanks, this actually solved my issue. I was passing NULL to third parameter because it was optional in SymFromAddr so I assumed the same for this function. – Imran Sep 17 '12 at 22:58
  • There are many API functions where we have optional parameters, but it's always safe to pass a non-null pointer to them. Another example of function with this kind of parameter, is `CreateThread`, where the `threadID` parameter is optional (and many others), and some people just pass `NULL` to it, but others pass pointer. IMHO, I like to always pass a valid pointer for safety reasons. Of course if you know the API function well, you can do whatever you want with it, but in doubt, do the safe way. – Toribio Sep 17 '12 at 23:08
  • Yes, you are absolutely right. it happened with me because I just wanted to save few seconds which I could save at the end:) And both functions signatures were so similar (except the last parameter) that I could not think this way. – Imran Sep 17 '12 at 23:12