remote_gdb.cc revision 10595
18544Sguodeyuan@tsinghua.org.cn/*
210595Sgabeblack@google.com * Copyright 2014 Google, Inc.
38544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2010 ARM Limited
48544Sguodeyuan@tsinghua.org.cn * All rights reserved
58544Sguodeyuan@tsinghua.org.cn *
68544Sguodeyuan@tsinghua.org.cn * The license below extends only to copyright in the software and shall
78544Sguodeyuan@tsinghua.org.cn * not be construed as granting a license to any other intellectual
88544Sguodeyuan@tsinghua.org.cn * property including but not limited to intellectual property relating
98544Sguodeyuan@tsinghua.org.cn * to a hardware implementation of the functionality of the software
108544Sguodeyuan@tsinghua.org.cn * licensed hereunder.  You may use the software subject to the license
118544Sguodeyuan@tsinghua.org.cn * terms below provided that you ensure that this notice is replicated
128544Sguodeyuan@tsinghua.org.cn * unmodified and in its entirety in all distributions of the software,
138544Sguodeyuan@tsinghua.org.cn * modified or unmodified, in source code or in binary form.
148544Sguodeyuan@tsinghua.org.cn *
158544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2002-2005 The Regents of The University of Michigan
168544Sguodeyuan@tsinghua.org.cn * All rights reserved.
178544Sguodeyuan@tsinghua.org.cn *
188544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
198544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions are
208544Sguodeyuan@tsinghua.org.cn * met: redistributions of source code must retain the above copyright
218544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer;
228544Sguodeyuan@tsinghua.org.cn * redistributions in binary form must reproduce the above copyright
238544Sguodeyuan@tsinghua.org.cn * notice, this list of conditions and the following disclaimer in the
248544Sguodeyuan@tsinghua.org.cn * documentation and/or other materials provided with the distribution;
258544Sguodeyuan@tsinghua.org.cn * neither the name of the copyright holders nor the names of its
268544Sguodeyuan@tsinghua.org.cn * contributors may be used to endorse or promote products derived from
278544Sguodeyuan@tsinghua.org.cn * this software without specific prior written permission.
288544Sguodeyuan@tsinghua.org.cn *
298544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
308544Sguodeyuan@tsinghua.org.cn * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
318544Sguodeyuan@tsinghua.org.cn * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
328544Sguodeyuan@tsinghua.org.cn * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
338544Sguodeyuan@tsinghua.org.cn * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
348544Sguodeyuan@tsinghua.org.cn * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
358544Sguodeyuan@tsinghua.org.cn * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
368544Sguodeyuan@tsinghua.org.cn * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
378544Sguodeyuan@tsinghua.org.cn * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
388544Sguodeyuan@tsinghua.org.cn * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
398544Sguodeyuan@tsinghua.org.cn * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
408544Sguodeyuan@tsinghua.org.cn *
418544Sguodeyuan@tsinghua.org.cn * Authors: Nathan Binkert
428544Sguodeyuan@tsinghua.org.cn *          William Wang
438544Sguodeyuan@tsinghua.org.cn *          Deyuan Guo
448544Sguodeyuan@tsinghua.org.cn */
458544Sguodeyuan@tsinghua.org.cn
468544Sguodeyuan@tsinghua.org.cn/*
478544Sguodeyuan@tsinghua.org.cn * Copyright (c) 1990, 1993 The Regents of the University of California
488544Sguodeyuan@tsinghua.org.cn * All rights reserved
498544Sguodeyuan@tsinghua.org.cn *
508544Sguodeyuan@tsinghua.org.cn * This software was developed by the Computer Systems Engineering group
518544Sguodeyuan@tsinghua.org.cn * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
528544Sguodeyuan@tsinghua.org.cn * contributed to Berkeley.
538544Sguodeyuan@tsinghua.org.cn *
548544Sguodeyuan@tsinghua.org.cn * All advertising materials mentioning features or use of this software
558544Sguodeyuan@tsinghua.org.cn * must display the following acknowledgement:
568544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the University of
578544Sguodeyuan@tsinghua.org.cn *      California, Lawrence Berkeley Laboratories.
588544Sguodeyuan@tsinghua.org.cn *
598544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
608544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions
618544Sguodeyuan@tsinghua.org.cn * are met:
628544Sguodeyuan@tsinghua.org.cn * 1. Redistributions of source code must retain the above copyright
638544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer.
648544Sguodeyuan@tsinghua.org.cn * 2. Redistributions in binary form must reproduce the above copyright
658544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer in the
668544Sguodeyuan@tsinghua.org.cn *    documentation and/or other materials provided with the distribution.
678544Sguodeyuan@tsinghua.org.cn * 3. All advertising materials mentioning features or use of this software
688544Sguodeyuan@tsinghua.org.cn *    must display the following acknowledgement:
698544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the University of
708544Sguodeyuan@tsinghua.org.cn *      California, Berkeley and its contributors.
718544Sguodeyuan@tsinghua.org.cn * 4. Neither the name of the University nor the names of its contributors
728544Sguodeyuan@tsinghua.org.cn *    may be used to endorse or promote products derived from this software
738544Sguodeyuan@tsinghua.org.cn *    without specific prior written permission.
748544Sguodeyuan@tsinghua.org.cn *
758544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
768544Sguodeyuan@tsinghua.org.cn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
778544Sguodeyuan@tsinghua.org.cn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
788544Sguodeyuan@tsinghua.org.cn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
798544Sguodeyuan@tsinghua.org.cn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
808544Sguodeyuan@tsinghua.org.cn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
818544Sguodeyuan@tsinghua.org.cn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
828544Sguodeyuan@tsinghua.org.cn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
838544Sguodeyuan@tsinghua.org.cn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
848544Sguodeyuan@tsinghua.org.cn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
858544Sguodeyuan@tsinghua.org.cn * SUCH DAMAGE.
868544Sguodeyuan@tsinghua.org.cn *
878544Sguodeyuan@tsinghua.org.cn *      @(#)kgdb_stub.c 8.4 (Berkeley) 1/12/94
888544Sguodeyuan@tsinghua.org.cn */
898544Sguodeyuan@tsinghua.org.cn
908544Sguodeyuan@tsinghua.org.cn/*-
918544Sguodeyuan@tsinghua.org.cn * Copyright (c) 2001 The NetBSD Foundation, Inc.
928544Sguodeyuan@tsinghua.org.cn * All rights reserved.
938544Sguodeyuan@tsinghua.org.cn *
948544Sguodeyuan@tsinghua.org.cn * This code is derived from software contributed to The NetBSD Foundation
958544Sguodeyuan@tsinghua.org.cn * by Jason R. Thorpe.
968544Sguodeyuan@tsinghua.org.cn *
978544Sguodeyuan@tsinghua.org.cn * Redistribution and use in source and binary forms, with or without
988544Sguodeyuan@tsinghua.org.cn * modification, are permitted provided that the following conditions
998544Sguodeyuan@tsinghua.org.cn * are met:
1008544Sguodeyuan@tsinghua.org.cn * 1. Redistributions of source code must retain the above copyright
1018544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer.
1028544Sguodeyuan@tsinghua.org.cn * 2. Redistributions in binary form must reproduce the above copyright
1038544Sguodeyuan@tsinghua.org.cn *    notice, this list of conditions and the following disclaimer in the
1048544Sguodeyuan@tsinghua.org.cn *    documentation and/or other materials provided with the distribution.
1058544Sguodeyuan@tsinghua.org.cn * 3. All advertising materials mentioning features or use of this software
1068544Sguodeyuan@tsinghua.org.cn *    must display the following acknowledgement:
1078544Sguodeyuan@tsinghua.org.cn *      This product includes software developed by the NetBSD
1088544Sguodeyuan@tsinghua.org.cn *      Foundation, Inc. and its contributors.
1098544Sguodeyuan@tsinghua.org.cn * 4. Neither the name of The NetBSD Foundation nor the names of its
1108544Sguodeyuan@tsinghua.org.cn *    contributors may be used to endorse or promote products derived
1118544Sguodeyuan@tsinghua.org.cn *    from this software without specific prior written permission.
1128544Sguodeyuan@tsinghua.org.cn *
1138544Sguodeyuan@tsinghua.org.cn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1148544Sguodeyuan@tsinghua.org.cn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1158544Sguodeyuan@tsinghua.org.cn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1168544Sguodeyuan@tsinghua.org.cn * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
1178544Sguodeyuan@tsinghua.org.cn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1188544Sguodeyuan@tsinghua.org.cn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1198544Sguodeyuan@tsinghua.org.cn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1208544Sguodeyuan@tsinghua.org.cn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1218544Sguodeyuan@tsinghua.org.cn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1228544Sguodeyuan@tsinghua.org.cn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1238544Sguodeyuan@tsinghua.org.cn * POSSIBILITY OF SUCH DAMAGE.
1248544Sguodeyuan@tsinghua.org.cn */
1258544Sguodeyuan@tsinghua.org.cn
1268544Sguodeyuan@tsinghua.org.cn/*
1278544Sguodeyuan@tsinghua.org.cn * $NetBSD: kgdb_stub.c,v 1.8 2001/07/07 22:58:00 wdk Exp $
1288544Sguodeyuan@tsinghua.org.cn *
1298544Sguodeyuan@tsinghua.org.cn * Taken from NetBSD
1308544Sguodeyuan@tsinghua.org.cn *
1318544Sguodeyuan@tsinghua.org.cn * "Stub" to allow remote cpu to debug over a serial line using gdb.
1328544Sguodeyuan@tsinghua.org.cn */
1338544Sguodeyuan@tsinghua.org.cn
1348544Sguodeyuan@tsinghua.org.cn#include <sys/signal.h>
1358544Sguodeyuan@tsinghua.org.cn#include <unistd.h>
1368544Sguodeyuan@tsinghua.org.cn
1378544Sguodeyuan@tsinghua.org.cn#include <string>
1388544Sguodeyuan@tsinghua.org.cn
1399020Sgblack@eecs.umich.edu#include "arch/mips/decoder.hh"
1408544Sguodeyuan@tsinghua.org.cn#include "arch/mips/remote_gdb.hh"
1418544Sguodeyuan@tsinghua.org.cn#include "arch/mips/vtophys.hh"
1428544Sguodeyuan@tsinghua.org.cn#include "cpu/thread_state.hh"
1438544Sguodeyuan@tsinghua.org.cn#include "debug/GDBAcc.hh"
1448544Sguodeyuan@tsinghua.org.cn#include "debug/GDBMisc.hh"
1458544Sguodeyuan@tsinghua.org.cn#include "mem/page_table.hh"
1468775Sgblack@eecs.umich.edu#include "sim/full_system.hh"
1478544Sguodeyuan@tsinghua.org.cn
1488544Sguodeyuan@tsinghua.org.cnusing namespace std;
1498544Sguodeyuan@tsinghua.org.cnusing namespace MipsISA;
1508544Sguodeyuan@tsinghua.org.cn
1518544Sguodeyuan@tsinghua.org.cnRemoteGDB::RemoteGDB(System *_system, ThreadContext *tc)
15210595Sgabeblack@google.com    : BaseRemoteGDB(_system, tc, GdbNumRegs * sizeof(uint32_t))
1538544Sguodeyuan@tsinghua.org.cn{
1548544Sguodeyuan@tsinghua.org.cn}
1558544Sguodeyuan@tsinghua.org.cn
1568544Sguodeyuan@tsinghua.org.cn/*
1578544Sguodeyuan@tsinghua.org.cn * Determine if the mapping at va..(va+len) is valid.
1588544Sguodeyuan@tsinghua.org.cn */
1598544Sguodeyuan@tsinghua.org.cnbool
1608544Sguodeyuan@tsinghua.org.cnRemoteGDB::acc(Addr va, size_t len)
1618544Sguodeyuan@tsinghua.org.cn{
1628544Sguodeyuan@tsinghua.org.cn    TlbEntry entry;
1638544Sguodeyuan@tsinghua.org.cn    //Check to make sure the first byte is mapped into the processes address
1648544Sguodeyuan@tsinghua.org.cn    //space.
1658775Sgblack@eecs.umich.edu    if (FullSystem)
1668775Sgblack@eecs.umich.edu        panic("acc not implemented for MIPS FS!");
1678775Sgblack@eecs.umich.edu    else
1688775Sgblack@eecs.umich.edu        return context->getProcessPtr()->pTable->lookup(va, entry);
1698544Sguodeyuan@tsinghua.org.cn}
1708544Sguodeyuan@tsinghua.org.cn
1718544Sguodeyuan@tsinghua.org.cn/*
1728544Sguodeyuan@tsinghua.org.cn * Translate the kernel debugger register format into the GDB register
1738544Sguodeyuan@tsinghua.org.cn * format.
1748544Sguodeyuan@tsinghua.org.cn */
1758544Sguodeyuan@tsinghua.org.cnvoid
1768544Sguodeyuan@tsinghua.org.cnRemoteGDB::getregs()
1778544Sguodeyuan@tsinghua.org.cn{
1788544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBAcc, "getregs in remotegdb \n");
1798544Sguodeyuan@tsinghua.org.cn    memset(gdbregs.regs, 0, gdbregs.bytes());
1808544Sguodeyuan@tsinghua.org.cn
1818544Sguodeyuan@tsinghua.org.cn    // MIPS registers are 32 bits wide, gdb registers are 64 bits wide
1828544Sguodeyuan@tsinghua.org.cn    // two MIPS registers are packed into one gdb register (little endian)
1838544Sguodeyuan@tsinghua.org.cn
1848544Sguodeyuan@tsinghua.org.cn    // INTREG: R0~R31
18510595Sgabeblack@google.com    for (int i = 0; i < GdbIntArchRegs; i++)
18610595Sgabeblack@google.com        gdbregs.regs32[i] = context->readIntReg(i);
1878544Sguodeyuan@tsinghua.org.cn    // SR, LO, HI, BADVADDR, CAUSE, PC
18810595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 0] =
18910595Sgabeblack@google.com        context->readMiscRegNoEffect(MISCREG_STATUS);
19010595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 1] = context->readIntReg(INTREG_LO);
19110595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 2] = context->readIntReg(INTREG_HI);
19210595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 3] =
19310595Sgabeblack@google.com        context->readMiscRegNoEffect(MISCREG_BADVADDR);
19410595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 4] =
19510595Sgabeblack@google.com        context->readMiscRegNoEffect(MISCREG_CAUSE);
19610595Sgabeblack@google.com    gdbregs.regs32[GdbIntArchRegs + 5] = context->pcState().pc();
1978544Sguodeyuan@tsinghua.org.cn    // FLOATREG: F0~F31
19810595Sgabeblack@google.com    for (int i = 0; i < GdbFloatArchRegs; i++)
19910595Sgabeblack@google.com        gdbregs.regs32[GdbIntRegs + i] = context->readFloatRegBits(i);
2008544Sguodeyuan@tsinghua.org.cn    // FCR, FIR
20110595Sgabeblack@google.com    gdbregs.regs32[GdbIntRegs + GdbFloatArchRegs + 0] =
20210595Sgabeblack@google.com        context->readFloatRegBits(FLOATREG_FCCR);
20310595Sgabeblack@google.com    gdbregs.regs32[GdbIntRegs + GdbFloatArchRegs + 1] =
20410595Sgabeblack@google.com        context->readFloatRegBits(FLOATREG_FIR);
2058544Sguodeyuan@tsinghua.org.cn}
2068544Sguodeyuan@tsinghua.org.cn
2078544Sguodeyuan@tsinghua.org.cn/*
2088544Sguodeyuan@tsinghua.org.cn * Translate the GDB register format into the kernel debugger register
2098544Sguodeyuan@tsinghua.org.cn * format.
2108544Sguodeyuan@tsinghua.org.cn */
2118544Sguodeyuan@tsinghua.org.cnvoid
2128544Sguodeyuan@tsinghua.org.cnRemoteGDB::setregs()
2138544Sguodeyuan@tsinghua.org.cn{
2148544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBAcc, "setregs in remotegdb \n");
2158544Sguodeyuan@tsinghua.org.cn
2168544Sguodeyuan@tsinghua.org.cn    // INTREG: R0~R31
21710595Sgabeblack@google.com    for (int i = 1; i < GdbIntArchRegs; i++)
21810595Sgabeblack@google.com        context->setIntReg(i, gdbregs.regs32[i]);
2198544Sguodeyuan@tsinghua.org.cn    // SR, LO, HI, BADVADDR, CAUSE, PC
2208544Sguodeyuan@tsinghua.org.cn    context->setMiscRegNoEffect(MISCREG_STATUS,
22110595Sgabeblack@google.com        gdbregs.regs32[GdbIntArchRegs + 0]);
22210595Sgabeblack@google.com    context->setIntReg(INTREG_LO, gdbregs.regs32[GdbIntArchRegs + 1]);
22310595Sgabeblack@google.com    context->setIntReg(INTREG_HI, gdbregs.regs32[GdbIntArchRegs + 2]);
2248544Sguodeyuan@tsinghua.org.cn    context->setMiscRegNoEffect(MISCREG_BADVADDR,
22510595Sgabeblack@google.com        gdbregs.regs32[GdbIntArchRegs + 3]);
2268544Sguodeyuan@tsinghua.org.cn    context->setMiscRegNoEffect(MISCREG_CAUSE,
22710595Sgabeblack@google.com        gdbregs.regs32[GdbIntArchRegs + 4]);
22810595Sgabeblack@google.com    context->pcState(gdbregs.regs32[GdbIntArchRegs + 5]);
2298544Sguodeyuan@tsinghua.org.cn    // FLOATREG: F0~F31
23010595Sgabeblack@google.com    for (int i = 0; i < GdbFloatArchRegs; i++)
23110595Sgabeblack@google.com        context->setFloatRegBits(i, gdbregs.regs32[GdbIntRegs + i]);
2328544Sguodeyuan@tsinghua.org.cn    // FCR, FIR
2338544Sguodeyuan@tsinghua.org.cn    context->setFloatRegBits(FLOATREG_FCCR,
23410595Sgabeblack@google.com        gdbregs.regs32[GdbIntRegs + GdbFloatArchRegs + 0]);
2358544Sguodeyuan@tsinghua.org.cn    context->setFloatRegBits(FLOATREG_FIR,
23610595Sgabeblack@google.com        gdbregs.regs32[GdbIntRegs + GdbFloatArchRegs + 1]);
2378544Sguodeyuan@tsinghua.org.cn}
2388544Sguodeyuan@tsinghua.org.cn
2398544Sguodeyuan@tsinghua.org.cnvoid
2408544Sguodeyuan@tsinghua.org.cnRemoteGDB::clearSingleStep()
2418544Sguodeyuan@tsinghua.org.cn{
2428544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBMisc, "clearSingleStep bt_addr=%#x nt_addr=%#x\n",
2438544Sguodeyuan@tsinghua.org.cn            takenBkpt, notTakenBkpt);
2448544Sguodeyuan@tsinghua.org.cn
2458544Sguodeyuan@tsinghua.org.cn    if (takenBkpt != 0)
2468544Sguodeyuan@tsinghua.org.cn        clearTempBreakpoint(takenBkpt);
2478544Sguodeyuan@tsinghua.org.cn
2488544Sguodeyuan@tsinghua.org.cn    if (notTakenBkpt != 0)
2498544Sguodeyuan@tsinghua.org.cn        clearTempBreakpoint(notTakenBkpt);
2508544Sguodeyuan@tsinghua.org.cn}
2518544Sguodeyuan@tsinghua.org.cn
2528544Sguodeyuan@tsinghua.org.cnvoid
2538544Sguodeyuan@tsinghua.org.cnRemoteGDB::setSingleStep()
2548544Sguodeyuan@tsinghua.org.cn{
2558544Sguodeyuan@tsinghua.org.cn    PCState pc = context->pcState();
2568544Sguodeyuan@tsinghua.org.cn    PCState bpc;
2578544Sguodeyuan@tsinghua.org.cn    bool set_bt = false;
2588544Sguodeyuan@tsinghua.org.cn
2598544Sguodeyuan@tsinghua.org.cn    // User was stopped at pc, e.g. the instruction at pc was not
2608544Sguodeyuan@tsinghua.org.cn    // executed.
2618544Sguodeyuan@tsinghua.org.cn    MachInst inst = read<MachInst>(pc.pc());
2628544Sguodeyuan@tsinghua.org.cn    StaticInstPtr si = context->getDecoderPtr()->decode(inst, pc.pc());
2638544Sguodeyuan@tsinghua.org.cn    if (si->hasBranchTarget(pc, context, bpc)) {
2648544Sguodeyuan@tsinghua.org.cn        // Don't bother setting a breakpoint on the taken branch if it
2658544Sguodeyuan@tsinghua.org.cn        // is the same as the next npc
2668544Sguodeyuan@tsinghua.org.cn        if (bpc.npc() != pc.nnpc())
2678544Sguodeyuan@tsinghua.org.cn            set_bt = true;
2688544Sguodeyuan@tsinghua.org.cn    }
2698544Sguodeyuan@tsinghua.org.cn
2708544Sguodeyuan@tsinghua.org.cn    DPRINTF(GDBMisc, "setSingleStep bt_addr=%#x nt_addr=%#x\n",
2718544Sguodeyuan@tsinghua.org.cn            takenBkpt, notTakenBkpt);
2728544Sguodeyuan@tsinghua.org.cn
2738544Sguodeyuan@tsinghua.org.cn    notTakenBkpt = pc.nnpc();
2748544Sguodeyuan@tsinghua.org.cn    setTempBreakpoint(notTakenBkpt);
2758544Sguodeyuan@tsinghua.org.cn
2768544Sguodeyuan@tsinghua.org.cn    if (set_bt) {
2778544Sguodeyuan@tsinghua.org.cn        takenBkpt = bpc.npc();
2788544Sguodeyuan@tsinghua.org.cn        setTempBreakpoint(takenBkpt);
2798544Sguodeyuan@tsinghua.org.cn    }
2808544Sguodeyuan@tsinghua.org.cn}
2818544Sguodeyuan@tsinghua.org.cn
282