]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a new client request, VG_USERREQ__LOGMESSAGE, and use this to route
authorJulian Seward <jseward@acm.org>
Sun, 3 Nov 2002 13:41:41 +0000 (13:41 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 3 Nov 2002 13:41:41 +0000 (13:41 +0000)
all commentary from our libpthread.so through to the valgrind core and
hence to the selected logging sink.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1274

coregrind/arch/x86-linux/vg_libpthread.c
coregrind/vg_include.h
coregrind/vg_libpthread.c
coregrind/vg_scheduler.c

index aa5104c9206d4d78b2f7d49e8517d1463a167701..517aec11451db4dde04cb0b223170b5a964683aa 100644 (file)
@@ -159,40 +159,44 @@ static
 __attribute__((noreturn))
 void barf ( char* str )
 {
-   char buf[100];
+   int res;
+   char buf[1000];
    buf[0] = 0;
    strcat(buf, "\nvalgrind's libpthread.so: ");
    strcat(buf, str);
    strcat(buf, "\n\n");
-   my_write(2, buf, strlen(buf));
+   VALGRIND_MAGIC_SEQUENCE(res, 0, /* irrelevant default */
+                           VG_USERREQ__LOGMESSAGE, buf, 0, 0, 0);
    my_exit(1);
    /* We have to persuade gcc into believing this doesn't return. */
    while (1) { };
 }
 
 
-static void ignored ( char* msg )
+static void cat_n_send ( char* pre, char* msg )
 {
+   char  buf[1000];
+   int   res;
    if (get_pt_trace_level() >= 0) {
-      char* ig = "valgrind's libpthread.so: IGNORED call to: ";
-      my_write(2, ig, strlen(ig));
-      my_write(2, msg, strlen(msg));
-      ig = "\n";
-      my_write(2, ig, strlen(ig));
+      snprintf(buf, sizeof(buf), "%s%s", pre, msg );
+      buf[sizeof(buf)-1] = '\0';
+      VALGRIND_MAGIC_SEQUENCE(res, 0, /* irrelevant default */
+                              VG_USERREQ__LOGMESSAGE, buf, 0, 0, 0);
    }
 }
 
+static void ignored ( char* msg )
+{
+   cat_n_send ( "valgrind's libpthread.so: IGNORED call to: ", msg );
+}
+
+
 static void kludged ( char* msg )
 {
-   if (get_pt_trace_level() >= 0) {
-      char* ig = "valgrind's libpthread.so: KLUDGED call to: ";
-      my_write(2, ig, strlen(ig));
-      my_write(2, msg, strlen(msg));
-      ig = "\n";
-      my_write(2, ig, strlen(ig));
-   }
+   cat_n_send ( "valgrind's libpthread.so: KLUDGED call to: ", msg );
 }
 
+
 static void not_inside ( char* msg )
 {
    VG_(startup)();
@@ -201,11 +205,8 @@ static void not_inside ( char* msg )
 __attribute__((noreturn))
 void vgPlain_unimp ( char* what )
 {
-   char* ig = "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: ";
-   my_write(2, ig, strlen(ig));
-   my_write(2, what, strlen(what));
-   ig = "\n";
-   my_write(2, ig, strlen(ig));
+   cat_n_send ( 
+      "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: ", what );
    barf("Please report this bug to me at: jseward@acm.org");
 }
 
@@ -213,14 +214,17 @@ void vgPlain_unimp ( char* what )
 static
 void my_assert_fail ( Char* expr, Char* file, Int line, Char* fn )
 {
+   char buf[1000];
    static Bool entered = False;
    if (entered) 
       my_exit(2);
    entered = True;
-   fprintf(stderr, "\n%s: %s:%d (%s): Assertion `%s' failed.\n",
-                   "valgrind", file, line, fn, expr );
-   fprintf(stderr, "Please report this bug to me at: %s\n\n", 
-                   VG_EMAIL_ADDR);
+   sprintf(buf, "\n%s: %s:%d (%s): Assertion `%s' failed.\n",
+                "valgrind", file, line, fn, expr );
+   cat_n_send ( "", buf );
+   sprintf(buf, "Please report this bug to me at: %s\n\n", 
+                 VG_EMAIL_ADDR);
+   cat_n_send ( "", buf );
    my_exit(1);
 }
 
index d9ff25bca54c521bc91aa503da60cd6b752ca81f..b5311833e7d6ebc9d03af83450aaf59566b6deb1 100644 (file)
@@ -426,6 +426,9 @@ extern Bool  VG_(is_empty_arena) ( ArenaId aid );
 #define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
 /* Log a pthread error from client-space.  Cosmetic. */
 #define VG_USERREQ__PTHREAD_ERROR           0x3102
+/* Write a string to the logging sink. */
+#define VG_USERREQ__LOGMESSAGE              0x3103
+
 
 /* 
 In vg_constants.h:
index aa5104c9206d4d78b2f7d49e8517d1463a167701..517aec11451db4dde04cb0b223170b5a964683aa 100644 (file)
@@ -159,40 +159,44 @@ static
 __attribute__((noreturn))
 void barf ( char* str )
 {
-   char buf[100];
+   int res;
+   char buf[1000];
    buf[0] = 0;
    strcat(buf, "\nvalgrind's libpthread.so: ");
    strcat(buf, str);
    strcat(buf, "\n\n");
-   my_write(2, buf, strlen(buf));
+   VALGRIND_MAGIC_SEQUENCE(res, 0, /* irrelevant default */
+                           VG_USERREQ__LOGMESSAGE, buf, 0, 0, 0);
    my_exit(1);
    /* We have to persuade gcc into believing this doesn't return. */
    while (1) { };
 }
 
 
