Move trace file writer out of tracepoint.c
This patch is a refactor which moves trace file writer related code
out of tracepoint.c, which has 6k LOC. It moves general trace file
writer to a new file tracefile.c and moves tfile specific writer to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* Makefile.in (REMOTE_OBS): Append tracefile.o and
tracefile-tfile.o.
(HFILES_NO_SRCDIR): Add tracefile.h.
* ctf.c: Include "tracefile.h".
* tracefile.h: New file.
* tracefile.c: New file
* tracefile-tfile.c: New file.
* tracepoint.c: Include "tracefile.h".
(free_uploaded_tps, free_uploaded_tsvs): Remove declarations.
(stop_reason_names): Add const.
(trace_file_writer_xfree): Move it to tracefile.c.
(trace_save, trace_save_command, trace_save_tfile): Likewise.
(trace_save_ctf): Likewise.
(struct tfile_trace_file_writer): Move it to tracefile-tfile.c.
(tfile_target_save, tfile_dtor, tfile_start): Likewise.
(tfile_write_header, tfile_write_regblock_type): Likewise.
(tfile_write_status, tfile_write_uploaded_tsv): Likewise.
(tfile_write_uploaded_tp, tfile_write_definition_end): Likewise.
(tfile_write_raw_data, tfile_end): Likewise.
(tfile_trace_file_writer_new): Likewise.
(free_uploaded_tp): Make it extern.
(free_uploaded_tsv): Make it extern.
(_initialize_tracepoint): Move code to register command 'tsave'
to tracefile.c.
* tracepoint.h (stop_reason_names): Declare.
(struct trace_frame_write_ops): Move it to tracefile.h.
(struct trace_file_write_ops): Likewise.
(struct trace_file_writer): Likewise.
(free_uploaded_tsvs, free_uploaded_tps): Declare.
2014-02-10 05:31:12 +00:00
|
|
|
/* Trace file TFILE format support in GDB.
|
|
|
|
|
2015-01-01 09:32:14 +00:00
|
|
|
Copyright (C) 1997-2015 Free Software Foundation, Inc.
|
Move trace file writer out of tracepoint.c
This patch is a refactor which moves trace file writer related code
out of tracepoint.c, which has 6k LOC. It moves general trace file
writer to a new file tracefile.c and moves tfile specific writer to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* Makefile.in (REMOTE_OBS): Append tracefile.o and
tracefile-tfile.o.
(HFILES_NO_SRCDIR): Add tracefile.h.
* ctf.c: Include "tracefile.h".
* tracefile.h: New file.
* tracefile.c: New file
* tracefile-tfile.c: New file.
* tracepoint.c: Include "tracefile.h".
(free_uploaded_tps, free_uploaded_tsvs): Remove declarations.
(stop_reason_names): Add const.
(trace_file_writer_xfree): Move it to tracefile.c.
(trace_save, trace_save_command, trace_save_tfile): Likewise.
(trace_save_ctf): Likewise.
(struct tfile_trace_file_writer): Move it to tracefile-tfile.c.
(tfile_target_save, tfile_dtor, tfile_start): Likewise.
(tfile_write_header, tfile_write_regblock_type): Likewise.
(tfile_write_status, tfile_write_uploaded_tsv): Likewise.
(tfile_write_uploaded_tp, tfile_write_definition_end): Likewise.
(tfile_write_raw_data, tfile_end): Likewise.
(tfile_trace_file_writer_new): Likewise.
(free_uploaded_tp): Make it extern.
(free_uploaded_tsv): Make it extern.
(_initialize_tracepoint): Move code to register command 'tsave'
to tracefile.c.
* tracepoint.h (stop_reason_names): Declare.
(struct trace_frame_write_ops): Move it to tracefile.h.
(struct trace_file_write_ops): Likewise.
(struct trace_file_writer): Likewise.
(free_uploaded_tsvs, free_uploaded_tps): Declare.
2014-02-10 05:31:12 +00:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "tracefile.h"
|
|
|
|
#include "readline/tilde.h"
|
|
|
|
#include "filestuff.h"
|
|
|
|
#include "rsp-low.h" /* bin2hex */
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
#include "regcache.h"
|
|
|
|
#include "inferior.h"
|
|
|
|
#include "gdbthread.h"
|
|
|
|
#include "exec.h" /* exec_bfd */
|
|
|
|
#include "completer.h"
|
|
|
|
#include "filenames.h"
|
|
|
|
|
|
|
|
#ifndef O_LARGEFILE
|
|
|
|
#define O_LARGEFILE 0
|
|
|
|
#endif
|
Move trace file writer out of tracepoint.c
This patch is a refactor which moves trace file writer related code
out of tracepoint.c, which has 6k LOC. It moves general trace file
writer to a new file tracefile.c and moves tfile specific writer to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* Makefile.in (REMOTE_OBS): Append tracefile.o and
tracefile-tfile.o.
(HFILES_NO_SRCDIR): Add tracefile.h.
* ctf.c: Include "tracefile.h".
* tracefile.h: New file.
* tracefile.c: New file
* tracefile-tfile.c: New file.
* tracepoint.c: Include "tracefile.h".
(free_uploaded_tps, free_uploaded_tsvs): Remove declarations.
(stop_reason_names): Add const.
(trace_file_writer_xfree): Move it to tracefile.c.
(trace_save, trace_save_command, trace_save_tfile): Likewise.
(trace_save_ctf): Likewise.
(struct tfile_trace_file_writer): Move it to tracefile-tfile.c.
(tfile_target_save, tfile_dtor, tfile_start): Likewise.
(tfile_write_header, tfile_write_regblock_type): Likewise.
(tfile_write_status, tfile_write_uploaded_tsv): Likewise.
(tfile_write_uploaded_tp, tfile_write_definition_end): Likewise.
(tfile_write_raw_data, tfile_end): Likewise.
(tfile_trace_file_writer_new): Likewise.
(free_uploaded_tp): Make it extern.
(free_uploaded_tsv): Make it extern.
(_initialize_tracepoint): Move code to register command 'tsave'
to tracefile.c.
* tracepoint.h (stop_reason_names): Declare.
(struct trace_frame_write_ops): Move it to tracefile.h.
(struct trace_file_write_ops): Likewise.
(struct trace_file_writer): Likewise.
(free_uploaded_tsvs, free_uploaded_tps): Declare.
2014-02-10 05:31:12 +00:00
|
|
|
|
|
|
|
/* TFILE trace writer. */
|
|
|
|
|
|
|
|
struct tfile_trace_file_writer
|
|
|
|
{
|
|
|
|
struct trace_file_writer base;
|
|
|
|
|
|
|
|
/* File pointer to tfile trace file. */
|
|
|
|
FILE *fp;
|
|
|
|
/* Path name of the tfile trace file. */
|
|
|
|
char *pathname;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
target_save. We just call the generic target
|
|
|
|
target_save_trace_data to do target-side saving. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
tfile_target_save (struct trace_file_writer *self,
|
|
|
|
const char *filename)
|
|
|
|
{
|
|
|
|
int err = target_save_trace_data (filename);
|
|
|
|
|
|
|
|
return (err >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
dtor. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_dtor (struct trace_file_writer *self)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
xfree (writer->pathname);
|
|
|
|
|
|
|
|
if (writer->fp != NULL)
|
|
|
|
fclose (writer->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
start. It creates the trace file FILENAME and registers some
|
|
|
|
cleanups. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_start (struct trace_file_writer *self, const char *filename)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
writer->pathname = tilde_expand (filename);
|
|
|
|
writer->fp = gdb_fopen_cloexec (writer->pathname, "wb");
|
|
|
|
if (writer->fp == NULL)
|
|
|
|
error (_("Unable to open file '%s' for saving trace data (%s)"),
|
|
|
|
writer->pathname, safe_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_header. Write the TFILE header. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_header (struct trace_file_writer *self)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
int written;
|
|
|
|
|
|
|
|
/* Write a file header, with a high-bit-set char to indicate a
|
|
|
|
binary file, plus a hint as what this file is, and a version
|
|
|
|
number in case of future needs. */
|
|
|
|
written = fwrite ("\x7fTRACE0\n", 8, 1, writer->fp);
|
|
|
|
if (written < 1)
|
|
|
|
perror_with_name (writer->pathname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_regblock_type. Write the size of register block. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_regblock_type (struct trace_file_writer *self, int size)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
fprintf (writer->fp, "R %x\n", size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_status. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_status (struct trace_file_writer *self,
|
|
|
|
struct trace_status *ts)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
fprintf (writer->fp, "status %c;%s",
|
|
|
|
(ts->running ? '1' : '0'), stop_reason_names[ts->stop_reason]);
|
|
|
|
if (ts->stop_reason == tracepoint_error
|
|
|
|
|| ts->stop_reason == tstop_command)
|
|
|
|
{
|
|
|
|
char *buf = (char *) alloca (strlen (ts->stop_desc) * 2 + 1);
|
|
|
|
|
|
|
|
bin2hex ((gdb_byte *) ts->stop_desc, buf, strlen (ts->stop_desc));
|
|
|
|
fprintf (writer->fp, ":%s", buf);
|
|
|
|
}
|
|
|
|
fprintf (writer->fp, ":%x", ts->stopping_tracepoint);
|
|
|
|
if (ts->traceframe_count >= 0)
|
|
|
|
fprintf (writer->fp, ";tframes:%x", ts->traceframe_count);
|
|
|
|
if (ts->traceframes_created >= 0)
|
|
|
|
fprintf (writer->fp, ";tcreated:%x", ts->traceframes_created);
|
|
|
|
if (ts->buffer_free >= 0)
|
|
|
|
fprintf (writer->fp, ";tfree:%x", ts->buffer_free);
|
|
|
|
if (ts->buffer_size >= 0)
|
|
|
|
fprintf (writer->fp, ";tsize:%x", ts->buffer_size);
|
|
|
|
if (ts->disconnected_tracing)
|
|
|
|
fprintf (writer->fp, ";disconn:%x", ts->disconnected_tracing);
|
|
|
|
if (ts->circular_buffer)
|
|
|
|
fprintf (writer->fp, ";circular:%x", ts->circular_buffer);
|
|
|
|
if (ts->start_time)
|
|
|
|
{
|
|
|
|
fprintf (writer->fp, ";starttime:%s",
|
|
|
|
phex_nz (ts->start_time, sizeof (ts->start_time)));
|
|
|
|
}
|
|
|
|
if (ts->stop_time)
|
|
|
|
{
|
|
|
|
fprintf (writer->fp, ";stoptime:%s",
|
|
|
|
phex_nz (ts->stop_time, sizeof (ts->stop_time)));
|
|
|
|
}
|
|
|
|
if (ts->notes != NULL)
|
|
|
|
{
|
|
|
|
char *buf = (char *) alloca (strlen (ts->notes) * 2 + 1);
|
|
|
|
|
|
|
|
bin2hex ((gdb_byte *) ts->notes, buf, strlen (ts->notes));
|
|
|
|
fprintf (writer->fp, ";notes:%s", buf);
|
|
|
|
}
|
|
|
|
if (ts->user_name != NULL)
|
|
|
|
{
|
|
|
|
char *buf = (char *) alloca (strlen (ts->user_name) * 2 + 1);
|
|
|
|
|
|
|
|
bin2hex ((gdb_byte *) ts->user_name, buf, strlen (ts->user_name));
|
|
|
|
fprintf (writer->fp, ";username:%s", buf);
|
|
|
|
}
|
|
|
|
fprintf (writer->fp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_uploaded_tsv. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_uploaded_tsv (struct trace_file_writer *self,
|
|
|
|
struct uploaded_tsv *utsv)
|
|
|
|
{
|
|
|
|
char *buf = "";
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
if (utsv->name)
|
|
|
|
{
|
|
|
|
buf = (char *) xmalloc (strlen (utsv->name) * 2 + 1);
|
|
|
|
bin2hex ((gdb_byte *) (utsv->name), buf, strlen (utsv->name));
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf (writer->fp, "tsv %x:%s:%x:%s\n",
|
|
|
|
utsv->number, phex_nz (utsv->initial_value, 8),
|
|
|
|
utsv->builtin, buf);
|
|
|
|
|
|
|
|
if (utsv->name)
|
|
|
|
xfree (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_TRACE_UPLOAD 2000
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_uploaded_tp. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_uploaded_tp (struct trace_file_writer *self,
|
|
|
|
struct uploaded_tp *utp)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
int a;
|
|
|
|
char *act;
|
|
|
|
char buf[MAX_TRACE_UPLOAD];
|
|
|
|
|
|
|
|
fprintf (writer->fp, "tp T%x:%s:%c:%x:%x",
|
|
|
|
utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
|
|
|
|
(utp->enabled ? 'E' : 'D'), utp->step, utp->pass);
|
|
|
|
if (utp->type == bp_fast_tracepoint)
|
|
|
|
fprintf (writer->fp, ":F%x", utp->orig_size);
|
|
|
|
if (utp->cond)
|
|
|
|
fprintf (writer->fp,
|
|
|
|
":X%x,%s", (unsigned int) strlen (utp->cond) / 2,
|
|
|
|
utp->cond);
|
|
|
|
fprintf (writer->fp, "\n");
|
|
|
|
for (a = 0; VEC_iterate (char_ptr, utp->actions, a, act); ++a)
|
|
|
|
fprintf (writer->fp, "tp A%x:%s:%s\n",
|
|
|
|
utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
|
|
|
|
for (a = 0; VEC_iterate (char_ptr, utp->step_actions, a, act); ++a)
|
|
|
|
fprintf (writer->fp, "tp S%x:%s:%s\n",
|
|
|
|
utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act);
|
|
|
|
if (utp->at_string)
|
|
|
|
{
|
|
|
|
encode_source_string (utp->number, utp->addr,
|
|
|
|
"at", utp->at_string, buf, MAX_TRACE_UPLOAD);
|
|
|
|
fprintf (writer->fp, "tp Z%s\n", buf);
|
|
|
|
}
|
|
|
|
if (utp->cond_string)
|
|
|
|
{
|
|
|
|
encode_source_string (utp->number, utp->addr,
|
|
|
|
"cond", utp->cond_string,
|
|
|
|
buf, MAX_TRACE_UPLOAD);
|
|
|
|
fprintf (writer->fp, "tp Z%s\n", buf);
|
|
|
|
}
|
|
|
|
for (a = 0; VEC_iterate (char_ptr, utp->cmd_strings, a, act); ++a)
|
|
|
|
{
|
|
|
|
encode_source_string (utp->number, utp->addr, "cmd", act,
|
|
|
|
buf, MAX_TRACE_UPLOAD);
|
|
|
|
fprintf (writer->fp, "tp Z%s\n", buf);
|
|
|
|
}
|
|
|
|
fprintf (writer->fp, "tp V%x:%s:%x:%s\n",
|
|
|
|
utp->number, phex_nz (utp->addr, sizeof (utp->addr)),
|
|
|
|
utp->hit_count,
|
|
|
|
phex_nz (utp->traceframe_usage,
|
|
|
|
sizeof (utp->traceframe_usage)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_definition_end. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_definition_end (struct trace_file_writer *self)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
fprintf (writer->fp, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
write_raw_data. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_write_raw_data (struct trace_file_writer *self, gdb_byte *buf,
|
|
|
|
LONGEST len)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
|
|
|
|
if (fwrite (buf, len, 1, writer->fp) < 1)
|
|
|
|
perror_with_name (writer->pathname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is the implementation of trace_file_write_ops method
|
|
|
|
end. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_end (struct trace_file_writer *self)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
|
|
|
= (struct tfile_trace_file_writer *) self;
|
|
|
|
uint32_t gotten = 0;
|
|
|
|
|
|
|
|
/* Mark the end of trace data. */
|
|
|
|
if (fwrite (&gotten, 4, 1, writer->fp) < 1)
|
|
|
|
perror_with_name (writer->pathname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Operations to write trace buffers into TFILE format. */
|
|
|
|
|
|
|
|
static const struct trace_file_write_ops tfile_write_ops =
|
|
|
|
{
|
|
|
|
tfile_dtor,
|
|
|
|
tfile_target_save,
|
|
|
|
tfile_start,
|
|
|
|
tfile_write_header,
|
|
|
|
tfile_write_regblock_type,
|
|
|
|
tfile_write_status,
|
|
|
|
tfile_write_uploaded_tsv,
|
|
|
|
tfile_write_uploaded_tp,
|
|
|
|
tfile_write_definition_end,
|
|
|
|
tfile_write_raw_data,
|
|
|
|
NULL,
|
|
|
|
tfile_end,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Return a trace writer for TFILE format. */
|
|
|
|
|
|
|
|
struct trace_file_writer *
|
|
|
|
tfile_trace_file_writer_new (void)
|
|
|
|
{
|
|
|
|
struct tfile_trace_file_writer *writer
|
Replace some xmalloc-family functions with XNEW-family ones
This patch is part of the make-gdb-buildable-in-C++ effort. The idea is
to change some calls to the xmalloc family of functions to calls to the
equivalents in the XNEW family. This avoids adding an explicit cast, so
it keeps the code a bit more readable. Some of them also map relatively
well to a C++ equivalent (XNEW (struct foo) -> new foo), so it will be
possible to do scripted replacements if needed.
I only changed calls that were obviously allocating memory for one or
multiple "objects". Allocation of variable sizes (such as strings or
buffer handling) will be for later (and won't use XNEW).
- xmalloc (sizeof (struct foo)) -> XNEW (struct foo)
- xmalloc (num * sizeof (struct foo)) -> XNEWVEC (struct foo, num)
- xcalloc (1, sizeof (struct foo)) -> XCNEW (struct foo)
- xcalloc (num, sizeof (struct foo)) -> XCNEWVEC (struct foo, num)
- xrealloc (p, num * sizeof (struct foo) -> XRESIZEVEC (struct foo, p, num)
- obstack_alloc (ob, sizeof (struct foo)) -> XOBNEW (ob, struct foo)
- obstack_alloc (ob, num * sizeof (struct foo)) -> XOBNEWVEC (ob, struct foo, num)
- alloca (sizeof (struct foo)) -> XALLOCA (struct foo)
- alloca (num * sizeof (struct foo)) -> XALLOCAVEC (struct foo, num)
Some instances of xmalloc followed by memset to zero the buffer were
replaced by XCNEW or XCNEWVEC.
I regtested on x86-64, Ubuntu 14.04, but the patch touches many
architecture-specific files. For those I'll have to rely on the
buildbot or people complaining that I broke their gdb.
gdb/ChangeLog:
* aarch64-linux-nat.c (aarch64_add_process): Likewise.
* aarch64-tdep.c (aarch64_gdbarch_init): Likewise.
* ada-exp.y (write_ambiguous_var): Likewise.
* ada-lang.c (resolve_subexp): Likewise.
(user_select_syms): Likewise.
(assign_aggregate): Likewise.
(ada_evaluate_subexp): Likewise.
(cache_symbol): Likewise.
* addrmap.c (allocate_key): Likewise.
(addrmap_create_mutable): Likewise.
* aix-thread.c (sync_threadlists): Likewise.
* alpha-tdep.c (alpha_push_dummy_call): Likewise.
(alpha_gdbarch_init): Likewise.
* amd64-windows-tdep.c (amd64_windows_push_arguments): Likewise.
* arm-linux-nat.c (arm_linux_add_process): Likewise.
* arm-linux-tdep.c (arm_linux_displaced_step_copy_insn): Likewise.
* arm-tdep.c (push_stack_item): Likewise.
(arm_displaced_step_copy_insn): Likewise.
(arm_gdbarch_init): Likewise.
(_initialize_arm_tdep): Likewise.
* avr-tdep.c (push_stack_item): Likewise.
* ax-general.c (new_agent_expr): Likewise.
* block.c (block_initialize_namespace): Likewise.
* breakpoint.c (alloc_counted_command_line): Likewise.
(update_dprintf_command_list): Likewise.
(parse_breakpoint_sals): Likewise.
(decode_static_tracepoint_spec): Likewise.
(until_break_command): Likewise.
(clear_command): Likewise.
(update_global_location_list): Likewise.
(get_breakpoint_objfile_data) Likewise.
* btrace.c (ftrace_new_function): Likewise.
(btrace_set_insn_history): Likewise.
(btrace_set_call_history): Likewise.
* buildsym.c (add_symbol_to_list): Likewise.
(record_pending_block): Likewise.
(start_subfile): Likewise.
(start_buildsym_compunit): Likewise.
(push_subfile): Likewise.
(end_symtab_get_static_block): Likewise.
(buildsym_init): Likewise.
* cli/cli-cmds.c (source_command): Likewise.
* cli/cli-decode.c (add_cmd): Likewise.
* cli/cli-script.c (build_command_line): Likewise.
(setup_user_args): Likewise.
(realloc_body_list): Likewise.
(process_next_line): Likewise.
(copy_command_lines): Likewise.
* cli/cli-setshow.c (do_set_command): Likewise.
* coff-pe-read.c (read_pe_exported_syms): Likewise.
* coffread.c (coff_locate_sections): Likewise.
(coff_symtab_read): Likewise.
(coff_read_struct_type): Likewise.
* common/cleanups.c (make_my_cleanup2): Likewise.
* common/common-exceptions.c (throw_it): Likewise.
* common/filestuff.c (make_cleanup_close): Likewise.
* common/format.c (parse_format_string): Likewise.
* common/queue.h (DEFINE_QUEUE_P): Likewise.
* compile/compile-object-load.c (munmap_list_add): Likewise.
(compile_object_load): Likewise.
* compile/compile-object-run.c (compile_object_run): Likewise.
* compile/compile.c (append_args): Likewise.
* corefile.c (specify_exec_file_hook): Likewise.
* cp-support.c (make_symbol_overload_list): Likewise.
* cris-tdep.c (push_stack_item): Likewise.
(cris_gdbarch_init): Likewise.
* ctf.c (ctf_trace_file_writer_new): Likewise.
* dbxread.c (init_header_files): Likewise.
(add_new_header_file): Likewise.
(init_bincl_list): Likewise.
(dbx_end_psymtab): Likewise.
(start_psymtab): Likewise.
(dbx_end_psymtab): Likewise.
* dcache.c (dcache_init): Likewise.
* dictionary.c (dict_create_hashed): Likewise.
(dict_create_hashed_expandable): Likewise.
(dict_create_linear): Likewise.
(dict_create_linear_expandable): Likewise.
* dtrace-probe.c (dtrace_process_dof_probe): Likewise.
* dummy-frame.c (register_dummy_frame_dtor): Likewise.
* dwarf2-frame-tailcall.c (cache_new_ref1): Likewise.
* dwarf2-frame.c (dwarf2_build_frame_info): Likewise.
(decode_frame_entry_1): Likewise.
* dwarf2expr.c (new_dwarf_expr_context): Likewise.
* dwarf2loc.c (dwarf2_compile_expr_to_ax): Likewise.
* dwarf2read.c (dwarf2_has_info): Likewise.
(create_signatured_type_table_from_index): Likewise.
(dwarf2_read_index): Likewise.
(dw2_get_file_names_reader): Likewise.
(create_all_type_units): Likewise.
(read_cutu_die_from_dwo): Likewise.
(init_tu_and_read_dwo_dies): Likewise.
(init_cutu_and_read_dies): Likewise.
(create_all_comp_units): Likewise.
(queue_comp_unit): Likewise.
(inherit_abstract_dies): Likewise.
(read_call_site_scope): Likewise.
(dwarf2_add_field): Likewise.
(dwarf2_add_typedef): Likewise.
(dwarf2_add_member_fn): Likewise.
(attr_to_dynamic_prop): Likewise.
(abbrev_table_alloc_abbrev): Likewise.
(abbrev_table_read_table): Likewise.
(add_include_dir): Likewise.
(add_file_name): Likewise.
(dwarf_decode_line_header): Likewise.
(dwarf2_const_value_attr): Likewise.
(dwarf_alloc_block): Likewise.
(parse_macro_definition): Likewise.
(set_die_type): Likewise.
(write_psymtabs_to_index): Likewise.
(create_cus_from_index): Likewise.
(dwarf2_create_include_psymtab): Likewise.
(process_psymtab_comp_unit_reader): Likewise.
(build_type_psymtab_dependencies): Likewise.
(read_comp_units_from_section): Likewise.
(compute_compunit_symtab_includes): Likewise.
(create_dwo_unit_in_dwp_v1): Likewise.
(create_dwo_unit_in_dwp_v2): Likewise.
(read_func_scope): Likewise.
(process_structure_scope): Likewise.
(mark_common_block_symbol_computed): Likewise.
(load_partial_dies): Likewise.
(dwarf2_symbol_mark_computed): Likewise.
* elfread.c (elf_symfile_segments): Likewise.
(elf_read_minimal_symbols): Likewise.
* environ.c (make_environ): Likewise.
* eval.c (evaluate_subexp_standard): Likewise.
* event-loop.c (create_file_handler): Likewise.
(create_async_signal_handler): Likewise.
(create_async_event_handler): Likewise.
(create_timer): Likewise.
* exec.c (build_section_table): Likewise.
* fbsd-nat.c (fbsd_remember_child): Likewise.
* fork-child.c (fork_inferior): Likewise.
* frv-tdep.c (new_variant): Likewise.
* gdbarch.sh (gdbarch_alloc): Likewise.
(append_name): Likewise.
* gdbtypes.c (rank_function): Likewise.
(copy_type_recursive): Likewise.
(add_dyn_prop): Likewise.
* gnu-nat.c (make_proc): Likewise.
(make_inf): Likewise.
(gnu_write_inferior): Likewise.
* gnu-v3-abi.c (build_gdb_vtable_type): Likewise.
(build_std_type_info_type): Likewise.
* guile/scm-param.c (compute_enum_list): Likewise.
* guile/scm-utils.c (gdbscm_parse_function_args): Likewise.
* guile/scm-value.c (gdbscm_value_call): Likewise.
* h8300-tdep.c (h8300_gdbarch_init): Likewise.
* hppa-tdep.c (hppa_init_objfile_priv_data): Likewise.
(read_unwind_info): Likewise.
* ia64-tdep.c (ia64_gdbarch_init): Likewise.
* infcall.c (dummy_frame_context_saver_setup): Likewise.
(call_function_by_hand_dummy): Likewise.
* infcmd.c (step_once): Likewise.
(finish_forward): Likewise.
(attach_command): Likewise.
(notice_new_inferior): Likewise.
* inferior.c (add_inferior_silent): Likewise.
* infrun.c (add_displaced_stepping_state): Likewise.
(save_infcall_control_state): Likewise.
(save_inferior_ptid): Likewise.
(_initialize_infrun): Likewise.
* jit.c (bfd_open_from_target_memory): Likewise.
(jit_gdbarch_data_init): Likewise.
* language.c (add_language): Likewise.
* linespec.c (decode_line_2): Likewise.
* linux-nat.c (add_to_pid_list): Likewise.
(add_initial_lwp): Likewise.
* linux-thread-db.c (add_thread_db_info): Likewise.
(record_thread): Likewise.
(info_auto_load_libthread_db): Likewise.
* m32c-tdep.c (m32c_gdbarch_init): Likewise.
* m68hc11-tdep.c (m68hc11_gdbarch_init): Likewise.
* m68k-tdep.c (m68k_gdbarch_init): Likewise.
* m88k-tdep.c (m88k_analyze_prologue): Likewise.
* macrocmd.c (macro_define_command): Likewise.
* macroexp.c (gather_arguments): Likewise.
* macroscope.c (sal_macro_scope): Likewise.
* macrotab.c (new_macro_table): Likewise.
* mdebugread.c (push_parse_stack): Likewise.
(parse_partial_symbols): Likewise.
(parse_symbol): Likewise.
(psymtab_to_symtab_1): Likewise.
(new_block): Likewise.
(new_psymtab): Likewise.
(mdebug_build_psymtabs): Likewise.
(add_pending): Likewise.
(elfmdebug_build_psymtabs): Likewise.
* mep-tdep.c (mep_gdbarch_init): Likewise.
* mi/mi-main.c (mi_execute_command): Likewise.
* mi/mi-parse.c (mi_parse_argv): Likewise.
* minidebug.c (lzma_open): Likewise.
* minsyms.c (terminate_minimal_symbol_table): Likewise.
* mips-linux-nat.c (mips_linux_insert_watchpoint): Likewise.
* mips-tdep.c (mips_gdbarch_init): Likewise.
* mn10300-tdep.c (mn10300_gdbarch_init): Likewise.
* msp430-tdep.c (msp430_gdbarch_init): Likewise.
* mt-tdep.c (mt_registers_info): Likewise.
* nat/aarch64-linux.c (aarch64_linux_new_thread): Likewise.
* nat/linux-btrace.c (linux_enable_bts): Likewise.
(linux_enable_pt): Likewise.
* nat/linux-osdata.c (linux_xfer_osdata_processes): Likewise.
(linux_xfer_osdata_processgroups): Likewise.
* nios2-tdep.c (nios2_gdbarch_init): Likewise.
* nto-procfs.c (procfs_meminfo): Likewise.
* objc-lang.c (start_msglist): Likewise.
(selectors_info): Likewise.
(classes_info): Likewise.
(find_methods): Likewise.
* objfiles.c (allocate_objfile): Likewise.
(update_section_map): Likewise.
* osabi.c (gdbarch_register_osabi): Likewise.
(gdbarch_register_osabi_sniffer): Likewise.
* parse.c (start_arglist): Likewise.
* ppc-linux-nat.c (hwdebug_find_thread_points_by_tid): Likewise.
(hwdebug_insert_point): Likewise.
* printcmd.c (display_command): Likewise.
(ui_printf): Likewise.
* procfs.c (create_procinfo): Likewise.
(load_syscalls): Likewise.
(proc_get_LDT_entry): Likewise.
(proc_update_threads): Likewise.
* prologue-value.c (make_pv_area): Likewise.
(pv_area_store): Likewise.
* psymtab.c (extend_psymbol_list): Likewise.
(init_psymbol_list): Likewise.
(allocate_psymtab): Likewise.
* python/py-inferior.c (add_thread_object): Likewise.
* python/py-param.c (compute_enum_values): Likewise.
* python/py-value.c (valpy_call): Likewise.
* python/py-varobj.c (py_varobj_iter_next): Likewise.
* python/python.c (ensure_python_env): Likewise.
* record-btrace.c (record_btrace_start_replaying): Likewise.
* record-full.c (record_full_reg_alloc): Likewise.
(record_full_mem_alloc): Likewise.
(record_full_end_alloc): Likewise.
(record_full_core_xfer_partial): Likewise.
* regcache.c (get_thread_arch_aspace_regcache): Likewise.
* remote-fileio.c (remote_fileio_init_fd_map): Likewise.
* remote-notif.c (remote_notif_state_allocate): Likewise.
* remote.c (demand_private_info): Likewise.
(remote_notif_stop_alloc_reply): Likewise.
(remote_enable_btrace): Likewise.
* reverse.c (save_bookmark_command): Likewise.
* rl78-tdep.c (rl78_gdbarch_init): Likewise.
* rx-tdep.c (rx_gdbarch_init): Likewise.
* s390-linux-nat.c (s390_insert_watchpoint): Likewise.
* ser-go32.c (dos_get_tty_state): Likewise.
(dos_copy_tty_state): Likewise.
* ser-mingw.c (ser_windows_open): Likewise.
(ser_console_wait_handle): Likewise.
(ser_console_get_tty_state): Likewise.
(make_pipe_state): Likewise.
(net_windows_open): Likewise.
* ser-unix.c (hardwire_get_tty_state): Likewise.
(hardwire_copy_tty_state): Likewise.
* solib-aix.c (solib_aix_new_lm_info): Likewise.
* solib-dsbt.c (dsbt_current_sos): Likewise.
(dsbt_relocate_main_executable): Likewise.
* solib-frv.c (frv_current_sos): Likewise.
(frv_relocate_main_executable): Likewise.
* solib-spu.c (spu_bfd_fopen): Likewise.
* solib-svr4.c (lm_info_read): Likewise.
(svr4_copy_library_list): Likewise.
(svr4_default_sos): Likewise.
* source.c (find_source_lines): Likewise.
(line_info): Likewise.
(add_substitute_path_rule): Likewise.
* spu-linux-nat.c (spu_bfd_open): Likewise.
* spu-tdep.c (info_spu_dma_cmdlist): Likewise.
* stabsread.c (dbx_lookup_type): Likewise.
(read_type): Likewise.
(read_member_functions): Likewise.
(read_struct_fields): Likewise.
(read_baseclasses): Likewise.
(read_args): Likewise.
(_initialize_stabsread): Likewise.
* stack.c (func_command): Likewise.
* stap-probe.c (handle_stap_probe): Likewise.
* symfile.c (addrs_section_sort): Likewise.
(addr_info_make_relative): Likewise.
(load_section_callback): Likewise.
(add_symbol_file_command): Likewise.
(init_filename_language_table): Likewise.
* symtab.c (create_filename_seen_cache): Likewise.
(sort_search_symbols_remove_dups): Likewise.
(search_symbols): Likewise.
* target.c (make_cleanup_restore_target_terminal): Likewise.
* thread.c (new_thread): Likewise.
(enable_thread_stack_temporaries): Likewise.
(make_cleanup_restore_current_thread): Likewise.
(thread_apply_all_command): Likewise.
* tic6x-tdep.c (tic6x_gdbarch_init): Likewise.
* top.c (gdb_readline_wrapper): Likewise.
* tracefile-tfile.c (tfile_trace_file_writer_new): Likewise.
* tracepoint.c (trace_find_line_command): Likewise.
(all_tracepoint_actions_and_cleanup): Likewise.
(make_cleanup_restore_current_traceframe): Likewise.
(get_uploaded_tp): Likewise.
(get_uploaded_tsv): Likewise.
* tui/tui-data.c (tui_alloc_generic_win_info): Likewise.
(tui_alloc_win_info): Likewise.
(tui_alloc_content): Likewise.
(tui_add_content_elements): Likewise.
* tui/tui-disasm.c (tui_find_disassembly_address): Likewise.
(tui_set_disassem_content): Likewise.
* ui-file.c (ui_file_new): Likewise.
(stdio_file_new): Likewise.
(tee_file_new): Likewise.
* utils.c (make_cleanup_restore_integer): Likewise.
(add_internal_problem_command): Likewise.
* v850-tdep.c (v850_gdbarch_init): Likewise.
* valops.c (find_oload_champ): Likewise.
* value.c (allocate_value_lazy): Likewise.
(record_latest_value): Likewise.
(create_internalvar): Likewise.
* varobj.c (install_variable): Likewise.
(new_variable): Likewise.
(new_root_variable): Likewise.
(cppush): Likewise.
(_initialize_varobj): Likewise.
* windows-nat.c (windows_make_so): Likewise.
* x86-nat.c (x86_add_process): Likewise.
* xcoffread.c (arrange_linetable): Likewise.
(allocate_include_entry): Likewise.
(process_linenos): Likewise.
(SYMBOL_DUP): Likewise.
(xcoff_start_psymtab): Likewise.
(xcoff_end_psymtab): Likewise.
* xml-support.c (gdb_xml_parse_attr_ulongest): Likewise.
* xtensa-tdep.c (xtensa_register_type): Likewise.
* gdbarch.c: Regenerate.
* gdbarch.h: Regenerate.
gdb/gdbserver/ChangeLog:
* ax.c (gdb_parse_agent_expr): Likewise.
(compile_bytecodes): Likewise.
* dll.c (loaded_dll): Likewise.
* event-loop.c (append_callback_event): Likewise.
(create_file_handler): Likewise.
(create_file_event): Likewise.
* hostio.c (handle_open): Likewise.
* inferiors.c (add_thread): Likewise.
(add_process): Likewise.
* linux-aarch64-low.c (aarch64_linux_new_process): Likewise.
* linux-arm-low.c (arm_new_process): Likewise.
(arm_new_thread): Likewise.
* linux-low.c (add_to_pid_list): Likewise.
(linux_add_process): Likewise.
(handle_extended_wait): Likewise.
(add_lwp): Likewise.
(enqueue_one_deferred_signal): Likewise.
(enqueue_pending_signal): Likewise.
(linux_resume_one_lwp_throw): Likewise.
(linux_resume_one_thread): Likewise.
(linux_read_memory): Likewise.
(linux_write_memory): Likewise.
* linux-mips-low.c (mips_linux_new_process): Likewise.
(mips_linux_new_thread): Likewise.
(mips_add_watchpoint): Likewise.
* linux-x86-low.c (initialize_low_arch): Likewise.
* lynx-low.c (lynx_add_process): Likewise.
* mem-break.c (set_raw_breakpoint_at): Likewise.
(set_breakpoint): Likewise.
(add_condition_to_breakpoint): Likewise.
(add_commands_to_breakpoint): Likewise.
(clone_agent_expr): Likewise.
(clone_one_breakpoint): Likewise.
* regcache.c (new_register_cache): Likewise.
* remote-utils.c (look_up_one_symbol): Likewise.
* server.c (queue_stop_reply): Likewise.
(start_inferior): Likewise.
(queue_stop_reply_callback): Likewise.
(handle_target_event): Likewise.
* spu-low.c (fetch_ppc_memory): Likewise.
(store_ppc_memory): Likewise.
* target.c (set_target_ops): Likewise.
* thread-db.c (thread_db_load_search): Likewise.
(try_thread_db_load_1): Likewise.
* tracepoint.c (add_tracepoint): Likewise.
(add_tracepoint_action): Likewise.
(create_trace_state_variable): Likewise.
(cmd_qtdpsrc): Likewise.
(cmd_qtro): Likewise.
(add_while_stepping_state): Likewise.
* win32-low.c (child_add_thread): Likewise.
(get_image_name): Likewise.
2015-08-26 21:16:07 +00:00
|
|
|
= XNEW (struct tfile_trace_file_writer);
|
Move trace file writer out of tracepoint.c
This patch is a refactor which moves trace file writer related code
out of tracepoint.c, which has 6k LOC. It moves general trace file
writer to a new file tracefile.c and moves tfile specific writer to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* Makefile.in (REMOTE_OBS): Append tracefile.o and
tracefile-tfile.o.
(HFILES_NO_SRCDIR): Add tracefile.h.
* ctf.c: Include "tracefile.h".
* tracefile.h: New file.
* tracefile.c: New file
* tracefile-tfile.c: New file.
* tracepoint.c: Include "tracefile.h".
(free_uploaded_tps, free_uploaded_tsvs): Remove declarations.
(stop_reason_names): Add const.
(trace_file_writer_xfree): Move it to tracefile.c.
(trace_save, trace_save_command, trace_save_tfile): Likewise.
(trace_save_ctf): Likewise.
(struct tfile_trace_file_writer): Move it to tracefile-tfile.c.
(tfile_target_save, tfile_dtor, tfile_start): Likewise.
(tfile_write_header, tfile_write_regblock_type): Likewise.
(tfile_write_status, tfile_write_uploaded_tsv): Likewise.
(tfile_write_uploaded_tp, tfile_write_definition_end): Likewise.
(tfile_write_raw_data, tfile_end): Likewise.
(tfile_trace_file_writer_new): Likewise.
(free_uploaded_tp): Make it extern.
(free_uploaded_tsv): Make it extern.
(_initialize_tracepoint): Move code to register command 'tsave'
to tracefile.c.
* tracepoint.h (stop_reason_names): Declare.
(struct trace_frame_write_ops): Move it to tracefile.h.
(struct trace_file_write_ops): Likewise.
(struct trace_file_writer): Likewise.
(free_uploaded_tsvs, free_uploaded_tps): Declare.
2014-02-10 05:31:12 +00:00
|
|
|
|
|
|
|
writer->base.ops = &tfile_write_ops;
|
|
|
|
writer->fp = NULL;
|
|
|
|
writer->pathname = NULL;
|
|
|
|
|
|
|
|
return (struct trace_file_writer *) writer;
|
|
|
|
}
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
|
|
|
|
/* target tfile command */
|
|
|
|
|
|
|
|
static struct target_ops tfile_ops;
|
|
|
|
|
|
|
|
/* Fill in tfile_ops with its defined operations and properties. */
|
|
|
|
|
|
|
|
#define TRACE_HEADER_SIZE 8
|
|
|
|
|
|
|
|
#define TFILE_PID (1)
|
|
|
|
|
|
|
|
static char *trace_filename;
|
|
|
|
static int trace_fd = -1;
|
|
|
|
static off_t trace_frames_offset;
|
|
|
|
static off_t cur_offset;
|
|
|
|
static int cur_data_size;
|
|
|
|
int trace_regblock_size;
|
|
|
|
|
|
|
|
static void tfile_interp_line (char *line,
|
|
|
|
struct uploaded_tp **utpp,
|
|
|
|
struct uploaded_tsv **utsvp);
|
|
|
|
|
|
|
|
/* Read SIZE bytes into READBUF from the trace frame, starting at
|
|
|
|
TRACE_FD's current position. Note that this call `read'
|
|
|
|
underneath, hence it advances the file's seek position. Throws an
|
|
|
|
error if the `read' syscall fails, or less than SIZE bytes are
|
|
|
|
read. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_read (gdb_byte *readbuf, int size)
|
|
|
|
{
|
|
|
|
int gotten;
|
|
|
|
|
|
|
|
gotten = read (trace_fd, readbuf, size);
|
|
|
|
if (gotten < 0)
|
|
|
|
perror_with_name (trace_filename);
|
|
|
|
else if (gotten < size)
|
|
|
|
error (_("Premature end of file while reading trace file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
constify to_open
This makes target_ops::to_open take a const string and then fixes the
fallout.
There were a few of these I could not build. However I eyeballed it
and in any case the fixes should generally be trivial.
This is based on the patch to fix up the target debugging for to_open,
because that changes gdb to not directly install to_open as the target
command
2014-07-30 Tom Tromey <tromey@redhat.com>
* bsd-kvm.c (bsd_kvm_open): Constify.
* corelow.c (core_open): Constify.
* ctf.c (ctf_open): Constify.
* dbug-rom.c (dbug_open): Constify.
* exec.c (exec_open): Constify.
* m32r-rom.c (m32r_open, mon2000_open): Constify.
* microblaze-rom.c (picobug_open): Constify.
* nto-procfs.c (procfs_open_1, procfs_open, procfs_native_open):
Constify.
* ppcbug-rom.c (ppcbug_open0, ppcbug_open1): Constify.
* record-btrace.c (record_btrace_open): Constify.
* record-full.c (record_full_core_open_1, record_full_open_1)
(record_full_open): Constify.
* remote-m32r-sdi.c (m32r_open): Constify.
* remote-mips.c (common_open, mips_open, pmon_open, ddb_open)
(rockhopper_open, lsi_open): Constify.
* remote-sim.c (gdbsim_open): Constify.
* remote.c (remote_open, extended_remote_open, remote_open_1):
Constify.
* target.h (struct target_ops) <to_open>: Make "arg" const.
* tracefile-tfile.c (tfile_open): Constify.
2014-07-22 16:56:01 +00:00
|
|
|
tfile_open (const char *arg, int from_tty)
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
char *temp;
|
|
|
|
struct cleanup *old_chain;
|
|
|
|
int flags;
|
|
|
|
int scratch_chan;
|
|
|
|
char header[TRACE_HEADER_SIZE];
|
|
|
|
char linebuf[1000]; /* Should be max remote packet size or so. */
|
|
|
|
gdb_byte byte;
|
|
|
|
int bytes, i;
|
|
|
|
struct trace_status *ts;
|
|
|
|
struct uploaded_tp *uploaded_tps = NULL;
|
|
|
|
struct uploaded_tsv *uploaded_tsvs = NULL;
|
constify to_open
This makes target_ops::to_open take a const string and then fixes the
fallout.
There were a few of these I could not build. However I eyeballed it
and in any case the fixes should generally be trivial.
This is based on the patch to fix up the target debugging for to_open,
because that changes gdb to not directly install to_open as the target
command
2014-07-30 Tom Tromey <tromey@redhat.com>
* bsd-kvm.c (bsd_kvm_open): Constify.
* corelow.c (core_open): Constify.
* ctf.c (ctf_open): Constify.
* dbug-rom.c (dbug_open): Constify.
* exec.c (exec_open): Constify.
* m32r-rom.c (m32r_open, mon2000_open): Constify.
* microblaze-rom.c (picobug_open): Constify.
* nto-procfs.c (procfs_open_1, procfs_open, procfs_native_open):
Constify.
* ppcbug-rom.c (ppcbug_open0, ppcbug_open1): Constify.
* record-btrace.c (record_btrace_open): Constify.
* record-full.c (record_full_core_open_1, record_full_open_1)
(record_full_open): Constify.
* remote-m32r-sdi.c (m32r_open): Constify.
* remote-mips.c (common_open, mips_open, pmon_open, ddb_open)
(rockhopper_open, lsi_open): Constify.
* remote-sim.c (gdbsim_open): Constify.
* remote.c (remote_open, extended_remote_open, remote_open_1):
Constify.
* target.h (struct target_ops) <to_open>: Make "arg" const.
* tracefile-tfile.c (tfile_open): Constify.
2014-07-22 16:56:01 +00:00
|
|
|
char *filename;
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
|
|
|
|
target_preopen (from_tty);
|
constify to_open
This makes target_ops::to_open take a const string and then fixes the
fallout.
There were a few of these I could not build. However I eyeballed it
and in any case the fixes should generally be trivial.
This is based on the patch to fix up the target debugging for to_open,
because that changes gdb to not directly install to_open as the target
command
2014-07-30 Tom Tromey <tromey@redhat.com>
* bsd-kvm.c (bsd_kvm_open): Constify.
* corelow.c (core_open): Constify.
* ctf.c (ctf_open): Constify.
* dbug-rom.c (dbug_open): Constify.
* exec.c (exec_open): Constify.
* m32r-rom.c (m32r_open, mon2000_open): Constify.
* microblaze-rom.c (picobug_open): Constify.
* nto-procfs.c (procfs_open_1, procfs_open, procfs_native_open):
Constify.
* ppcbug-rom.c (ppcbug_open0, ppcbug_open1): Constify.
* record-btrace.c (record_btrace_open): Constify.
* record-full.c (record_full_core_open_1, record_full_open_1)
(record_full_open): Constify.
* remote-m32r-sdi.c (m32r_open): Constify.
* remote-mips.c (common_open, mips_open, pmon_open, ddb_open)
(rockhopper_open, lsi_open): Constify.
* remote-sim.c (gdbsim_open): Constify.
* remote.c (remote_open, extended_remote_open, remote_open_1):
Constify.
* target.h (struct target_ops) <to_open>: Make "arg" const.
* tracefile-tfile.c (tfile_open): Constify.
2014-07-22 16:56:01 +00:00
|
|
|
if (!arg)
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
error (_("No trace file specified."));
|
|
|
|
|
constify to_open
This makes target_ops::to_open take a const string and then fixes the
fallout.
There were a few of these I could not build. However I eyeballed it
and in any case the fixes should generally be trivial.
This is based on the patch to fix up the target debugging for to_open,
because that changes gdb to not directly install to_open as the target
command
2014-07-30 Tom Tromey <tromey@redhat.com>
* bsd-kvm.c (bsd_kvm_open): Constify.
* corelow.c (core_open): Constify.
* ctf.c (ctf_open): Constify.
* dbug-rom.c (dbug_open): Constify.
* exec.c (exec_open): Constify.
* m32r-rom.c (m32r_open, mon2000_open): Constify.
* microblaze-rom.c (picobug_open): Constify.
* nto-procfs.c (procfs_open_1, procfs_open, procfs_native_open):
Constify.
* ppcbug-rom.c (ppcbug_open0, ppcbug_open1): Constify.
* record-btrace.c (record_btrace_open): Constify.
* record-full.c (record_full_core_open_1, record_full_open_1)
(record_full_open): Constify.
* remote-m32r-sdi.c (m32r_open): Constify.
* remote-mips.c (common_open, mips_open, pmon_open, ddb_open)
(rockhopper_open, lsi_open): Constify.
* remote-sim.c (gdbsim_open): Constify.
* remote.c (remote_open, extended_remote_open, remote_open_1):
Constify.
* target.h (struct target_ops) <to_open>: Make "arg" const.
* tracefile-tfile.c (tfile_open): Constify.
2014-07-22 16:56:01 +00:00
|
|
|
filename = tilde_expand (arg);
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
if (!IS_ABSOLUTE_PATH(filename))
|
|
|
|
{
|
|
|
|
temp = concat (current_directory, "/", filename, (char *) NULL);
|
|
|
|
xfree (filename);
|
|
|
|
filename = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_chain = make_cleanup (xfree, filename);
|
|
|
|
|
|
|
|
flags = O_BINARY | O_LARGEFILE;
|
|
|
|
flags |= O_RDONLY;
|
|
|
|
scratch_chan = gdb_open_cloexec (filename, flags, 0);
|
|
|
|
if (scratch_chan < 0)
|
|
|
|
perror_with_name (filename);
|
|
|
|
|
|
|
|
/* Looks semi-reasonable. Toss the old trace file and work on the new. */
|
|
|
|
|
|
|
|
discard_cleanups (old_chain); /* Don't free filename any more. */
|
|
|
|
unpush_target (&tfile_ops);
|
|
|
|
|
|
|
|
trace_filename = xstrdup (filename);
|
|
|
|
trace_fd = scratch_chan;
|
|
|
|
|
|
|
|
bytes = 0;
|
|
|
|
/* Read the file header and test for validity. */
|
|
|
|
tfile_read ((gdb_byte *) &header, TRACE_HEADER_SIZE);
|
|
|
|
|
|
|
|
bytes += TRACE_HEADER_SIZE;
|
|
|
|
if (!(header[0] == 0x7f
|
2015-03-06 09:42:06 +00:00
|
|
|
&& (startswith (header + 1, "TRACE0\n"))))
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
error (_("File is not a valid trace file."));
|
|
|
|
|
|
|
|
push_target (&tfile_ops);
|
|
|
|
|
|
|
|
trace_regblock_size = 0;
|
|
|
|
ts = current_trace_status ();
|
|
|
|
/* We know we're working with a file. Record its name. */
|
|
|
|
ts->filename = trace_filename;
|
|
|
|
/* Set defaults in case there is no status line. */
|
|
|
|
ts->running_known = 0;
|
|
|
|
ts->stop_reason = trace_stop_reason_unknown;
|
|
|
|
ts->traceframe_count = -1;
|
|
|
|
ts->buffer_free = 0;
|
|
|
|
ts->disconnected_tracing = 0;
|
|
|
|
ts->circular_buffer = 0;
|
|
|
|
|
Split TRY_CATCH into TRY + CATCH
This patch splits the TRY_CATCH macro into three, so that we go from
this:
~~~
volatile gdb_exception ex;
TRY_CATCH (ex, RETURN_MASK_ERROR)
{
}
if (ex.reason < 0)
{
}
~~~
to this:
~~~
TRY
{
}
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
~~~
Thus, we'll be getting rid of the local volatile exception object, and
declaring the caught exception in the catch block.
This allows reimplementing TRY/CATCH in terms of C++ exceptions when
building in C++ mode, while still allowing to build GDB in C mode
(using setjmp/longjmp), as a transition step.
TBC, after this patch, is it _not_ valid to have code between the TRY
and the CATCH blocks, like:
TRY
{
}
// some code here.
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
Just like it isn't valid to do that with C++'s native try/catch.
By switching to creating the exception object inside the CATCH block
scope, we can get rid of all the explicitly allocated volatile
exception objects all over the tree, and map the CATCH block more
directly to C++'s catch blocks.
The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was
done with a script, rerun from scratch at every rebase, no manual
editing involved. After the mechanical conversion, a few places
needed manual intervention, to fix preexisting cases where we were
using the exception object outside of the TRY_CATCH block, and cases
where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH
after this patch]. The result was folded into this patch so that GDB
still builds at each incremental step.
END_CATCH is necessary for two reasons:
First, because we name the exception object in the CATCH block, which
requires creating a scope, which in turn must be closed somewhere.
Declaring the exception variable in the initializer field of a for
block, like:
#define CATCH(EXCEPTION, mask) \
for (struct gdb_exception EXCEPTION; \
exceptions_state_mc_catch (&EXCEPTION, MASK); \
EXCEPTION = exception_none)
would avoid needing END_CATCH, but alas, in C mode, we build with C90,
which doesn't allow mixed declarations and code.
Second, because when TRY/CATCH are wired to real C++ try/catch, as
long as we need to handle cleanup chains, even if there's no CATCH
block that wants to catch the exception, we need for stop at every
frame in the unwind chain and run cleanups, then rethrow. That will
be done in END_CATCH.
After we require C++, we'll still need TRY/CATCH/END_CATCH until
cleanups are completely phased out -- TRY/CATCH in C++ mode will
save/restore the current cleanup chain, like in C mode, and END_CATCH
catches otherwise uncaugh exceptions, runs cleanups and rethrows, so
that C++ cleanups and exceptions can coexist.
IMO, this still makes the TRY/CATCH code look a bit more like a
newcomer would expect, so IMO worth it even if we weren't considering
C++.
gdb/ChangeLog.
2015-03-07 Pedro Alves <palves@redhat.com>
* common/common-exceptions.c (struct catcher) <exception>: No
longer a pointer to volatile exception. Now an exception value.
<mask>: Delete field.
(exceptions_state_mc_init): Remove all parameters. Adjust.
(exceptions_state_mc): No longer pop the catcher here.
(exceptions_state_mc_catch): New function.
(throw_exception): Adjust.
* common/common-exceptions.h (exceptions_state_mc_init): Remove
all parameters.
(exceptions_state_mc_catch): Declare.
(TRY_CATCH): Rename to ...
(TRY): ... this. Remove EXCEPTION and MASK parameters.
(CATCH, END_CATCH): New.
All callers adjusted.
gdb/gdbserver/ChangeLog:
2015-03-07 Pedro Alves <palves@redhat.com>
Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH
instead.
2015-03-07 15:14:14 +00:00
|
|
|
TRY
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
/* Read through a section of newline-terminated lines that
|
|
|
|
define things like tracepoints. */
|
|
|
|
i = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
tfile_read (&byte, 1);
|
|
|
|
|
|
|
|
++bytes;
|
|
|
|
if (byte == '\n')
|
|
|
|
{
|
|
|
|
/* Empty line marks end of the definition section. */
|
|
|
|
if (i == 0)
|
|
|
|
break;
|
|
|
|
linebuf[i] = '\0';
|
|
|
|
i = 0;
|
|
|
|
tfile_interp_line (linebuf, &uploaded_tps, &uploaded_tsvs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
linebuf[i++] = byte;
|
|
|
|
if (i >= 1000)
|
|
|
|
error (_("Excessively long lines in trace file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Record the starting offset of the binary trace data. */
|
|
|
|
trace_frames_offset = bytes;
|
|
|
|
|
|
|
|
/* If we don't have a blocksize, we can't interpret the
|
|
|
|
traceframes. */
|
|
|
|
if (trace_regblock_size == 0)
|
|
|
|
error (_("No register block size recorded in trace file"));
|
|
|
|
}
|
Split TRY_CATCH into TRY + CATCH
This patch splits the TRY_CATCH macro into three, so that we go from
this:
~~~
volatile gdb_exception ex;
TRY_CATCH (ex, RETURN_MASK_ERROR)
{
}
if (ex.reason < 0)
{
}
~~~
to this:
~~~
TRY
{
}
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
~~~
Thus, we'll be getting rid of the local volatile exception object, and
declaring the caught exception in the catch block.
This allows reimplementing TRY/CATCH in terms of C++ exceptions when
building in C++ mode, while still allowing to build GDB in C mode
(using setjmp/longjmp), as a transition step.
TBC, after this patch, is it _not_ valid to have code between the TRY
and the CATCH blocks, like:
TRY
{
}
// some code here.
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
Just like it isn't valid to do that with C++'s native try/catch.
By switching to creating the exception object inside the CATCH block
scope, we can get rid of all the explicitly allocated volatile
exception objects all over the tree, and map the CATCH block more
directly to C++'s catch blocks.
The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was
done with a script, rerun from scratch at every rebase, no manual
editing involved. After the mechanical conversion, a few places
needed manual intervention, to fix preexisting cases where we were
using the exception object outside of the TRY_CATCH block, and cases
where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH
after this patch]. The result was folded into this patch so that GDB
still builds at each incremental step.
END_CATCH is necessary for two reasons:
First, because we name the exception object in the CATCH block, which
requires creating a scope, which in turn must be closed somewhere.
Declaring the exception variable in the initializer field of a for
block, like:
#define CATCH(EXCEPTION, mask) \
for (struct gdb_exception EXCEPTION; \
exceptions_state_mc_catch (&EXCEPTION, MASK); \
EXCEPTION = exception_none)
would avoid needing END_CATCH, but alas, in C mode, we build with C90,
which doesn't allow mixed declarations and code.
Second, because when TRY/CATCH are wired to real C++ try/catch, as
long as we need to handle cleanup chains, even if there's no CATCH
block that wants to catch the exception, we need for stop at every
frame in the unwind chain and run cleanups, then rethrow. That will
be done in END_CATCH.
After we require C++, we'll still need TRY/CATCH/END_CATCH until
cleanups are completely phased out -- TRY/CATCH in C++ mode will
save/restore the current cleanup chain, like in C mode, and END_CATCH
catches otherwise uncaugh exceptions, runs cleanups and rethrows, so
that C++ cleanups and exceptions can coexist.
IMO, this still makes the TRY/CATCH code look a bit more like a
newcomer would expect, so IMO worth it even if we weren't considering
C++.
gdb/ChangeLog.
2015-03-07 Pedro Alves <palves@redhat.com>
* common/common-exceptions.c (struct catcher) <exception>: No
longer a pointer to volatile exception. Now an exception value.
<mask>: Delete field.
(exceptions_state_mc_init): Remove all parameters. Adjust.
(exceptions_state_mc): No longer pop the catcher here.
(exceptions_state_mc_catch): New function.
(throw_exception): Adjust.
* common/common-exceptions.h (exceptions_state_mc_init): Remove
all parameters.
(exceptions_state_mc_catch): Declare.
(TRY_CATCH): Rename to ...
(TRY): ... this. Remove EXCEPTION and MASK parameters.
(CATCH, END_CATCH): New.
All callers adjusted.
gdb/gdbserver/ChangeLog:
2015-03-07 Pedro Alves <palves@redhat.com>
Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH
instead.
2015-03-07 15:14:14 +00:00
|
|
|
CATCH (ex, RETURN_MASK_ALL)
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
/* Remove the partially set up target. */
|
|
|
|
unpush_target (&tfile_ops);
|
|
|
|
throw_exception (ex);
|
|
|
|
}
|
Split TRY_CATCH into TRY + CATCH
This patch splits the TRY_CATCH macro into three, so that we go from
this:
~~~
volatile gdb_exception ex;
TRY_CATCH (ex, RETURN_MASK_ERROR)
{
}
if (ex.reason < 0)
{
}
~~~
to this:
~~~
TRY
{
}
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
~~~
Thus, we'll be getting rid of the local volatile exception object, and
declaring the caught exception in the catch block.
This allows reimplementing TRY/CATCH in terms of C++ exceptions when
building in C++ mode, while still allowing to build GDB in C mode
(using setjmp/longjmp), as a transition step.
TBC, after this patch, is it _not_ valid to have code between the TRY
and the CATCH blocks, like:
TRY
{
}
// some code here.
CATCH (ex, RETURN_MASK_ERROR)
{
}
END_CATCH
Just like it isn't valid to do that with C++'s native try/catch.
By switching to creating the exception object inside the CATCH block
scope, we can get rid of all the explicitly allocated volatile
exception objects all over the tree, and map the CATCH block more
directly to C++'s catch blocks.
The majority of the TRY_CATCH -> TRY+CATCH+END_CATCH conversion was
done with a script, rerun from scratch at every rebase, no manual
editing involved. After the mechanical conversion, a few places
needed manual intervention, to fix preexisting cases where we were
using the exception object outside of the TRY_CATCH block, and cases
where we were using "else" after a 'if (ex.reason) < 0)' [a CATCH
after this patch]. The result was folded into this patch so that GDB
still builds at each incremental step.
END_CATCH is necessary for two reasons:
First, because we name the exception object in the CATCH block, which
requires creating a scope, which in turn must be closed somewhere.
Declaring the exception variable in the initializer field of a for
block, like:
#define CATCH(EXCEPTION, mask) \
for (struct gdb_exception EXCEPTION; \
exceptions_state_mc_catch (&EXCEPTION, MASK); \
EXCEPTION = exception_none)
would avoid needing END_CATCH, but alas, in C mode, we build with C90,
which doesn't allow mixed declarations and code.
Second, because when TRY/CATCH are wired to real C++ try/catch, as
long as we need to handle cleanup chains, even if there's no CATCH
block that wants to catch the exception, we need for stop at every
frame in the unwind chain and run cleanups, then rethrow. That will
be done in END_CATCH.
After we require C++, we'll still need TRY/CATCH/END_CATCH until
cleanups are completely phased out -- TRY/CATCH in C++ mode will
save/restore the current cleanup chain, like in C mode, and END_CATCH
catches otherwise uncaugh exceptions, runs cleanups and rethrows, so
that C++ cleanups and exceptions can coexist.
IMO, this still makes the TRY/CATCH code look a bit more like a
newcomer would expect, so IMO worth it even if we weren't considering
C++.
gdb/ChangeLog.
2015-03-07 Pedro Alves <palves@redhat.com>
* common/common-exceptions.c (struct catcher) <exception>: No
longer a pointer to volatile exception. Now an exception value.
<mask>: Delete field.
(exceptions_state_mc_init): Remove all parameters. Adjust.
(exceptions_state_mc): No longer pop the catcher here.
(exceptions_state_mc_catch): New function.
(throw_exception): Adjust.
* common/common-exceptions.h (exceptions_state_mc_init): Remove
all parameters.
(exceptions_state_mc_catch): Declare.
(TRY_CATCH): Rename to ...
(TRY): ... this. Remove EXCEPTION and MASK parameters.
(CATCH, END_CATCH): New.
All callers adjusted.
gdb/gdbserver/ChangeLog:
2015-03-07 Pedro Alves <palves@redhat.com>
Adjust all callers of TRY_CATCH to use TRY/CATCH/END_CATCH
instead.
2015-03-07 15:14:14 +00:00
|
|
|
END_CATCH
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
|
|
|
|
inferior_appeared (current_inferior (), TFILE_PID);
|
|
|
|
inferior_ptid = pid_to_ptid (TFILE_PID);
|
|
|
|
add_thread_silent (inferior_ptid);
|
|
|
|
|
|
|
|
if (ts->traceframe_count <= 0)
|
|
|
|
warning (_("No traceframes present in this file."));
|
|
|
|
|
|
|
|
/* Add the file's tracepoints and variables into the current mix. */
|
|
|
|
|
|
|
|
/* Get trace state variables first, they may be checked when parsing
|
|
|
|
uploaded commands. */
|
|
|
|
merge_uploaded_trace_state_variables (&uploaded_tsvs);
|
|
|
|
|
|
|
|
merge_uploaded_tracepoints (&uploaded_tps);
|
|
|
|
|
|
|
|
post_create_inferior (&tfile_ops, from_tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interpret the given line from the definitions part of the trace
|
|
|
|
file. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_interp_line (char *line, struct uploaded_tp **utpp,
|
|
|
|
struct uploaded_tsv **utsvp)
|
|
|
|
{
|
|
|
|
char *p = line;
|
|
|
|
|
2015-03-06 09:42:06 +00:00
|
|
|
if (startswith (p, "R "))
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
p += strlen ("R ");
|
|
|
|
trace_regblock_size = strtol (p, &p, 16);
|
|
|
|
}
|
2015-03-06 09:42:06 +00:00
|
|
|
else if (startswith (p, "status "))
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
p += strlen ("status ");
|
|
|
|
parse_trace_status (p, current_trace_status ());
|
|
|
|
}
|
2015-03-06 09:42:06 +00:00
|
|
|
else if (startswith (p, "tp "))
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
p += strlen ("tp ");
|
|
|
|
parse_tracepoint_definition (p, utpp);
|
|
|
|
}
|
2015-03-06 09:42:06 +00:00
|
|
|
else if (startswith (p, "tsv "))
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
{
|
|
|
|
p += strlen ("tsv ");
|
|
|
|
parse_tsv_definition (p, utsvp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
warning (_("Ignoring trace file definition \"%s\""), line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the trace file and generally clean up. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_close (struct target_ops *self)
|
|
|
|
{
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
if (trace_fd < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pid = ptid_get_pid (inferior_ptid);
|
|
|
|
inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
|
|
|
|
exit_inferior_silent (pid);
|
|
|
|
|
|
|
|
close (trace_fd);
|
|
|
|
trace_fd = -1;
|
|
|
|
xfree (trace_filename);
|
|
|
|
trace_filename = NULL;
|
|
|
|
|
|
|
|
trace_reset_local_state ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_files_info (struct target_ops *t)
|
|
|
|
{
|
|
|
|
printf_filtered ("\t`%s'\n", trace_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_get_tracepoint_status (struct target_ops *self,
|
|
|
|
struct breakpoint *tp, struct uploaded_tp *utp)
|
|
|
|
{
|
|
|
|
/* Other bits of trace status were collected as part of opening the
|
|
|
|
trace files, so nothing to do here. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given the position of a traceframe in the file, figure out what
|
|
|
|
address the frame was collected at. This would normally be the
|
|
|
|
value of a collected PC register, but if not available, we
|
|
|
|
improvise. */
|
|
|
|
|
|
|
|
static CORE_ADDR
|
|
|
|
tfile_get_traceframe_address (off_t tframe_offset)
|
|
|
|
{
|
|
|
|
CORE_ADDR addr = 0;
|
|
|
|
short tpnum;
|
|
|
|
struct tracepoint *tp;
|
|
|
|
off_t saved_offset = cur_offset;
|
|
|
|
|
|
|
|
/* FIXME dig pc out of collected registers. */
|
|
|
|
|
|
|
|
/* Fall back to using tracepoint address. */
|
|
|
|
lseek (trace_fd, tframe_offset, SEEK_SET);
|
|
|
|
tfile_read ((gdb_byte *) &tpnum, 2);
|
|
|
|
tpnum = (short) extract_signed_integer ((gdb_byte *) &tpnum, 2,
|
|
|
|
gdbarch_byte_order
|
|
|
|
(target_gdbarch ()));
|
|
|
|
|
|
|
|
tp = get_tracepoint_by_number_on_target (tpnum);
|
|
|
|
/* FIXME this is a poor heuristic if multiple locations. */
|
|
|
|
if (tp && tp->base.loc)
|
|
|
|
addr = tp->base.loc->address;
|
|
|
|
|
|
|
|
/* Restore our seek position. */
|
|
|
|
cur_offset = saved_offset;
|
|
|
|
lseek (trace_fd, cur_offset, SEEK_SET);
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given a type of search and some parameters, scan the collection of
|
|
|
|
traceframes in the file looking for a match. When found, return
|
|
|
|
both the traceframe and tracepoint number, otherwise -1 for
|
|
|
|
each. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
tfile_trace_find (struct target_ops *self, enum trace_find_type type, int num,
|
|
|
|
CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
|
|
|
|
{
|
|
|
|
short tpnum;
|
|
|
|
int tfnum = 0, found = 0;
|
|
|
|
unsigned int data_size;
|
|
|
|
struct tracepoint *tp;
|
|
|
|
off_t offset, tframe_offset;
|
|
|
|
CORE_ADDR tfaddr;
|
|
|
|
|
|
|
|
if (num == -1)
|
|
|
|
{
|
|
|
|
if (tpp)
|
|
|
|
*tpp = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lseek (trace_fd, trace_frames_offset, SEEK_SET);
|
|
|
|
offset = trace_frames_offset;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
tframe_offset = offset;
|
|
|
|
tfile_read ((gdb_byte *) &tpnum, 2);
|
|
|
|
tpnum = (short) extract_signed_integer ((gdb_byte *) &tpnum, 2,
|
|
|
|
gdbarch_byte_order
|
|
|
|
(target_gdbarch ()));
|
|
|
|
offset += 2;
|
|
|
|
if (tpnum == 0)
|
|
|
|
break;
|
|
|
|
tfile_read ((gdb_byte *) &data_size, 4);
|
|
|
|
data_size = (unsigned int) extract_unsigned_integer
|
|
|
|
((gdb_byte *) &data_size, 4,
|
|
|
|
gdbarch_byte_order (target_gdbarch ()));
|
|
|
|
offset += 4;
|
|
|
|
|
|
|
|
if (type == tfind_number)
|
|
|
|
{
|
|
|
|
/* Looking for a specific trace frame. */
|
|
|
|
if (tfnum == num)
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Start from the _next_ trace frame. */
|
|
|
|
if (tfnum > get_traceframe_number ())
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case tfind_pc:
|
|
|
|
tfaddr = tfile_get_traceframe_address (tframe_offset);
|
|
|
|
if (tfaddr == addr1)
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
case tfind_tp:
|
|
|
|
tp = get_tracepoint (num);
|
|
|
|
if (tp && tpnum == tp->number_on_target)
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
case tfind_range:
|
|
|
|
tfaddr = tfile_get_traceframe_address (tframe_offset);
|
|
|
|
if (addr1 <= tfaddr && tfaddr <= addr2)
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
case tfind_outside:
|
|
|
|
tfaddr = tfile_get_traceframe_address (tframe_offset);
|
|
|
|
if (!(addr1 <= tfaddr && tfaddr <= addr2))
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
internal_error (__FILE__, __LINE__, _("unknown tfind type"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
if (tpp)
|
|
|
|
*tpp = tpnum;
|
|
|
|
cur_offset = offset;
|
|
|
|
cur_data_size = data_size;
|
|
|
|
|
|
|
|
return tfnum;
|
|
|
|
}
|
|
|
|
/* Skip past the traceframe's data. */
|
|
|
|
lseek (trace_fd, data_size, SEEK_CUR);
|
|
|
|
offset += data_size;
|
|
|
|
/* Update our own count of traceframes. */
|
|
|
|
++tfnum;
|
|
|
|
}
|
|
|
|
/* Did not find what we were looking for. */
|
|
|
|
if (tpp)
|
|
|
|
*tpp = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prototype of the callback passed to tframe_walk_blocks. */
|
|
|
|
typedef int (*walk_blocks_callback_func) (char blocktype, void *data);
|
|
|
|
|
|
|
|
/* Callback for traceframe_walk_blocks, used to find a given block
|
|
|
|
type in a traceframe. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
match_blocktype (char blocktype, void *data)
|
|
|
|
{
|
|
|
|
char *wantedp = data;
|
|
|
|
|
|
|
|
if (*wantedp == blocktype)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Walk over all traceframe block starting at POS offset from
|
|
|
|
CUR_OFFSET, and call CALLBACK for each block found, passing in DATA
|
|
|
|
unmodified. If CALLBACK returns true, this returns the position in
|
|
|
|
the traceframe where the block is found, relative to the start of
|
|
|
|
the traceframe (cur_offset). Returns -1 if no callback call
|
|
|
|
returned true, indicating that all blocks have been walked. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
traceframe_walk_blocks (walk_blocks_callback_func callback,
|
|
|
|
int pos, void *data)
|
|
|
|
{
|
|
|
|
/* Iterate through a traceframe's blocks, looking for a block of the
|
|
|
|
requested type. */
|
|
|
|
|
|
|
|
lseek (trace_fd, cur_offset + pos, SEEK_SET);
|
|
|
|
while (pos < cur_data_size)
|
|
|
|
{
|
|
|
|
unsigned short mlen;
|
|
|
|
char block_type;
|
|
|
|
|
|
|
|
tfile_read ((gdb_byte *) &block_type, 1);
|
|
|
|
|
|
|
|
++pos;
|
|
|
|
|
|
|
|
if ((*callback) (block_type, data))
|
|
|
|
return pos;
|
|
|
|
|
|
|
|
switch (block_type)
|
|
|
|
{
|
|
|
|
case 'R':
|
|
|
|
lseek (trace_fd, cur_offset + pos + trace_regblock_size, SEEK_SET);
|
|
|
|
pos += trace_regblock_size;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
lseek (trace_fd, cur_offset + pos + 8, SEEK_SET);
|
|
|
|
tfile_read ((gdb_byte *) &mlen, 2);
|
|
|
|
mlen = (unsigned short)
|
|
|
|
extract_unsigned_integer ((gdb_byte *) &mlen, 2,
|
|
|
|
gdbarch_byte_order
|
|
|
|
(target_gdbarch ()));
|
|
|
|
lseek (trace_fd, mlen, SEEK_CUR);
|
|
|
|
pos += (8 + 2 + mlen);
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
lseek (trace_fd, cur_offset + pos + 4 + 8, SEEK_SET);
|
|
|
|
pos += (4 + 8);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error (_("Unknown block type '%c' (0x%x) in trace frame"),
|
|
|
|
block_type, block_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convenience wrapper around traceframe_walk_blocks. Looks for the
|
|
|
|
position offset of a block of type TYPE_WANTED in the current trace
|
|
|
|
frame, starting at POS. Returns -1 if no such block was found. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
traceframe_find_block_type (char type_wanted, int pos)
|
|
|
|
{
|
|
|
|
return traceframe_walk_blocks (match_blocktype, pos, &type_wanted);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for a block of saved registers in the traceframe, and get the
|
|
|
|
requested register from it. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
tfile_fetch_registers (struct target_ops *ops,
|
|
|
|
struct regcache *regcache, int regno)
|
|
|
|
{
|
|
|
|
struct gdbarch *gdbarch = get_regcache_arch (regcache);
|
2014-04-18 11:32:01 +00:00
|
|
|
int offset, regn, regsize;
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
|
|
|
|
/* An uninitialized reg size says we're not going to be
|
|
|
|
successful at getting register blocks. */
|
|
|
|
if (!trace_regblock_size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (traceframe_find_block_type ('R', 0) >= 0)
|
|
|
|
{
|
2014-04-18 11:32:01 +00:00
|
|
|
gdb_byte *regs = alloca (trace_regblock_size);
|
|
|
|
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
tfile_read (regs, trace_regblock_size);
|
|
|
|
|
|
|
|
/* Assume the block is laid out in GDB register number order,
|
|
|
|
each register with the size that it has in GDB. */
|
|
|
|
offset = 0;
|
|
|
|
for (regn = 0; regn < gdbarch_num_regs (gdbarch); regn++)
|
|
|
|
{
|
|
|
|
regsize = register_size (gdbarch, regn);
|
|
|
|
/* Make sure we stay within block bounds. */
|
|
|
|
if (offset + regsize >= trace_regblock_size)
|
|
|
|
break;
|
|
|
|
if (regcache_register_status (regcache, regn) == REG_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (regno == regn)
|
|
|
|
{
|
|
|
|
regcache_raw_supply (regcache, regno, regs + offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (regno == -1)
|
|
|
|
{
|
|
|
|
regcache_raw_supply (regcache, regn, regs + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += regsize;
|
|
|
|
}
|
|
|
|
}
|
2014-04-18 11:32:01 +00:00
|
|
|
else
|
|
|
|
tracefile_fetch_registers (regcache, regno);
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum target_xfer_status
|
|
|
|
tfile_xfer_partial (struct target_ops *ops, enum target_object object,
|
|
|
|
const char *annex, gdb_byte *readbuf,
|
|
|
|
const gdb_byte *writebuf, ULONGEST offset, ULONGEST len,
|
|
|
|
ULONGEST *xfered_len)
|
|
|
|
{
|
|
|
|
/* We're only doing regular memory for now. */
|
|
|
|
if (object != TARGET_OBJECT_MEMORY)
|
|
|
|
return TARGET_XFER_E_IO;
|
|
|
|
|
|
|
|
if (readbuf == NULL)
|
|
|
|
error (_("tfile_xfer_partial: trace file is read-only"));
|
|
|
|
|
|
|
|
if (get_traceframe_number () != -1)
|
|
|
|
{
|
|
|
|
int pos = 0;
|
Move the traceframe_available_memory code from memory_xfer_partial_1 down to the targets
As a follow-up to
[PATCH 7/8] Adjust read_value_memory to use to_xfer_partial
https://sourceware.org/ml/gdb-patches/2014-02/msg00384.html
this patch moves traceframe_available_memory down to the target side.
After this patch, the gdb core code is cleaner, and code on handling
unavailable memory is moved to remote/tfile/ctf targets.
In details, this patch moves traceframe_available_memory code from
memory_xfer_partial_1 to remote target only, so remote target still
uses traceframe_info mechanism to check unavailable memory, and use
remote_ops to read them from read-only sections. We don't use
traceframe_info mechanism for tfile and ctf target, because it is
fast to iterate all traceframes from trace file, so the summary
information got from traceframe_info is not necessary.
This patch also moves two functions to remote.c from target.c,
because they are only used in remote.c. I'll clean them up in another
patch.
gdb:
2014-03-22 Yao Qi <yao@codesourcery.com>
* ctf.c (ctf_xfer_partial): Check the return value of
exec_read_partial_read_only, if it is not TARGET_XFER_OK,
return TARGET_XFER_UNAVAILABLE.
* tracefile-tfile.c (tfile_xfer_partial): Likewise.
* target.c (target_read_live_memory): Move it to remote.c.
(memory_xfer_live_readonly_partial): Likewise.
(memory_xfer_partial_1): Move some code to remote_read_bytes.
* remote.c (target_read_live_memory): Moved from target.c.
(memory_xfer_live_readonly_partial): Likewise.
(remote_read_bytes): New, factored out from
memory_xfer_partial_1.
2014-03-11 02:47:48 +00:00
|
|
|
enum target_xfer_status res;
|
Partially available/unavailable data in requested range
In gdb.trace/unavailable.exp, an action is defined to collect
struct_b.struct_a.array[2] and struct_b.struct_a.array[100],
struct StructB
{
int d, ef;
StructA struct_a;
int s:1;
static StructA static_struct_a;
const char *string;
};
and the other files are not collected.
When GDB examine traceframe collected by the action, "struct_b" is
unavailable completely, which is wrong.
(gdb) p struct_b
$1 = <unavailable>
When GDB reads 'struct_b', it will request to read memory at struct_b's address
of length LEN. Since struct_b.d is not collected, no 'M' block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the whole requested range is unavailable.
In order to fix this problem, in the iteration to 'M' blocks, we record the
lowest address of blocks within the request range. If it has, the requested
range isn't unavailable completely. This applies to ctf too. With this patch
applied, the result looks good and fails in unavailable.exp is fixed.
(gdb) p struct_b
$1 = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>,
<unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>,
bitfield = <unavailable>}, string = <unavailable>}
gdb:
2014-05-05 Yao Qi <yao@codesourcery.com>
Pedro Alves <palves@redhat.com>
* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
address of blocks that intersects the requested range. Trim
LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
sections.
* ctf.c (ctf_xfer_partial): Likewise.
gdb/testsuite:
2014-05-05 Yao Qi <yao@codesourcery.com>
* gdb.trace/unavailable.exp (gdb_collect_args_test): Save
traceframes into tfile and ctf trace files. Read data from
trace file and test collected data.
(gdb_collect_locals_test): Likewise.
(gdb_unavailable_registers_test): Likewise.
(gdb_unavailable_floats): Likewise.
(gdb_collect_globals_test): Likewise.
(top-level): Append "ctf" to trace_file_targets if GDB
supports.
2014-04-26 02:14:52 +00:00
|
|
|
/* Records the lowest available address of all blocks that
|
|
|
|
intersects the requested range. */
|
|
|
|
ULONGEST low_addr_available = 0;
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
|
|
|
|
/* Iterate through the traceframe's blocks, looking for
|
|
|
|
memory. */
|
|
|
|
while ((pos = traceframe_find_block_type ('M', pos)) >= 0)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (maddr != offset)
|
|
|
|
lseek (trace_fd, offset - maddr, SEEK_CUR);
|
|
|
|
tfile_read (readbuf, amt);
|
|
|
|
*xfered_len = amt;
|
|
|
|
return TARGET_XFER_OK;
|
|
|
|
}
|
|
|
|
|
Partially available/unavailable data in requested range
In gdb.trace/unavailable.exp, an action is defined to collect
struct_b.struct_a.array[2] and struct_b.struct_a.array[100],
struct StructB
{
int d, ef;
StructA struct_a;
int s:1;
static StructA static_struct_a;
const char *string;
};
and the other files are not collected.
When GDB examine traceframe collected by the action, "struct_b" is
unavailable completely, which is wrong.
(gdb) p struct_b
$1 = <unavailable>
When GDB reads 'struct_b', it will request to read memory at struct_b's address
of length LEN. Since struct_b.d is not collected, no 'M' block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the whole requested range is unavailable.
In order to fix this problem, in the iteration to 'M' blocks, we record the
lowest address of blocks within the request range. If it has, the requested
range isn't unavailable completely. This applies to ctf too. With this patch
applied, the result looks good and fails in unavailable.exp is fixed.
(gdb) p struct_b
$1 = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>,
<unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>,
bitfield = <unavailable>}, string = <unavailable>}
gdb:
2014-05-05 Yao Qi <yao@codesourcery.com>
Pedro Alves <palves@redhat.com>
* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
address of blocks that intersects the requested range. Trim
LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
sections.
* ctf.c (ctf_xfer_partial): Likewise.
gdb/testsuite:
2014-05-05 Yao Qi <yao@codesourcery.com>
* gdb.trace/unavailable.exp (gdb_collect_args_test): Save
traceframes into tfile and ctf trace files. Read data from
trace file and test collected data.
(gdb_collect_locals_test): Likewise.
(gdb_unavailable_registers_test): Likewise.
(gdb_unavailable_floats): Likewise.
(gdb_collect_globals_test): Likewise.
(top-level): Append "ctf" to trace_file_targets if GDB
supports.
2014-04-26 02:14:52 +00:00
|
|
|
if (offset < maddr && maddr < (offset + len))
|
|
|
|
if (low_addr_available == 0 || low_addr_available > maddr)
|
|
|
|
low_addr_available = maddr;
|
|
|
|
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
/* Skip over this block. */
|
|
|
|
pos += (8 + 2 + mlen);
|
|
|
|
}
|
|
|
|
|
Move the traceframe_available_memory code from memory_xfer_partial_1 down to the targets
As a follow-up to
[PATCH 7/8] Adjust read_value_memory to use to_xfer_partial
https://sourceware.org/ml/gdb-patches/2014-02/msg00384.html
this patch moves traceframe_available_memory down to the target side.
After this patch, the gdb core code is cleaner, and code on handling
unavailable memory is moved to remote/tfile/ctf targets.
In details, this patch moves traceframe_available_memory code from
memory_xfer_partial_1 to remote target only, so remote target still
uses traceframe_info mechanism to check unavailable memory, and use
remote_ops to read them from read-only sections. We don't use
traceframe_info mechanism for tfile and ctf target, because it is
fast to iterate all traceframes from trace file, so the summary
information got from traceframe_info is not necessary.
This patch also moves two functions to remote.c from target.c,
because they are only used in remote.c. I'll clean them up in another
patch.
gdb:
2014-03-22 Yao Qi <yao@codesourcery.com>
* ctf.c (ctf_xfer_partial): Check the return value of
exec_read_partial_read_only, if it is not TARGET_XFER_OK,
return TARGET_XFER_UNAVAILABLE.
* tracefile-tfile.c (tfile_xfer_partial): Likewise.
* target.c (target_read_live_memory): Move it to remote.c.
(memory_xfer_live_readonly_partial): Likewise.
(memory_xfer_partial_1): Move some code to remote_read_bytes.
* remote.c (target_read_live_memory): Moved from target.c.
(memory_xfer_live_readonly_partial): Likewise.
(remote_read_bytes): New, factored out from
memory_xfer_partial_1.
2014-03-11 02:47:48 +00:00
|
|
|
/* Requested memory is unavailable in the context of traceframes,
|
|
|
|
and this address falls within a read-only section, fallback
|
Partially available/unavailable data in requested range
In gdb.trace/unavailable.exp, an action is defined to collect
struct_b.struct_a.array[2] and struct_b.struct_a.array[100],
struct StructB
{
int d, ef;
StructA struct_a;
int s:1;
static StructA static_struct_a;
const char *string;
};
and the other files are not collected.
When GDB examine traceframe collected by the action, "struct_b" is
unavailable completely, which is wrong.
(gdb) p struct_b
$1 = <unavailable>
When GDB reads 'struct_b', it will request to read memory at struct_b's address
of length LEN. Since struct_b.d is not collected, no 'M' block
includes the first part of the desired range, so tfile_xfer_partial returns
TARGET_XFER_UNAVAILABLE and GDB thinks the whole requested range is unavailable.
In order to fix this problem, in the iteration to 'M' blocks, we record the
lowest address of blocks within the request range. If it has, the requested
range isn't unavailable completely. This applies to ctf too. With this patch
applied, the result looks good and fails in unavailable.exp is fixed.
(gdb) p struct_b
$1 = {d = <unavailable>, ef = <unavailable>, struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable>,
<unavailable>, -1431655766, <unavailable> <repeats 97 times>, -1431655766, <unavailable> <repeats 9899 times>}, ptr = <unavailable>, bitfield = <unavailable>}, s = <unavailable>, static static_struct_a = {a = <unavailable>, b = <unavailable>, array = {<unavailable> <repeats 10000 times>}, ptr = <unavailable>,
bitfield = <unavailable>}, string = <unavailable>}
gdb:
2014-05-05 Yao Qi <yao@codesourcery.com>
Pedro Alves <palves@redhat.com>
* tracefile-tfile.c (tfile_xfer_partial): Record the lowest
address of blocks that intersects the requested range. Trim
LEN up to LOW_ADDR_AVAILABLE if read from executable read-only
sections.
* ctf.c (ctf_xfer_partial): Likewise.
gdb/testsuite:
2014-05-05 Yao Qi <yao@codesourcery.com>
* gdb.trace/unavailable.exp (gdb_collect_args_test): Save
traceframes into tfile and ctf trace files. Read data from
trace file and test collected data.
(gdb_collect_locals_test): Likewise.
(gdb_unavailable_registers_test): Likewise.
(gdb_unavailable_floats): Likewise.
(gdb_collect_globals_test): Likewise.
(top-level): Append "ctf" to trace_file_targets if GDB
supports.
2014-04-26 02:14:52 +00:00
|
|
|
to reading from executable, up to LOW_ADDR_AVAILABLE. */
|
|
|
|
if (offset < low_addr_available)
|
|
|
|
len = min (len, low_addr_available - offset);
|
Move the traceframe_available_memory code from memory_xfer_partial_1 down to the targets
As a follow-up to
[PATCH 7/8] Adjust read_value_memory to use to_xfer_partial
https://sourceware.org/ml/gdb-patches/2014-02/msg00384.html
this patch moves traceframe_available_memory down to the target side.
After this patch, the gdb core code is cleaner, and code on handling
unavailable memory is moved to remote/tfile/ctf targets.
In details, this patch moves traceframe_available_memory code from
memory_xfer_partial_1 to remote target only, so remote target still
uses traceframe_info mechanism to check unavailable memory, and use
remote_ops to read them from read-only sections. We don't use
traceframe_info mechanism for tfile and ctf target, because it is
fast to iterate all traceframes from trace file, so the summary
information got from traceframe_info is not necessary.
This patch also moves two functions to remote.c from target.c,
because they are only used in remote.c. I'll clean them up in another
patch.
gdb:
2014-03-22 Yao Qi <yao@codesourcery.com>
* ctf.c (ctf_xfer_partial): Check the return value of
exec_read_partial_read_only, if it is not TARGET_XFER_OK,
return TARGET_XFER_UNAVAILABLE.
* tracefile-tfile.c (tfile_xfer_partial): Likewise.
* target.c (target_read_live_memory): Move it to remote.c.
(memory_xfer_live_readonly_partial): Likewise.
(memory_xfer_partial_1): Move some code to remote_read_bytes.
* remote.c (target_read_live_memory): Moved from target.c.
(memory_xfer_live_readonly_partial): Likewise.
(remote_read_bytes): New, factored out from
memory_xfer_partial_1.
2014-03-11 02:47:48 +00:00
|
|
|
res = exec_read_partial_read_only (readbuf, offset, len, xfered_len);
|
|
|
|
|
|
|
|
if (res == TARGET_XFER_OK)
|
|
|
|
return TARGET_XFER_OK;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No use trying further, we know some memory starting
|
|
|
|
at MEMADDR isn't available. */
|
|
|
|
*xfered_len = len;
|
|
|
|
return TARGET_XFER_UNAVAILABLE;
|
|
|
|
}
|
2014-02-11 04:20:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Fallback to reading from read-only sections. */
|
|
|
|
return section_table_read_available_memory (readbuf, offset, len,
|
|
|
|
xfered_len);
|
|
|
|
}
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Iterate through the blocks of a trace frame, looking for a 'V'
|
|
|
|
block with a matching tsv number. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
tfile_get_trace_state_variable_value (struct target_ops *self,
|
|
|
|
int tsvnum, LONGEST *val)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
/* Iterate over blocks in current frame and find the last 'V'
|
|
|
|
block in which tsv number is TSVNUM. In one trace frame, there
|
|
|
|
may be multiple 'V' blocks created for a given trace variable,
|
|
|
|
and the last matched 'V' block contains the updated value. */
|
|
|
|
pos = 0;
|
|
|
|
while ((pos = traceframe_find_block_type ('V', pos)) >= 0)
|
|
|
|
{
|
|
|
|
int vnum;
|
|
|
|
|
|
|
|
tfile_read ((gdb_byte *) &vnum, 4);
|
|
|
|
vnum = (int) extract_signed_integer ((gdb_byte *) &vnum, 4,
|
|
|
|
gdbarch_byte_order
|
|
|
|
(target_gdbarch ()));
|
|
|
|
if (tsvnum == vnum)
|
|
|
|
{
|
|
|
|
tfile_read ((gdb_byte *) val, 8);
|
|
|
|
*val = extract_signed_integer ((gdb_byte *) val, 8,
|
|
|
|
gdbarch_byte_order
|
|
|
|
(target_gdbarch ()));
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
pos += (4 + 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for traceframe_walk_blocks. Builds a traceframe_info
|
|
|
|
object for the tfile target's current traceframe. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
build_traceframe_info (char blocktype, void *data)
|
|
|
|
{
|
|
|
|
struct traceframe_info *info = data;
|
|
|
|
|
|
|
|
switch (blocktype)
|
|
|
|
{
|
|
|
|
case 'M':
|
|
|
|
{
|
|
|
|
struct mem_range *r;
|
|
|
|
ULONGEST maddr;
|
|
|
|
unsigned short mlen;
|
|
|
|
|
|
|
|
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 ()));
|
|
|
|
|
|
|
|
r = VEC_safe_push (mem_range_s, info->memory, NULL);
|
|
|
|
|
|
|
|
r->start = maddr;
|
|
|
|
r->length = mlen;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'V':
|
|
|
|
{
|
|
|
|
int vnum;
|
|
|
|
|
|
|
|
tfile_read ((gdb_byte *) &vnum, 4);
|
|
|
|
VEC_safe_push (int, info->tvars, vnum);
|
|
|
|
}
|
|
|
|
case 'R':
|
|
|
|
case 'S':
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
warning (_("Unhandled trace block type (%d) '%c ' "
|
|
|
|
"while building trace frame info."),
|
|
|
|
blocktype, blocktype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct traceframe_info *
|
|
|
|
tfile_traceframe_info (struct target_ops *self)
|
|
|
|
{
|
|
|
|
struct traceframe_info *info = XCNEW (struct traceframe_info);
|
|
|
|
|
|
|
|
traceframe_walk_blocks (build_traceframe_info, 0, info);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_tfile_ops (void)
|
|
|
|
{
|
2014-02-10 07:22:55 +00:00
|
|
|
init_tracefile_ops (&tfile_ops);
|
|
|
|
|
Move tfile target to tracefile-tfile.c
This patch moves tfile target related code from tracepoint.c to
tracefile-tfile.c.
gdb:
2014-02-23 Yao Qi <yao@codesourcery.com>
* tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
(O_LARGEFILE): Likewise.
(tfile_ops): Likewise.
(TRACE_HEADER_SIZE): Likewise.
(trace_fd, trace_frames_offset, cur_offset): Likewise.
(cur_data_size): Likewise.
(tfile_read, tfile_open, tfile_interp_line): Likewise.
(tfile_close, tfile_files_info): Likewise.
(tfile_get_trace_status): Likewise.
(tfile_get_tracepoint_status): Likewise.
(tfile_get_traceframe_address): Likewise.
(tfile_trace_find, match_blocktype): Likewise.
(traceframe_walk_blocks, traceframe_find_block_type): Likewise.
(tfile_fetch_registers, tfile_xfer_partial): Likewise.
(tfile_get_trace_state_variable_value): Likewise.
(tfile_has_all_memory, tfile_has_memory): Likewise.
(tfile_has_stack, tfile_has_registers): Likewise.
(tfile_thread_alive, build_traceframe_info): Likewise.
(tfile_traceframe_info, init_tfile_ops): Likewise.
(_initialize_tracepoint): Don't call init_tfile_ops
and add_target_with_completer.
* tracefile-tfile.c: Include regcache.h, inferior.h, gdbthread.h,
exec.h, completer.h and filenames.h.
(_initialize_tracefile_tfile): New function.
2014-02-10 06:38:26 +00:00
|
|
|
tfile_ops.to_shortname = "tfile";
|
|
|
|
tfile_ops.to_longname = "Local trace dump file";
|
|
|
|
tfile_ops.to_doc
|
|
|
|
= "Use a trace file as a target. Specify the filename of the trace file.";
|
|
|
|
tfile_ops.to_open = tfile_open;
|
|
|
|
tfile_ops.to_close = tfile_close;
|
|
|
|
tfile_ops.to_fetch_registers = tfile_fetch_registers;
|
|
|
|
tfile_ops.to_xfer_partial = tfile_xfer_partial;
|
|
|
|
tfile_ops.to_files_info = tfile_files_info;
|
|
|
|
tfile_ops.to_get_tracepoint_status = tfile_get_tracepoint_status;
|
|
|
|
tfile_ops.to_trace_find = tfile_trace_find;
|
|
|
|
tfile_ops.to_get_trace_state_variable_value
|
|
|
|
= tfile_get_trace_state_variable_value;
|
|
|
|
tfile_ops.to_traceframe_info = tfile_traceframe_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern initialize_file_ftype _initialize_tracefile_tfile;
|
|
|
|
|
|
|
|
void
|
|
|
|
_initialize_tracefile_tfile (void)
|
|
|
|
{
|
|
|
|
init_tfile_ops ();
|
|
|
|
|
|
|
|
add_target_with_completer (&tfile_ops, filename_completer);
|
|
|
|
}
|