[Lldb-commits] [PATCH] D156979: [lldb][lldb-vscode] Pretty print JSON to log files

2023-08-03 Thread David Spickett via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG165f45a87774: [lldb][lldb-vscode] Pretty print JSON to log 
files (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156979/new/

https://reviews.llvm.org/D156979

Files:
  lldb/tools/lldb-vscode/VSCode.cpp


Index: lldb/tools/lldb-vscode/VSCode.cpp
===
--- lldb/tools/lldb-vscode/VSCode.cpp
+++ lldb/tools/lldb-vscode/VSCode.cpp
@@ -89,12 +89,6 @@
   output.write_full(llvm::utostr(json_str.size()));
   output.write_full("\r\n\r\n");
   output.write_full(json_str);
-
-  if (log) {
-*log << "<-- " << std::endl
- << "Content-Length: " << json_str.size() << "\r\n\r\n"
- << json_str << std::endl;
-  }
 }
 
 // Serialize the JSON value into a string and send the JSON packet to
@@ -105,7 +99,14 @@
   strm << json;
   static std::mutex mutex;
   std::lock_guard locker(mutex);
-  SendJSON(strm.str());
+  std::string json_str = strm.str();
+  SendJSON(json_str);
+
+  if (log) {
+*log << "<-- " << std::endl
+ << "Content-Length: " << json_str.size() << "\r\n\r\n"
+ << llvm::formatv("{0:2}", json).str() << std::endl;
+  }
 }
 
 // Read a JSON packet from the "in" stream.
@@ -129,11 +130,8 @@
   if (!input.read_full(log.get(), length, json_str))
 return json_str;
 
-  if (log) {
-*log << "--> " << std::endl
- << "Content-Length: " << length << "\r\n\r\n"
- << json_str << std::endl;
-  }
+  if (log)
+*log << "--> " << std::endl << "Content-Length: " << length << "\r\n\r\n";
 
   return json_str;
 }
@@ -523,6 +521,11 @@
 }
 return PacketStatus::JSONMalformed;
   }
+
+  if (log) {
+*log << llvm::formatv("{0:2}", *json_value).str() << std::endl;
+  }
+
   llvm::json::Object *object_ptr = json_value->getAsObject();
   if (!object_ptr) {
 if (log)


Index: lldb/tools/lldb-vscode/VSCode.cpp
===
--- lldb/tools/lldb-vscode/VSCode.cpp
+++ lldb/tools/lldb-vscode/VSCode.cpp
@@ -89,12 +89,6 @@
   output.write_full(llvm::utostr(json_str.size()));
   output.write_full("\r\n\r\n");
   output.write_full(json_str);
-
-  if (log) {
-*log << "<-- " << std::endl
- << "Content-Length: " << json_str.size() << "\r\n\r\n"
- << json_str << std::endl;
-  }
 }
 
 // Serialize the JSON value into a string and send the JSON packet to
@@ -105,7 +99,14 @@
   strm << json;
   static std::mutex mutex;
   std::lock_guard locker(mutex);
-  SendJSON(strm.str());
+  std::string json_str = strm.str();
+  SendJSON(json_str);
+
+  if (log) {
+*log << "<-- " << std::endl
+ << "Content-Length: " << json_str.size() << "\r\n\r\n"
+ << llvm::formatv("{0:2}", json).str() << std::endl;
+  }
 }
 
 // Read a JSON packet from the "in" stream.
@@ -129,11 +130,8 @@
   if (!input.read_full(log.get(), length, json_str))
 return json_str;
 
-  if (log) {
-*log << "--> " << std::endl
- << "Content-Length: " << length << "\r\n\r\n"
- << json_str << std::endl;
-  }
+  if (log)
+*log << "--> " << std::endl << "Content-Length: " << length << "\r\n\r\n";
 
   return json_str;
 }
@@ -523,6 +521,11 @@
 }
 return PacketStatus::JSONMalformed;
   }
