OS/161 - Debugging with Fault Addresses

Learning Outcome

Able to interpret EPC and vaddr, and use them to locate the offending code.

Introduction

When an exception occurs, OS/161 often stops and prints out the exception program counter (EPC) and the bad virtual address register (vaddr) related to whatever triggered the exception. It is very useful to be able to take these values, interpret them, and determine the code that triggered the exception.

Applicable subjects

COMP3231


Here is more detailed description of these two registers.

EPC Register

This is a 32-bit register containing the 32-bit address of the return point for an exception. The instruction causing (or suffering) the exception is at EPC, unless BD is set in Cause, in which case EPC points to the previous (branch) instruction.

BadVaddr Register (vaddr)

A 32-bit register containing the address whose reference led to an exception; set on any MMU-related exception, on an attempt by a user program to access addresses outside kuseg, or if an address is wrongly aligned for the datum size referenced.

After any other exception this register is undefined.


Example

$ sys161 kernel
sys161: System/161 release 2.0.8, compiled Feb 19 2017 14:31:53

OS/161 base system version 2.0.3
(with locks&CVs solution)
Copyright (c) 2000, 2001-2005, 2008-2011, 2013, 2014
President and Fellows of Harvard College.  All rights reserved.

Put-your-group-name-here's system version 0 (ASST0 #5)

16224k physical memory available
Device probe...
lamebus0 (system main bus)
emu0 at lamebus0
ltrace0 at lamebus0
ltimer0 at lamebus0
beep0 at ltimer0
rtclock0 at ltimer0
lrandom0 at lamebus0
random0 at lrandom0
lser0 at lamebus0
con0 at lser0

cpu0: MIPS/161 (System/161 2.x) features 0x0
panic: Fatal exception 3 (TLB miss on store) in kernel mode
panic: EPC 0x8000b504, exception vaddr 0x0
panic: I can't handle this... I think I'll just die now...
sys161: trace: software-requested debugger stop
sys161: Waiting for debugger connection...
panic: EPC 0x8000b504, exception vaddr 0x0