Changeset 9900


Ignore:
Timestamp:
Jul 6, 2008, 8:53:25 AM (11 years ago)
Author:
gb
Message:

Try to identify foreign function name and offset. Set a global if
exception was in foreign code, refuse to "show lisp registers" if
that global's set.
Use an extra #\% when writing x86 register names via fprintf.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/lisp-debug.c

    r8561 r9900  
    3030#ifndef WINDOWS
    3131#include <sys/socket.h>
     32#include <dlfcn.h>
    3233#endif
    3334#include <sys/stat.h>
     
    6566extern
    6667debug_command_entry debug_command_entries[];
     68
     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}
    6788
    6889
     
    365386debug_lisp_registers(ExceptionInformation *xp, siginfo_t *info, int arg)
    366387{
    367 #ifdef PPC
    368   TCR *xpcontext = (TCR *)ptr_from_lispobj(xpGPR(xp, rcontext));
    369 
    370   fprintf(stderr, "rcontext = 0x%lX ", xpcontext);
    371   if (!active_tcr_p(xpcontext)) {
    372     fprintf(stderr, "(INVALID)\n");
    373   } else {
    374     fprintf(stderr, "\nnargs = %d\n", xpGPR(xp, nargs) >> fixnumshift);
    375     show_lisp_register(xp, "fn", fn);
    376     show_lisp_register(xp, "arg_z", arg_z);
    377     show_lisp_register(xp, "arg_y", arg_y);
    378     show_lisp_register(xp, "arg_x", arg_x);
    379     show_lisp_register(xp, "temp0", temp0);
    380     show_lisp_register(xp, "temp1/next_method_context", temp1);
    381     show_lisp_register(xp, "temp2/nfn", temp2);
    382     show_lisp_register(xp, "temp3/fname", temp3);
    383     /*    show_lisp_register(xp, "new_fn", new_fn); */
    384     show_lisp_register(xp, "save0", save0);
    385     show_lisp_register(xp, "save1", save1);
    386     show_lisp_register(xp, "save2", save2);
    387     show_lisp_register(xp, "save3", save3);
    388     show_lisp_register(xp, "save4", save4);
    389     show_lisp_register(xp, "save5", save5);
    390     show_lisp_register(xp, "save6", save6);
    391     show_lisp_register(xp, "save7", save7);
    392   }
     388  if (lisp_debugger_in_foreign_code == false) {
     389#ifdef PPC
     390    TCR *xpcontext = (TCR *)ptr_from_lispobj(xpGPR(xp, rcontext));
     391
     392    fprintf(stderr, "rcontext = 0x%lX ", xpcontext);
     393    if (!active_tcr_p(xpcontext)) {
     394      fprintf(stderr, "(INVALID)\n");
     395    } else {
     396      fprintf(stderr, "\nnargs = %d\n", xpGPR(xp, nargs) >> fixnumshift);
     397      show_lisp_register(xp, "fn", fn);
     398      show_lisp_register(xp, "arg_z", arg_z);
     399      show_lisp_register(xp, "arg_y", arg_y);
     400      show_lisp_register(xp, "arg_x", arg_x);
     401      show_lisp_register(xp, "temp0", temp0);
     402      show_lisp_register(xp, "temp1/next_method_context", temp1);
     403      show_lisp_register(xp, "temp2/nfn", temp2);
     404      show_lisp_register(xp, "temp3/fname", temp3);
     405      /*    show_lisp_register(xp, "new_fn", new_fn); */
     406      show_lisp_register(xp, "save0", save0);
     407      show_lisp_register(xp, "save1", save1);
     408      show_lisp_register(xp, "save2", save2);
     409      show_lisp_register(xp, "save3", save3);
     410      show_lisp_register(xp, "save4", save4);
     411      show_lisp_register(xp, "save5", save5);
     412      show_lisp_register(xp, "save6", save6);
     413      show_lisp_register(xp, "save7", save7);
     414    }
    393415#endif
    394416#ifdef X8664
    395417
    396   show_lisp_register(xp, "arg_z", Iarg_z);
    397   show_lisp_register(xp, "arg_y", Iarg_y);
    398   show_lisp_register(xp, "arg_x", Iarg_x);
    399   fprintf(stderr,"------\n");
    400   show_lisp_register(xp, "fn", Ifn);
    401   fprintf(stderr,"------\n");
    402   show_lisp_register(xp, "save0", Isave0);
    403   show_lisp_register(xp, "save1", Isave1);
    404   show_lisp_register(xp, "save2", Isave2);
    405   show_lisp_register(xp, "save3", Isave3);
    406   fprintf(stderr,"------\n");
    407   show_lisp_register(xp, "temp0", Itemp0);
    408   show_lisp_register(xp, "temp1", Itemp1);
    409   show_lisp_register(xp, "temp2", Itemp2);
    410   fprintf(stderr,"------\n");
    411   if (tag_of(xpGPR(xp,Inargs)) == tag_fixnum) {
    412     fprintf(stderr,"%%cx (nargs) = %d (maybe)\n", unbox_fixnum(xpGPR(xp,Inargs)&0xffff));
    413   }
    414 #endif
     418    show_lisp_register(xp, "arg_z", Iarg_z);
     419    show_lisp_register(xp, "arg_y", Iarg_y);
     420    show_lisp_register(xp, "arg_x", Iarg_x);
     421    fprintf(stderr,"------\n");
     422    show_lisp_register(xp, "fn", Ifn);
     423    fprintf(stderr,"------\n");
     424    show_lisp_register(xp, "save0", Isave0);
     425    show_lisp_register(xp, "save1", Isave1);
     426    show_lisp_register(xp, "save2", Isave2);
     427    show_lisp_register(xp, "save3", Isave3);
     428    fprintf(stderr,"------\n");
     429    show_lisp_register(xp, "temp0", Itemp0);
     430    show_lisp_register(xp, "temp1", Itemp1);
     431    show_lisp_register(xp, "temp2", Itemp2);
     432    fprintf(stderr,"------\n");
     433    if (tag_of(xpGPR(xp,Inargs)) == tag_fixnum) {
     434      fprintf(stderr,"%%rcx (nargs) = %d (maybe)\n", unbox_fixnum(xpGPR(xp,Inargs)&0xffff));
     435    }
     436#endif
     437  }
    415438  return debug_continue;
    416439}
     
    565588debug_show_registers(ExceptionInformation *xp, siginfo_t *info, int arg)
    566589{
     590
     591#ifdef PPC
    567592  int a, b, c, d, i;
    568 
    569 #ifdef PPC
    570593#ifdef PPC64
    571594  for (a = 0, b = 16; a < 16; a++, b++) {
     
    599622
    600623#ifdef X8664
    601   fprintf(stderr,"%rax = 0x%016lX      %r8  = 0x%016lX\n", xpGPR(xp,REG_RAX),xpGPR(xp,REG_R8));
    602   fprintf(stderr,"%rcx = 0x%016lX      %r9  = 0x%016lX\n", xpGPR(xp,REG_RCX),xpGPR(xp,REG_R9));
    603   fprintf(stderr,"%rdx = 0x%016lX      %r10 = 0x%016lX\n", xpGPR(xp,REG_RDX),xpGPR(xp,REG_R10));
    604   fprintf(stderr,"%rbx = 0x%016lX      %r11 = 0x%016lX\n", xpGPR(xp,REG_RBX),xpGPR(xp,REG_R11));
    605   fprintf(stderr,"%rsp = 0x%016lX      %r12 = 0x%016lX\n", xpGPR(xp,REG_RSP),xpGPR(xp,REG_R12));
    606   fprintf(stderr,"%rbp = 0x%016lX      %r13 = 0x%016lX\n", xpGPR(xp,REG_RBP),xpGPR(xp,REG_R13));
    607   fprintf(stderr,"%rsi = 0x%016lX      %r14 = 0x%016lX\n", xpGPR(xp,REG_RSI),xpGPR(xp,REG_R14));
    608   fprintf(stderr,"%rdi = 0x%016lX      %r15 = 0x%016lX\n", xpGPR(xp,REG_RDI),xpGPR(xp,REG_R15));
    609   fprintf(stderr,"%rip = 0x%016lX   %rflags = 0x%016lX\n",
     624  fprintf(stderr,"%%rax = 0x%016lX      %%r8  = 0x%016lX\n", xpGPR(xp,REG_RAX),xpGPR(xp,REG_R8));
     625  fprintf(stderr,"%%rcx = 0x%016lX      %%r9  = 0x%016lX\n", xpGPR(xp,REG_RCX),xpGPR(xp,REG_R9));
     626  fprintf(stderr,"%%rdx = 0x%016lX      %%r10 = 0x%016lX\n", xpGPR(xp,REG_RDX),xpGPR(xp,REG_R10));
     627  fprintf(stderr,"%%rbx = 0x%016lX      %%r11 = 0x%016lX\n", xpGPR(xp,REG_RBX),xpGPR(xp,REG_R11));
     628  fprintf(stderr,"%%rsp = 0x%016lX      %%r12 = 0x%016lX\n", xpGPR(xp,REG_RSP),xpGPR(xp,REG_R12));
     629  fprintf(stderr,"%%rbp = 0x%016lX      %%r13 = 0x%016lX\n", xpGPR(xp,REG_RBP),xpGPR(xp,REG_R13));
     630  fprintf(stderr,"%%rsi = 0x%%016lX     %%r14 = 0x%016lX\n", xpGPR(xp,REG_RSI),xpGPR(xp,REG_R14));
     631  fprintf(stderr,"%%rdi = 0x%016lX      %%r15 = 0x%016lX\n", xpGPR(xp,REG_RDI),xpGPR(xp,REG_R15));
     632  fprintf(stderr,"%%rip = 0x%016lX   %%rflags = 0x%016lX\n",
    610633          xpGPR(xp, Iip), xpGPR(xp, Iflags));
    611634#endif
     
    863886      }
    864887    } else {
    865       fprintf(stderr, " In foreign code at address 0x%08lx\n", xpPC(xp));
     888      int disp;
     889      char *foreign_name;
     890      natural where = (natural)xpPC(xp);
     891
     892      fprintf(stderr, " In foreign code at address 0x%08lx\n", where);
     893      foreign_name = foreign_name_and_offset(where, &disp);
     894      if (foreign_name) {
     895        fprintf(stderr, "  [%s + %d]\n", foreign_name, disp);
     896      }
    866897    }
    867898  }
     
    872903extern pid_t main_thread_pid;
    873904#endif
     905
    874906
    875907OSStatus
     
    892924  fprintf(stderr, "\n");
    893925  va_end(args);
    894   if (in_foreign_code) {
     926 
     927  lisp_debugger_in_foreign_code = in_foreign_code;
     928  if (in_foreign_code) {   
     929    char *foreign_name;
     930    int disp;
    895931    fprintf(stderr, "Exception occurred while executing foreign code\n");
     932    foreign_name = foreign_name_and_offset((natural)xpPC(xp), &disp);
     933    if (foreign_name) {
     934      fprintf(stderr, " at %s + %d\n", foreign_name, disp);
     935    }
    896936  }
    897937
Note: See TracChangeset for help on using the changeset viewer.