aelitashen updated this revision to Diff 276172.
aelitashen added a comment.

Add test for loading symbols, other module info and Add version to module info


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82477

Files:
  lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
  lldb/test/API/tools/lldb-vscode/module/Makefile
  lldb/test/API/tools/lldb-vscode/module/TestVSCode_module.py
  lldb/test/API/tools/lldb-vscode/module/main.cpp
  lldb/tools/lldb-vscode/JSONUtils.cpp
  lldb/tools/lldb-vscode/JSONUtils.h
  lldb/tools/lldb-vscode/lldb-vscode.cpp

Index: lldb/tools/lldb-vscode/lldb-vscode.cpp
===================================================================
--- lldb/tools/lldb-vscode/lldb-vscode.cpp
+++ lldb/tools/lldb-vscode/lldb-vscode.cpp
@@ -1171,31 +1171,6 @@
   g_vsc.SendJSON(llvm::json::Value(std::move(response)));
 }
 
-void request_getCompileUnits(const llvm::json::Object &request) {
-  llvm::json::Object response;
-  FillResponse(request, response);
-  lldb::SBProcess process = g_vsc.target.GetProcess();
-  llvm::json::Object body;
-  llvm::json::Array units;
-  auto arguments = request.getObject("arguments");
-  std::string module_id = std::string(GetString(arguments, "moduleId"));
-  int num_modules = g_vsc.target.GetNumModules();
-  for (int i = 0; i < num_modules; i++) {
-    auto curr_module = g_vsc.target.GetModuleAtIndex(i);
-    if (module_id == curr_module.GetUUIDString()) {
-      int num_units = curr_module.GetNumCompileUnits();
-      for (int j = 0; j < num_units; j++) {
-        auto curr_unit = curr_module.GetCompileUnitAtIndex(j);
-        units.emplace_back(CreateCompileUnit(curr_unit));
-      }
-      body.try_emplace("compileUnits", std::move(units));
-      break;
-    }
-  }
-  response.try_emplace("body", std::move(body));
-  g_vsc.SendJSON(llvm::json::Value(std::move(response)));
-}
-
 // "InitializeRequest": {
 //   "allOf": [ { "$ref": "#/definitions/Request" }, {
 //     "type": "object",
@@ -2779,7 +2754,6 @@
       REQUEST_CALLBACK(disconnect),
       REQUEST_CALLBACK(evaluate),
       REQUEST_CALLBACK(exceptionInfo),
-      REQUEST_CALLBACK(getCompileUnits),
       REQUEST_CALLBACK(initialize),
       REQUEST_CALLBACK(launch),
       REQUEST_CALLBACK(next),
Index: lldb/tools/lldb-vscode/JSONUtils.h
===================================================================
--- lldb/tools/lldb-vscode/JSONUtils.h
+++ lldb/tools/lldb-vscode/JSONUtils.h
@@ -441,8 +441,6 @@
 llvm::json::Value CreateVariable(lldb::SBValue v, int64_t variablesReference,
                                  int64_t varID, bool format_hex);
 
-llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit);
-
 } // namespace lldb_vscode
 
 #endif
Index: lldb/tools/lldb-vscode/JSONUtils.cpp
===================================================================
--- lldb/tools/lldb-vscode/JSONUtils.cpp
+++ lldb/tools/lldb-vscode/JSONUtils.cpp
@@ -342,25 +342,22 @@
     char symbol_path_arr[PATH_MAX];
     module.GetSymbolFileSpec().GetPath(symbol_path_arr, sizeof(symbol_path_arr));
     std::string symbol_path(symbol_path_arr);
-    if (symbol_path != module_path) {
-      object.try_emplace("symbolFilePath", symbol_path);
-    }
+    object.try_emplace("symbolFilePath", symbol_path);
   }
   std::string loaded_addr = std::to_string(
       module.GetObjectFileHeaderAddress().GetLoadAddress(g_vsc.target));
   object.try_emplace("addressRange", loaded_addr);
-  // uint32_t version_nums[5];
-  // const uint32_t num_versions = module.GetVersion(version_nums, sizeof(version_nums));
-  // std::string version_str = "dummy";
-  // for (uint32_t i = 0; i < num_versions; ++i) {
-  //   if (!version_str.empty()) {
-  //     version_str += ".";
-  //   }
-  //   version_str += std::to_string(version_nums[i]);
-  // }
-  // if (!version_str.empty()) {
-  //   object.try_emplace("version", version_str);
-  // }
+  std::string version_str;
+  uint32_t version_nums[3];
+  uint32_t num_versions = module.GetVersion(version_nums, sizeof(version_nums)/sizeof(uint32_t));
+  for (uint32_t i=0; i<num_versions; ++i) {
+    if (!version_str.empty())
+      version_str += ".";
+    version_str += std::to_string(version_nums[i]);
+  }
+if (!version_str.empty()){
+  object.try_emplace("version", version_str);
+}
   return llvm::json::Value(std::move(object));
 }
 
@@ -939,12 +936,4 @@
   return llvm::json::Value(std::move(object));
 }
 
