1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
/*
* Minimalist Kernel Debugger - Architecture Independent Instruction Disassembly
*
* Copyright (C) 1999 Silicon Graphics, Inc.
* Copyright (C) Scott Lurndal (slurn@engr.sgi.com)
* Copyright (C) Scott Foehner (sfoehner@engr.sgi.com)
* Copyright (C) Srinivasa Thirumalachar (sprasad@engr.sgi.com)
*
* See the file LIA-COPYRIGHT for additional information.
*
* Written March 1999 by Scott Lurndal at Silicon Graphics, Inc.
*
* Modifications from:
* Richard Bass 1999/07/20
* Many bug fixes and enhancements.
* Scott Foehner
* Port to ia64
* Srinivasa Thirumalachar
* RSE support for ia64
* Masahiro Adegawa 1999/12/01
* 'sr' command, active flag in 'ps'
* Scott Lurndal 1999/12/12
* Significantly restructure for linux2.3
* Keith Owens 2000/05/23
* KDB v1.2
*
*/
#include <stdarg.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <linux/kdb.h>
#include <linux/kdbprivate.h>
disassemble_info kdb_di;
/*
* kdb_id
*
* Handle the id (instruction display) command.
*
* id [<addr>]
*
* Parameters:
* argc Count of arguments in argv
* argv Space delimited command line arguments
* envp Environment value
* regs Exception frame at entry to kernel debugger
* Outputs:
* None.
* Returns:
* Zero for success, a kdb diagnostic if failure.
* Locking:
* None.
* Remarks:
*/
int
kdb_id(int argc, const char **argv, const char **envp, struct pt_regs* regs)
{
kdb_machreg_t pc;
int icount;
int diag;
int i;
char * mode;
int nextarg;
long offset = 0;
static kdb_machreg_t lastpc;
struct disassemble_info *dip = &kdb_di;
char lastbuf[50];
unsigned long word;
if (argc != 1) {
if (lastpc == 0) {
return KDB_ARGCOUNT;
} else {
sprintf(lastbuf, "0x%lx", lastpc);
argv[1] = lastbuf;
argc = 1;
}
}
/*
* Fetch PC. First, check to see if it is a symbol, if not,
* try address.
*/
nextarg = 1;
diag = kdbgetaddrarg(argc, argv, &nextarg, &pc, &offset, NULL, regs);
if (diag)
return diag;
kdba_check_pc(&pc);
if (kdb_getarea(word, pc))
return(0);
/*
* Number of lines to display
*/
diag = kdbgetintenv("IDCOUNT", &icount);
if (diag)
return diag;
dip->fprintf_dummy = kdb_dis_fprintf;
mode = kdbgetenv("IDMODE");
diag = kdba_id_parsemode(mode, dip);
if (diag) {
return diag;
}
for(i=0; i<icount; i++) {
pc += kdba_id_printinsn(pc, &kdb_di);
kdb_printf("\n");
}
lastpc = pc;
return 0;
}
/*
* kdb_id1
*
* Disassemble a single instruction at 'pc'.
*
* Parameters:
* pc Address of instruction to disassemble
* Outputs:
* None.
* Returns:
* Zero for success, a kdb diagnostic if failure.
* Locking:
* None.
* Remarks:
*/
void
kdb_id1(unsigned long pc)
{
char *mode;
int diag;
/*
* Allow the user to specify that this instruction
* should be treated differently.
*/
kdb_di.fprintf_dummy = kdb_dis_fprintf_dummy;
mode = kdbgetenv("IDMODE");
diag = kdba_id_parsemode(mode, &kdb_di);
if (diag) {
kdb_printf("kdb_id: bad value in 'IDMODE' environment variable ignored\n");
}
(void) kdba_id_printinsn(pc, &kdb_di);
kdb_printf("\n");
}
/*
* kdb_dis_fprintf
*
* Format and print a string.
*
* Parameters:
* file Unused paramter.
* fmt Format string
* ... Optional additional parameters.
* Returns:
* 0
* Locking:
* Remarks:
* Result of format conversion cannot exceed 255 bytes.
*/
int
kdb_dis_fprintf(PTR file, const char *fmt, ...)
{
char buffer[256];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
kdb_printf("%s", buffer);
return 0;
}
/*
* kdb_dis_fprintf_dummy
*
* A dummy printf function for the disassembler, it does nothing.
* This lets code call the disassembler to step through
* instructions without actually printing anything.
* Inputs:
* Always ignored.
* Outputs:
* None.
* Returns:
* Always 0.
* Locking:
* none.
* Remarks:
* None.
*/
int
kdb_dis_fprintf_dummy(PTR file, const char *fmt, ...)
{
return(0);
}
/*
* kdb_disinit
*
* Initialize the disassembly information structure
* for the GNU disassembler.
*
* Parameters:
* None.
* Outputs:
* None.
* Returns:
* Zero for success, a kdb diagnostic if failure.
* Locking:
* None.
* Remarks:
*/
void __init
kdb_id_init(void)
{
kdb_di.stream = NULL;
kdb_di.application_data = NULL;
kdb_di.symbols = NULL;
kdb_di.num_symbols = 0;
kdb_di.flags = 0;
kdb_di.private_data = NULL;
kdb_di.buffer = NULL;
kdb_di.buffer_vma = 0;
kdb_di.buffer_length = 0;
kdb_di.bytes_per_line = 0;
kdb_di.bytes_per_chunk = 0;
kdb_di.insn_info_valid = 0;
kdb_di.branch_delay_insns = 0;
kdb_di.data_size = 0;
kdb_di.insn_type = 0;
kdb_di.target = 0;
kdb_di.target2 = 0;
kdb_di.fprintf_func = kdb_dis_fprintf;
kdba_id_init(&kdb_di);
}
|