View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0001676||OpenFOAM||[All Projects] Bug||public||2015-04-28 14:59||2015-05-19 08:46|
|Fixed in Version|
|Summary||0001676: printStack implementation|
|Description||Currently printStack function is implemented using backtrace_symbols call.|
It takes string array returned by the call, parses these strings for symbol
name/address/offset, and finally uses addr2line utility for extract debug
information. Most of the time this procedure works OK except when the function
is not able to parse symbol name correctly.
backtrace_symbols itself uses dladdr to query stack address for file name,
symbol name, file base address, and symbol address. After it calculates size of
the string to host information, and writes it there using sprintf . Though
dladdr is not in POSIX, it is available in GNU and BSD libc. Also dladdr is
used in printSourceFileAndLine function, so, I guess, its absence in POSIX was
not the reason for current printStack implementation.
Please find printStack.C file rewritten to utilize dladdr for resolution of the
stack addresses. It was tested in Scientific Linux 7.1 / OpenFOAM 2.3.x and the
output seems to be reasonable. Also symbol name parsing bug has gone. I have
decided to attach the file instead of a patch as original file is almost
To illustrate new and old behavior of printStack I also attached logs of
several crashes (cavity icoFoam tutorial case with negative kinematic
viscosity). *.orig.Debug and *.orig.Opt are output of the original function
built with and without debug symbols. *.new.* are the same outputs with new
implementation. Problems with symbol name parsing in the original function
appear at #7, #8, and #9 in printStack.log.orig.Opt.
|Tags||No tags attached.|
printStack.C (5,648 bytes)
printStack.log.orig.Opt (2,098 bytes)
printStack.log.orig.Debug (2,931 bytes)
printStack.log.new.Opt (2,107 bytes)
printStack.log.new.Debug (2,940 bytes)
Thanks for the update of printStack. Could you clarify what the advantage of the method is? Looking at the logs you provided:
#9 __libc_start_main in "/lib64/libc.so.6"
#7 ? at ??:?
#8 ? at ??:?
#9 __libc_start_main in "/usr/lib64/libc.so.6"
the only difference appears to be the "/usr" in the new log other than the spurious newlines in the old log.
1. As you have mentioned, symbol parsing errors are gone. I.e. there will be no more spurious new lines during printStack.
2. Old procedure is redundant
backtrace -> backtrace_symbols (dladdr -> sprintf -> string) -> parse address from string -> dladdr -> execute addr2line
new one is shorter
backtrace -> dladdr -> execute addr2line
3. Removed unused hash table addressMap.
4. As dladdr is used directly, new method is protected from possible future changes of backtrace_symbols sprintf format.
5. In fact I did not pay attention to absent "/usr" part. So old version also had problems with file name parsing. New version does not have them.
6. Due to exclusion of redundant steps new version is shorter and clearer (though here I can be biased).
||Thanks for the details. I will test you new method on a range of GNU/Linux distributions here.|
Thanks for the patch and explanations. I have tested it on several systems with several compilers and it works well.
I have included it in OpenFOAM-2.3.x:
|2015-04-28 14:59||alexeym||New Issue|
|2015-04-28 14:59||alexeym||File Added: printStack.C|
|2015-04-28 14:59||alexeym||File Added: printStack.log.orig.Opt|
|2015-04-28 14:59||alexeym||File Added: printStack.log.orig.Debug|
|2015-04-28 15:00||alexeym||File Added: printStack.log.new.Opt|
|2015-04-28 15:00||alexeym||File Added: printStack.log.new.Debug|
|2015-04-29 09:59||henry||Note Added: 0004688|
|2015-04-29 13:19||alexeym||Note Added: 0004690|
|2015-04-29 13:22||henry||Note Added: 0004691|
|2015-05-19 08:46||henry||Note Added: 0004774|
|2015-05-19 08:46||henry||Status||new => resolved|
|2015-05-19 08:46||henry||Resolution||open => fixed|
|2015-05-19 08:46||henry||Assigned To||=> henry|