#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"
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);
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;
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) {
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';
VG_(kill)(pid, VKI_SIGKILL);
VG_(waitpid)(pid, &status, 0);
}
+# undef N_BUF
}