Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Oct 2008 09:29:45 GMT
From:      Peter Wemm <peter@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 151797 for review
Message-ID:  <200810230929.m9N9TjOb085265@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=151797

Change 151797 by peter@peter_cheese on 2008/10/23 09:29:26

	Get --version to not crash.  This means parsing procfs and surviving the
	handoff to the tool backend.
	
	$ /home/peter/vginst/bin/valgrind --version
	valgrind-3.4.0.SVN

Affected files ...

.. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#3 edit
.. //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-linux.c#3 edit
.. //depot/projects/valgrind/coregrind/m_libcbase.c#4 edit
.. //depot/projects/valgrind/coregrind/m_main.c#6 edit

Differences ...

==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-freebsd.c#3 (text+ko) ====

@@ -3049,6 +3049,7 @@
    UInt	  prot;
    UWord  maj, min;
    ULong  foffset, dev, ino;
+   UInt   junk;
    ULong  junk64;
 
    foffset = ino = 0; /* keep gcc-4.1.0 happy */
@@ -3086,7 +3087,7 @@
       if (j > 0) i += j; else goto syntaxerror;
       j = readchar(&procmap_buf[i], &ch);
       if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-      j = readhex64(&procmap_buf[i], &junk64);
+      j = readhex(&procmap_buf[i], &junk);
       if (j > 0) i += j; else goto syntaxerror;
       j = readchar(&procmap_buf[i], &ch);
       if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
@@ -3110,7 +3111,7 @@
       j = readchar(&procmap_buf[i], &ch);
       if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
 
-      j = readhex64(&procmap_buf[i], &junk64);
+      j = readhex(&procmap_buf[i], &junk);
       if (j > 0) i += j; else goto syntaxerror;
 
       j = readchar(&procmap_buf[i], &ch);
@@ -3223,30 +3224,7 @@
       if (ww == 'w') prot |= VKI_PROT_WRITE;
       if (xx == 'x') prot |= VKI_PROT_EXEC;
 
-#if defined(VGO_linux)
-      /* Linux has two ways to encode a device number when it
-         is exposed to user space (via fstat etc). The old way
-         is the traditional unix scheme that produces a 16 bit
-         device number with the top 8 being the major number and
-         the bottom 8 the minor number.
-         
-         The new scheme allows for a 12 bit major number and
-         a 20 bit minor number by using a 32 bit device number
-         and putting the top 12 bits of the minor number into
-         the top 12 bits of the device number thus leaving an
-         extra 4 bits for the major number.
-         
-         If the minor and major number are both single byte
-         values then both schemes give the same result so we
-         use the new scheme here in case either number is
-         outside the 0-255 range and then use fstat64 when
-         available (or fstat on 64 bit systems) so that we
-         should always have a new style device number and
-         everything should match. */
-      dev = (min & 0xff) | (maj << 8) | ((min & ~0xff) << 12);
-#else
       dev = 0;
-#endif
       if (record_gap && gapStart < start)
          (*record_gap) ( gapStart, start-gapStart );
 

==== //depot/projects/valgrind/coregrind/m_aspacemgr/aspacemgr-linux.c#3 (text+ko) ====

@@ -352,7 +352,6 @@
 /* Given a file descriptor, attempt to deduce its filename.  To do
    this, we use /proc/self/fd/<FD>.  If this doesn't point to a file,
    or if it doesn't exist, we return False. */
-#if defined(VGO_linux)
 static
 Bool get_name_for_fd ( Int fd, /*OUT*/HChar* buf, Int nbuf )
 {
@@ -367,51 +366,8 @@
    else
       return False;
 }
-#elif defined(VGO_freebsd)
-static
-Bool get_name_for_fd ( Int fd, HChar* buf, Int nbuf )
-{
-   static int nr_fromfd = -1;
-   SysRes res;
-   Int   i;
 
-   for (i = 0; i < nbuf; i++) buf[i] = 0;
-   if (nr_fromfd == -1) {
-      int oid[2];
-      int real_oid[10];
-      vki_size_t oidlen;
-      char *name = "machdep.getpath_fromfd_num";
-      vki_size_t len;
-      int sc;
 
-      oid[0] = 0;	/* magic */
-      oid[1] = 3;	/* undocumented */
-      oidlen = sizeof(real_oid);
-      res = VG_(do_syscall6)(__NR___sysctl, (UWord)oid, 2, (UWord)real_oid, (UWord)&oidlen, (UWord)name, strlen(name));
-      oidlen /= sizeof(int);
-      if (!res.isError && oidlen > 0) {
-	 len = sizeof(sc);
-	 res = VG_(do_syscall6)(__NR___sysctl, (UWord)real_oid, oidlen, (UWord)&sc, (UWord)&len, 0, 0);
-	 if (!res.isError && sc > 0)
-	    nr_fromfd = sc;
-      }
-      if (nr_fromfd == -1)
-	 nr_fromfd = -2;
-   }
-   if (nr_fromfd < 0)
-      return False;
-
-   res = VG_(do_syscall3)(nr_fromfd, fd, (UWord)buf, nbuf);
-   if (!res.isError && buf[0] == '/')
-      return True;
-   else
-      return False;
-}
-#else
-#error undefined os
-#endif
-
-
 /*-----------------------------------------------------------------*/
 /*---                                                           ---*/
 /*--- SegName array management.                                 ---*/
@@ -1007,14 +963,12 @@
 
       same = same
              && seg_prot == prot
-#ifndef VGO_freebsd
              && (cmp_devino
                    ? (nsegments[i].dev == dev && nsegments[i].ino == ino)
                    : True)
              && (cmp_offsets 
                    ? nsegments[i].start-nsegments[i].offset == addr-offset
                    : True)
-#endif
 	     ;
       if (!same) {
          sync_check_ok = False;
@@ -1539,9 +1493,6 @@
    if (dev != 0 && ino != 0) 
       seg.kind = SkFileV;
    if (filename) {
-#if defined(VGO_freebsd)
-      seg.kind = SkFileV;
-#endif
       seg.fnIdx = allocate_segname( filename );
    }
 
@@ -1590,11 +1541,7 @@
                     "        sp_at_startup = 0x%010llx (supplied)\n", 
                     (ULong)sp_at_startup );
 
-#ifdef VGP_x86_freebsd
-   aspacem_minAddr = (Addr) 0x00010000; // 64K
-#else
    aspacem_minAddr = (Addr) 0x04000000; // 64M
-#endif
 
 #  if VG_WORDSIZE == 8
      aspacem_maxAddr = (Addr)0x800000000 - 1; // 32G
@@ -1658,18 +1605,10 @@
 
    VG_(am_show_nsegments)(2, "Initial layout");
 
-#ifdef VGO_freebsd
-   VG_(debugLog)(2, "aspacem", "Reading /proc/curproc/map\n");
-#else
    VG_(debugLog)(2, "aspacem", "Reading /proc/self/maps\n");
-#endif
    parse_procselfmaps( read_maps_callback, NULL );
 
-#ifdef VGO_freebsd
-   VG_(am_show_nsegments)(2, "With contents of /proc/curproc/map");
-#else
    VG_(am_show_nsegments)(2, "With contents of /proc/self/maps");
-#endif
 
    AM_SANITY_CHECK;
    return suggested_clstack_top;
@@ -3088,9 +3027,6 @@
    UInt	  prot;
    UWord  maj, min;
    ULong  foffset, dev, ino;
-#ifdef VGO_freebsd
-   UInt   junk;
-#endif
 
    foffset = ino = 0; /* keep gcc-4.1.0 happy */
 
@@ -3107,7 +3043,6 @@
    while (True) {
       if (i >= buf_n_tot) break;
 
-#if defined(VGO_linux)
       /* Read (without fscanf :) the pattern %16x-%16x %c%c%c%c %16x %2x:%2x %d */
       j = readhex(&procmap_buf[i], &start);
       if (j > 0) i += j; else goto syntaxerror;
@@ -3151,121 +3086,12 @@
 
       j = readdec64(&procmap_buf[i], &ino);
       if (j > 0) i += j; else goto syntaxerror;
-#elif defined(VGO_freebsd)
-      /* Read (without fscanf :) the pattern %8x %8x %d %d %8x %c%c%c%c %d %d %8x .* .* .* */
-      /* 0x38000000 0x38119000 281 748 0xd76df8a0 r-x 2 1 0x0 COW NC vnode */
-      j = readhex(&procmap_buf[i], &start);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-      j = readhex(&procmap_buf[i], &endPlusOne);
-      if (j > 0) i += j; else goto syntaxerror;
-
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      j = readdec(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-      j = readdec(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-      j = readhex(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      j = readchar(&procmap_buf[i], &rr);
-      if (j == 1 && (rr == 'r' || rr == '-')) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ww);
-      if (j == 1 && (ww == 'w' || ww == '-')) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &xx);
-      if (j == 1 && (xx == 'x' || xx == '-')) i += j; else goto syntaxerror;
-
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      j = readdec(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-      j = readdec(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      j = readhex(&procmap_buf[i], &junk);
-      if (j > 0) i += j; else goto syntaxerror;
-
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      /* COW or NCOW */
-      j = readchar(&procmap_buf[i], &ch);
-      if (j != 1) goto syntaxerror;
-      if (ch == 'N') {
-              i += j;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'C') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'O') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'W') i += j; else goto syntaxerror;
-      } else if (ch == 'C') {
-              i += j;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'O') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'W') i += j; else goto syntaxerror;
-      } else {
-              goto syntaxerror;
-      }
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      /* NC or NNC */
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == 'N') i += j; else goto syntaxerror;
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && (ch == 'N' || ch == 'C')) i += j; else goto syntaxerror;
-      if (ch == 'N') {
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'C') i += j; else goto syntaxerror;
-      }
-      j = readchar(&procmap_buf[i], &ch);
-      if (j == 1 && ch == ' ') i += j; else goto syntaxerror;
-
-      /* map type (vnode, swap, default) */
-      j = readchar(&procmap_buf[i], &ch);
-      if (j != 1) goto syntaxerror;
-      if (ch == 'v') {
-              i += j;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'n') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'o') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'd') i += j; else goto syntaxerror;
-              j = readchar(&procmap_buf[i], &ch);
-              if (j == 1 && ch == 'e') i += j; else goto syntaxerror;
-      }
-      foffset = 0;
-#else
-#error "Unknown OS"
-#endif
  
       goto read_line_ok;
 
     syntaxerror:
-#ifdef VGO_freebsd
-      VG_(debugLog)(0, "Valgrind:", 
-                       "FATAL: syntax error reading /proc/curproc/map\n");
-#else
       VG_(debugLog)(0, "Valgrind:", 
                        "FATAL: syntax error reading /proc/self/maps\n");
-#endif
       { Int k, m;
         HChar buf50[51];
         m = 0;
@@ -3307,19 +3133,11 @@
          foffset = 0;
       }
 
-#if 0
-#ifdef VGO_freebsd
-      if (!filename)
-         filename = find_path(start);
-#endif
-#endif
-
       prot = 0;
       if (rr == 'r') prot |= VKI_PROT_READ;
       if (ww == 'w') prot |= VKI_PROT_WRITE;
       if (xx == 'x') prot |= VKI_PROT_EXEC;
 
-#if defined(VGO_linux)
       /* Linux has two ways to encode a device number when it
          is exposed to user space (via fstat etc). The old way
          is the traditional unix scheme that produces a 16 bit
@@ -3340,9 +3158,6 @@
          should always have a new style device number and
          everything should match. */
       dev = (min & 0xff) | (maj << 8) | ((min & ~0xff) << 12);
-#else
-      dev = 0;
-#endif
       if (record_gap && gapStart < start)
          (*record_gap) ( gapStart, start-gapStart );
 

==== //depot/projects/valgrind/coregrind/m_libcbase.c#4 (text+ko) ====

@@ -501,14 +501,6 @@
    return dest;
 }
 
-#ifdef VGO_freebsd
-/* Gcc generates internal inline calls for struct copies */
-void* memcpy ( void *dest, const void *src, SizeT sz )
-{
-	return VG_(memcpy)(dest, src, sz);
-}
-#endif
-
 void* VG_(memmove)(void *dest, const void *src, SizeT sz)
 {
    SizeT i;

==== //depot/projects/valgrind/coregrind/m_main.c#6 (text+ko) ====

@@ -339,7 +339,7 @@
 	 VG_(message)(Vg_UserMsg, "There is a copy in valgrind/getpath/*");
 #endif
 	 VG_(message)(Vg_UserMsg, "");
-	 VG_(nanosleep)(&ts);
+	 VG_(do_syscall2)(__NR_nanosleep, (UWord)&ts, (UWord)NULL);
       }
    }
 #endif
@@ -2304,7 +2304,7 @@
 /*=== Getting to main() alive: LINUX (for AIX5 see below)          ===*/
 /*====================================================================*/
 
-#if defined(VGO_linux)
+#if defined(VGO_linux) || defined(VGO_freebsd)
 
 /* If linking of the final executables is done with glibc present,
    then Valgrind starts at main() above as usual, and all of the
@@ -2483,9 +2483,9 @@
     "\tandl  $~15, %eax\n"
     /* install it, and collect the original one */
     "\txchgl %eax, %esp\n"
-    /* call _start_in_C, passing it the startup %esp */
+    /* call _start_in_C_linux, passing it the startup %esp */
     "\tpushl %eax\n"
-    "\tcall  _start_in_C\n"
+    "\tcall  _start_in_C_linux\n"
     "\thlt\n"
     ".previous\n"
 );
@@ -2502,8 +2502,8 @@
     "\tandq  $~15, %rdi\n"
     /* install it, and collect the original one */
     "\txchgq %rdi, %rsp\n"
-    /* call _start_in_C, passing it the startup %rsp */
-    "\tcall  _start_in_C\n"
+    /* call _start_in_C_linux, passing it the startup %rsp */
+    "\tcall  _start_in_C_linux\n"
     "\thlt\n"
     ".previous\n"
 );



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810230929.m9N9TjOb085265>