[FIX] msg mapping list 25/25225/3
authorVitaliy Cherepanov <v.cherepanov@samsung.com>
Thu, 31 Jul 2014 12:30:57 +0000 (16:30 +0400)
committerVitaliy Andreevich <v.cherepanov@samsung.com>
Mon, 4 Aug 2014 11:48:48 +0000 (04:48 -0700)
fix problem with ld probes missing
probes called before mapping message were not collected

Change-Id: I5403a3067a4055dbd1ad4201e74096afa8ecf55f
Signed-off-by: Vitaliy Cherepanov <v.cherepanov@samsung.com>
helper/damaps.c
helper/libdaprobe.c

index 5dad110406044e1e5c765b72479de3abef027dad..a2793d22849c3eaaafee87da5ffc446d21fc0ad0 100755 (executable)
@@ -469,6 +469,8 @@ static inline void maps_writer_unlock()
        pthread_mutex_unlock(&maps_lock);
 }
 
+// WARNING! this function use maps_set and set it to NULL
+// so first param must be malloced and do not free maps_set after call
 int set_map_inst_list(char **maps_set, uint32_t maps_count)
 {
        int res = 0;
@@ -490,11 +492,11 @@ int set_map_inst_list(char **maps_set, uint32_t maps_count)
 
        map_inst_list = real_malloc(sizeof(*map_inst_list) * maps_count);
        if (maps_set != NULL && *maps_set != NULL)
-               map_inst_list_set = *maps_set + sizeof(maps_count);
+               map_inst_list_set = *maps_set;
        map_inst_count = maps_count;
 
        /* add library mapping names */
-       p = map_inst_list_set;
+       p = map_inst_list_set + sizeof(maps_count);
        for (i = 0; i < maps_count; i++) {
                map_inst_list[i] = p;
                p += strlen(p) + 1;
index 4090e62b10119fd132ab0eb97411cb63348912b8..a57f36ab2d49b5c8b48bfe64713679f8de730173 100755 (executable)
@@ -97,7 +97,16 @@ static void _configure(char* configstr)
        PRINTMSG(buf);
 }
 
+void application_exit()
+{
+       PRINTMSG("App termination: EXIT(0)");
+       /* TODO think of another way for correct app termination */
+       exit(0);
+}
+
 // create socket to daemon and connect
+#define MSG_CONFIG_RECV 0x01
+#define MSG_MAPS_INST_LIST_RECV 0x02
 static int createSocket(void)
 {
        ssize_t recvlen;
@@ -117,40 +126,65 @@ static int createSocket(void)
                            (struct sockaddr *)&clientAddr, clientLen) >= 0)
                {
                        char buf[64];
+                       int recved = 0;
                        /* send pid */
                        sprintf(buf, "%d|%llu", getpid(),
                                gTraceInfo.app.startTime);
                        print_log_str(MSG_PID, buf);
 
-                       /* recv initial configuration value */
-                       recvlen = recv(gTraceInfo.socket.daemonSock, &log,
-                                      sizeof(log.type) + sizeof(log.length),
-                                      MSG_WAITALL);
-
-                       if (recvlen > 0) {/* recv succeed */
-                               if (log.length > 0) {
-                                       if(log.length >= DA_LOG_MAX)
-                                               log.length = DA_LOG_MAX - 1;
-                                       recvlen = recv(gTraceInfo.socket.daemonSock, log.data,
+                       /* we need recv this messages right now! */
+                       while (((recved & MSG_CONFIG_RECV) == 0) ||
+                              ((recved & MSG_MAPS_INST_LIST_RECV) == 0))
+                       {
+                               fprintf(stderr, "wait message\n");
+                               PRINTMSG("wait incoming message");
+                               /* recv header */
+                               recvlen = recv(gTraceInfo.socket.daemonSock, &log,
+                                              sizeof(log.type) + sizeof(log.length),
+                                              MSG_WAITALL);
+
+                               fprintf(stderr, "recv %d\n", recvlen);
+                               if (recvlen > 0) {/* recv succeed */
+                                       char *data_buf = NULL;
+
+                                       data_buf = real_malloc(log.length);
+
+                                       if (data_buf == NULL) {
+                                               PRINTERR("cannot allocate buf to recv msg");
+                                               break;
+                                       }
+
+                                       recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
                                                       log.length, MSG_WAITALL);
-                               } else {
-                                       log.length = 0;
-                               }
 
-                               log.data[log.length] = '\0';
+                                       if (log.type == MSG_CONFIG) {
+                                               PRINTMSG("MSG_CONFIG");
+                                               _configure(data_buf);
+                                               recved |= MSG_CONFIG_RECV;
+                                       } else if(log.type ==  MSG_MAPS_INST_LIST) {
+                                               PRINTMSG("MSG_MAPS_INST_LIST <%u>", *((uint32_t *)data_buf));
+                                               set_map_inst_list(&data_buf, *((uint32_t *)data_buf));
+                                               recved |= MSG_MAPS_INST_LIST_RECV;
+                                       } else {
+                                               // unexpected case
+                                               PRINTERR("unknown message! %d", log.type);
+                                       }
 
-                               if(log.type == MSG_CONFIG)
-                               {
-                                       _configure(log.data);
-                               }
-                               else
-                               {
-                                       // unexpected case
+                                       if (data_buf != NULL)
+                                               free(data_buf);
+
+                               } else if (recvlen < 0) {
+                                       fprintf(stderr, "recv failed in socket creation with error(%d)\n", recvlen);
+                                       ret = -1;
+                                       application_exit();
+                                       break;
+                               } else {
+                                       /* closed by other peer */
+                                       ret = -1;
+                                       application_exit();
+                                       break;
                                }
-                       } else if (recvlen < 0) {
-                               sprintf(buf, "recv failed in socket creation with error(%d)\n", recvlen);
-                       } else {
-                               /* closed by other peer */
+
                        }
 
                        PRINTMSG("createSocket connect() success\n");
@@ -163,6 +197,7 @@ static int createSocket(void)
                ret = -1;
        }
 
+       PRINTMSG("socket create done with result = %d", ret);
        return ret;
 }
 
@@ -213,13 +248,6 @@ pid_t _gettid()
        return gTid;
 }
 
