Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@redhat.com>
To: Yao Qi <yao@codesourcery.com>
Cc: <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/5] Save trace into CTF format
Date: Fri, 01 Mar 2013 19:22:00 -0000	[thread overview]
Message-ID: <87621avsam.fsf@fleche.redhat.com> (raw)
In-Reply-To: <512F38CE.5030802@codesourcery.com> (Yao Qi's message of "Thu, 28	Feb 2013 19:00:30 +0800")

>>>>> "Yao" == Yao Qi <yao@codesourcery.com> writes:

Yao> +/* Handler of writing trace of CTF format.  */
Yao> +
Yao> +struct trace_write_handler

I don't think that comment is very useful.
Perhaps it could just say that this is the state kept while writing a
CTF file.  Assuming that is what it is.

Yao> +  if (fwrite (buf, size, 1, fd) != 1)
Yao> +    error (_("Unable to write file for saving trace data (%s)"),
Yao> +	   safe_strerror (errno));

We had this whole thread about using ui-out with patches and everything.
Upthread you said that it was abandoned due to lack of error checking on
write.  But I thought that was addressed in the previous thread?

I suppose I don't really care enough to press it.
I don't recall offhand why I thought it was important; maybe some code
duplication, but I don't really see it any more.

Yao> +static void
Yao> +ctf_save_fwrite_format_1 (FILE *fd, const char *format, va_list args)
Yao> +{
Yao> +  char *linebuffer;
Yao> +  struct cleanup *old_cleanups;
Yao> +
Yao> +  linebuffer = xstrvprintf (format, args);
Yao> +  old_cleanups = make_cleanup (xfree, linebuffer);
Yao> +  ctf_save_fwrite (fd, linebuffer, strlen (linebuffer));
Yao> +  do_cleanups (old_cleanups);
Yao> +}
Yao> +
Yao> +/* Write data in FORMAT to FD.  */
Yao> +
Yao> +static void
Yao> +ctf_save_fwrite_format (FILE *fd, const char *format, ...)
Yao> +{
Yao> +  va_list args;
Yao> +
Yao> +  va_start (args, format);
Yao> +  ctf_save_fwrite_format_1 (fd, format, args);
Yao> +  va_end (args);
Yao> +}

Why not just use vfprintf directly and drop ctf_save_fwrite_format_1 and
the cleanups and the rest?

Yao> +static int
Yao> +ctf_save_fseek (struct trace_write_handler *handler, long offset,
Yao> +		int whence)
Yao> +{
Yao> +  if (fseek (handler->datastream_fd, offset, whence))
Yao> +    error (_("Unable to seek file for saving trace data (%s)"),
Yao> +	   safe_strerror (errno));
Yao> +
Yao> +  if (whence == SEEK_CUR)
Yao> +    handler->content_size += offset;

Why only update the size in this one case?
If it is because the callers only use it in specific ways, then I
suggest assertions to cover this, like maybe:

    gdb_assert (whence != SEEK_END);
    gdb_assert (whence != SEEK_SET || offset < handler->content_size);

Yao> +/* Change the datastream file position to align on ALIGN_SIZE,
Yao> +   and Write BUF to datastream file.  The size of BUF is SIZE.  */

Lowercase "w" in "write".

Yao> +  if (handler->metadata_fd)
Yao> +    fclose (handler->metadata_fd);
Yao> +
Yao> +  if (handler->datastream_fd)
Yao> +    fclose (handler->datastream_fd);

Use the "!= NULL" form.

Yao> +  /* Create DIRNAME.  */
Yao> +  file_name = alloca (strlen (dirname) + 1
Yao> +		      + strlen (CTF_DATASTREAM_NAME) + 1);

I think this assignment is dead.

Yao> +  if (!data->tcs.datastream_fd)

Use "!= NULL".
I think there are some other cases I didn't point out.

Yao> +  /* Tracepoint number.  */
Yao> +  ctf_save_write (&data->tcs, (gdb_byte *) &tpnum, 2);

Does endianness matter?

Yao> +  /* Step 2: Write event "frame".  */
Yao> +  /* Event Id.  */
Yao> +  ctf_save_align_write (&data->tcs, (gdb_byte *) &two, 4, 4);

The comments Andreas and Pedro made apply here.

Yao> +  /* Event Id.  */
Yao> +  ctf_save_align_write (&data->tcs, (gdb_byte *) &event_id, 4, 4);
Yao> +
Yao> +  /* Address.  */
Yao> +  ctf_save_align_write (&data->tcs, (gdb_byte *) &addr, 8, 8);

Here too I think.
There are more spots as well.

Yao> +/* Operations to write various types of trace frames into CTF
Yao> +   format.  */
Yao> +
Yao> +static struct trace_frame_write_ops ctf_write_frame_ops =

Why not const?

Yao> +static struct trace_file_write_ops ctf_write_ops =

Likewise.

Yao> +extern struct trace_file_writer *ctf_trace_file_writer (void);
Yao> +#endif

Newline between these two.

Yao>  mi_cmd_trace_save (char *command, char **argv, int argc)
Yao>  {
Yao>    int target_saves = 0;
Yao> +  int generate_ctf = 0;
Yao>    char *filename;

Yao>    if (argc != 1 && argc != 2)
Yao> -    error (_("Usage: -trace-save [-r] filename"));
Yao> +    error (_("Usage: -trace-save [-r] [-ctf] filename"));

Yao>    if (argc == 2)
Yao>      {
Yao>        filename = argv[1];
Yao>        if (strcmp (argv[0], "-r") == 0)
Yao>  	target_saves = 1;
Yao> +      if (strcmp (argv[0], "-ctf") == 0)
Yao> +	generate_ctf = 1;

I wonder why this doesn't use mi_getopt.
(Not your problem unless you feel like cleaning it up.)

Yao>    add_com ("tsave", class_trace, trace_save_command, _("\
Yao>  Save the trace data to a file.\n\
Yao>  Use the '-r' option to direct the target to save directly to the file,\n\
Yao> +Use the '-ctf' option to save the data to CTF format,\n\
Yao>  using its own filesystem."));

This reads strangely after the change.
Does -ctf direct the target to use its own filesystem?
Perhaps rewriting all this into a more "--help" style would be better;
or otherwise at least repeating the final clause.

Tom


  parent reply	other threads:[~2013-03-01 19:22 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-27  2:18 [PATCH 0/5, 2nd try] CTF Support Yao Qi
2013-02-27  2:18 ` [PATCH 1/5] Refactor 'tsave' Yao Qi
2013-02-28 16:49   ` Pedro Alves
2013-03-01  8:58     ` Yao Qi
2013-03-01 10:05       ` Pedro Alves
2013-03-01 10:41         ` Pedro Alves
2013-03-01 11:26         ` Yao Qi
2013-03-01 12:13           ` Pedro Alves
2013-03-01 15:55             ` Yao Qi
2013-03-05 20:59               ` Pedro Alves
2013-03-03  8:45         ` Yao Qi
2013-02-27  2:19 ` [PATCH 2/5] Save trace into CTF format Yao Qi
2013-02-28 13:17   ` Yao Qi
2013-02-28 13:17     ` Andreas Schwab
2013-02-28 17:19       ` Pedro Alves
2013-03-01 19:22     ` Tom Tromey [this message]
2013-03-03 10:19       ` Yao Qi
2013-03-07 21:29         ` Tom Tromey
2013-03-16  2:30         ` Joel Brobecker
2013-03-16  4:22           ` Yao Qi
2013-02-27  2:19 ` [PATCH 4/5] ctf doc and NEWS Yao Qi
2013-02-27 18:39   ` Eli Zaretskii
2013-02-27  2:19 ` [PATCH 3/5] Read CTF by the ctf target Yao Qi
2013-02-28 17:59   ` Pedro Alves
2013-03-01  2:38     ` Hui Zhu
2013-05-07 13:07       ` Mathieu Desnoyers
2013-05-07 13:24         ` Yao Qi
2013-05-07 13:28           ` Mathieu Desnoyers
2013-03-01  7:55     ` Yao Qi
2013-03-01  9:15       ` Pedro Alves
2013-03-01 15:51   ` Tom Tromey
2013-03-03 10:39     ` Yao Qi
2013-03-03 10:46       ` Yao Qi
2013-02-27  2:19 ` [PATCH 5/5] ctf test: report.exp Yao Qi
2013-02-27 18:48   ` Pedro Alves
2013-02-28  1:36     ` Yao Qi
2013-02-28 18:30       ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87621avsam.fsf@fleche.redhat.com \
    --to=tromey@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=yao@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox