stacktrace.c 16.8 KB
Newer Older
1 2 3 4
/* Copyright (C) 2000 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6 7 8 9 10 11 12 13 14 15

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

16 17 18
/* Workaround for Bug#32082: VOID redefinition on Win results in compile errors*/
#define DONT_DEFINE_VOID 1

19
#include <my_global.h>
20
#include "stacktrace.h"
21 22

#ifndef __WIN__
23
#include <signal.h>
24
#include <my_pthread.h>
25 26
#ifdef HAVE_STACKTRACE
#include <unistd.h>
27
#include <strings.h>
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

#define PTR_SANE(p) ((p) && (char*)(p) >= heap_start && (char*)(p) <= heap_end)

char *heap_start;

void safe_print_str(const char* name, const char* val, int max_len)
{
  char *heap_end= (char*) sbrk(0);
  fprintf(stderr, "%s at %p ", name, val);

  if (!PTR_SANE(val))
  {
    fprintf(stderr, " is invalid pointer\n");
    return;
  }

  fprintf(stderr, "= ");
45
  for (; max_len && PTR_SANE(val) && *val; --max_len)
46 47 48 49
    fputc(*val++, stderr);
  fputc('\n', stderr);
}

50
#ifdef TARGET_OS_LINUX
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#ifdef __i386__
#define SIGRETURN_FRAME_OFFSET 17
#endif

#ifdef __x86_64__
#define SIGRETURN_FRAME_OFFSET 23
#endif

static my_bool is_nptl;

/* Check if we are using NPTL or LinuxThreads on Linux */
void check_thread_lib(void)
{
  char buf[5];

67
#ifdef _CS_GNU_LIBPTHREAD_VERSION
68 69
  confstr(_CS_GNU_LIBPTHREAD_VERSION, buf, sizeof(buf));
  is_nptl = !strncasecmp(buf, "NPTL", sizeof(buf));
70 71 72
#else
  is_nptl = 0;
#endif
73
}
74 75 76 77 78 79 80 81 82 83 84 85 86 87

#if defined(__alpha__) && defined(__GNUC__)
/*
  The only way to backtrace without a symbol table on alpha
  is to find stq fp,N(sp), and the first byte
  of the instruction opcode will give us the value of N. From this
  we can find where the old value of fp is stored
*/

#define MAX_INSTR_IN_FUNC  10000

inline uchar** find_prev_fp(uint32* pc, uchar** fp)
{
  int i;
88
  for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
89 90 91 92 93 94 95 96 97 98 99 100 101
  {
    uchar* p = (uchar*)pc;
    if (p[2] == 222 &&  p[3] == 35)
    {
      return (uchar**)((uchar*)fp - *(short int*)p);
    }
  }
  return 0;
}

inline uint32* find_prev_pc(uint32* pc, uchar** fp)
{
  int i;
102
  for (i = 0; i < MAX_INSTR_IN_FUNC; ++i,--pc)
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
  {
    char* p = (char*)pc;
    if (p[1] == 0 && p[2] == 94 &&  p[3] == -73)
    {
      uint32* prev_pc = (uint32*)*((fp+p[0]/sizeof(fp)));
      return prev_pc;
    }
  }
  return 0;
}
#endif /* defined(__alpha__) && defined(__GNUC__) */


void  print_stacktrace(gptr stack_bottom, ulong thread_stack)
{
  uchar** fp;
119
  uint frame_count = 0, sigreturn_frame_count;
120 121 122 123 124
#if defined(__alpha__) && defined(__GNUC__)
  uint32* pc;
#endif
  LINT_INIT(fp);

125

126
#ifdef __i386__
127 128 129
  __asm __volatile__ ("movl %%ebp,%0"
		      :"=r"(fp)
		      :"r"(fp));
130 131 132 133 134
#endif
#ifdef __x86_64__
  __asm __volatile__ ("movq %%rbp,%0"
		      :"=r"(fp)
		      :"r"(fp));
135 136
#endif
#if defined(__alpha__) && defined(__GNUC__) 
sasha@mysql.sashanet.com's avatar
sasha@mysql.sashanet.com committed
137
  __asm __volatile__ ("mov $30,%0"
138 139
		      :"=r"(fp)
		      :"r"(fp));
140
#endif
141 142
  if (!fp)
  {
143
    fprintf(stderr, "frame pointer is NULL, did you compile with\n\
144 145 146
-fomit-frame-pointer? Aborting backtrace!\n");
    return;
  }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
147

148
  if (!stack_bottom || (gptr) stack_bottom > (gptr) &fp)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  {
    ulong tmp= min(0x10000,thread_stack);
    /* Assume that the stack starts at the previous even 65K */
    stack_bottom= (gptr) (((ulong) &fp + tmp) &
			  ~(ulong) 0xFFFF);
    fprintf(stderr, "Cannot determine thread, fp=%p, backtrace may not be correct.\n", fp);
  }
  if (fp > (uchar**) stack_bottom ||
      fp < (uchar**) stack_bottom - thread_stack)
  {
    fprintf(stderr, "Bogus stack limit or frame pointer,\
 fp=%p, stack_bottom=%p, thread_stack=%ld, aborting backtrace.\n",
	    fp, stack_bottom, thread_stack);
    return;
  }

  fprintf(stderr, "Stack range sanity check OK, backtrace follows:\n");
#if defined(__alpha__) && defined(__GNUC__)
  fprintf(stderr, "Warning: Alpha stacks are difficult -\
 will be taking some wild guesses, stack trace may be incorrect or \
 terminate abruptly\n");
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
170
  /* On Alpha, we need to get pc */
171 172 173 174
  __asm __volatile__ ("bsr %0, do_next; do_next: "
		      :"=r"(pc)
		      :"r"(pc));
#endif  /* __alpha__ */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
175

176 177 178
  /* We are 1 frame above signal frame with NPTL and 2 frames above with LT */
  sigreturn_frame_count = is_nptl ? 1 : 2;
  
179 180
  while (fp < (uchar**) stack_bottom)
  {
181
#if defined(__i386__) || defined(__x86_64__)
182
    uchar** new_fp = (uchar**)*fp;
183 184 185
    fprintf(stderr, "%p\n", frame_count == sigreturn_frame_count ?
	    *(fp + SIGRETURN_FRAME_OFFSET) : *(fp + 1));
#endif /* defined(__386__)  || defined(__x86_64__) */
186 187 188

#if defined(__alpha__) && defined(__GNUC__)
    uchar** new_fp = find_prev_fp(pc, fp);
189
    if (frame_count == sigreturn_frame_count - 1)
190 191 192
    {
      new_fp += 90;
    }
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
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
    if (fp && pc)
    {
      pc = find_prev_pc(pc, fp);
      if (pc)
	fprintf(stderr, "%p\n", pc);
      else
      {
	fprintf(stderr, "Not smart enough to deal with the rest\
 of this stack\n");
	goto end;
      }
    }
    else
    {
      fprintf(stderr, "Not smart enough to deal with the rest of this stack\n");
      goto end;
    }
#endif /* defined(__alpha__) && defined(__GNUC__) */
    if (new_fp <= fp )
    {
      fprintf(stderr, "New value of fp=%p failed sanity check,\
 terminating stack trace!\n", new_fp);
      goto end;
    }
    fp = new_fp;
    ++frame_count;
  }

  fprintf(stderr, "Stack trace seems successful - bottom reached\n");
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
223

224
end:
225
  fprintf(stderr, "Please read http://dev.mysql.com/doc/mysql/en/using-stack-trace.html and follow instructions on how to resolve the stack trace. Resolved\n\
226 227 228
stack trace is much more helpful in diagnosing the problem, so please do \n\
resolve it\n");
}
229

230
#elif defined(HAVE_PRINTSTACK)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247

/* Use Solaris' symbolic stack trace routine. */
#include <ucontext.h>

void  print_stacktrace(gptr stack_bottom __attribute__((unused)), 
                       ulong thread_stack __attribute__((unused)))
{
  if (printstack(fileno(stderr)) == -1)
    fprintf(stderr, "Error when traversing the stack, stack appears corrupt.\n");
  else
    fprintf(stderr, "Please read "
            "http://dev.mysql.com/doc/mysql/en/using-stack-trace.html "
            "and follow instructions on how to resolve the stack trace. "
            "Resolved\nstack trace is much more helpful in diagnosing the "
            "problem, so please do \nresolve it\n");
}

248
#endif /* TARGET_OS_LINUX */
249 250 251 252
#endif /* HAVE_STACKTRACE */

/* Produce a core for the thread */

253
#ifdef NOT_USED /* HAVE_LINUXTHREADS */
254 255 256
void write_core(int sig)
{
  signal(sig, SIG_DFL);
salle@geopard.online.bg's avatar
salle@geopard.online.bg committed
257 258
  if (fork() != 0) exit(1);			/* Abort main program */
  /* Core will be written at exit */
259
}
260 261 262 263
#else
void write_core(int sig)
{
  signal(sig, SIG_DFL);
264 265 266 267 268 269 270 271 272
#ifdef HAVE_gcov
  /*
    For GCOV build, crashing will prevent the writing of code coverage
    information from this process, causing gcov output to be incomplete.
    So we force the writing of coverage information here before terminating.
  */
  extern void __gcov_flush(void);
  __gcov_flush();
#endif
273
  pthread_kill(pthread_self(), sig);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
274
#if defined(P_MYID) && !defined(SCO)
275 276
  /* On Solaris, the above kill is not enough */
  sigsend(P_PID,P_MYID,sig);
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
277
#endif
278 279
}
#endif
280 281 282
#else /* __WIN__*/

#include <dbghelp.h>
283
#include <tlhelp32.h>
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371

/*
  Stack tracing on Windows is implemented using Debug Helper library(dbghelp.dll)
  We do not redistribute dbghelp and the one comes with older OS (up to Windows 2000)
  is missing some important functions like functions StackWalk64 or MinidumpWriteDump.
  Hence, we have to load functions at runtime using LoadLibrary/GetProcAddress.
*/

typedef DWORD (WINAPI *SymSetOptions_FctType)(DWORD dwOptions);
typedef BOOL  (WINAPI *SymGetModuleInfo64_FctType)
  (HANDLE,DWORD64,PIMAGEHLP_MODULE64) ;
typedef BOOL  (WINAPI *SymGetSymFromAddr64_FctType)
  (HANDLE,DWORD64,PDWORD64,PIMAGEHLP_SYMBOL64) ;
typedef BOOL  (WINAPI *SymGetLineFromAddr64_FctType)
  (HANDLE,DWORD64,PDWORD,PIMAGEHLP_LINE64);
typedef BOOL  (WINAPI *SymInitialize_FctType)
  (HANDLE,PSTR,BOOL);
typedef BOOL  (WINAPI *StackWalk64_FctType)
  (DWORD,HANDLE,HANDLE,LPSTACKFRAME64,PVOID,PREAD_PROCESS_MEMORY_ROUTINE64,
  PFUNCTION_TABLE_ACCESS_ROUTINE64,PGET_MODULE_BASE_ROUTINE64 ,
  PTRANSLATE_ADDRESS_ROUTINE64);
typedef BOOL (WINAPI *MiniDumpWriteDump_FctType)(
    IN HANDLE hProcess,
    IN DWORD ProcessId,
    IN HANDLE hFile,
    IN MINIDUMP_TYPE DumpType,
    IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL
    IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL
    IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL
    );

static SymSetOptions_FctType           pSymSetOptions;
static SymGetModuleInfo64_FctType      pSymGetModuleInfo64;
static SymGetSymFromAddr64_FctType     pSymGetSymFromAddr64;
static SymInitialize_FctType           pSymInitialize;
static StackWalk64_FctType             pStackWalk64;
static SymGetLineFromAddr64_FctType    pSymGetLineFromAddr64;
static MiniDumpWriteDump_FctType       pMiniDumpWriteDump;

static EXCEPTION_POINTERS *exception_ptrs;

#define MODULE64_SIZE_WINXP 576
#define STACKWALK_MAX_FRAMES 64

/*
  Dynamically load dbghelp functions
*/
BOOL init_dbghelp_functions()
{
  static BOOL first_time= TRUE;
  static BOOL rc;
  HMODULE hDbghlp;

  if(first_time)
  {
    first_time= FALSE;
    hDbghlp= LoadLibrary("dbghelp");
    if(!hDbghlp)
    {
      rc= FALSE;
      return rc;
    }
    pSymSetOptions= (SymSetOptions_FctType)
      GetProcAddress(hDbghlp,"SymSetOptions");
    pSymInitialize= (SymInitialize_FctType)
      GetProcAddress(hDbghlp,"SymInitialize");
    pSymGetModuleInfo64= (SymGetModuleInfo64_FctType)
      GetProcAddress(hDbghlp,"SymGetModuleInfo64");
    pSymGetLineFromAddr64= (SymGetLineFromAddr64_FctType)
      GetProcAddress(hDbghlp,"SymGetLineFromAddr64");
    pSymGetSymFromAddr64=(SymGetSymFromAddr64_FctType)
      GetProcAddress(hDbghlp,"SymGetSymFromAddr64");
    pStackWalk64= (StackWalk64_FctType)
      GetProcAddress(hDbghlp,"StackWalk64");
    pMiniDumpWriteDump = (MiniDumpWriteDump_FctType)
      GetProcAddress(hDbghlp,"MiniDumpWriteDump");

    rc = (BOOL)(pSymSetOptions && pSymInitialize && pSymGetModuleInfo64
    && pSymGetLineFromAddr64 && pSymGetSymFromAddr64 && pStackWalk64);
  }
  return rc;
}

void set_exception_pointers(EXCEPTION_POINTERS *ep)
{
  exception_ptrs = ep;
}

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

/*
  Get symbol path - semicolon-separated list of directories to search for debug
  symbols. We expect PDB in the same directory as corresponding exe or dll,
  so the path is build from directories of the loaded modules. If environment
  variable _NT_SYMBOL_PATH is set, it's value appended to the symbol search path
*/
static void get_symbol_path(char *path, size_t size)
{ 
  HANDLE hSnap; 
  char *envvar;

  path[0]= '\0';
  /*
    Enumerate all modules, and add their directories to the path.
    Avoid duplicate entries.
  */
  hSnap= CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId());
  if (hSnap != INVALID_HANDLE_VALUE)
  {
    BOOL ret;
    MODULEENTRY32 mod;
    mod.dwSize= sizeof(MODULEENTRY32);
    for (ret= Module32First(hSnap, &mod); ret; ret= Module32Next(hSnap, &mod))
    {
      char *module_dir= mod.szExePath;
      char *p= strrchr(module_dir,'\\');
      if (!p)
      {
        /*
          Path separator was not found. Not known to happen, if ever happens,
          will indicate current directory.
        */
        module_dir[0]= '.';
        p= module_dir + 1;
      }
      *p++= ';';
      *p= '\0';

      if (!strstr(path, module_dir))
      {
413 414 415 416 417 418
        size_t dir_len = strlen(module_dir);
        if (size > dir_len)
        {
          strncat(path, module_dir, size-1);
          size -= dir_len;
        }
419 420 421 422 423 424 425
      }
    }
    CloseHandle(hSnap);
  }

  /* Add _NT_SYMBOL_PATH, if present. */
  envvar= getenv("_NT_SYMBOL_PATH");
426
  if(envvar && size)
427
  {
428
    strncat(path, envvar, size-1);
429 430 431 432 433
  }
}

#define MAX_SYMBOL_PATH 32768

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
/* Platform SDK in VS2003 does not have definition for SYMOPT_NO_PROMPTS*/
#ifndef SYMOPT_NO_PROMPTS
#define SYMOPT_NO_PROMPTS 0
#endif

void print_stacktrace(gptr unused1, ulong unused2)
{
  HANDLE  hProcess= GetCurrentProcess();
  HANDLE  hThread= GetCurrentThread();
  static  IMAGEHLP_MODULE64 module= {sizeof(module)};
  static  IMAGEHLP_SYMBOL64_PACKAGE package;
  DWORD64 addr;
  DWORD   machine;
  int     i;
  CONTEXT context;
  STACKFRAME64 frame={0};
450
  static char symbol_path[MAX_SYMBOL_PATH];
451 452 453 454 455 456 457 458

  if(!exception_ptrs || !init_dbghelp_functions())
    return;

  /* Copy context, as stackwalking on original will unwind the stack */
  context = *(exception_ptrs->ContextRecord);
  /*Initialize symbols.*/
  pSymSetOptions(SYMOPT_LOAD_LINES|SYMOPT_NO_PROMPTS|SYMOPT_DEFERRED_LOADS|SYMOPT_DEBUG);
459
  get_symbol_path(symbol_path, sizeof(symbol_path));
460
  pSymInitialize(hProcess, symbol_path, TRUE);
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

  /*Prepare stackframe for the first StackWalk64 call*/
  frame.AddrFrame.Mode= frame.AddrPC.Mode= frame.AddrStack.Mode= AddrModeFlat;
#if (defined _M_IX86)
  machine= IMAGE_FILE_MACHINE_I386;
  frame.AddrFrame.Offset= context.Ebp;
  frame.AddrPC.Offset=    context.Eip;
  frame.AddrStack.Offset= context.Esp;
#elif (defined _M_X64)
  machine = IMAGE_FILE_MACHINE_AMD64;
  frame.AddrFrame.Offset= context.Rbp;
  frame.AddrPC.Offset=    context.Rip;
  frame.AddrStack.Offset= context.Rsp;
#else
  /*There is currently no need to support IA64*/
#pragma error ("unsupported architecture")
#endif

  package.sym.SizeOfStruct= sizeof(package.sym);
  package.sym.MaxNameLength= sizeof(package.name);

  /*Walk the stack, output useful information*/ 
  for(i= 0; i< STACKWALK_MAX_FRAMES;i++)
  {
    DWORD64 function_offset= 0;
    DWORD line_offset= 0;
    IMAGEHLP_LINE64 line= {sizeof(line)};
    BOOL have_module= FALSE;
    BOOL have_symbol= FALSE;
    BOOL have_source= FALSE;

    if(!pStackWalk64(machine, hProcess, hThread, &frame, &context, 0, 0, 0 ,0))
      break;
    addr= frame.AddrPC.Offset;

    have_module= pSymGetModuleInfo64(hProcess,addr,&module);
#ifdef _M_IX86
    if(!have_module)
    {
      /*
        ModuleInfo structure has been "compatibly" extended in releases after XP,
        and its size was increased. To make XP dbghelp.dll function
        happy, pretend passing the old structure.
      */
      module.SizeOfStruct= MODULE64_SIZE_WINXP;
      have_module= pSymGetModuleInfo64(hProcess, addr, &module);
    }
#endif

    have_symbol= pSymGetSymFromAddr64(hProcess, addr, &function_offset,
      &(package.sym));
    have_source= pSymGetLineFromAddr64(hProcess, addr, &line_offset, &line);

    fprintf(stderr, "%p    ", addr);
    if(have_module)
    {
      char *base_image_name= strrchr(module.ImageName, '\\');
      if(base_image_name)
        base_image_name++;
      else
        base_image_name= module.ImageName;
      fprintf(stderr, "%s!", base_image_name);
    }
    if(have_symbol)
      fprintf(stderr, "%s()", package.sym.Name);
    else if(have_module)
      fprintf(stderr, "???");

    if(have_source)
    {
      char *base_file_name= strrchr(line.FileName, '\\');
      if(base_file_name)
        base_file_name++;
      else
        base_file_name= line.FileName;
      fprintf(stderr,"[%s:%u]", base_file_name, line.LineNumber);
    }
    fprintf(stderr, "\n");
  }
  fflush(stderr);
}


/*
  Write dump. The dump is created in current directory,
  file name is constructed from executable name plus
  ".dmp" extension
*/
void write_core(int unused)
{
  char path[MAX_PATH];
  char dump_fname[MAX_PATH]= "core.dmp";
  MINIDUMP_EXCEPTION_INFORMATION info;
  HANDLE hFile;

  if(!exception_ptrs || !init_dbghelp_functions() || !pMiniDumpWriteDump)
    return;

  info.ExceptionPointers= exception_ptrs;
  info.ClientPointers= FALSE;
  info.ThreadId= GetCurrentThreadId();

  if(GetModuleFileName(NULL, path, sizeof(path)))
  {
    _splitpath(path, NULL, NULL,dump_fname,NULL);
    strncat(dump_fname, ".dmp", sizeof(dump_fname));
  }

  hFile= CreateFile(dump_fname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS,
    FILE_ATTRIBUTE_NORMAL, 0);
  if(hFile)
  {
    /* Create minidump */
    if(pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
      hFile, MiniDumpNormal, &info, 0, 0))
    {
      fprintf(stderr, "Minidump written to %s\n",
        _fullpath(path, dump_fname, sizeof(path)) ? path : dump_fname);
    }
    else
    {
      fprintf(stderr,"MiniDumpWriteDump() failed, last error %u\n",
        GetLastError());
    }
    CloseHandle(hFile);
  }
  else
  {
    fprintf(stderr, "CreateFile(%s) failed, last error %u\n", dump_fname,
      GetLastError());
  }
  fflush(stderr);
}


void safe_print_str(const char *name, const char *val, int len)
{
  fprintf(stderr,"%s at %p", name, val);
  __try 
  {
    fprintf(stderr,"=%.*s\n", len, val);
  }
  __except(EXCEPTION_EXECUTE_HANDLER)
  {
    fprintf(stderr,"is an invalid string pointer\n");
  }
}
#endif /*__WIN__*/