There are two ways addr2line
is used in the script in the article you linked:
addr2line -f -e ${EXECUTABLE} ${FADDR}
and:
addr2line -s -e ${EXECUTABLE} ${CADDR}
The first one uses the -f
option, which causes addr2line
to output the function name on a line by itself before showing the filename and line number on a second line. In that script, only the first line is used (it's piped through head -1
).
atos
always outputs the function name, so there's no need for an equivalent to that -f
option. [Whereas addr2line
is short for "address to line" (filename and line number), making the function name ancillary to its main purpose, atos
is short for "address to symbol", so producing the symbol name is its core purpose.]
The next option used for addr2line
is -e ${EXECUTABLE}
. The equivalent for atos
is -o ${EXECUTABLE}
.
After that, the arguments are addresses. That's the same between addr2line
and atos
.
So, the atos
command that corresponds to addr2line -f -e ${EXECUTABLE} ${FADDR}
is atos -o ${EXECUTABLE} ${FADDR}
. However, the script is "parsing" the output from the command and the two programs produce output in different formats. To get just the function name from the output of atos
, you can pipe it through perl -lne 'print "$1" if m/^(.*) \(in .*\)/'
.
The second type of addr2line
command does not use the -f
option, so it doesn't print the function name. It's just used to get the filename and line number. As mentioned before, atos
always prints the function name. So, the atos
command is the same as before. To get just the file name and line number from its output, you can pipe it through perl -lne 'print "$1" if m/^.* \(in .*\) \((.*)\)$/'
.
This addr2line
command also uses the -s
option. That makes it print only the basename of the file path, not the whole path. That's what atos
does anyway, so there's no need to translate that option to anything.