2004-07-25 05:29:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004 Marcel Moolenaar
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <machine/pcb.h>
|
2005-09-10 20:12:52 +00:00
|
|
|
#include <machine/frame.h>
|
2004-07-25 05:29:15 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <defs.h>
|
|
|
|
#include <target.h>
|
|
|
|
#include <gdbthread.h>
|
|
|
|
#include <inferior.h>
|
|
|
|
#include <regcache.h>
|
2005-09-10 18:25:53 +00:00
|
|
|
#include <frame-unwind.h>
|
2005-09-10 20:12:52 +00:00
|
|
|
#include <i386-tdep.h>
|
2005-09-10 18:25:53 +00:00
|
|
|
|
|
|
|
#include "kgdb.h"
|
2004-07-25 05:29:15 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
kgdb_trgt_fetch_registers(int regno __unused)
|
|
|
|
{
|
|
|
|
struct kthr *kt;
|
|
|
|
struct pcb pcb;
|
|
|
|
|
2005-02-20 22:55:07 +00:00
|
|
|
kt = kgdb_thr_lookup_tid(ptid_get_tid(inferior_ptid));
|
2004-07-25 05:29:15 +00:00
|
|
|
if (kt == NULL)
|
|
|
|
return;
|
|
|
|
if (kvm_read(kvm, kt->pcb, &pcb, sizeof(pcb)) != sizeof(pcb)) {
|
|
|
|
warnx("kvm_read: %s", kvm_geterr(kvm));
|
|
|
|
memset(&pcb, 0, sizeof(pcb));
|
|
|
|
}
|
2005-09-10 20:12:52 +00:00
|
|
|
supply_register(I386_EBX_REGNUM, (char *)&pcb.pcb_ebx);
|
|
|
|
supply_register(I386_ESP_REGNUM, (char *)&pcb.pcb_esp);
|
|
|
|
supply_register(I386_EBP_REGNUM, (char *)&pcb.pcb_ebp);
|
|
|
|
supply_register(I386_ESI_REGNUM, (char *)&pcb.pcb_esi);
|
|
|
|
supply_register(I386_EDI_REGNUM, (char *)&pcb.pcb_edi);
|
|
|
|
supply_register(I386_EIP_REGNUM, (char *)&pcb.pcb_eip);
|
2004-07-25 05:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
kgdb_trgt_store_registers(int regno __unused)
|
|
|
|
{
|
|
|
|
fprintf_unfiltered(gdb_stderr, "XXX: %s\n", __func__);
|
|
|
|
}
|
2005-09-10 18:25:53 +00:00
|
|
|
|
2005-09-10 20:12:52 +00:00
|
|
|
struct kgdb_frame_cache {
|
2005-09-11 05:36:30 +00:00
|
|
|
int intrframe;
|
2005-09-10 20:12:52 +00:00
|
|
|
CORE_ADDR pc;
|
|
|
|
CORE_ADDR sp;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int kgdb_trgt_frame_offset[15] = {
|
|
|
|
offsetof(struct trapframe, tf_eax),
|
|
|
|
offsetof(struct trapframe, tf_ecx),
|
|
|
|
offsetof(struct trapframe, tf_edx),
|
|
|
|
offsetof(struct trapframe, tf_ebx),
|
|
|
|
offsetof(struct trapframe, tf_esp),
|
|
|
|
offsetof(struct trapframe, tf_ebp),
|
|
|
|
offsetof(struct trapframe, tf_esi),
|
|
|
|
offsetof(struct trapframe, tf_edi),
|
|
|
|
offsetof(struct trapframe, tf_eip),
|
|
|
|
offsetof(struct trapframe, tf_eflags),
|
|
|
|
offsetof(struct trapframe, tf_cs),
|
|
|
|
offsetof(struct trapframe, tf_ss),
|
|
|
|
offsetof(struct trapframe, tf_ds),
|
|
|
|
offsetof(struct trapframe, tf_es),
|
|
|
|
offsetof(struct trapframe, tf_fs)
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kgdb_frame_cache *
|
|
|
|
kgdb_trgt_frame_cache(struct frame_info *next_frame, void **this_cache)
|
|
|
|
{
|
|
|
|
char buf[MAX_REGISTER_SIZE];
|
|
|
|
struct kgdb_frame_cache *cache;
|
2005-09-11 05:36:30 +00:00
|
|
|
char *pname;
|
2005-09-10 20:12:52 +00:00
|
|
|
|
|
|
|
cache = *this_cache;
|
|
|
|
if (cache == NULL) {
|
|
|
|
cache = FRAME_OBSTACK_ZALLOC(struct kgdb_frame_cache);
|
|
|
|
*this_cache = cache;
|
|
|
|
cache->pc = frame_func_unwind(next_frame);
|
2005-09-11 05:36:30 +00:00
|
|
|
find_pc_partial_function(cache->pc, &pname, NULL, NULL);
|
|
|
|
cache->intrframe = (pname[0] == 'X') ? 1 : 0;
|
2005-09-10 20:12:52 +00:00
|
|
|
frame_unwind_register(next_frame, SP_REGNUM, buf);
|
|
|
|
cache->sp = extract_unsigned_integer(buf,
|
|
|
|
register_size(current_gdbarch, SP_REGNUM));
|
|
|
|
}
|
|
|
|
return (cache);
|
|
|
|
}
|
|
|
|
|
2005-09-10 18:25:53 +00:00
|
|
|
static void
|
|
|
|
kgdb_trgt_trapframe_this_id(struct frame_info *next_frame, void **this_cache,
|
|
|
|
struct frame_id *this_id)
|
|
|
|
{
|
2005-09-10 20:12:52 +00:00
|
|
|
struct kgdb_frame_cache *cache;
|
|
|
|
|
|
|
|
cache = kgdb_trgt_frame_cache(next_frame, this_cache);
|
|
|
|
*this_id = frame_id_build(cache->sp, cache->pc);
|
2005-09-10 18:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kgdb_trgt_trapframe_prev_register(struct frame_info *next_frame,
|
|
|
|
void **this_cache, int regnum, int *optimizedp, enum lval_type *lvalp,
|
|
|
|
CORE_ADDR *addrp, int *realnump, void *valuep)
|
|
|
|
{
|
2005-09-10 20:12:52 +00:00
|
|
|
char dummy_valuep[MAX_REGISTER_SIZE];
|
|
|
|
struct kgdb_frame_cache *cache;
|
|
|
|
int ofs, regsz;
|
2007-03-01 13:56:08 +00:00
|
|
|
static int ofs_fix = 0;
|
|
|
|
static int ofs_fixed = 0;
|
2005-09-10 20:12:52 +00:00
|
|
|
|
|
|
|
regsz = register_size(current_gdbarch, regnum);
|
|
|
|
|
|
|
|
if (valuep == NULL)
|
|
|
|
valuep = dummy_valuep;
|
|
|
|
memset(valuep, 0, regsz);
|
|
|
|
*optimizedp = 0;
|
|
|
|
*addrp = 0;
|
|
|
|
*lvalp = not_lval;
|
|
|
|
*realnump = -1;
|
|
|
|
|
2007-03-01 13:56:08 +00:00
|
|
|
if (!ofs_fixed) {
|
|
|
|
uintptr_t calltrap_addr;
|
|
|
|
char calltrap[1];
|
|
|
|
|
|
|
|
calltrap_addr = kgdb_lookup("calltrap");
|
|
|
|
if (calltrap_addr != 0) {
|
|
|
|
if (kvm_read(kvm, calltrap_addr, calltrap,
|
|
|
|
sizeof(calltrap)) != sizeof(calltrap)) {
|
|
|
|
warnx("kvm_read: %s", kvm_geterr(kvm));
|
|
|
|
} else if (calltrap[0] == 0x54) /* push %esp */ {
|
|
|
|
/*
|
|
|
|
* To accomodate for rev. 1.117 of
|
|
|
|
* i386/i386/exception.s
|
|
|
|
*/
|
|
|
|
ofs_fix = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ofs_fixed = 1;
|
|
|
|
}
|
2005-09-10 20:12:52 +00:00
|
|
|
ofs = (regnum >= I386_EAX_REGNUM && regnum <= I386_FS_REGNUM)
|
2007-03-01 13:56:08 +00:00
|
|
|
? kgdb_trgt_frame_offset[regnum] + ofs_fix : -1;
|
2005-09-10 20:12:52 +00:00
|
|
|
if (ofs == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cache = kgdb_trgt_frame_cache(next_frame, this_cache);
|
2005-09-11 05:36:30 +00:00
|
|
|
*addrp = cache->sp + ofs + (cache->intrframe ? 4 : 0);
|
2005-09-10 20:12:52 +00:00
|
|
|
*lvalp = lval_memory;
|
|
|
|
target_read_memory(*addrp, valuep, regsz);
|
2005-09-10 18:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct frame_unwind kgdb_trgt_trapframe_unwind = {
|
|
|
|
UNKNOWN_FRAME,
|
|
|
|
&kgdb_trgt_trapframe_this_id,
|
|
|
|
&kgdb_trgt_trapframe_prev_register
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct frame_unwind *
|
|
|
|
kgdb_trgt_trapframe_sniffer(struct frame_info *next_frame)
|
|
|
|
{
|
2005-09-10 20:12:52 +00:00
|
|
|
char *pname;
|
|
|
|
CORE_ADDR pc;
|
2005-09-10 18:25:53 +00:00
|
|
|
|
2005-09-10 20:12:52 +00:00
|
|
|
pc = frame_pc_unwind(next_frame);
|
|
|
|
pname = NULL;
|
|
|
|
find_pc_partial_function(pc, &pname, NULL, NULL);
|
|
|
|
if (pname == NULL)
|
|
|
|
return (NULL);
|
2005-09-11 05:36:30 +00:00
|
|
|
if (strcmp(pname, "calltrap") == 0 ||
|
|
|
|
(pname[0] == 'X' && pname[1] != '_'))
|
2005-09-10 20:12:52 +00:00
|
|
|
return (&kgdb_trgt_trapframe_unwind);
|
|
|
|
/* printf("%s: %llx =%s\n", __func__, pc, pname); */
|
2005-09-11 05:36:30 +00:00
|
|
|
return (NULL);
|
2005-09-10 18:25:53 +00:00
|
|
|
}
|