perf annotate: Fix objdump comment parsing for Intel mov dissassembly
PATCH 1/1 perf annotate: Fix objdump comment parsing for Intel mov dissassembly
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>
and the function mov__parse() is called to investigate the complete line. Mov__parse() breaks this line into several parts and finally calls function comment__symbol() to parse the data after the comment character '#'. Comment__symbol() expects a hexadecimal address followed by a symbol in '<' and '>' brackets.
However the 2nd parameter given to function comment__symbol() always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit and strtoull() fails without being noticed.
Fix this by advancing the second parameter to function comment__symbol() by one byte before invocation and add an error check after strtoull() has been called.
--- tools/perf/util/annotate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/annotate.c +5 -3
@@ -323,6 +323,8 @@ static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep)return 0 ; *addrp =strtoull (comment, &endptr,16 ); +if (endptr == comment) +return 0 ; name =strchr (endptr,'<' );if (name ==NULL )return -1 ;
@@ -436,8 +438,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map *mreturn 0 ; comment =ltrim (comment); -comment__symbol (ops->source.raw, comment, &ops->source.addr, &ops->source.name); -comment__symbol (ops->target.raw, comment, &ops->target.addr, &ops->target.name); +comment__symbol (ops->source.raw, comment +1 , &ops->source.addr, &ops->source.name); +comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);return 0 ;
@@ -481,7 +483,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *opsreturn 0 ; comment =ltrim (comment); -comment__symbol (ops->target.raw, comment, &ops->target.addr, &ops->target.name); +comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);return 0 ; }
Signature · 1 line
2.13.4
Quoted 13 lines · Thomas Richter
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>and the function
mov__parse()is called to investigate the complete line.Mov__parse()breaks this line into several parts and finally calls functioncomment__symbol()to parse the data after the comment character '#'.Comment__symbol()expects a hexadecimal address followed by a symbol in '<' and '>' brackets.
Quoted 8 lines
However the 2nd parameter given to function
comment__symbol()always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit andstrtoull()fails without being noticed.Fix this by advancing the second parameter to function
comment__symbol()by one byte before invocation and add an error check afterstrtoull()has been called.
Yeah, looks like it fails to get correct value in 'addrp'.
Can you please show the difference in perf annotate output before and after patch.
Thanks,
Ravi
Quoted 25 lines · Ravi Bangoria
Quoted 13 lines · Thomas Richter
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>and the function
mov__parse()is called to investigate the complete line.Mov__parse()breaks this line into several parts and finally calls functioncomment__symbol()to parse the data after the comment character '#'.Comment__symbol()expects a hexadecimal address followed by a symbol in '<' and '>' brackets.Quoted 8 lines
However the 2nd parameter given to function
comment__symbol()always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit andstrtoull()fails without being noticed.Fix this by advancing the second parameter to function
comment__symbol()by one byte before invocation and add an error check afterstrtoull()has been called.
Quoted 8 lines
Yeah, looks like it fails to get correct value in 'addrp'.
Can you please show the difference in perf annotate output before and after patch.
Thanks,
Ravi
There is no difference in output of --stdio. The adress value is not read and remains 0x0 in ops->source.addr or ops->target.addr. That is not visible because in function mov__scnprintf() that wrong address is not printed:
static int mov__scnprintf(struct ins *ins, char *bf, size_t size,
struct ins_operands *ops)
{
return scnprintf(bf, size, "%-6.6s %s,%s", ins->name,
ops->source.name ?: ops->source.raw,
ops->target.name ?: ops->target.raw);
}Signature · 5 lines
Thomas Richter, Dept 3303, IBM LTC Boeblingen Germany -- Vorsitzende des Aufsichtsrats: Martina Koederitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294
Quoted 38 lines · Thomas-Mich Richter
Quoted 23 lines · Ravi Bangoria
Quoted 13 lines · Thomas Richter
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>and the function
mov__parse()is called to investigate the complete line.Mov__parse()breaks this line into several parts and finally calls functioncomment__symbol()to parse the data after the comment character '#'.Comment__symbol()expects a hexadecimal address followed by a symbol in '<' and '>' brackets.Quoted 8 lines
However the 2nd parameter given to function
comment__symbol()always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit andstrtoull()fails without being noticed.Fix this by advancing the second parameter to function
comment__symbol()by one byte before invocation and add an error check afterstrtoull()has been called.Quoted 8 lines
Yeah, looks like it fails to get correct value in 'addrp'.
Can you please show the difference in perf annotate output before and after patch.
Thanks,
RaviThere is no difference in output of --stdio. The adress value is not read and remains
0x0inops->source.addrorops->target.addr. That is not visible because in functionmov__scnprintf()that wrong address is not printed:
Quoted 7 lines
static int mov__scnprintf(struct ins *ins, char *bf,
size_tsize,
structins_operands*ops){ return scnprintf(bf, size, "%-6.6s %s,%s", ins->name, ops->source.name ?: ops->source.raw, ops->target.name ?: ops->target.raw); }
Looks good. Ack-by: Ravi Bangoria <[email protected]>
Thanks,
Ravi
Em Wed, Nov 29, 2017 at 08:52:13PM +0530, Ravi Bangoria escreveu:
Quoted 49 lines · Thomas-Mich Richter
Quoted 38 lines · Ravi Bangoria
Quoted 23 lines · Thomas Richter
Quoted 13 lines
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>and the function
mov__parse()is called to investigate the complete line.Mov__parse()breaks this line into several parts and finally calls functioncomment__symbol()to parse the data after the comment character '#'.Comment__symbol()expects a hexadecimal address followed by a symbol in '<' and '>' brackets.Quoted 8 lines
However the 2nd parameter given to function
comment__symbol()always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit andstrtoull()fails without being noticed.Fix this by advancing the second parameter to function
comment__symbol()by one byte before invocation and add an error check afterstrtoull()has been called.Quoted 8 lines
Yeah, looks like it fails to get correct value in 'addrp'.
Can you please show the difference in perf annotate output before and after patch.
Thanks,
RaviThere is no difference in output of --stdio. The adress value is not read and remains
0x0inops->source.addrorops->target.addr. That is not visible because in functionmov__scnprintf()that wrong address is not printed:Quoted 7 lines
static int mov__scnprintf(struct ins *ins, char *bf,
size_tsize,
structins_operands*ops){ return scnprintf(bf, size, "%-6.6s %s,%s", ins->name, ops->source.name ?: ops->source.raw, ops->target.name ?: ops->target.raw); }
Quoted 1 line
Looks good. Ack-by: Ravi Bangoria <[email protected]>
Thanks, applied.
- Arnaldo
tip-bot for Thomas Richter
merge botperf annotate: Fix objdump comment parsing for Intel mov dissassembly
Commit-ID: 35a8a148d8c1ee9e5ae18f9565a880490f816f89 Gitweb: https://git.kernel.org/tip/35a8a148d8c1ee9e5ae18f9565a880490f816f89 Author: Thomas Richter <[email protected]> AuthorDate: Tue, 28 Nov 2017 08:56:32 +0100 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 5 Dec 2017 10:24:30 -0300
perf annotate: Fix objdump comment parsing for Intel mov dissassembly
The command 'perf annotate' parses the output of objdump and also investigates the comments produced by objdump. For example the output of objdump produces (on x86):
23eee: 4c 8b 3d 13 01 21 00 mov 0x210113(%rip),%r15
# 234008 <stderr@@GLIBC_2.2.5+0x9a8>
and the function mov__parse() is called to investigate the complete line. Mov__parse() breaks this line into several parts and finally calls function comment__symbol() to parse the data after the comment character '#'. Comment__symbol() expects a hexadecimal address followed by a symbol in '<' and '>' brackets.
However the 2nd parameter given to function comment__symbol() always points to the comment character '#'. The address parsing always returns 0 because the character '#' is not a digit and strtoull() fails without being noticed.
Fix this by advancing the second parameter to function comment__symbol() by one byte before invocation and add an error check after strtoull() has been called.
--- tools/perf/util/annotate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/annotate.c +5 -3
@@ -322,6 +322,8 @@ static int comment__symbol(char *raw, char *comment, u64 *addrp, char **namep)return 0 ; *addrp =strtoull (comment, &endptr,16 ); +if (endptr == comment) +return 0 ; name =strchr (endptr,'<' );if (name ==NULL )return -1 ;
@@ -435,8 +437,8 @@ static int mov__parse(struct arch *arch, struct ins_operands *ops, struct map *mreturn 0 ; comment =ltrim (comment); -comment__symbol (ops->source.raw, comment, &ops->source.addr, &ops->source.name); -comment__symbol (ops->target.raw, comment, &ops->target.addr, &ops->target.name); +comment__symbol (ops->source.raw, comment +1 , &ops->source.addr, &ops->source.name); +comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);return 0 ;
@@ -480,7 +482,7 @@ static int dec__parse(struct arch *arch __maybe_unused, struct ins_operands *opsreturn 0 ; comment =ltrim (comment); -comment__symbol (ops->target.raw, comment, &ops->target.addr, &ops->target.name); +comment__symbol (ops->target.raw, comment +1 , &ops->target.addr, &ops->target.name);return 0 ; }