]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Merge r5368 (More space for debugger cmd line (Dan Thaler))
authorJulian Seward <jseward@acm.org>
Tue, 27 Dec 2005 14:43:31 +0000 (14:43 +0000)
committerJulian Seward <jseward@acm.org>
Tue, 27 Dec 2005 14:43:31 +0000 (14:43 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_3_1_BRANCH@5448

coregrind/m_debugger.c

index 8c0bc27f97a3b889f14e2b9b344480fd65ed3987..62cef13117190a9c76774c4dad63101a805efcad 100644 (file)
@@ -36,6 +36,7 @@
 #include "pub_core_libcprint.h"
 #include "pub_core_libcproc.h"
 #include "pub_core_libcsignal.h"
+#include "pub_core_libcassert.h"
 #include "pub_core_options.h"
 
 
@@ -142,9 +143,10 @@ static Int ptrace_setregs(Int pid, VexGuestArchState* vex)
    continue, quit the debugger.  */
 void VG_(start_debugger) ( ThreadId tid )
 {
-  Int pid;
+#  define N_BUF 4096
+   Int pid;
 
-  if ((pid = VG_(fork)()) == 0) {
+   if ((pid = VG_(fork)()) == 0) {
       VG_(ptrace)(VKI_PTRACE_TRACEME, 0, NULL, NULL);
       VG_(kill)(VG_(getpid)(), VKI_SIGSTOP);
 
@@ -159,8 +161,8 @@ void VG_(start_debugger) ( ThreadId tid )
           VG_(ptrace)(VKI_PTRACE_DETACH, pid, NULL, 0) == 0)
       {
          Char pidbuf[15];
-         Char file[30];
-         Char buf[100];
+         Char file[50];
+         Char buf[N_BUF];
          Char *bufptr;
          Char *cmdptr;
          
@@ -171,6 +173,10 @@ void VG_(start_debugger) ( ThreadId tid )
          cmdptr = VG_(clo_db_command);
          
          while (*cmdptr) {
+            /* each iteration can advance bufptr by at most the length
+               of file[], so the following assertion is generously
+               over-paranoid. */
+            vg_assert(bufptr - buf < N_BUF-15-50-10/*paranoia*/);
             switch (*cmdptr) {
                case '%':
                   switch (*++cmdptr) {
@@ -179,20 +185,21 @@ void VG_(start_debugger) ( ThreadId tid )
                         bufptr += VG_(strlen)(file);
                         cmdptr++;
                         break;
-                  case 'p':
-                     VG_(memcpy)(bufptr, pidbuf, VG_(strlen)(pidbuf));
-                     bufptr += VG_(strlen)(pidbuf);
-                     cmdptr++;
-                     break;
-                  default:
-                     *bufptr++ = *cmdptr++;
-                     break;
+                     case 'p':
+                        VG_(memcpy)(bufptr, pidbuf, VG_(strlen)(pidbuf));
+                        bufptr += VG_(strlen)(pidbuf);
+                        cmdptr++;
+                        break;
+                     default:
+                        *bufptr++ = *cmdptr++;
+                        break;
                   }
                   break;
                default:
                   *bufptr++ = *cmdptr++;
                   break;
             }
+            vg_assert(bufptr - buf < N_BUF-15-50-10/*paranoia*/);
          }
          
          *bufptr++ = '\0';
@@ -212,6 +219,7 @@ void VG_(start_debugger) ( ThreadId tid )
       VG_(kill)(pid, VKI_SIGKILL);
       VG_(waitpid)(pid, &status, 0);
    }
+#  undef N_BUF
 }