-void application_exit()
-{
-       PRINTMSG("App termination: EXIT(0)");
-       /* TODO think of another way for correct app termination */
-       exit(0);
-}
-
 static void *recvThread(void __unused * data)
 {
        fd_set readfds, workfds;
@@ -281,11 +309,8 @@ static void *recvThread(void __unused * data)
                        if(recvlen > 0) // recv succeed
                        {
 
-                               if (log.type == MSG_MAPS_INST_LIST) {
-                                       if (data_buf)
-                                               free(data_buf);
-
-                                       data_buf = malloc(log.length);
+                               if(log.length > 0) {
+                                       data_buf = real_malloc(log.length);
                                        if (data_buf == NULL) {
                                                PRINTERR("cannot allocate buf to recv msg");
                                                break;
@@ -293,47 +318,38 @@ static void *recvThread(void __unused * data)
                                        recvlen = recv(gTraceInfo.socket.daemonSock, data_buf,
                                                log.length, MSG_WAITALL);
 
-                               } else {
-
-                                       if(log.length > 0)
-                                       {
-                                               if(log.length >= DA_LOG_MAX)
-                                                       log.length = DA_LOG_MAX-1;
-
-                                               recvlen = recv(gTraceInfo.socket.daemonSock, log.data,
-                                                       log.length, MSG_WAITALL);
-                                       }
-                                       else
-                                       {
-                                               log.length = 0;
-                                       }
-
-                                       log.data[log.length] = '\0';
                                }
 
                                if (log.type == MSG_CAPTURE_SCREEN) {
                                        captureScreen();
                                } else if (log.type == MSG_CONFIG) {
-                                       _configure(log.data);
-                               }
-                               else if(log.type == MSG_STOP)
-                               {
+                                       _configure(data_buf);
+                               } else if(log.type == MSG_STOP) {
                                        PRINTMSG("MSG_STOP");
+                                       if (data_buf) {
+                                               free(data_buf);
+                                               data_buf = NULL;
+                                       }
                                        application_exit();
                                        break;
+                               } else if(log.type == MSG_MAPS_INST_LIST) {
+                                       if(log.length > 0) {
+                                               tmp = *((uint32_t *)data_buf);
+                                               PRINTMSG("MSG_MAPS_INST_LIST <%u>", tmp);
+                                               set_map_inst_list(&data_buf, tmp);
+                                               continue;
+                                       } else {
+                                               PRINTERR("WRONG MSG_MAPS_INST_LIST");
+                                       }
+                               } else {
+                                       PRINTERR("recv unknown message. id = (%d)", log.type);
                                }
-                               else if(log.type == MSG_MAPS_INST_LIST)
-                               {
-                                       tmp = *((uint32_t *)data_buf);
-                                       PRINTMSG("MSG_MAPS_INST_LIST <%u>", tmp);
-                                       set_map_inst_list(&data_buf, tmp);
-                                       continue;
-                               }
-                               else
-                               {
-                                       PRINTERR("recv unknown message(%d)", log.type);
-                                       continue;
+
+                               if (data_buf) {
+                                       free(data_buf);
+                                       data_buf = NULL;
                                }
+
                        }
                        else if(recvlen == 0)   // closed by other peer
                        {