In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge of this article "how to use the objdump command of Linux", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the objdump command of Linux" article.
The Linux common command objdump command is a gcc tool that uses to view the object file or the composition of the executable object file.
Objdump displays binary file information
The option-a-- archive-headers # displays the information about the members of the archive, similar to ls-l, which lists the information for lib*.a. -b bfdname-- target=bfdname # specifies the object code format. This is not necessary, objdump can automatically recognize many formats, such as: objdump-b oasys-m vax-h fu.o # displays the header summary information of fu.o, clearly indicating that the file is the target file generated by the Oasys compiler under the Vax system. Objdump-I will give you a list of object code formats that can be specified here. C-- demangle # decrypts the underlying symbolic names into user-level names, which not only removes the underscore at the beginning, but also makes the C++ function name display in an understandable way. -- debugging-g # displays debugging information. An attempt is made to parse the debug information saved in the file and display it in C language syntax. Only certain types of debugging information are supported. Some other formats are supported by readelf-w. -e-- debugging-tags # is similar to the-g option, but the generated information is in a format compatible with the ctags tool. -- disassemble-d # disassembles the section of those specific instruction machine codes from objfile. -D-- disassemble-all # is similar to-d, but disassembles all section. When prefix-addresses # disassembles, the full address of each line is displayed. This is an older disassembly format. -EB-EL-- endian= {big | little} # specifies the small end of the target file. This item will affect the disassembled instructions. Used when the disassembled file does not describe the small end information. For example, S-records. -f-- file-headers displays the overall header summary information for each file in the objfile. -h-- section-headers-- headers displays header summary information for each section of the target file. -H-- short help information for help. -I-- info displays a list of schemas and target formats available for the-b or-m options. -j name-- section=name only displays information about the specified section named name-- l-- line-numbers marks the corresponding object code with a file name and line number. Using-ld only with-d,-D, or-r is not very different from using-d. It is useful when debugging at the source code level, requiring debug compilation options such as-g at compile time. -m machine-- architecture=machine specifies the schema to use when disassembling the target file, which is useful when the disassembly file itself does not describe the schema information (such as S-records). You can use the-I option to list the architecture that can be specified here. -- reloc-r shows the relocation entry of the file. If used with-d or-D, the relocation section is displayed in a disassembled format. -- dynamic-reloc-R shows the dynamic relocation entry of the file, which is only meaningful to the dynamic target file, such as some shared libraries. -s-- full-contents displays the full contents of the specified section. By default, all non-empty section will be displayed. -S-- source disassembles the source code as much as possible, especially when the debug parameter-g is specified when compiling. The-d parameter is implied. When show-raw-insn disassembles, displays the machine code corresponding to each assembly instruction. If you do not specify-- prefix-addresses, this will be the default option. When no-show-raw-insn disassembles, the machine code of the assembly instruction is not displayed. If you do not specify-- prefix-addresses, this will be the default option. -- start-address=address displays data from the specified address, which affects the output of the-d,-r, and-s options. -- stop-address=address displays data until the specified address, which affects the output of the-d,-r, and-s options. -t-- syms displays the symbol table entry of the file. Similar to the information provided by nm-s-T-dynamic-syms shows the dynamic symbol table entry of the file, meaning only to the dynamic target file, such as some shared libraries. It displays information similar to that displayed by nm-D |-- dynamic. -V-- version version information-- all-headers-x displays the available header information, including symbol tables and relocation entries. -x is equivalent to-a-f-h-r-t at the same time. -z-- disassemble-zeroes general disassembly output will omit large chunks of zeros, which causes these zeros to be disassembled as well. @ file can centralize the options into a file and then load them using the @ file option. First of all, the source code and compilation instructions on which most of the tests are based are given. The source code is as follows:
Root@localhost [test] # nl mytest.cpp void printTest () {char a; a = 'ajar;} void printTest2 () {int a = 2; axioms 2;} compile the above source code as follows:
[root@localhost test] # Gmail +-c-g mytest.cpp here, the generated file is mytest.o, in order to facilitate the test contains debugging information, the test of the executable file shows similar results.
Check the version number of the objdump currently in use:
[root@localhost test] # objdump-V GNU objdump 2.17.50.0.6-14.el5 20061020 Copyright 2005 free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty. View the information in the archive file:
[root@localhost test] # objdump-a libmy2.an In archive libmy2.a: myfile.o: file format elf32-i386 rwxrwxrwx 0 2724 Nov 16 16:06 2009 myfile.o mytest.o: file format elf32-i386 rw-r--r-- 0727 Jul 13 15:32 2011 mytest.o here, libmy2.an is a static library generated by packaging multiple * .o object files using the ar command. The output of the command is similar to ar-tv, compared to the output of ar-tv as follows:
[root@localhost test] # ar-tv libmy2.a rwxrwxrwx 0 root@localhost test 0 2724 Nov 16 16:06 2009 myfile.o rw-r--r-- 0tha 0727 Jul 13 15:32 2011 mytest.o displays a list of available architectures and target structures:
[root@localhost test] # objdump-i BFD header file version 2.17.50.0.6-14.el5 20061020 elf32-i386 (header little endian, data little endian) i386 a.out-i386-linux (header little endian, data little endian) i386 efi-app-ia32 (header little endian, data little endian) i386 elf64-x86-64 (header little endian, data little endian) i386 elf64-little (header little endian, data little endian) i386 elf64-big (header big endian Data big endian) i386 elf32-little (header little endian, data little endian) i386 elf32-big (header big endian, data big endian) i386 srec (header endianness unknown, data endianness unknown) i386 symbolsrec (header endianness unknown, data endianness unknown) i386 tekhex (header endianness unknown, data endianness unknown) i386 binary (header endianness unknown, data endianness unknown) i386 ihex (header endianness unknown, data endianness unknown) i386 trad-core (header endianness unknown) Data endianness unknown) elf32-i386 a.out-i386-linux efi-app-ia32 elf64-x86-64 i386 elf32-i386 a.out-i386-linux efi-app-ia32 elf64-x86-64 elf64-little elf64-big elf32-little elf32-big srec symbolsrec i386 elf64-little elf64-big elf32-little elf32-big srec symbolsrec tekhex binary ihex trad-core i386 -tekhex binary ihex.-here. The information displayed is a list of schemas and target formats available relative to the-b or-m options.
Display the contents of the text section in the mytest.o file:
[root@localhost test] # objdump-- section=.text-s mytest.o mytest.o: file format elf32-i386 Contents of section .text: 0000 5589e583 ec10c645 ff61c9c3 5589e583 U.E.A. U. 0010 ec10c745 fc020000 008345fc 02c9c3. E.E. Note here that-j or-section cannot be used alone, such as objdump-- section=.text mytest.o will not run successfully.
Disassemble the contents of the text segment in mytest.o and express it in source code as much as possible:
[root@localhost test] # objdump-j. Text-S mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000: void printTest () 0: 55 push% ebp 1: 89 e5 mov% esp,%ebp 3: 83 ec 10 sub $0x10 sub% esp {char a; a ='a' 6: c6 45 ff 61 movb $0x61 esp,%ebp 0xffffffff (% ebp)} a: c9 leave b: c3 ret 000000c: void printTest2 () c: 55 push% ebp d: 89 e5 mov% esp,%ebp f: 83 ec 10 sub $0x10 % esp {int a = 2 12: c7 45 fc 02 00 00 movl $0x2 fc 02 addl 0xfffffffc (% ebp) 0xfffffffc (% ebp)} 1d: c9 leave 1e: c3 ret note that you cannot use-j or-section alone, such as objdump-j. Text mytest.o will not run successfully. In addition, the-S command displays better results for the target files that contain debugging information. If you do not specify the-g option of grub + when compiling, then the target file does not contain debugging information, so the display effect is much worse.
Disassemble the source code of mytest.o:
[root@localhost test] # objdump-S mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000: void printTest () 0: 55 push% ebp 1: 89 e5 mov% esp,%ebp 3: 83 ec 10 sub $0x10 sub% esp {char a; a ='a' 6: c6 45 ff 61 movb $0x61 leave 0xffffffff (% ebp)} a: c9 leave b: c3 ret 0000000c: void printTest2 () c: 55 push% ebp d: 89 e5 mov% esp,%ebp f: 83 ec 10 sub $0x10 % esp {int a = 2 12: c7 45 fc 02 00 00 movl $0x2 fc 0xfffffffc (% ebp) axifc 2; 19: 83 45 fc 02 addl $0xfffffffc (% ebp)} 1d: c9 leave 1e: c3 ret here, especially when the debug parameter-g is specified during compilation, the effect of disassembly is more obvious. The-d parameter is implied.
Display the symbol table entry for the file:
[root@localhost test] # objdump-t mytest.o mytest.o: file format elf32-i386 SYMBOL TABLE: 00000000 l df * ABS* 00000000 mytest.cpp 00000000 l d .text 00000000 .text 00000000 l d .dat a 00000000 .data 00000000 l d .BSS 00000000 .BSS 00000000 l d .debug _ abbrev 00000000 l d .debug _ info 00000000 l d .debug _ info 00000000 l d .debug _ line 00000000 l d .debug _ frame 00000000 .debug _ frame 00000000 l d .debug _ loc 00000000 .debug _ loc 00000000 l d. Debug _ pubnames 00000000 .debug _ pubnames 00000000 l d. Debug _ aranges 00000000 l d. Note.GNU-stack 00000000. Note.GNU-stack 00000000 l d .comment 00000000 .text 0000000c _ Z9printTestv 00000000 * UND* 00000000 _ gxx_personality_v0 0000000c g F .text 00000013 _ Z10printTest2v here The output information is similar to that of the nm-s command. By comparison, the output of the nm command is as follows:
[root@localhost test] # nm-s mytest.o 0000000c T _ Z10printTest2v 00000000 T _ Z9printTestv U _ gxx_personality_v0 displays the symbol table entry of the file, decoding the underlying symbols and representing them at the user level:
[root@localhost test] # objdump-t-C mytest.o mytest.o: file format elf32-i386 SYMBOL TABLE: 00000000 l df * ABS* 00000000 mytest.cpp 00000000 l d .text 00000000 .text 00000000 l d .d ata 00000000 .data 00000000 l d .BSS 00000000 .BSS 00000000 l d .debug _ abbrev 00000000 l d .debug _ info 00000000 .debug _ info 00000000 l d .debug _ line 00000000 l D .debug _ frame 00000000 l d .debug _ loc 00000000 .debug _ loc 00000000 l d. Debug _ pubnames 00000000 .debug _ pubnames 00000000 l d. Debug _ aranges 00000000 .debug _ aranges 00000000 l d. Note.GNU-stack 00000000. Note.GNU-stack 00000000 l d .comment 00000000 .comment 00000000 g F .text 00000c printTest () 00000000 * UND* 00000000 _ gxx_personality _ v00000000c g F. text 00000013 printTest2 () here Compared with no-C, the readability of the printTest2 function is increased.
Disassemble the specific machine code segment of the target file:
[root@localhost test] # objdump-d mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000: 0: 55 push% ebp 1: 89 e5 mov% esp,%ebp 3: 83 ec 10 sub $0x10 % esp 6: c6 45 ff 61 movb $0xffffffff (% ebp) a: c9 leave b: c3 ret 00000000c: C: 55 push% ebp d: 89 e5 mov% esp,%ebp f: 83 ec 10 sub $0x10 % esp 12: c7 45 fc 02 00 00 movl $0x2ret 0xfffffffc (% ebp) 19: 83,45 fc 02 addl $0x2memoir 0xfffffffc (% ebp) 1d: c9 leave 1e: c3 ret here Disassemble the contents of the text section.
Disassemble specific segments and match the file name and line number corresponding to the assembly code:
[root@localhost test] # objdump-d-l mytest.o mytest.o: file format elf32-i386 Disassembly of section .text: 00000000: _ Z9printTestv (): / root/test/04_libraryTest/mytest.cpp:1 0: 55 push% ebp 1: 89 e5 mov% esp,%ebp 3: 83 ec 10 sub $0x10 % esp / root/test/04_libraryTest/mytest.cpp:4 6: c6 45 ff 61 movb $0x61 leave 0xffffffff (% ebp) / root/test/04_libraryTest/mytest.cpp:5 a: C9 leave b: c3 ret 0000000c: _ Z10printTest2v (): / root/test/04_libraryTest/mytest.cpp:6 c: 55 Push% ebp d: 89 e5 mov% esp % ebp f: 83 ec 10 sub $0x10 % esp / root/test/04_libraryTest/mytest.cpp:8 12: c7 45 fc 02 00 00 movl $0x2 root/test/04_libraryTest/mytest.cpp:9 0xfffffffc (% ebp) / root/test/04_libraryTest/mytest.cpp:9 19: 83 45 fc 02 addl $0x2authoring 0xfffffffc (% ebp) / root/test/04_libraryTest/mytest.cpp:10 1d: c9 leave 1e: c3 ret here The item "- d" disassembles the section of those specific instructions from objfile, and uses "- l" to specify that the corresponding object code is marked with a file name and line number, only used with-d,-D or-r, the difference between using-ld and using-d is not very big, it is useful when debugging at the source code level, and requires debugging compilation options such as-g at compile time.
Displays the header summary information for each segment of the target file:
[root@localhost test] # objdump-h mytest.o mytest.o: file format elf32-i386 Sections: Idx Name Size VMA LMA File off Algn 0.text 0000001f 00000000 00000000 00000034 2 CONTENTS, ALLOC, LOAD, readonly, CODE 1 .data 00000000 00000000 0000000000000054 2 CONTENTS, ALLOC, LOAD DATA 2 .bss 00000000 00000000 00000000 00000054 2 questions 2 ALLOC 3. Debug _ abbrev 00000046 00000000 00000000 00000054 2 debugging 0 CONTENTS, READONLY, DEBUGGING 4 .debug _ info 000000ed 000000000000009a 2examples 0 CONTENTS, RELOC, READONLY, DEBUGGING 5 .debug _ line 0000003e 0000000000000187 2 steps 0 CONTENTS, RELOC, READONLY DEBUGGING 6. Debug _ frame 00000044 00000000 00000000 000001c8 2 protocols 2 CONTENTS, RELOC, READONLY, DEBUGGING 7. Debug _ loc 000058 00000000000000000020c 2examples 0 CONTENTS, READONLY, DEBUGGING 8 .debug _ pubnames 0000002f 0000000000000264 2boxes 0 CONTENTS, RELOC, READONLY, DEBUGGING 9 .debug _ aranges 000000200000000000000293 CONTENTS, RELOC, READONLY DEBUGGING 10. Comment 0000002e 00000000 00000000 000002b3 2 CONTENTS, READONLY 11. Note.GNU-stack 00000000 00000000 00000000 000002e1 2 million 0 CONTENTS, READONLY For more information, see this option in man objdump.
The above is about the content of this article on "how to use the objdump command of Linux". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.