-llvm::json::Value CreateCompileUnit(lldb::SBCompileUnit unit) {
-  llvm::json::Object object;
-  std::string path = std::string(unit.GetFileSpec().GetDirectory()) + "/" +
-                      std::string(unit.GetFileSpec().GetFilename());
-  object.try_emplace("compileUnitPath", path);
-  return llvm::json::Value(std::move(object));
-}
-
 } // namespace lldb_vscode
Index: lldb/test/API/tools/lldb-vscode/module/main.cpp
===================================================================
--- lldb/test/API/tools/lldb-vscode/module/main.cpp
+++ lldb/test/API/tools/lldb-vscode/module/main.cpp
@@ -1,3 +1,4 @@
 int main(int argc, char const *argv[]) {
-  return 0; // breakpoint 1
+  int x = 12; // breakpoint 1
+  return 0;
 }
Index: lldb/test/API/tools/lldb-vscode/module/TestVSCode_module.py
===================================================================
--- lldb/test/API/tools/lldb-vscode/module/TestVSCode_module.py
+++ lldb/test/API/tools/lldb-vscode/module/TestVSCode_module.py
@@ -17,34 +17,29 @@
     mydir = TestBase.compute_mydir(__file__)
     
     def test_modules_event(self):
-        program= self.getBuildArtifact("a.out")
-        self.build_and_launch(program)
-        source = "main.cpp"
-        breakpoint1_line = line_number(source, '// breakpoint 1')
-        lines = [breakpoint1_line]
-        breakpoint_ids = self.set_source_breakpoints(source, lines)
-        self.continue_to_breakpoints(breakpoint_ids)
-        self.assertTrue('a.out' in self.vscode.get_active_modules(), 
-                        'Module: a.out is loaded')
-        self.assertTrue('symbolFilePath' in self.vscode.get_active_modules()['a.out'],
-                        'Symbol exists')
-    
-    def test_compile_units(self):
-        program= self.getBuildArtifact("a.out")
+        program_basename = "a.out.stripped"
+        program= self.getBuildArtifact(program_basename)
         self.build_and_launch(program)
         source = "main.cpp"
         main_source_path = self.getSourcePath(source)
-        breakpoint1_line = line_number(source, '// breakpoint 1')
-        lines = [breakpoint1_line]
-        breakpoint_ids = self.set_source_breakpoints(source, lines)
+        functions = ['main']
+        breakpoint_ids = self.set_function_breakpoints(functions)
+        self.assertEquals(len(breakpoint_ids), len(functions),
+                        'expect one breakpoint')
         self.continue_to_breakpoints(breakpoint_ids)
-        moduleId = self.vscode.get_active_modules()['a.out']['id']
-        response = self.vscode.request_getCompileUnits(moduleId)
-        print(response['body'])
-        self.assertTrue(response['body'])
-        self.assertTrue(len(response['body']['compileUnits']) == 1,
-                        'Only one source file should exist')
-        self.assertTrue(response['body']['compileUnits'][0]['compileUnitPath'] == main_source_path, 
-                        'Real path to main.cpp matches')
-        
-
+        active_modules = self.vscode.get_active_modules()
+        self.assertIn(program_basename, active_modules, '%s module is in active modules' % (program_basename))
+        program_module = active_modules[program_basename]
+        self.assertIn('name', program_module, 'make sure name is in module')
+        self.assertEqual(program_basename, program_module['name'])
+        self.assertTrue('symbolFilePath' not in program_module, 'Make sure a.out.stripped has no debug info')
+        symbol_path = self.getBuildArtifact("a.out")
+        response = self.vscode.request_evaluate('`%s' % ('target symbols add -s "%s" "%s"' % (program, symbol_path)))
+        active_modules = self.vscode.get_active_modules()
+        program_module = active_modules[program_basename]
+        self.assertEqual(program_basename, program_module['name'])
+        self.assertEqual('Symbols loaded.', program_module['symbolStatus'])
+        self.assertIn('symbolFilePath', program_module)
+        self.assertEqual(symbol_path, program_module['symbolFilePath'])
+        self.assertIn('addressRange', program_module)
+        
\ No newline at end of file
Index: lldb/test/API/tools/lldb-vscode/module/Makefile
===================================================================
--- lldb/test/API/tools/lldb-vscode/module/Makefile
+++ lldb/test/API/tools/lldb-vscode/module/Makefile
@@ -1,3 +1,10 @@
 CXX_SOURCES := main.cpp
 
+all:        a.out.stripped
 include Makefile.rules
+
+a.out.stripped: a.out.dSYM
+	strip -o a.out.stripped a.out
+ifneq "$(CODESIGN)" ""
+	$(CODESIGN) -fs - a.out.stripped
+endif
\ No newline at end of file
Index: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
+++ lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/vscode.py
@@ -756,16 +756,6 @@
         }
         return self.send_recv(command_dict)
 
-    def request_getCompileUnits(self, moduleId):
-        args_dict = {'moduleId': moduleId}
-        command_dict = {
-            'command': 'getCompileUnits',
-            'type': 'request',
-            'arguments': args_dict
-        }
-        response = self.send_recv(command_dict)
-        return response
-
     def request_stackTrace(self, threadId=None, startFrame=None, levels=None,
                            dump=False):
         if threadId is None:
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to