linux/kernel/debug/kdb/kdb_private.h
<<
>>
Prefs
   1#ifndef _KDBPRIVATE_H
   2#define _KDBPRIVATE_H
   3
   4/*
   5 * Kernel Debugger Architecture Independent Private Headers
   6 *
   7 * This file is subject to the terms and conditions of the GNU General Public
   8 * License.  See the file "COPYING" in the main directory of this archive
   9 * for more details.
  10 *
  11 * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
  12 * Copyright (c) 2009 Wind River Systems, Inc.  All Rights Reserved.
  13 */
  14
  15#include <linux/kgdb.h>
  16#include "../debug_core.h"
  17
  18/* Kernel Debugger Error codes.  Must not overlap with command codes. */
  19#define KDB_NOTFOUND    (-1)
  20#define KDB_ARGCOUNT    (-2)
  21#define KDB_BADWIDTH    (-3)
  22#define KDB_BADRADIX    (-4)
  23#define KDB_NOTENV      (-5)
  24#define KDB_NOENVVALUE  (-6)
  25#define KDB_NOTIMP      (-7)
  26#define KDB_ENVFULL     (-8)
  27#define KDB_ENVBUFFULL  (-9)
  28#define KDB_TOOMANYBPT  (-10)
  29#define KDB_TOOMANYDBREGS (-11)
  30#define KDB_DUPBPT      (-12)
  31#define KDB_BPTNOTFOUND (-13)
  32#define KDB_BADMODE     (-14)
  33#define KDB_BADINT      (-15)
  34#define KDB_INVADDRFMT  (-16)
  35#define KDB_BADREG      (-17)
  36#define KDB_BADCPUNUM   (-18)
  37#define KDB_BADLENGTH   (-19)
  38#define KDB_NOBP        (-20)
  39#define KDB_BADADDR     (-21)
  40
  41/* Kernel Debugger Command codes.  Must not overlap with error codes. */
  42#define KDB_CMD_GO      (-1001)
  43#define KDB_CMD_CPU     (-1002)
  44#define KDB_CMD_SS      (-1003)
  45#define KDB_CMD_SSB     (-1004)
  46#define KDB_CMD_KGDB (-1005)
  47#define KDB_CMD_KGDB2 (-1006)
  48
  49/* Internal debug flags */
  50#define KDB_DEBUG_FLAG_BP       0x0002  /* Breakpoint subsystem debug */
  51#define KDB_DEBUG_FLAG_BB_SUMM  0x0004  /* Basic block analysis, summary only */
  52#define KDB_DEBUG_FLAG_AR       0x0008  /* Activation record, generic */
  53#define KDB_DEBUG_FLAG_ARA      0x0010  /* Activation record, arch specific */
  54#define KDB_DEBUG_FLAG_BB       0x0020  /* All basic block analysis */
  55#define KDB_DEBUG_FLAG_STATE    0x0040  /* State flags */
  56#define KDB_DEBUG_FLAG_MASK     0xffff  /* All debug flags */
  57#define KDB_DEBUG_FLAG_SHIFT    16      /* Shift factor for dbflags */
  58
  59#define KDB_DEBUG(flag) (kdb_flags & \
  60        (KDB_DEBUG_FLAG_##flag << KDB_DEBUG_FLAG_SHIFT))
  61#define KDB_DEBUG_STATE(text, value) if (KDB_DEBUG(STATE)) \
  62                kdb_print_state(text, value)
  63
  64#if BITS_PER_LONG == 32
  65
  66#define KDB_PLATFORM_ENV        "BYTESPERWORD=4"
  67
  68#define kdb_machreg_fmt         "0x%lx"
  69#define kdb_machreg_fmt0        "0x%08lx"
  70#define kdb_bfd_vma_fmt         "0x%lx"
  71#define kdb_bfd_vma_fmt0        "0x%08lx"
  72#define kdb_elfw_addr_fmt       "0x%x"
  73#define kdb_elfw_addr_fmt0      "0x%08x"
  74#define kdb_f_count_fmt         "%d"
  75
  76#elif BITS_PER_LONG == 64
  77
  78#define KDB_PLATFORM_ENV        "BYTESPERWORD=8"
  79
  80#define kdb_machreg_fmt         "0x%lx"
  81#define kdb_machreg_fmt0        "0x%016lx"
  82#define kdb_bfd_vma_fmt         "0x%lx"
  83#define kdb_bfd_vma_fmt0        "0x%016lx"
  84#define kdb_elfw_addr_fmt       "0x%x"
  85#define kdb_elfw_addr_fmt0      "0x%016x"
  86#define kdb_f_count_fmt         "%ld"
  87
  88#endif
  89
  90/*
  91 * KDB_MAXBPT describes the total number of breakpoints
  92 * supported by this architecure.
  93 */
  94#define KDB_MAXBPT      16
  95
  96/* Maximum number of arguments to a function  */
  97#define KDB_MAXARGS    16
  98
  99typedef enum {
 100        KDB_REPEAT_NONE = 0,    /* Do not repeat this command */
 101        KDB_REPEAT_NO_ARGS,     /* Repeat the command without arguments */
 102        KDB_REPEAT_WITH_ARGS,   /* Repeat the command including its arguments */
 103} kdb_repeat_t;
 104
 105typedef int (*kdb_func_t)(int, const char **);
 106
 107/* Symbol table format returned by kallsyms. */
 108typedef struct __ksymtab {
 109                unsigned long value;    /* Address of symbol */
 110                const char *mod_name;   /* Module containing symbol or
 111                                         * "kernel" */
 112                unsigned long mod_start;
 113                unsigned long mod_end;
 114                const char *sec_name;   /* Section containing symbol */
 115                unsigned long sec_start;
 116                unsigned long sec_end;
 117                const char *sym_name;   /* Full symbol name, including
 118                                         * any version */
 119                unsigned long sym_start;
 120                unsigned long sym_end;
 121                } kdb_symtab_t;
 122extern int kallsyms_symbol_next(char *prefix_name, int flag);
 123extern int kallsyms_symbol_complete(char *prefix_name, int max_len);
 124
 125/* Exported Symbols for kernel loadable modules to use. */
 126extern int kdb_register(char *, kdb_func_t, char *, char *, short);
 127extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
 128                               short, kdb_repeat_t);
 129extern int kdb_unregister(char *);
 130
 131extern int kdb_getarea_size(void *, unsigned long, size_t);
 132extern int kdb_putarea_size(unsigned long, void *, size_t);
 133
 134/*
 135 * Like get_user and put_user, kdb_getarea and kdb_putarea take variable
 136 * names, not pointers.  The underlying *_size functions take pointers.
 137 */
 138#define kdb_getarea(x, addr) kdb_getarea_size(&(x), addr, sizeof((x)))
 139#define kdb_putarea(addr, x) kdb_putarea_size(addr, &(x), sizeof((x)))
 140
 141extern int kdb_getphysword(unsigned long *word,
 142                        unsigned long addr, size_t size);
 143extern int kdb_getword(unsigned long *, unsigned long, size_t);
 144extern int kdb_putword(unsigned long, unsigned long, size_t);
 145
 146extern int kdbgetularg(const char *, unsigned long *);
 147extern int kdb_set(int, const char **);
 148extern char *kdbgetenv(const char *);
 149extern int kdbgetintenv(const char *, int *);
 150extern int kdbgetaddrarg(int, const char **, int*, unsigned long *,
 151                         long *, char **);
 152extern int kdbgetsymval(const char *, kdb_symtab_t *);
 153extern int kdbnearsym(unsigned long, kdb_symtab_t *);
 154extern void kdbnearsym_cleanup(void);
 155extern char *kdb_strdup(const char *str, gfp_t type);
 156extern void kdb_symbol_print(unsigned long, const kdb_symtab_t *, unsigned int);
 157
 158/* Routine for debugging the debugger state. */
 159extern void kdb_print_state(const char *, int);
 160
 161extern int kdb_state;
 162#define KDB_STATE_KDB           0x00000001      /* Cpu is inside kdb */
 163#define KDB_STATE_LEAVING       0x00000002      /* Cpu is leaving kdb */
 164#define KDB_STATE_CMD           0x00000004      /* Running a kdb command */
 165#define KDB_STATE_KDB_CONTROL   0x00000008      /* This cpu is under
 166                                                 * kdb control */
 167#define KDB_STATE_HOLD_CPU      0x00000010      /* Hold this cpu inside kdb */
 168#define KDB_STATE_DOING_SS      0x00000020      /* Doing ss command */
 169#define KDB_STATE_DOING_SSB     0x00000040      /* Doing ssb command,
 170                                                 * DOING_SS is also set */
 171#define KDB_STATE_SSBPT         0x00000080      /* Install breakpoint
 172                                                 * after one ss, independent of
 173                                                 * DOING_SS */
 174#define KDB_STATE_REENTRY       0x00000100      /* Valid re-entry into kdb */
 175#define KDB_STATE_SUPPRESS      0x00000200      /* Suppress error messages */
 176#define KDB_STATE_PAGER         0x00000400      /* pager is available */
 177#define KDB_STATE_GO_SWITCH     0x00000800      /* go is switching
 178                                                 * back to initial cpu */
 179#define KDB_STATE_PRINTF_LOCK   0x00001000      /* Holds kdb_printf lock */
 180#define KDB_STATE_WAIT_IPI      0x00002000      /* Waiting for kdb_ipi() NMI */
 181#define KDB_STATE_RECURSE       0x00004000      /* Recursive entry to kdb */
 182#define KDB_STATE_IP_ADJUSTED   0x00008000      /* Restart IP has been
 183                                                 * adjusted */
 184#define KDB_STATE_GO1           0x00010000      /* go only releases one cpu */
 185#define KDB_STATE_KEYBOARD      0x00020000      /* kdb entered via
 186                                                 * keyboard on this cpu */
 187#define KDB_STATE_KEXEC         0x00040000      /* kexec issued */
 188#define KDB_STATE_DOING_KGDB    0x00080000      /* kgdb enter now issued */
 189#define KDB_STATE_DOING_KGDB2   0x00100000      /* kgdb enter now issued */
 190#define KDB_STATE_KGDB_TRANS    0x00200000      /* Transition to kgdb */
 191#define KDB_STATE_ARCH          0xff000000      /* Reserved for arch
 192                                                 * specific use */
 193
 194#define KDB_STATE(flag) (kdb_state & KDB_STATE_##flag)
 195#define KDB_STATE_SET(flag) ((void)(kdb_state |= KDB_STATE_##flag))
 196#define KDB_STATE_CLEAR(flag) ((void)(kdb_state &= ~KDB_STATE_##flag))
 197
 198extern int kdb_nextline; /* Current number of lines displayed */
 199
 200typedef struct _kdb_bp {
 201        unsigned long   bp_addr;        /* Address breakpoint is present at */
 202        unsigned int    bp_free:1;      /* This entry is available */
 203        unsigned int    bp_enabled:1;   /* Breakpoint is active in register */
 204        unsigned int    bp_type:4;      /* Uses hardware register */
 205        unsigned int    bp_installed:1; /* Breakpoint is installed */
 206        unsigned int    bp_delay:1;     /* Do delayed bp handling */
 207        unsigned int    bp_delayed:1;   /* Delayed breakpoint */
 208        unsigned int    bph_length;     /* HW break length */
 209} kdb_bp_t;
 210
 211#ifdef CONFIG_KGDB_KDB
 212extern kdb_bp_t kdb_breakpoints[/* KDB_MAXBPT */];
 213
 214/* The KDB shell command table */
 215typedef struct _kdbtab {
 216        char    *cmd_name;              /* Command name */
 217        kdb_func_t cmd_func;            /* Function to execute command */
 218        char    *cmd_usage;             /* Usage String for this command */
 219        char    *cmd_help;              /* Help message for this command */
 220        short    cmd_flags;             /* Parsing flags */
 221        short    cmd_minlen;            /* Minimum legal # command
 222                                         * chars required */
 223        kdb_repeat_t cmd_repeat;        /* Does command auto repeat on enter? */
 224} kdbtab_t;
 225
 226extern int kdb_bt(int, const char **);  /* KDB display back trace */
 227
 228/* KDB breakpoint management functions */
 229extern void kdb_initbptab(void);
 230extern void kdb_bp_install(struct pt_regs *);
 231extern void kdb_bp_remove(void);
 232
 233typedef enum {
 234        KDB_DB_BPT,     /* Breakpoint */
 235        KDB_DB_SS,      /* Single-step trap */
 236        KDB_DB_SSB,     /* Single step to branch */
 237        KDB_DB_SSBPT,   /* Single step over breakpoint */
 238        KDB_DB_NOBPT    /* Spurious breakpoint */
 239} kdb_dbtrap_t;
 240
 241extern int kdb_main_loop(kdb_reason_t, kdb_reason_t,
 242                         int, kdb_dbtrap_t, struct pt_regs *);
 243
 244/* Miscellaneous functions and data areas */
 245extern int kdb_grepping_flag;
 246extern char kdb_grep_string[];
 247extern int kdb_grep_leading;
 248extern int kdb_grep_trailing;
 249extern char *kdb_cmds[];
 250extern void kdb_syslog_data(char *syslog_data[]);
 251extern unsigned long kdb_task_state_string(const char *);
 252extern char kdb_task_state_char (const struct task_struct *);
 253extern unsigned long kdb_task_state(const struct task_struct *p,
 254                                    unsigned long mask);
 255extern void kdb_ps_suppressed(void);
 256extern void kdb_ps1(const struct task_struct *p);
 257extern void kdb_print_nameval(const char *name, unsigned long val);
 258extern void kdb_send_sig_info(struct task_struct *p, struct siginfo *info);
 259extern void kdb_meminfo_proc_show(void);
 260extern const char *kdb_walk_kallsyms(loff_t *pos);
 261extern char *kdb_getstr(char *, size_t, char *);
 262
 263/* Defines for kdb_symbol_print */
 264#define KDB_SP_SPACEB   0x0001          /* Space before string */
 265#define KDB_SP_SPACEA   0x0002          /* Space after string */
 266#define KDB_SP_PAREN    0x0004          /* Parenthesis around string */
 267#define KDB_SP_VALUE    0x0008          /* Print the value of the address */
 268#define KDB_SP_SYMSIZE  0x0010          /* Print the size of the symbol */
 269#define KDB_SP_NEWLINE  0x0020          /* Newline after string */
 270#define KDB_SP_DEFAULT (KDB_SP_VALUE|KDB_SP_PAREN)
 271
 272#define KDB_TSK(cpu) kgdb_info[cpu].task
 273#define KDB_TSKREGS(cpu) kgdb_info[cpu].debuggerinfo
 274
 275extern struct task_struct *kdb_curr_task(int);
 276
 277#define kdb_task_has_cpu(p) (task_curr(p))
 278
 279/* Simplify coexistence with NPTL */
 280#define kdb_do_each_thread(g, p) do_each_thread(g, p)
 281#define kdb_while_each_thread(g, p) while_each_thread(g, p)
 282
 283#define GFP_KDB (in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
 284
 285extern void *debug_kmalloc(size_t size, gfp_t flags);
 286extern void debug_kfree(void *);
 287extern void debug_kusage(void);
 288
 289extern void kdb_set_current_task(struct task_struct *);
 290extern struct task_struct *kdb_current_task;
 291#ifdef CONFIG_MODULES
 292extern struct list_head *kdb_modules;
 293#endif /* CONFIG_MODULES */
 294
 295extern char kdb_prompt_str[];
 296
 297#define KDB_WORD_SIZE   ((int)sizeof(unsigned long))
 298
 299#endif /* CONFIG_KGDB_KDB */
 300#endif  /* !_KDBPRIVATE_H */
 301
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.