Prepare to follow the Iostat (included in the Sysstat software package) source code. Create a new Makefile project in Eclipse and import the source code for Sysstat 9.1.3. Code can be compiled, compiled Iostat can also run normally. However, the breakpoint in the code does not work when Eclipse debugging runs but prompts "function ' main ' not defined."
Debugging with GDB at the command line also prompts "function ' main ' not defined" when a breakpoint is set on the main function.
The Iostat is disassembled with Objdump, and a "call __libc_start_main" is seen in the assembly code. In GdB, we set a breakpoint on the __libc_start_main function, succeeding, stepping through, but following the libc-start.c "result = Main (argc, argv, __environ main_auxvec_param)" This line will never be followed.
Build a contrast C project in Eclipse, compile it, and then use the Objdump disassembly to discover that the "symbol table". Symtab ' "In the disassembly result contains the symbol" main ", but not in the iostat of the front disassembly.
Then consider whether the GCC compilation parameters for the two projects are different, and then compare:
Iostat:
Compile:
Gcc-o iostat.o-c-g3-o0-wall-wstrict-prototypes-pipe-o0-dsa_dir=/"/var/log/sa/"-DSADC_PATH=/"/usr/local/lib/sa/s" adc/"-duse_nls-dpackage=/" sysstat/"-dlocaledir=/"/usr/local/share/locale/"iostat.c"
Link:
Gcc-o iostat-g3-o0-wall-wstrict-prototypes-pipe-o0 IOSTAT.O LIBRDSTATS.A libsyscom.a-s
Compare C Project:
Compile:
Gcc-o0-g3-wall-c-fmessage-length=0-mmd-mp-mf "TTT.D"-MT "TTT.D"-O "TTT.O" ". /ttt.c "
Link:
Gcc-o "Testtest"./TTT.O
A lot of differences in parameters, after a number of access to data, found that the problem in the Iostat link parameters of "-S", the GCC manual written "-S" role is "Remove all symbol table and relocation information from the" Executable ".
So into the Sysstat project makefile, "Lflags" in the "-S" deleted. In this way, the iostat can be debugged properly. I do not know much about GCC, this small problem on a half-day, but also let me learn a lot.