]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gprofng: skip unrecognized input command
authorVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Wed, 27 Nov 2024 03:40:16 +0000 (19:40 -0800)
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Wed, 27 Nov 2024 21:55:02 +0000 (13:55 -0800)
gprofng crashes when the GUI sends an invalid command.
Skip unrecognized commands and return an error status to the GUI.

gprofng/ChangeLog
2024-11-26  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/ipc.cc (ipc_doWork): Skip unrecognized commands.
* src/ipcio.cc (writeError): New function.
* src/ipcio.h: Add RESPONSE_STATUS_ERROR.

gprofng/src/ipc.cc
gprofng/src/ipcio.cc
gprofng/src/ipcio.h

index 3e706dbc9d078c50c70831c0d423ccc4cb52a208..feda1f8eb08ee6239f39a523871210afc2f65dd3 100644 (file)
@@ -2534,8 +2534,10 @@ ipc_doWork (void *arg)
     }
   else
     {
-      ipc_log ("Unrecognized input cmd \"%s\"; Aborting.\n", inp);
-      return 1;
+      char *s = dbe_sprintf ("Unrecognized request: \"%s\"", inp);
+      ipc_log ("%s\n", s);
+      writeError (s, req);
+      free (s);
     }
   ipc_log ("  processing IPC command %s complete\n", inp);
   free (inp);
index 8ff16d5a8e2385790cb718262735c6dd60435cb5..c20a22f9b60d7272941414db48780c19c3ed2ce1 100644 (file)
@@ -776,6 +776,16 @@ writeString (const char *s, IPCrequest* req)
                           RESPONSE_TYPE_COMPLETE, RESPONSE_STATUS_SUCCESS, OUTS);
 }
 
+void
+writeError (const char *s, IPCrequest* req)
+{
+  IPCresponse *OUTS = responseBufferPool->getNewResponse (BUFFER_SIZE_LARGE);
+  OUTS->sendByte (L_STRING);
+  OUTS->sendSVal (s);
+  writeResponseWithHeader (req->getRequestID (), req->getChannelID (),
+                          RESPONSE_TYPE_COMPLETE, RESPONSE_STATUS_ERROR, OUTS);
+}
+
 void
 writeObject (DbeObj obj, IPCrequest* req)
 {
index 23c35fc33dd4d984de7b41957070ccd7b264691e..7cef74311b8c7e5580d4473f2abc64fcb899544c 100644 (file)
@@ -40,6 +40,7 @@ typedef char *String;
 #define RESPONSE_STATUS_SUCCESS     1
 #define RESPONSE_STATUS_FAILURE     2
 #define RESPONSE_STATUS_CANCELLED   3
+#define RESPONSE_STATUS_ERROR       4
 
 #define RESPONSE_TYPE_ACK           0
 #define RESPONSE_TYPE_PROGRESS      1
@@ -60,7 +61,8 @@ enum IPCrequestStatus
   IN_PROGRESS,
   COMPLETED,
   CANCELLED_DEFAULT,
-  CANCELLED_IMMEDIATE
+  CANCELLED_IMMEDIATE,
+  UNDEFINED_REGUEST
 };
 
 enum IPCTraceLevel
@@ -151,6 +153,7 @@ String readString (IPCrequest*);
 void readRequestHeader ();
 
 // write to the wire
+void writeError (const char *, IPCrequest*);
 void writeString (const char *, IPCrequest*);
 void writeBoolean (bool, IPCrequest*);
 void writeInt (int, IPCrequest*);