+/* This is the implementation of trace_file_write_ops method
+ write_tdesc. */
+
+static void
+tfile_write_tdesc (struct trace_file_writer *self)
+{
+ struct tfile_trace_file_writer *writer
+ = (struct tfile_trace_file_writer *) self;
+
+ gdb::optional<std::string> tdesc
+ = target_fetch_description_xml (¤t_target);
+
+ if (!tdesc)
+ return;
+
+ const char *ptr = tdesc->c_str ();
+
+ /* Write tdesc line by line, prefixing each line with "tdesc ". */
+ while (ptr != NULL)
+ {
+ const char *next = strchr (ptr, '\n');
+ if (next != NULL)
+ {
+ fprintf (writer->fp, "tdesc %.*s\n", (int) (next - ptr), ptr);
+ /* Skip the \n. */
+ next++;
+ }
+ else if (*ptr != '\0')
+ {
+ /* Last line, doesn't have a newline. */
+ fprintf (writer->fp, "tdesc %s\n", ptr);
+ }
+ ptr = next;
+ }
+}
+