This is kernel.c in view mode; [Download] [Up]

#include "defs.h"
#include "inferior.h"
#include "target.h"
#include <objc/objc.h>
#include <sys/signal.h>

extern struct symbol *step_start_function;
extern int stop_soon_quietly;
extern int stop_print_frame;
extern char * reg_names[];

#ifdef GDB_88K
static const char *kernel_reg_names[] = {
    	"zero",	"rpc",	"a0",	"a1",	"a2",	"a3",	"a4",	"a5",
    	"a6",   "a7",	"t0",	"t1",	"t2",	"t3",	"s0",	"s1",
    	"s2",   "s3",	"s4",	"s5",	"s6",	"s7",	"s8",	"s9",
    	"s10",	"s11",	"t4",	"at",	"lk0",	"lk1",	"fp",	"sp",
    	"xip", 	"xip_in_bd", 	"nip", 	"psr",
    	"xzero","xt0",	"xt1",	"xt2",	"xt3",	"xt4",	"xt5",	"xt6",
    	"xt7",	"xt8",	"xt9",	"xt10",	"xt11",	"xt12",	"xt13",	"xt14",
    	"xt15",	"xt16",	"xt17",	"xt18",	"xt19",	"xt20",	"xs0",	"xs1",
    	"xs2",	"xs3",	"xs4",	"xs5",	"xs6",	"xs7",	"xr0",	"xr1",
    	"fpsr",	"fpcr"
#endif GDB_88K

void msleep(msg_timeout_t timeout)
  port_t port;
  msg_header_t msg;

  port_allocate(task_self(), &port);
  msg.msg_size = sizeof(msg);
  msg.msg_local_port = port;
  msg_receive(&msg, RCV_TIMEOUT, timeout);
  port_deallocate(task_self(), port);

kernel_attach_command(char *args, int from_tty)
  extern struct target_ops child_ops;
  char portname[50];
  task_t kernel_task;
  int kdbPid;
  int tries;
  BOOL found;


  if (!args)
    error_no_arg ("hostname of kernel to attach to");

  if (inferior_pid) {
    if (query ("A program is being debugged already.  Kill it? "))
      target_kill ();
      error ("Inferior not killed.");

  if (from_tty)
    printf("Attaching program: %s to kernel on %s.\n",
	   get_exec_file(1), args);

  sprintf (portname, "gdb_%s", args);
  if (netname_look_up(name_server_port, "", portname, &kernel_task) != 0) {
    kdbPid = vfork();
    if (kdbPid) {
      for (tries = 0, found = NO; (tries < 20) && !found; tries++) {
	QUIT;			/* Allow this to be interruptable */
	found = (netname_look_up(name_server_port,
				 "", portname, &kernel_task) == 0);
      if (!found) {
	kill(kdbPid, SIGKILL);
	error("Couldn't find kernel kdb port, %s", portname);
    } else
#ifdef GDB_88K	
      execl("/usr/lib/kdb88", "/usr/lib/kdb88", args, NULL);
    execl("/usr/lib/kdb", "/usr/lib/kdb", args, NULL);
#endif GDB_88K

  push_target (&child_ops);

  kernel_attached = YES;

  create_inferior_for_task(kernel_task, YES);

  mark_breakpoints_out ();
  target_terminal_init ();
  clear_proceed_status ();

#ifdef GDB_88K
  memcpy(reg_names, kernel_reg_names, sizeof(kernel_reg_names));
#endif GDB_88K    
  stop_pc = read_pc();
  step_start_function = find_pc_function(stop_pc);
  inferior_pid = -1;
  stop_soon_quietly = 1;
  stop_print_frame = 1;
  attach_flag = 1;
  normal_stop ();

kernel_reboot_command(char *args)
  if (kernel_attached) {
    if (!args)
      args = "";
    mach_call(task_reboot(inferior_task, args, strlen(args)),
	      "task_reboot", "kernel_reboot_command");
  } else
    error("Not attached to kernel.");

kselect_frame_command (args)
char *args;
  value_ptr val;
  int fp,pc;

  if (!args)
    error ("select-frame fp, pc.");
  val = parse_to_comma_and_eval (&args);
  if (!val) 
    error ("select-frame fp, pc.");
  fp = value_as_long(val);
  if (*args++ != ',')
     error ("select-frame fp, pc.");
  val = parse_and_eval (args);
  if (!val) 
    error ("select-frame fp, pc.");
  pc = value_as_long(val);
  flush_cached_frames ();
  set_current_frame (create_new_frame (fp, pc));
  select_frame (get_current_frame (), 0);

  add_com("kattach", class_run, kernel_attach_command,
	  "Attach to a kernel on HOSTNAME.");
  add_com ("select-frame", class_support, kselect_frame_command,
	   "select frame at fp, pc.");
  add_com("kreboot", class_run, kernel_reboot_command,
	  "Reboot an attached kernel with ARGS");

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.