This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 2/2] Introduce the gcc option --record-gcc-command-line
Hi!
On Wed, Nov 06, 2019 at 06:21:34PM +0100, Egeyar Bagcioglu wrote:
> +static const char *
> +record_gcc_command_line_spec_function(int argc ATTRIBUTE_UNUSED, const char **argv)
> +{
> + const char *filename = argv[0];
> + FILE *out = fopen (filename, "w");
> + if (out)
> + {
> + fputs (_gcc_argv[0], out);
> + for (int i = 1; i < _gcc_argc; i += 1)
> + {
> + fputc (' ', out);
> + fputs (_gcc_argv[i], out);
> + }
> + fclose (out);
> + }
> + return filename;
> +}
Pet peeve: just use fprintf?
If there is an error, should this return 0 or indicate error some way?
Making the error silent ("if (out)") seems weird, otherwise -- if it is
on purpose, a comment might help.
> +int
> +elf_record_gcc_command_line ()
> +{
> + char cmdline[256];
> + section * sec;
section *sec;
> + sec = get_section (targetm.asm_out.record_gcc_switches_section,
> + SECTION_DEBUG | SECTION_MERGE
> + | SECTION_STRINGS | (SECTION_ENTSIZE & 1),
> + NULL);
> + switch_to_section (sec);
> +
> + ASM_OUTPUT_ASCII(asm_out_file, version_string, strlen(version_string));
> +
> + FILE *out_stream = fopen (gcc_command_line_file, "r");
> + if (out_stream)
> + {
> + ASM_OUTPUT_ASCII(asm_out_file, " : ", 3);
> + ssize_t cmdline_length;
> + while ((cmdline_length = fread(cmdline, 1, 256, out_stream)))
fread (
(and many more like it).
> + ASM_OUTPUT_ASCII(asm_out_file, cmdline, cmdline_length);
> + }
> + cmdline[0] = 0;
> + ASM_OUTPUT_ASCII(asm_out_file, cmdline, 1);
> +
> + /* The return value is currently ignored by the caller, but must be 0. */
> + return 0;
> +}
A temporary file like this isn't so great. Opening a file as "r" but then
accessing it with "fread" is peculiar, too.
HTH,
Segher