This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
tfile target, no selected traceframe, no stack or registers
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb-patches at sourceware dot org
- Date: Fri, 28 Jan 2011 16:20:49 +0000
- Subject: tfile target, no selected traceframe, no stack or registers
Before:
(gdb) tfind
Found trace frame 0, tracepoint 1
#0 write_basic_trace_file () at ../../../src/gdb/testsuite/gdb.trace/tfile.c:68
68 {
(gdb) tfind end
No longer looking at any trace frame
#0 0x0000000000000000 in ?? () from /lib64/ld-linux-x86-64.so.2
(gdb) info registers
rax 0x0 0
rbx 0x0 0
rcx 0x0 0
rdx 0x0 0
rsi 0x0 0
rdi 0x0 0
rbp 0x0 0x0
rsp 0x0 0x0
r8 0x0 0
r9 0x0 0
r10 0x0 0
r11 0x0 0
r12 0x0 0
r13 0x0 0
r14 0x0 0
r15 0x0 0
rip 0x0 0
eflags 0x0 [ ]
cs 0x0 0
ss 0x0 0
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
With the tfile target, it does not make much sense to print a
current completely bogus frame when we do "tfind end", and to allow
looking at a backtrace / inspect registers if we aren't looking
at a traceframe.
Afterward the patch:
Found trace frame 0, tracepoint 1
#0 write_basic_trace_file () at ../../../src/gdb/testsuite/gdb.trace/tfile.c:68
68 {
(gdb) tfind end
No longer looking at any trace frame
(gdb) bt
No stack.
(gdb) info registers
The program has no registers now.
Doesn't make much sense to try reading memory from an invalid
traceframe either, so the patch handles that too [this was the
original motivation for the patch :-) ].
Applied.
--
Pedro Alves
2011-01-28 Pedro Alves <pedro@codesourcery.com>
gdb/
* tracepoint.c (tfile_xfer_partial): If there's no traceframe
selected, don't try iterating over the traceframe's blocks.
(tfile_has_stack): If there's no traceframe selected, then there's
no stack.
(tfile_has_registers): If there's no traceframe selected, then
there's no registers.
gdb/testsuite/
* gdb.trace/tfile.exp: Test that with no traceframe selected,
there's no stack or registers.
---
gdb/testsuite/gdb.trace/tfile.exp | 8 ++++
gdb/tracepoint.c | 62 ++++++++++++++++++++------------------
2 files changed, 41 insertions(+), 29 deletions(-)
Index: src/gdb/tracepoint.c
===================================================================
--- src.orig/gdb/tracepoint.c 2011-01-27 21:38:12.941609001 +0000
+++ src/gdb/tracepoint.c 2011-01-28 16:05:05.487137002 +0000
@@ -3970,8 +3970,6 @@ tfile_xfer_partial (struct target_ops *o
const char *annex, gdb_byte *readbuf,
const gdb_byte *writebuf, ULONGEST offset, LONGEST len)
{
- int pos;
-
/* We're only doing regular memory for now. */
if (object != TARGET_OBJECT_MEMORY)
return -1;
@@ -3979,36 +3977,42 @@ tfile_xfer_partial (struct target_ops *o
if (readbuf == NULL)
error (_("tfile_xfer_partial: trace file is read-only"));
- /* Iterate through the traceframe's blocks, looking for memory. */
- pos = 0;
- while ((pos = traceframe_find_block_type ('M', pos)) >= 0)
+ if (traceframe_number != -1)
{
- ULONGEST maddr, amt;
- unsigned short mlen;
+ int pos = 0;
- tfile_read ((gdb_byte *) &maddr, 8);
- maddr = extract_unsigned_integer ((gdb_byte *) &maddr, 8,
- gdbarch_byte_order (target_gdbarch));
- tfile_read ((gdb_byte *) &mlen, 2);
- mlen = (unsigned short)
- extract_unsigned_integer ((gdb_byte *) &mlen, 2,
- gdbarch_byte_order (target_gdbarch));
-
- /* If the block includes the first part of the desired range,
- return as much it has; GDB will re-request the remainder,
- which might be in a different block of this trace frame. */
- if (maddr <= offset && offset < (maddr + mlen))
+ /* Iterate through the traceframe's blocks, looking for
+ memory. */
+ while ((pos = traceframe_find_block_type ('M', pos)) >= 0)
{
- amt = (maddr + mlen) - offset;
- if (amt > len)
- amt = len;
+ ULONGEST maddr, amt;
+ unsigned short mlen;
+ enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
+
+ tfile_read ((gdb_byte *) &maddr, 8);
+ maddr = extract_unsigned_integer ((gdb_byte *) &maddr, 8,
+ byte_order);
+ tfile_read ((gdb_byte *) &mlen, 2);
+ mlen = (unsigned short)
+ extract_unsigned_integer ((gdb_byte *) &mlen, 2, byte_order);
+
+ /* If the block includes the first part of the desired
+ range, return as much it has; GDB will re-request the
+ remainder, which might be in a different block of this
+ trace frame. */
+ if (maddr <= offset && offset < (maddr + mlen))
+ {
+ amt = (maddr + mlen) - offset;
+ if (amt > len)
+ amt = len;
- tfile_read (readbuf, amt);
- return amt;
- }
+ tfile_read (readbuf, amt);
+ return amt;
+ }
- /* Skip over this block. */
- pos += (8 + 2 + mlen);
+ /* Skip over this block. */
+ pos += (8 + 2 + mlen);
+ }
}
/* It's unduly pedantic to refuse to look at the executable for
@@ -4095,13 +4099,13 @@ tfile_has_memory (struct target_ops *ops
static int
tfile_has_stack (struct target_ops *ops)
{
- return 1;
+ return traceframe_number != -1;
}
static int
tfile_has_registers (struct target_ops *ops)
{
- return 1;
+ return traceframe_number != -1;
}
static void
Index: src/gdb/testsuite/gdb.trace/tfile.exp
===================================================================
--- src.orig/gdb/testsuite/gdb.trace/tfile.exp 2011-01-28 16:13:20.000000000 +0000
+++ src/gdb/testsuite/gdb.trace/tfile.exp 2011-01-28 16:13:43.807137001 +0000
@@ -92,6 +92,14 @@ Trace buffer has 256 bytes of 4096 bytes
Looking at trace frame 0, tracepoint .*" \
"tstatus on trace file"
+gdb_test "tfind end" "No longer looking at any trace frame" "leave tfind mode"
+
+gdb_test "backtrace" "No stack\." \
+ "no stack if no traceframe selected"
+
+gdb_test "info registers" "The program has no registers now\." \
+ "no registers if no traceframe selected"
+
# Now start afresh, using only a trace file.
gdb_exit