Changeset 9962


Ignore:
Timestamp:
Jul 10, 2008, 9:23:22 AM (11 years ago)
Author:
gb
Message:

More WINDOWS nonsense.
Use dladdr() to report foreign addresses symbolically in some cases.
Ignore EIO errors.
Remove some unused variables.
Use %% when printing x8664 register names via fprintf.
Set a global if we were entered via exception in foreign code, keep
show_lisp_registers() from doing anything in that case. (Would
be even better to disable the menu option.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lisp-kernel/lisp-debug.c

    r7752 r9962  
    2828#include <stdio.h>
    2929
     30#ifndef WINDOWS
    3031#include <sys/socket.h>
     32#include <dlfcn.h>
     33#endif
    3134#include <sys/stat.h>
    3235
     
    6467debug_command_entry debug_command_entries[];
    6568
     69Boolean lisp_debugger_in_foreign_code = false;
     70
     71char *
     72foreign_name_and_offset(natural addr, int *delta)
     73{
     74  Dl_info info;
     75  char *ret = NULL;
     76
     77  if (delta) {
     78    *delta = 0;
     79  }
     80#ifndef WINDOWS
     81  if (dladdr((void *)addr, &info)) {
     82    ret = (char *)info.dli_sname;
     83    *delta = ((natural)addr - (natural)info.dli_saddr);
     84  }
     85#endif
     86  return ret;
     87}
     88
    6689
    6790#if defined(LINUX) || defined(SOLARIS)
    6891#define fpurge __fpurge
     92#endif
     93
     94#ifdef WINDOWS
     95void
     96fpurge (FILE* file)
     97{
     98}
    6999#endif
    70100
     
    80110    case EOF:
    81111      if (ferror(stdin)) {
    82         if (errno == EINTR) {
     112        if ((errno == EINTR) || (errno == EIO)) {
    83113          continue;
    84114        }
     
    110140                     "r14", "r15", "rip", "rfl"};
    111141#endif
     142#ifdef WINDOWS
     143/* is this correct? */
     144char* Iregnames[] = {"r8 ","r9 ","r10","r11","r12","r13","r14","r15",
     145                     "rdi","rsi","rbp", "rbx", "rdx", "rax", "rcx","rsp"};
     146#endif
    112147#endif
    113148
     
    147182{
    148183  pc where = xpPC(xp);
    149   opcode the_uuo = *where, instr2;
     184  opcode the_uuo = *where;
    150185  Boolean described = false;
    151186
     
    153188    unsigned
    154189      minor = UUO_MINOR(the_uuo),
    155       rt = 0x1f & (the_uuo >> 21),
    156       ra = 0x1f & (the_uuo >> 16),
    157       rb = 0x1f & (the_uuo >> 11),
    158190      errnum = 0x3ff & (the_uuo >> 16);
    159191
     
    191223  pc where = xpPC(xp);
    192224  opcode the_trap = *where, instr;
    193   int  err_arg1, err_arg2, ra, rs;
    194   char *name = NULL;
     225  int err_arg2, ra, rs;
    195226  Boolean identified = false;
    196227
     
    351382debug_lisp_registers(ExceptionInformation *xp, siginfo_t *info, int arg)
    352383{
    353 #ifdef PPC
    354   TCR *xpcontext = (TCR *)ptr_from_lispobj(xpGPR(xp, rcontext));
    355 
    356   fprintf(stderr, "rcontext = 0x%lX ", xpcontext);
    357   if (!active_tcr_p(xpcontext)) {
    358     fprintf(stderr, "(INVALID)\n");
    359   } else {
    360     fprintf(stderr, "\nnargs = %d\n", xpGPR(xp, nargs) >> fixnumshift);
    361     show_lisp_register(xp, "fn", fn);
    362     show_lisp_register(xp, "arg_z", arg_z);
    363     show_lisp_register(xp, "arg_y", arg_y);
    364     show_lisp_register(xp, "arg_x", arg_x);
    365     show_lisp_register(xp, "temp0", temp0);
    366     show_lisp_register(xp, "temp1/next_method_context", temp1);
    367     show_lisp_register(xp, "temp2/nfn", temp2);
    368     show_lisp_register(xp, "temp3/fname", temp3);
    369     /*    show_lisp_register(xp, "new_fn", new_fn); */
    370     show_lisp_register(xp, "save0", save0);
    371     show_lisp_register(xp, "save1", save1);
    372     show_lisp_register(xp, "save2", save2);
    373     show_lisp_register(xp, "save3", save3);
    374     show_lisp_register(xp, "save4", save4);
    375     show_lisp_register(xp, "save5", save5);
    376     show_lisp_register(xp, "save6", save6);
    377     show_lisp_register(xp, "save7", save7);
    378   }
     384  if (lisp_debugger_in_foreign_code == false) {
     385#ifdef PPC
     386    TCR *xpcontext = (TCR *)ptr_from_lispobj(xpGPR(xp, rcontext));
     387
     388    fprintf(stderr, "rcontext = 0x%lX ", xpcontext);
     389    if (!active_tcr_p(xpcontext)) {
     390      fprintf(stderr, "(INVALID)\n");
     391    } else {
     392      fprintf(stderr, "\nnargs = %d\n", xpGPR(xp, nargs) >> fixnumshift);
     393      show_lisp_register(xp, "fn", fn);
     394      show_lisp_register(xp, "arg_z", arg_z);
     395      show_lisp_register(xp, "arg_y", arg_y);
     396      show_lisp_register(xp, "arg_x", arg_x);
     397      show_lisp_register(xp, "temp0", temp0);
     398      show_lisp_register(xp, "temp1/next_method_context", temp1);
     399      show_lisp_register(xp, "temp2/nfn", temp2);
     400      show_lisp_register(xp, "temp3/fname", temp3);
     401      /*    show_lisp_register(xp, "new_fn", new_fn); */
     402      show_lisp_register(xp, "save0", save0);
     403      show_lisp_register(xp, "save1", save1);
     404      show_lisp_register(xp, "save2", save2);
     405      show_lisp_register(xp, "save3", save3);
     406      show_lisp_register(xp, "save4", save4);
     407      show_lisp_register(xp, "save5", save5);
     408      show_lisp_register(xp, "save6", save6);
     409      show_lisp_register(xp, "save7", save7);
     410    }
    379411#endif
    380412#ifdef X8664
    381413
    382   show_lisp_register(xp, "arg_z", Iarg_z);
    383   show_lisp_register(xp, "arg_y", Iarg_y);
    384   show_lisp_register(xp, "arg_x", Iarg_x);
    385   fprintf(stderr,"------\n");
    386   show_lisp_register(xp, "fn", Ifn);
    387   fprintf(stderr,"------\n");
    388   show_lisp_register(xp, "save0", Isave0);
    389   show_lisp_register(xp, "save1", Isave1);
    390   show_lisp_register(xp, "save2", Isave2);
    391   show_lisp_register(xp, "save3", Isave3);
    392   fprintf(stderr,"------\n");
    393   show_lisp_register(xp, "temp0", Itemp0);
    394   show_lisp_register(xp, "temp1", Itemp1);
    395   show_lisp_register(xp, "temp2", Itemp2);
    396   fprintf(stderr,"------\n");
    397   if (tag_of(xpGPR(xp,Inargs)) == tag_fixnum) {
    398     fprintf(stderr,"%%cx (nargs) = %d (maybe)\n", unbox_fixnum(xpGPR(xp,Inargs)&0xffff));
    399   }
    400 #endif
     414    show_lisp_register(xp, "arg_z", Iarg_z);
     415    show_lisp_register(xp, "arg_y", Iarg_y);
     416    show_lisp_register(xp, "arg_x", Iarg_x);
     417    fprintf(stderr,"------\n");
     418    show_lisp_register(xp, "fn", Ifn);
     419    fprintf(stderr,"------\n");
     420    show_lisp_register(xp, "save0", Isave0);
     421    show_lisp_register(xp, "save1", Isave1);
     422    show_lisp_register(xp, "save2", Isave2);
     423    show_lisp_register(xp, "save3", Isave3);
     424    fprintf(stderr,"------\n");
     425    show_lisp_register(xp, "temp0", Itemp0);
     426    show_lisp_register(xp, "temp1", Itemp1);
     427    show_lisp_register(xp, "temp2", Itemp2);
     428    fprintf(stderr,"------\n");
     429    if (tag_of(xpGPR(xp,Inargs)) == tag_fixnum) {
     430      fprintf(stderr,"%%rcx (nargs) = %ld (maybe)\n", unbox_fixnum(xpGPR(xp,Inargs)&0xffff));
     431    }
     432#endif
     433  }
    401434  return debug_continue;
    402435}
     
    529562     
    530563
     564#ifdef WINDOWS
     565debug_command_return
     566debug_set_gpr(ExceptionInformation *xp, siginfo_t *info, int arg)
     567{
     568}
     569#else
    531570debug_command_return
    532571debug_set_gpr(ExceptionInformation *xp, siginfo_t *info, int arg)
     
    540579  return debug_continue;
    541580}
    542 
     581#endif
    543582
    544583debug_command_return
    545584debug_show_registers(ExceptionInformation *xp, siginfo_t *info, int arg)
    546585{
    547   int a, b, c, d, i;
    548586
    549587#ifdef PPC
    550588#ifdef PPC64
     589  int a, b;
    551590  for (a = 0, b = 16; a < 16; a++, b++) {
    552591    fprintf(stderr,"r%02d = 0x%016lX    r%02d = 0x%016lX\n",
     
    564603          xpDAR(xp), xpDSISR(xp));
    565604#else
     605  int a, b, c, d;;
    566606  for (a = 0, b = 8, c = 16, d = 24; a < 8; a++, b++, c++, d++) {
    567607    fprintf(stderr,"r%02d = 0x%08X  r%02d = 0x%08X  r%02d = 0x%08X  r%02d = 0x%08X\n",
     
    579619
    580620#ifdef X8664
    581   fprintf(stderr,"%rax = 0x%016lX      %r8  = 0x%016lX\n", xpGPR(xp,REG_RAX),xpGPR(xp,REG_R8));
    582   fprintf(stderr,"%rcx = 0x%016lX      %r9  = 0x%016lX\n", xpGPR(xp,REG_RCX),xpGPR(xp,REG_R9));
    583   fprintf(stderr,"%rdx = 0x%016lX      %r10 = 0x%016lX\n", xpGPR(xp,REG_RDX),xpGPR(xp,REG_R10));
    584   fprintf(stderr,"%rbx = 0x%016lX      %r11 = 0x%016lX\n", xpGPR(xp,REG_RBX),xpGPR(xp,REG_R11));
    585   fprintf(stderr,"%rsp = 0x%016lX      %r12 = 0x%016lX\n", xpGPR(xp,REG_RSP),xpGPR(xp,REG_R12));
    586   fprintf(stderr,"%rbp = 0x%016lX      %r13 = 0x%016lX\n", xpGPR(xp,REG_RBP),xpGPR(xp,REG_R13));
    587   fprintf(stderr,"%rsi = 0x%016lX      %r14 = 0x%016lX\n", xpGPR(xp,REG_RSI),xpGPR(xp,REG_R14));
    588   fprintf(stderr,"%rdi = 0x%016lX      %r15 = 0x%016lX\n", xpGPR(xp,REG_RDI),xpGPR(xp,REG_R15));
    589   fprintf(stderr,"%rip = 0x%016lX   %rflags = 0x%016lX\n",
     621  fprintf(stderr,"%%rax = 0x%016lX      %%r8  = 0x%016lX\n", xpGPR(xp,REG_RAX),xpGPR(xp,REG_R8));
     622  fprintf(stderr,"%%rcx = 0x%016lX      %%r9  = 0x%016lX\n", xpGPR(xp,REG_RCX),xpGPR(xp,REG_R9));
     623  fprintf(stderr,"%%rdx = 0x%016lX      %%r10 = 0x%016lX\n", xpGPR(xp,REG_RDX),xpGPR(xp,REG_R10));
     624  fprintf(stderr,"%%rbx = 0x%016lX      %%r11 = 0x%016lX\n", xpGPR(xp,REG_RBX),xpGPR(xp,REG_R11));
     625  fprintf(stderr,"%%rsp = 0x%016lX      %%r12 = 0x%016lX\n", xpGPR(xp,REG_RSP),xpGPR(xp,REG_R12));
     626  fprintf(stderr,"%%rbp = 0x%016lX      %%r13 = 0x%016lX\n", xpGPR(xp,REG_RBP),xpGPR(xp,REG_R13));
     627  fprintf(stderr,"%%rsi = 0x%016lX      %%r14 = 0x%016lX\n", xpGPR(xp,REG_RSI),xpGPR(xp,REG_R14));
     628  fprintf(stderr,"%%rdi = 0x%016lX      %%r15 = 0x%016lX\n", xpGPR(xp,REG_RDI),xpGPR(xp,REG_R15));
     629  fprintf(stderr,"%%rip = 0x%016lX   %%rflags = 0x%016lX\n",
    590630          xpGPR(xp, Iip), xpGPR(xp, Iflags));
    591631#endif
     
    602642  np = (int *) dp;
    603643 
    604   for (i = 0; i < 32; i++) {
    605     fprintf(stderr, "f%02d : 0x%08X%08X (%f)\n", i,  *np++, *np++, *dp++);
     644  for (i = 0; i < 32; i++, np+=2) {
     645    fprintf(stderr, "f%02d : 0x%08X%08X (%f)\n", i,  np[0], np[1], *dp++);
    606646  }
    607647  fprintf(stderr, "FPSCR = %08X\n", xpFPSCR(xp));
     
    617657  struct xmm *xmmp = (struct xmm *)(xpFPRvector(xp));
    618658#endif
     659#ifdef WINDOWS
     660  struct xmm {
     661    char fpdata[16];
     662  };
     663  struct xmm *xmmp; /* XXX: actually get them */
     664#endif
    619665#ifdef FREEBSD
    620666  struct xmmacc *xmmp = xpXMMregs(xp);
     
    638684#ifdef FREEBSD
    639685          (((struct savefpu *)(&(xp)->uc_mcontext.mc_fpstate))->sv_env.en_mxcsr)
     686#endif
     687#ifdef WINDOWS
     688          0 /* XXX: get from somewhere */
    640689#endif
    641690          );
     
    834883      }
    835884    } else {
    836       fprintf(stderr, " In foreign code at address 0x%08lx\n", xpPC(xp));
    837     }
    838   }
    839 #endif
    840 }
    841 
     885      int disp;
     886      char *foreign_name;
     887      natural where = (natural)xpPC(xp);
     888
     889      fprintf(stderr, " In foreign code at address 0x%08lx\n", where);
     890      foreign_name = foreign_name_and_offset(where, &disp);
     891      if (foreign_name) {
     892        fprintf(stderr, "  [%s + %d]\n", foreign_name, disp);
     893      }
     894    }
     895  }
     896#endif
     897}
     898
     899#ifndef WINDOWS
    842900extern pid_t main_thread_pid;
     901#endif
     902
    843903
    844904OSStatus
     
    861921  fprintf(stderr, "\n");
    862922  va_end(args);
    863   if (in_foreign_code) {
     923 
     924  lisp_debugger_in_foreign_code = in_foreign_code;
     925  if (in_foreign_code) {   
     926    char *foreign_name;
     927    int disp;
    864928    fprintf(stderr, "Exception occurred while executing foreign code\n");
     929    foreign_name = foreign_name_and_offset((natural)xpPC(xp), &disp);
     930    if (foreign_name) {
     931      fprintf(stderr, " at %s + %d\n", foreign_name, disp);
     932    }
    865933  }
    866934
     
    876944  fprintf(stderr, "? for help\n");
    877945  while (state == debug_continue) {
     946#ifdef WINDOWS
     947    fprintf(stderr, "[%d] OpenMCL kernel debugger: ", 23 /* FIXME */);
     948#else
    878949    fprintf(stderr, "[%d] OpenMCL kernel debugger: ", main_thread_pid);
     950#endif
    879951    state = apply_debug_command(xp, readc(), info, why);
    880952  }
Note: See TracChangeset for help on using the changeset viewer.