-static void ignored ( char* msg )
+static void cat_n_send ( char* pre, char* msg )
 {
+   char  buf[1000];
+   int   res;
    if (get_pt_trace_level() >= 0) {
-      char* ig = "valgrind's libpthread.so: IGNORED call to: ";
-      my_write(2, ig, strlen(ig));
-      my_write(2, msg, strlen(msg));
-      ig = "\n";
-      my_write(2, ig, strlen(ig));
+      snprintf(buf, sizeof(buf), "%s%s", pre, msg );
+      buf[sizeof(buf)-1] = '\0';
+      VALGRIND_MAGIC_SEQUENCE(res, 0, /* irrelevant default */
+                              VG_USERREQ__LOGMESSAGE, buf, 0, 0, 0);
    }
 }
 
+static void ignored ( char* msg )
+{
+   cat_n_send ( "valgrind's libpthread.so: IGNORED call to: ", msg );
+}
+
+
 static void kludged ( char* msg )
 {
-   if (get_pt_trace_level() >= 0) {
-      char* ig = "valgrind's libpthread.so: KLUDGED call to: ";
-      my_write(2, ig, strlen(ig));
-      my_write(2, msg, strlen(msg));
-      ig = "\n";
-      my_write(2, ig, strlen(ig));
-   }
+   cat_n_send ( "valgrind's libpthread.so: KLUDGED call to: ", msg );
 }
 
+
 static void not_inside ( char* msg )
 {
    VG_(startup)();
@@ -201,11 +205,8 @@ static void not_inside ( char* msg )
 __attribute__((noreturn))
 void vgPlain_unimp ( char* what )
 {
-   char* ig = "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: ";
-   my_write(2, ig, strlen(ig));
-   my_write(2, what, strlen(what));
-   ig = "\n";
-   my_write(2, ig, strlen(ig));
+   cat_n_send ( 
+      "valgrind's libpthread.so: UNIMPLEMENTED FUNCTION: ", what );
    barf("Please report this bug to me at: jseward@acm.org");
 }
 
@@ -213,14 +214,17 @@ void vgPlain_unimp ( char* what )
 static
 void my_assert_fail ( Char* expr, Char* file, Int line, Char* fn )
 {
+   char buf[1000];
    static Bool entered = False;
    if (entered) 
       my_exit(2);
    entered = True;
-   fprintf(stderr, "\n%s: %s:%d (%s): Assertion `%s' failed.\n",
-                   "valgrind", file, line, fn, expr );
-   fprintf(stderr, "Please report this bug to me at: %s\n\n", 
-                   VG_EMAIL_ADDR);
+   sprintf(buf, "\n%s: %s:%d (%s): Assertion `%s' failed.\n",
+                "valgrind", file, line, fn, expr );
+   cat_n_send ( "", buf );
+   sprintf(buf, "Please report this bug to me at: %s\n\n", 
+                 VG_EMAIL_ADDR);
+   cat_n_send ( "", buf );
    my_exit(1);
 }
 
index 59804c4c60b65d43f01481e6d2471ef1ae1f9c85..0226d466ceb63cdd60ca78eb3d1fc8df7ad17257 100644 (file)
@@ -3469,6 +3469,10 @@ void do_client_request ( ThreadId tid )
       case VG_USERREQ__SIGNAL_RETURNS: 
          handle_signal_return(tid);
         break;
+      case VG_USERREQ__LOGMESSAGE:
+         VG_(message)(Vg_UserMsg, "%s", (Char*)(arg[1]));
+         break;
 
       /* Requests from the client program */