glog icon indicating copy to clipboard operation
glog copied to clipboard

Add filename / line number to stack traces on Windows.

Open bmahler opened this issue 5 years ago • 0 comments

Currently the glog stack trace facilities on Windows do not include file name and line number information (nor does the code for Linux as far as I can tell).

It's possible to retrieve file name and line number information using the following:

// Include SYMOPT_LOAD_LINES in SymSetOptions:
SymSetOptions(... | SYMOPT_LOAD_LINES);

...

// Later, when calling SymFromAddr, also call SymGetLineFromAddr64:
DWORD lineDisplacement = 0;
IMAGEHLP_LINE64 line = {};
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);

BOOL lineFound = SymGetLineFromAddr64(
    GetCurrentProcess(),
    reinterpret_cast<DWORD64>(pc),
    &lineDisplacement,
    &line);

I was able to use this to dump file names and line numbers:

E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	google::protobuf::internal::RepeatedPtrIterator<mesos::Resource_ReservationInfo const >::operator* [00007FF676253FEE+14] (c:\users\administrator\workspace\mesos\mesos_ci_windows-build-wip\mesos\build\3rdparty\protobuf-3.5.0\src\protobuf-3.5.0\src\google\protobuf\repeated_field.h:2266)
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000000D03DFFCA40+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	mesos::authorization::ActionObject::reserve [00007FF6778AFE40+720] (c:\users\administrator\workspace\mesos\mesos_ci_windows-build-wip\mesos\src\master\authorization.cpp:236)
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000000D03DFFC8A8+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000000D03DFFC9E8+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000000D03DFFC558+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [CCCCCCCCCCCCCCCC+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [CCCCCCCCCCCCCCCC+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000002ADCACC50F0+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000002ADC8AA0690+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000002ADC8AA0790+0]
E0000 00:00:00.000000  5928 logging.cpp:308] RAW: 	(No symbol) [000002ADC8AA0790+0]
...

Including these would helpful for debugging!

bmahler avatar Mar 13 '20 21:03 bmahler