Dumping C and Assembly with objdump

I just came across the objdump “–source” option, which will display the C source code from a program along with the assembly instructions that were generated from the C code. The following example shows a snippet of what is produced during a typical run:

$ objdump –source curl

08050ed0 <homedir >:

/* return the home directory of the current user as an allocated string */
char *homedir(void)
 8050ed0:       55                      push   %ebp
  char *home;

  home = GetEnv("CURL_HOME", FALSE);
 8050ed1:       31 d2                   xor    %edx,%edx
 8050ed3:       89 e5                   mov    %esp,%ebp
 8050ed5:       b8 01 d0 05 08          mov    $0x805d001,%eax
 8050eda:       53                      push   %ebx
 8050edb:       83 ec 04                sub    $0x4,%esp
 8050ede:       e8 bd ff ff ff          call   8050ea0 
 8050ee3:       85 c0                   test   %eax,%eax
 8050ee5:       89 c3                   mov    %eax,%ebx
 8050ee7:       74 08                   je     8050ef1 
    return home;

  home = GetEnv("HOME", FALSE);
    return home;

#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
   struct passwd *pw = getpwuid(geteuid());

   if (pw) {
#ifdef VMS
     home = decc$translate_vms(pw->pw_dir);
     home = pw->pw_dir;
     if (home && home[0])
       home = strdup(home);
#endif /* PWD-stuff */
#ifdef WIN32
  home = GetEnv("APPDATA", TRUE);
    home = GetEnv("%USERPROFILE%\\Application Data", TRUE); /* Normally only
                                                               on Win-2K/XP */
#endif /* WIN32 */
  return home;
 8050ee9:       89 d8                   mov    %ebx,%eax
 8050eeb:       83 c4 04                add    $0x4,%esp
 8050eee:       5b                      pop    %ebx
 8050eef:       5d                      pop    %ebp
 8050ef0:       c3                      ret    
 8050ef1:       31 d2                   xor    %edx,%edx
 8050ef3:       b8 06 d0 05 08          mov    $0x805d006,%eax
 8050ef8:       e8 a3 ff ff ff          call   8050ea0 
 8050efd:       85 c0                   test   %eax,%eax
 8050eff:       89 c3                   mov    %eax,%ebx
 8050f01:       75 e6                   jne    8050ee9 
 8050f03:       e8 3c 89 ff ff          call   8049844 
 8050f08:       89 04 24                mov    %eax,(%esp)
 8050f0b:       e8 54 85 ff ff          call   8049464 
 8050f10:       85 c0                   test   %eax,%eax
 8050f12:       74 d5                   je     8050ee9 
 8050f14:       8b 58 14                mov    0x14(%eax),%ebx
 8050f17:       85 db                   test   %ebx,%ebx
 8050f19:       74 ce                   je     8050ee9 
 8050f1b:       80 3b 00                cmpb   $0x0,(%ebx)
 8050f1e:       89 f6                   mov    %esi,%esi
 8050f20:       74 c7                   je     8050ee9 
 8050f22:       89 1c 24                mov    %ebx,(%esp)
 8050f25:       e8 7a 87 ff ff          call   80496a4 <__strdup@plt>
 8050f2a:       89 c3                   mov    %eax,%ebx
 8050f2c:       eb bb                   jmp    8050ee9 
 8050f2e:       90                      nop    
 8050f2f:       90                      nop    

This is neat!

1 thought on “Dumping C and Assembly with objdump”

Leave a Reply

Your email address will not be published. Required fields are marked *