/* Read all the auxv data into a contiguous xmalloc'd buffer, stored in *DATA. Return the size in bytes of this data. If zero, there is no data and *DATA is null. if < 0, there was an error and *DATA is null. */ LONGEST target_auxv_read (struct target_ops *ops, gdb_byte **data) { size_t auxv_alloc = 512, auxv_pos = 0; gdb_byte *auxv = xmalloc (auxv_alloc); int n; while (1) { n = target_read_partial (ops, TARGET_OBJECT_AUXV, NULL, &auxv[auxv_pos], 0, auxv_alloc - auxv_pos); if (n <= 0) break; auxv_pos += n; if (auxv_pos < auxv_alloc) /* Read all there was. */ break; gdb_assert (auxv_pos == auxv_alloc); auxv_alloc *= 2; auxv = xrealloc (auxv, auxv_alloc); } if (auxv_pos == 0) { xfree (auxv); *data = NULL; return n; } *data = auxv; return auxv_pos; }
static void gdb_kod_query (char *arg, char *result, int *maxsiz) { LONGEST bufsiz = 0; /* Check if current target has remote_query capabilities. If not, it does not have kod either. */ bufsiz = target_read_partial (¤t_target, TARGET_OBJECT_KOD, NULL, NULL, 0, 0); if (bufsiz < 0) { strcpy (result, "ERR: Kernel Object Display not supported by current target\n"); return; } /* Just get the maximum buffer size. */ /* Check if *we* were called just for getting the buffer size. */ if (*maxsiz == 0) { *maxsiz = bufsiz; strcpy (result, "OK"); return; } /* Check if caller can handle a buffer this large, if not, adjust. */ if (bufsiz > *maxsiz) bufsiz = *maxsiz; /* See if buffer can hold the query (usually it can, as the query is short). */ if (strlen (arg) >= bufsiz) error ("kod: query argument too long"); /* Send actual request. */ if (target_read_partial (¤t_target, TARGET_OBJECT_KOD, arg, result, 0, bufsiz) < 0) strcpy (result, "ERR: remote query failed"); }
ULONGEST sparc_fetch_wcookie (void) { struct target_ops *ops = ¤t_target; char buf[8]; int len; len = target_read_partial (ops, TARGET_OBJECT_WCOOKIE, NULL, buf, 0, 8); if (len == -1) return 0; /* We should have either an 32-bit or an 64-bit cookie. */ gdb_assert (len == 4 || len == 8); return extract_unsigned_integer (buf, len); }
/* Get a block from the inferior and save it: */ void memcache_get(struct checkpoint *cp, ULONGEST addr, int len) { struct memcache *mc; int actual; mc = (struct memcache *)xmalloc(sizeof(struct memcache)); mc->startaddr = addr; mc->len = len; mc->cache = (gdb_byte *)xmalloc(len); mc->next = cp->mem; cp->mem = mc; actual = (int)target_read_partial(¤t_target, TARGET_OBJECT_MEMORY, NULL, mc->cache, addr, len); #if defined(DEBUG) || defined(_DEBUG) printf("cached %d (orig %d) bytes at 0x%llx\n", actual, len, addr); #endif /* DEBUG || _DEBUG */ mc->cache = (gdb_byte *)xrealloc(mc->cache, actual); mc->len = actual; }