How to get source code inter mixed in disassembly code

Asked by Sandeep Gor

I want to generate ARM disassembly from AFX using fromelf or any other utility with the source code intermixed with disassembly code.

GCC compiler utility objdump has option “-S” which allows me to do that, but I could not find similar option in fromelf utility. I’ve seen such disassemble code being generated by ARM compiler tool chain some time back, but I do not know how to do that.

So, how do I do it?

Sample disassembly code generatd by objdump is given below.

//C Source File
#include "stdio.h"

void getCurrEl(int *el)
{
     printf ("FUNC : el=%x *el=%x\n", el, &el);
     if (el == 0)
     {
          printf ("el=0\n");
     }
     else
     {
          printf ("el!=0\n");
     };
};

void main(void)
{
     unsigned int el = 0;
     printf ("MAIN : el=%x *el=%x\n", el, &el);
     getCurrEl(&el);
};

//Sample code of disassembly file generated using $>objdump -d -S a.out command
00000000004004c8 <getCurrEl>:
#include "stdio.h"

void getCurrEl(int *el)
{
  4004c8: 55 push %rbp
  4004c9: 48 89 e5 mov %rsp,%rbp
  4004cc: 48 83 ec 10 sub $0x10,%rsp
  4004d0: 48 89 7d f8 mov %rdi,-0x8(%rbp)
     printf ("FUNC : el=%x *el=%x\n", el, &el);
  4004d4: 48 8b 75 f8 mov -0x8(%rbp),%rsi
  4004d8: 48 8d 55 f8 lea -0x8(%rbp),%rdx
  4004dc: bf 2c 06 40 00 mov $0x40062c,%edi
  4004e1: b8 00 00 00 00 mov $0x0,%eax
  4004e6: e8 ed fe ff ff callq 4003d8 <printf@plt>
     if (el == 0)
  4004eb: 48 8b 45 f8 mov -0x8(%rbp),%rax
  4004ef: 48 85 c0 test %rax,%rax
  4004f2: 75 0c jne 400500 <getCurrEl+0x38>
     {
          printf ("el=0\n");
  4004f4: bf 43 06 40 00 mov $0x400643,%edi
  4004f9: e8 ea fe ff ff callq 4003e8 <puts@plt>
  4004fe: eb 0a jmp 40050a <getCurrEl+0x42>
     }
     else
     {
          printf ("el!=0\n");
  400500: bf 48 06 40 00 mov $0x400648,%edi
  400505: e8 de fe ff ff callq 4003e8 <puts@plt>
     };
};
  40050a: c9 leaveq
  40050b: c3 retq

000000000040050c <main>:

void main(void)
{
  40050c: 55 push %rbp
  40050d: 48 89 e5 mov %rsp,%rbp
  400510: 48 83 ec 10 sub $0x10,%rsp
     unsigned int el = 0;
  400514: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
     printf ("MAIN : el=%x *el=%x\n", el, &el);
  40051b: 8b 75 fc mov -0x4(%rbp),%esi
  40051e: 48 8d 55 fc lea -0x4(%rbp),%rdx
  400522: bf 4e 06 40 00 mov $0x40064e,%edi
  400527: b8 00 00 00 00 mov $0x0,%eax
  40052c: e8 a7 fe ff ff callq 4003d8 <printf@plt>
     getCurrEl(&el);
  400531: 48 8d 7d fc lea -0x4(%rbp),%rdi
  400535: e8 8e ff ff ff callq 4004c8 <getCurrEl>
};

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#1

Hi Sandeep,

This forum is dedicated to questions related to the GNU ARM Embedded Toolchain, which fromelf is not part of. I suggest you ask your question again in the tools section of ARM Connected Community [1].

[1] https://community.arm.com/groups/tools

Best regards.

Can you help with this problem?

Provide an answer of your own, or ask Sandeep Gor for more information if necessary.

To post a message you must log in.