This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
PATCH fix start-time and stop-time in trace-status
- From: Dmitry Kozlov <dmitry_kozlov at mentor dot com>
- To: <gdb-patches at sourceware dot org>
- Cc: "'Stan_Shebs at mentor dot com'" <Stan_Shebs at mentor dot com>, Vladimir Prus <vladimir at codesourcery dot com>
- Date: Thu, 27 Sep 2012 16:21:49 +0400
- Subject: PATCH fix start-time and stop-time in trace-status
Hello,
I noticed that trace-status MI command reports incorrect start-time and
stop-time, sometimes even negative. Investigation showed that gdbserver
reports start-time and stop-time in decimal format, while gdb tries to
interpret it as hex adn then broke it during type conversion. I think
keeping decimal format for communication is useful because itis
human-readable in remote log, so the attached patch fixes this problem
on the gdb side.
Please consider applying it.
Thank you,
Dmitry
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0a1ccdf..b43928d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,9 @@
+2012-09-25 Dmitry Kozlov <ddk@mentor.com>
+
+ * tracepoint.c (trace_status_command): Fix type of printf arg.
+ (trace_status_mi): Likewise.
+ * remote.c (unpack_ulongest): New.
+
2012-09-24 Siddhesh Poyarekar <siddhesh@redhat.com>
* m2-typeprint.c (m2_enum): Expand LASTVAL to LONGEST.
diff --git a/gdb/remote.c b/gdb/remote.c
index 1750bee..cc871e5 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1892,6 +1892,8 @@ struct gdb_ext_thread_info
char *unpack_varlen_hex (char *buff, ULONGEST *result);
+char *unpack_ulongest (char *buff, ULONGEST *result);
+
static char *unpack_nibble (char *buf, int *val);
static char *pack_nibble (char *buf, int nibble);
@@ -2079,6 +2081,21 @@ stub_unpack_int (char *buff, int fieldlength)
}
char *
+unpack_ulongest (char *buff, ULONGEST *result)
+{
+ ULONGEST retval = 0;
+
+ while (isdigit (*buff))
+ {
+ retval *= 10;
+ retval += *buff - '0';
+ buff++;
+ }
+ *result = retval;
+ return buff;
+}
+
+char *
unpack_varlen_hex (char *buff, /* packet to parse */
ULONGEST *result)
{
diff --git a/gdb/remote.h b/gdb/remote.h
index 3adc54e..7dbe263 100644
--- a/gdb/remote.h
+++ b/gdb/remote.h
@@ -39,6 +39,8 @@ extern int putpkt (char *buf);
extern char *unpack_varlen_hex (char *buff, ULONGEST *result);
+extern char *unpack_ulongest (char *buff, ULONGEST *result);
+
extern void async_remote_interrupt_twice (void *arg);
void register_remote_g_packet_guess (struct gdbarch *gdbarch, int bytes,
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index bdd6f50..6ff3a2f 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2039,20 +2039,20 @@ trace_status_command (char *args, int from_tty)
/* Reporting a run time is more readable than two long numbers. */
printf_filtered (_("Trace started at %ld.%06ld secs, stopped %ld.%06ld secs later.\n"),
- (long int) ts->start_time / 1000000,
- (long int) ts->start_time % 1000000,
- (long int) run_time / 1000000,
- (long int) run_time % 1000000);
+ (long int) (ts->start_time / 1000000),
+ (long int) (ts->start_time % 1000000),
+ (long int) (run_time / 1000000),
+ (long int) (run_time % 1000000));
}
else
printf_filtered (_("Trace started at %ld.%06ld secs.\n"),
- (long int) ts->start_time / 1000000,
- (long int) ts->start_time % 1000000);
+ (long int) (ts->start_time / 1000000),
+ (long int) (ts->start_time % 1000000));
}
else if (ts->stop_time)
printf_filtered (_("Trace stopped at %ld.%06ld secs.\n"),
- (long int) ts->stop_time / 1000000,
- (long int) ts->stop_time % 1000000);
+ (long int) (ts->stop_time / 1000000),
+ (long int) (ts->stop_time % 1000000));
/* Now report any per-tracepoint status available. */
tp_vec = all_tracepoints ();
@@ -2167,12 +2167,12 @@ trace_status_mi (int on_stop)
char buf[100];
xsnprintf (buf, sizeof buf, "%ld.%06ld",
- (long int) ts->start_time / 1000000,
- (long int) ts->start_time % 1000000);
+ (long int) (ts->start_time / 1000000),
+ (long int) (ts->start_time % 1000000));
ui_out_field_string (uiout, "start-time", buf);
xsnprintf (buf, sizeof buf, "%ld.%06ld",
- (long int) ts->stop_time / 1000000,
- (long int) ts->stop_time % 1000000);
+ (long int) (ts->stop_time / 1000000),
+ (long int) (ts->stop_time % 1000000));
ui_out_field_string (uiout, "stop-time", buf);
}
}
@@ -3938,12 +3938,12 @@ Status line: '%s'\n"), p, line);
}
else if (strncmp (p, "starttime", p1 - p) == 0)
{
- p = unpack_varlen_hex (++p1, &val);
+ p = unpack_ulongest (++p1, &val);
ts->start_time = val;
}
else if (strncmp (p, "stoptime", p1 - p) == 0)
{
- p = unpack_varlen_hex (++p1, &val);
+ p = unpack_ulongest (++p1, &val);
ts->stop_time = val;
}
else if (strncmp (p, "username", p1 - p) == 0)