This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [objdump Question] How to sort assembly code by each line number ?

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! :)


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.

Pedro Alves

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]