[Lldb-commits] [lldb] 5cee8dd - [lldb-vscode] A couple of small style fixes

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 28 04:42:35 PDT 2020


Author: Pavel Labath
Date: 2020-04-28T13:35:07+02:00
New Revision: 5cee8ddcc7535c95e4dd00fc428d2a52630eaa31

URL: https://github.com/llvm/llvm-project/commit/5cee8ddcc7535c95e4dd00fc428d2a52630eaa31
DIFF: https://github.com/llvm/llvm-project/commit/5cee8ddcc7535c95e4dd00fc428d2a52630eaa31.diff

LOG: [lldb-vscode] A couple of small style fixes

to make the code conform to llvm style better:
- avoid use of auto where the type is not obivous
- avoid StringRef::data where it is not needed

No functional change intended.

Added: 
    

Modified: 
    lldb/tools/lldb-vscode/JSONUtils.cpp
    lldb/tools/lldb-vscode/lldb-vscode.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/tools/lldb-vscode/JSONUtils.cpp b/lldb/tools/lldb-vscode/JSONUtils.cpp
index 2e7a57ee397e..8fcf179b29aa 100644
--- a/lldb/tools/lldb-vscode/JSONUtils.cpp
+++ b/lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -9,9 +9,9 @@
 #include <algorithm>
 
 #include "llvm/ADT/Optional.h"
-
 #include "llvm/Support/FormatAdapters.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/ScopedPrinter.h"
 
 #include "lldb/API/SBBreakpoint.h"
 #include "lldb/API/SBBreakpointLocation.h"
@@ -41,8 +41,8 @@ llvm::StringRef GetAsString(const llvm::json::Value &value) {
 
 // Gets a string from a JSON object using the key, or returns an empty string.
 llvm::StringRef GetString(const llvm::json::Object &obj, llvm::StringRef key) {
-  if (auto value = obj.getString(key))
-    return GetAsString(*value);
+  if (llvm::Optional<llvm::StringRef> value = obj.getString(key))
+    return *value;
   return llvm::StringRef();
 }
 
@@ -114,13 +114,9 @@ std::vector<std::string> GetStrings(const llvm::json::Object *obj,
       strs.push_back(value.getAsString()->str());
       break;
     case llvm::json::Value::Number:
-    case llvm::json::Value::Boolean: {
-      std::string s;
-      llvm::raw_string_ostream strm(s);
-      strm << value;
-      strs.push_back(strm.str());
+    case llvm::json::Value::Boolean:
+      strs.push_back(llvm::to_string(value));
       break;
-    }
     case llvm::json::Value::Null:
     case llvm::json::Value::Object:
     case llvm::json::Value::Array:

diff  --git a/lldb/tools/lldb-vscode/lldb-vscode.cpp b/lldb/tools/lldb-vscode/lldb-vscode.cpp
index 04a2125e3456..b267ea088b1c 100644
--- a/lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ b/lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -531,15 +531,14 @@ void request_attach(const llvm::json::Object &request) {
   g_vsc.exit_commands = GetStrings(arguments, "exitCommands");
   auto attachCommands = GetStrings(arguments, "attachCommands");
   g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false);
-  const auto debuggerRoot = GetString(arguments, "debuggerRoot");
+  const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot");
 
   // This is a hack for loading DWARF in .o files on Mac where the .o files
   // in the debug map of the main executable have relative paths which require
   // the lldb-vscode binary to have its working directory set to that relative
   // root for the .o files in order to be able to load debug info.
-  if (!debuggerRoot.empty()) {
-    llvm::sys::fs::set_current_path(debuggerRoot.data());
-  }
+  if (!debuggerRoot.empty())
+    llvm::sys::fs::set_current_path(debuggerRoot);
 
   // Run any initialize LLDB commands the user specified in the launch.json
   g_vsc.RunInitCommands();
@@ -1363,15 +1362,14 @@ void request_launch(const llvm::json::Object &request) {
   g_vsc.exit_commands = GetStrings(arguments, "exitCommands");
   auto launchCommands = GetStrings(arguments, "launchCommands");
   g_vsc.stop_at_entry = GetBoolean(arguments, "stopOnEntry", false);
-  const auto debuggerRoot = GetString(arguments, "debuggerRoot");
+  const llvm::StringRef debuggerRoot = GetString(arguments, "debuggerRoot");
 
   // This is a hack for loading DWARF in .o files on Mac where the .o files
   // in the debug map of the main executable have relative paths which require
   // the lldb-vscode binary to have its working directory set to that relative
   // root for the .o files in order to be able to load debug info.
-  if (!debuggerRoot.empty()) {
-    llvm::sys::fs::set_current_path(debuggerRoot.data());
-  }
+  if (!debuggerRoot.empty())
+    llvm::sys::fs::set_current_path(debuggerRoot);
 
   // Run any initialize LLDB commands the user specified in the launch.json.
   // This is run before target is created, so commands can't do anything with


        


More information about the lldb-commits mailing list