public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [objdump Question] How to sort assembly code by each line number ?
@ 2017-02-21  6:01 Taeung Song
  2017-02-21  9:53 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Taeung Song @ 2017-02-21  6:01 UTC (permalink / raw)
  To: binutils

Hi all :)

I'm modifying perf-annotate (that are Linux kernel : tools/perf)
a perf tool use objdump with -d and -l or -S.

By the way,
If objdump has the option sorting assembly code according to line numbers,
I want to use the option.

For example,
I want to sort the below output.
(especially parts of assembly code of line number 34)

--

Disassembly of section .text:

0000000000400966 <get_cond_maxprice>:
get_cond_maxprice():

...

/home/taeung/workspace/perf-test/old_pack_knapsack.c:32
   40098d:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%rbp)
/home/taeung/workspace/perf-test/old_pack_knapsack.c:34
   400994:	c7 45 ec 01 00 00 00 	movl   $0x1,-0x14(%rbp)
   40099b:	eb 4d                	jmp    4009ea <get_cond_maxprice+0x84>
/home/taeung/workspace/perf-test/old_pack_knapsack.c:37
   40099d:	8b 55 dc             	mov    -0x24(%rbp),%edx

...

/home/taeung/workspace/perf-test/old_pack_knapsack.c:34 (discriminator 2)
   4009e6:	83 45 ec 01          	addl   $0x1,-0x14(%rbp)
/home/taeung/workspace/perf-test/old_pack_knapsack.c:34 (discriminator 1)
   4009ea:	8b 45 ec             	mov    -0x14(%rbp),%eax
   4009ed:	3b 45 f4             	cmp    -0xc(%rbp),%eax
   4009f0:	76 ab                	jbe    40099d

...

If there isn't the option for it, I'd manually parse the output from 
'objdump -dl'..

Thanks,
Taeung

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [objdump Question] How to sort assembly code by each line number ?
  2017-02-21  6:01 [objdump Question] How to sort assembly code by each line number ? Taeung Song
@ 2017-02-21  9:53 ` Nick Clifton
  2017-02-21 12:27   ` Pedro Alves
  2017-02-22  8:13   ` Taeung Song
  0 siblings, 2 replies; 5+ messages in thread
From: Nick Clifton @ 2017-02-21  9:53 UTC (permalink / raw)
  To: Taeung Song, binutils

Hi Taeung,

> If objdump has the option sorting assembly code according to line numbers,
> I want to use the option.

Sorry - objdump has no such option.

> For example,
> I want to sort the below output.
> (especially parts of assembly code of line number 34)

The problem is that the same line of source code can appear in lots of places
in the assembler (for example because of macros, inline functions, templates, etc).
Plus compiler optimizations like loop unrolling can replicate the same line
of source code multiple times in the assembler output.  So there really is no
easy way to produce *meaningful* disassembly sorted by line number.

> If there isn't the option for it, I'd manually parse the output from 'objdump -dl'..

You can of course write a script to perform this sorting for you, so that you
do not have to do it by hand every time.

Cheers
  Nick


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [objdump Question] How to sort assembly code by each line number ?
  2017-02-21  9:53 ` Nick Clifton
@ 2017-02-21 12:27   ` Pedro Alves
  2017-02-22  8:22     ` Taeung Song
  2017-02-22  8:13   ` Taeung Song
  1 sibling, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2017-02-21 12:27 UTC (permalink / raw)
  To: Nick Clifton, Taeung Song, binutils

On 02/21/2017 09:53 AM, Nick Clifton wrote:
> Hi Taeung,
> 
>> If objdump has the option sorting assembly code according to line numbers,
>> I want to use the option.
> 
> Sorry - objdump has no such option.
> 
>> For example,
>> I want to sort the below output.
>> (especially parts of assembly code of line number 34)
> 
> The problem is that the same line of source code can appear in lots of places
> in the assembler (for example because of macros, inline functions, templates, etc).
> Plus compiler optimizations like loop unrolling can replicate the same line
> of source code multiple times in the assembler output.  So there really is no
> easy way to produce *meaningful* disassembly sorted by line number.
> 
>> If there isn't the option for it, I'd manually parse the output from 'objdump -dl'..
> 
> You can of course write a script to perform this sorting for you, so that you
> do not have to do it by hand every time.

Might be easier to use GDB for this.  GDB's disassemble command has a
modifier that sorts by source line instead of address.  For example:

 $ gdb --batch -ex "disassemble /m function" PROGRAM

Funny enough the "/m" modifier is deprecated because
it wasn't found useful:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(gdb) help disassemble 
Disassemble a specified section of memory.
Default is the function surrounding the pc of the selected frame.

With a /m modifier, source lines are included (if available).
This view is "source centric": the output is in source line order,
regardless of any optimization that is present.  Only the main source file
is displayed, not those of, e.g., any inlined functions.
This modifier hasn't proved useful in practice and is deprecated
in favor of /s.

With a /s modifier, source lines are included (if available).
This differs from /m in two important respects:
- the output is still in pc address order, and
- file names and contents for all relevant source files are displayed.
[....]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

gdb uses the same library as objdump for the actual instruction
disassembly, so the output should be similar/familiar.

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [objdump Question] How to sort assembly code by each line number ?
  2017-02-21  9:53 ` Nick Clifton
  2017-02-21 12:27   ` Pedro Alves
@ 2017-02-22  8:13   ` Taeung Song
  1 sibling, 0 replies; 5+ messages in thread