+
+  if (log) {
+*log << llvm::formatv("{0:2}", *json_value).str() << std::endl;
+  }
+
   llvm::json::Object *object_ptr = json_value->getAsObject();
   if (!object_ptr) {
 if (log)
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156979: [lldb][lldb-vscode] Pretty print JSON to log files

2023-08-03 Thread walter erquinigo via Phabricator via lldb-commits
wallace accepted this revision.
wallace added a comment.
This revision is now accepted and ready to land.

nice improvement for sure


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156979/new/

https://reviews.llvm.org/D156979

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156979: [lldb][lldb-vscode] Pretty print JSON to log files

2023-08-03 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett added reviewers: ashgti, wallace.
DavidSpickett added a comment.

The one disadvantage here is that pretty printing adds more characters, so 
before you could copy paste the single JSON line and (I presume) it would have 
the same number of characters.

If that's a required use case then instead I can do the printing in the testing 
wrapper in lldb, by just going line by line and anything beginning with `{`, 
attempt to parse as JSON. I just figured that this formatting may be useful 
outside of the lldb context.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156979/new/

https://reviews.llvm.org/D156979

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D156979: [lldb][lldb-vscode] Pretty print JSON to log files

2023-08-03 Thread David Spickett via Phabricator via lldb-commits
DavidSpickett created this revision.
Herald added a project: All.
DavidSpickett requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

This makes anlysing test failures much more easy.

For SendJSON this is simple, just use llvm::format instead.

For GetNextObject/ReadJSON it's a bit more tricky.

- Print the "Content-Length:" line in ReadJSON, but not the json.
- Back in GetNextObject, if the JSON doesn't parse, it'll be printed as a 
normal string along with an error message.
- If we didn't error before, we have a JSON value so we pretty print it.
- Finally, if it isn't an object we'll log an error for that, not including the 
JSON.

Before:

  <--
  Content-Length: 81
  
  
{"command":"disconnect","request_seq":5,"seq":0,"success":true,"type":"response"}

After:

  <--
  Content-Length: 81
  
  {
"command": "disconnect",
"request_seq": 5,
"seq": 0,
"success": true,
"type": "response"
  }

There appear to be some responses that include strings that are themselves JSON,
and this won't pretty print those but I think it's still worth doing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156979

Files:
  lldb/tools/lldb-vscode/VSCode.cpp


Index: lldb/tools/lldb-vscode/VSCode.cpp
===
--- lldb/tools/lldb-vscode/VSCode.cpp
+++ lldb/tools/lldb-vscode/VSCode.cpp
@@ -89,12 +89,6 @@
   output.write_full(llvm::utostr(json_str.size()));
   output.write_full("\r\n\r\n");
   output.write_full(json_str);
-
-  if (log) {
-*log << "<-- " << std::endl
- << "Content-Length: " << json_str.size() << "\r\n\r\n"
- << json_str << std::endl;
-  }
 }
 
 // Serialize the JSON value into a string and send the JSON packet to
@@ -105,7 +99,14 @@
   strm << json;
   static std::mutex mutex;
   std::lock_guard locker(mutex);
-  SendJSON(strm.str());
+  std::string json_str = strm.str();
+  SendJSON(json_str);
+
+  if (log) {
+*log << "<-- " << std::endl
+ << "Content-Length: " << json_str.size() << "\r\n\r\n"
+ << llvm::formatv("{0:2}", json).str() << std::endl;
+  }
 }
 
 // Read a JSON packet from the "in" stream.
@@ -129,11 +130,8 @@
   if (!input.read_full(log.get(), length, json_str))
 return json_str;
 
-  if (log) {
-*log << "--> " << std::endl
- << "Content-Length: " << length << "\r\n\r\n"
- << json_str << std::endl;
-  }
+  if (log)
+*log << "--> " << std::endl << "Content-Length: " << length << "\r\n\r\n";
 
   return json_str;
 }
@@ -523,6 +521,11 @@
 }
 return PacketStatus::JSONMalformed;
   }
+
+  if (log) {
+*log << llvm::formatv("{0:2}", *json_value).str() << std::endl;
+  }
+
   llvm::json::Object *object_ptr = json_value->getAsObject();
   if (!object_ptr) {
 if (log)


Index: lldb/tools/lldb-vscode/VSCode.cpp
===
--- lldb/tools/lldb-vscode/VSCode.cpp
+++ lldb/tools/lldb-vscode/VSCode.cpp
@@ -89,12 +89,6 @@
   output.write_full(llvm::utostr(json_str.size()));
   output.write_full("\r\n\r\n");
   output.write_full(json_str);
-
-  if (log) {
-*log << "<-- " << std::endl
- << "Content-Length: " << json_str.size() << "\r\n\r\n"
- << json_str << std::endl;
-  }
 }
 
 // Serialize the JSON value into a string and send the JSON packet to
@@ -105,7 +99,14 @@
   strm << json;
   static std::mutex mutex;
   std::lock_guard locker(mutex);
-  SendJSON(strm.str());
+  std::string json_str = strm.str();
+  SendJSON(json_str);
+
+  if (log) {
+*log << "<-- " << std::endl
+ << "Content-Length: " << json_str.size() << "\r\n\r\n"
+ << llvm::formatv("{0:2}", json).str() << std::endl;
+  }
 }
 
 // Read a JSON packet from the "in" stream.
@@ -129,11 +130,8 @@
   if (!input.read_full(log.get(), length, json_str))
 return json_str;
 
-  if (log) {
-*log << "--> " << std::endl
- << "Content-Length: " << length << "\r\n\r\n"
- << json_str << std::endl;
-  }
+  if (log)
+*log << "--> " << std::endl << "Content-Length: " << length << "\r\n\r\n";
 
   return json_str;
 }
@@ -523,6 +521,11 @@
 }
 return PacketStatus::JSONMalformed;
   }
+
+  if (log) {
+*log << llvm::formatv("{0:2}", *json_value).str() << std::endl;
+  }
+
   llvm::json::Object *object_ptr = json_value->getAsObject();
   if (!object_ptr) {
 if (log)
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits