/* Caching code for GDB, the GNU debugger.
- Copyright (C) 1992-2015 Free Software Foundation, Inc.
+ Copyright (C) 1992-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "target-dcache.h"
#include "inferior.h"
#include "splay-tree.h"
+#include "gdbarch.h"
/* Commands with a prefix of `{set,show} dcache'. */
static struct cmd_list_element *dcache_set_list = NULL;
is set, etc., then the chunk is skipped. Those chunks are handled
in target_xfer_memory() (or target_xfer_memory_partial()).
- This doesn't occur very often. The most common occurance is when
+ This doesn't occur very often. The most common occurrence is when
the last bit of the .text segment and the first bit of the .data
segment fall within the same dcache page with a ro/cacheable memory
region defined for the .text segment and a rw/non-cacheable memory
/* The ptid of last inferior to use cache or null_ptid. */
ptid_t ptid;
+
+ /* The process target of last inferior to use the cache or
+ nullptr. */
+ process_stratum_target *proc_target;
};
typedef void (block_func) (struct dcache_block *block, void *param);
static struct dcache_block *dcache_alloc (DCACHE *dcache, CORE_ADDR addr);
-static void dcache_info (char *exp, int tty);
-
-void _initialize_dcache (void);
-
-static int dcache_enabled_p = 0; /* OBSOLETE */
+static bool dcache_enabled_p = false; /* OBSOLETE */
static void
show_dcache_enabled_p (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("Deprecated remotecache flag is %s.\n"), value);
+ gdb_printf (file, _("Deprecated remotecache flag is %s.\n"), value);
}
/* Add BLOCK to circular block list BLIST, behind the block at *BLIST.
dcache->oldest = NULL;
dcache->size = 0;
dcache->ptid = null_ptid;
+ dcache->proc_target = nullptr;
if (dcache->line_size != dcache_line_size)
{
reg_len = region->hi - memaddr;
/* Skip non-readable regions. The cache attribute can be ignored,
- since we may be loading this for a stack access. */
+ since we may be loading this for a stack access. */
if (region->attrib.mode == MEM_WO)
{
memaddr += reg_len;
if (db)
remove_block (&dcache->freelist, db);
else
- db = xmalloc (offsetof (struct dcache_block, data) +
- dcache->line_size);
+ db = ((struct dcache_block *)
+ xmalloc (offsetof (struct dcache_block, data)
+ + dcache->line_size));
dcache->size++;
}
db = dcache_alloc (dcache, addr);
if (!dcache_read_line (dcache, db))
- return 0;
+ return 0;
}
*ptr = db->data[XFORM (dcache, addr)];
DCACHE *
dcache_init (void)
{
- DCACHE *dcache;
-
- dcache = (DCACHE *) xmalloc (sizeof (*dcache));
+ DCACHE *dcache = XNEW (DCACHE);
dcache->tree = splay_tree_new (dcache_splay_tree_compare,
NULL,
dcache->size = 0;
dcache->line_size = dcache_line_size;
dcache->ptid = null_ptid;
+ dcache->proc_target = nullptr;
return dcache;
}
{
ULONGEST i;
- /* If this is a different inferior from what we've recorded,
- flush the cache. */
+ /* If this is a different thread from what we've recorded, flush the
+ cache. */
- if (! ptid_equal (inferior_ptid, dcache->ptid))
+ process_stratum_target *proc_target = current_inferior ()->process_target ();
+ if (proc_target != dcache->proc_target || inferior_ptid != dcache->ptid)
{
dcache_invalidate (dcache);
dcache->ptid = inferior_ptid;
+ dcache->proc_target = proc_target;
}
for (i = 0; i < len; i++)
{
/* Even though reading the whole line failed, we may be able to
read a piece starting where the caller wanted. */
- return ops->to_xfer_partial (ops, TARGET_OBJECT_MEMORY, NULL,
- myaddr, NULL, memaddr, len,
- xfered_len);
+ return raw_memory_xfer_partial (ops, myaddr, NULL, memaddr, len,
+ xfered_len);
}
else
{
if (dcache == NULL)
{
- printf_filtered (_("No data cache available.\n"));
+ gdb_printf (_("No data cache available.\n"));
return;
}
if (!n)
{
- printf_filtered (_("No such cache line exists.\n"));
+ gdb_printf (_("No such cache line exists.\n"));
return;
}
db = (struct dcache_block *) n->value;
- printf_filtered (_("Line %d: address %s [%d hits]\n"),
- index, paddress (target_gdbarch (), db->addr), db->refs);
+ gdb_printf (_("Line %d: address %s [%d hits]\n"),
+ index, paddress (target_gdbarch (), db->addr), db->refs);
for (j = 0; j < dcache->line_size; j++)
{
- printf_filtered ("%02x ", db->data[j]);
+ gdb_printf ("%02x ", db->data[j]);
/* Print a newline every 16 bytes (48 characters). */
if ((j % 16 == 15) && (j != dcache->line_size - 1))
- printf_filtered ("\n");
+ gdb_printf ("\n");
}
- printf_filtered ("\n");
+ gdb_printf ("\n");
}
/* Parse EXP and show the info about DCACHE. */
static void
-dcache_info_1 (DCACHE *dcache, char *exp)
+dcache_info_1 (DCACHE *dcache, const char *exp)
{
splay_tree_node n;
int i, refcount;
i = strtol (exp, &linestart, 10);
if (linestart == exp || i < 0)
{
- printf_filtered (_("Usage: info dcache [linenumber]\n"));
- return;
+ gdb_printf (_("Usage: info dcache [LINENUMBER]\n"));
+ return;
}
dcache_print_line (dcache, i);
return;
}
- printf_filtered (_("Dcache %u lines of %u bytes each.\n"),
- dcache_size,
- dcache ? (unsigned) dcache->line_size
- : dcache_line_size);
+ gdb_printf (_("Dcache %u lines of %u bytes each.\n"),
+ dcache_size,
+ dcache ? (unsigned) dcache->line_size
+ : dcache_line_size);
- if (dcache == NULL || ptid_equal (dcache->ptid, null_ptid))
+ if (dcache == NULL || dcache->ptid == null_ptid)
{
- printf_filtered (_("No data cache available.\n"));
+ gdb_printf (_("No data cache available.\n"));
return;
}
- printf_filtered (_("Contains data for %s\n"),
- target_pid_to_str (dcache->ptid));
+ gdb_printf (_("Contains data for %s\n"),
+ target_pid_to_str (dcache->ptid).c_str ());
refcount = 0;
{
struct dcache_block *db = (struct dcache_block *) n->value;
- printf_filtered (_("Line %d: address %s [%d hits]\n"),
- i, paddress (target_gdbarch (), db->addr), db->refs);
+ gdb_printf (_("Line %d: address %s [%d hits]\n"),
+ i, paddress (target_gdbarch (), db->addr), db->refs);
i++;
refcount += db->refs;
n = splay_tree_successor (dcache->tree, n->key);
}
- printf_filtered (_("Cache state: %d active lines, %d hits\n"), i, refcount);
+ gdb_printf (_("Cache state: %d active lines, %d hits\n"), i, refcount);
}
static void
-dcache_info (char *exp, int tty)
+info_dcache_command (const char *exp, int tty)
{
dcache_info_1 (target_dcache_get (), exp);
}
static void
-set_dcache_size (char *args, int from_tty,
+set_dcache_size (const char *args, int from_tty,
struct cmd_list_element *c)
{
if (dcache_size == 0)
}
static void
-set_dcache_line_size (char *args, int from_tty,
+set_dcache_line_size (const char *args, int from_tty,
struct cmd_list_element *c)
{
if (dcache_line_size < 2
target_dcache_invalidate ();
}
-static void
-set_dcache_command (char *arg, int from_tty)
-{
- printf_unfiltered (
- "\"set dcache\" must be followed by the name of a subcommand.\n");
- help_list (dcache_set_list, "set dcache ", all_commands, gdb_stdout);
-}
-
-static void
-show_dcache_command (char *args, int from_tty)
-{
- cmd_show_list (dcache_show_list, from_tty, "");
-}
-
+void _initialize_dcache ();
void
-_initialize_dcache (void)
+_initialize_dcache ()
{
add_setshow_boolean_cmd ("remotecache", class_support,
&dcache_enabled_p, _("\
show_dcache_enabled_p,
&setlist, &showlist);
- add_info ("dcache", dcache_info,
+ add_info ("dcache", info_dcache_command,
_("\
Print information on the dcache performance.\n\
+Usage: info dcache [LINENUMBER]\n\
With no arguments, this command prints the cache configuration and a\n\
-summary of each line in the cache. Use \"info dcache <lineno> to dump\"\n\
-the contents of a given line."));
+summary of each line in the cache. With an argument, dump\"\n\
+the contents of the given line."));
- add_prefix_cmd ("dcache", class_obscure, set_dcache_command, _("\
+ add_setshow_prefix_cmd ("dcache", class_obscure,
+ _("\
Use this command to set number of lines in dcache and line-size."),
- &dcache_set_list, "set dcache ", /*allow_unknown*/0, &setlist);
- add_prefix_cmd ("dcache", class_obscure, show_dcache_command, _("\
-Show dcachesettings."),
- &dcache_show_list, "show dcache ", /*allow_unknown*/0, &showlist);
+ ("Show dcache settings."),
+ &dcache_set_list, &dcache_show_list,
+ &setlist, &showlist);
add_setshow_zuinteger_cmd ("line-size", class_obscure,
&dcache_line_size, _("\