From: Taeung Song @ 2017-02-22  8:13 UTC (permalink / raw)
  To: Nick Clifton; +Cc: binutils

Hi Nick,

I'm sorry for my tardy response.
Thank you so much !! for your detailed answer !

Thanks,
Taeung

On 02/21/2017 06:53 PM, Nick Clifton wrote:
> Hi Taeung,
>
>> If objdump has the option sorting assembly code according to line numbers,
>> I want to use the option.
>
> Sorry - objdump has no such option.
>
>> For example,
>> I want to sort the below output.
>> (especially parts of assembly code of line number 34)
>
> The problem is that the same line of source code can appear in lots of places
> in the assembler (for example because of macros, inline functions, templates, etc).
> Plus compiler optimizations like loop unrolling can replicate the same line
> of source code multiple times in the assembler output.  So there really is no
> easy way to produce *meaningful* disassembly sorted by line number.
>
>> If there isn't the option for it, I'd manually parse the output from 'objdump -dl'..
>
> You can of course write a script to perform this sorting for you, so that you
> do not have to do it by hand every time.
>
> Cheers
>   Nick
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [objdump Question] How to sort assembly code by each line number ?
  2017-02-21 12:27   ` Pedro Alves
@ 2017-02-22  8:22     ` Taeung Song
  0 siblings, 0 replies; 5+ messages in thread
From: Taeung Song @ 2017-02-22  8:22 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Nick Clifton, binutils

Hi Pedro :)

Thanks for your kind answer!
I didn't consider gdb but if using gdb for my purpose as you said,
it seems like a great idea! :)

Thanks,
Taeung

On 02/21/2017 09:27 PM, Pedro Alves wrote:
> On 02/21/2017 09:53 AM, Nick Clifton wrote:
>> Hi Taeung,
>>
>>> If objdump has the option sorting assembly code according to line numbers,
>>> I want to use the option.
>>
>> Sorry - objdump has no such option.
>>
>>> For example,
>>> I want to sort the below output.
>>> (especially parts of assembly code of line number 34)
>>
>> The problem is that the same line of source code can appear in lots of places
>> in the assembler (for example because of macros, inline functions, templates, etc).
>> Plus compiler optimizations like loop unrolling can replicate the same line
>> of source code multiple times in the assembler output.  So there really is no
>> easy way to produce *meaningful* disassembly sorted by line number.
>>
>>> If there isn't the option for it, I'd manually parse the output from 'objdump -dl'..
>>
>> You can of course write a script to perform this sorting for you, so that you
>> do not have to do it by hand every time.
>
> Might be easier to use GDB for this.  GDB's disassemble command has a
> modifier that sorts by source line instead of address.  For example:
>
>  $ gdb --batch -ex "disassemble /m function" PROGRAM
>
> Funny enough the "/m" modifier is deprecated because
> it wasn't found useful:
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> (gdb) help disassemble
> Disassemble a specified section of memory.
> Default is the function surrounding the pc of the selected frame.
>
> With a /m modifier, source lines are included (if available).
> This view is "source centric": the output is in source line order,
> regardless of any optimization that is present.  Only the main source file
> is displayed, not those of, e.g., any inlined functions.
> This modifier hasn't proved useful in practice and is deprecated
> in favor of /s.
>
> With a /s modifier, source lines are included (if available).
> This differs from /m in two important respects:
> - the output is still in pc address order, and
> - file names and contents for all relevant source files are displayed.
> [....]
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> gdb uses the same library as objdump for the actual instruction
> disassembly, so the output should be similar/familiar.
>
> Thanks,
> Pedro Alves
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-22  8:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21  6:01 [objdump Question] How to sort assembly code by each line number ? Taeung Song
2017-02-21  9:53 ` Nick Clifton
2017-02-21 12:27   ` Pedro Alves
2017-02-22  8:22     ` Taeung Song
2017-02-22  8:13   ` Taeung Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).