fixathon updated this revision to Diff 452809.
fixathon marked an inline comment as done.
fixathon added a comment.

Convert raw pointers to shared_ptr


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131900

Files:
  lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp

Index: lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
===================================================================
--- lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -35,6 +35,8 @@
 using namespace lldb;
 using namespace lldb_private;
 
+using std::make_shared;
+
 LLDB_PLUGIN_DEFINE(InstrumentationRuntimeTSan)
 
 lldb::InstrumentationRuntimeSP
@@ -206,10 +208,10 @@
 t;
 )";
 
-static StructuredData::Array *
+static StructuredData::ArraySP
 CreateStackTrace(ValueObjectSP o,
                  const std::string &trace_item_name = ".trace") {
-  StructuredData::Array *trace = new StructuredData::Array();
+  auto trace_sp = make_shared<StructuredData::Array>();
   ValueObjectSP trace_value_object =
       o->GetValueForExpressionPath(trace_item_name.c_str());
   size_t count = trace_value_object->GetNumChildren();
@@ -218,18 +220,17 @@
         trace_value_object->GetChildAtIndex(j, true)->GetValueAsUnsigned(0);
     if (trace_addr == 0)
       break;
-    trace->AddItem(
-        StructuredData::ObjectSP(new StructuredData::Integer(trace_addr)));
+    trace_sp->AddItem(make_shared<StructuredData::Integer>(trace_addr));
   }
-  return trace;
+  return trace_sp;
 }
 
-static StructuredData::Array *ConvertToStructuredArray(
+static StructuredData::ArraySP ConvertToStructuredArray(
     ValueObjectSP return_value_sp, const std::string &items_name,
     const std::string &count_name,
-    std::function<void(ValueObjectSP o, StructuredData::Dictionary *dict)> const
-        &callback) {
-  StructuredData::Array *array = new StructuredData::Array();
+    std::function<void(ValueObjectSP o,
+                       StructuredData::DictionarySP dict)> const &callback) {
+  auto array_sp = make_shared<StructuredData::Array>();
   unsigned int count =
       return_value_sp->GetValueForExpressionPath(count_name.c_str())
           ->GetValueAsUnsigned(0);
@@ -237,13 +238,13 @@
       return_value_sp->GetValueForExpressionPath(items_name.c_str());
   for (unsigned int i = 0; i < count; i++) {
     ValueObjectSP o = objects->GetChildAtIndex(i, true);
-    StructuredData::Dictionary *dict = new StructuredData::Dictionary();
+    auto dict_sp = make_shared<StructuredData::Dictionary>();
 
-    callback(o, dict);
+    callback(o, dict_sp);
 
-    array->AddItem(StructuredData::ObjectSP(dict));
+    array_sp->AddItem(dict_sp);
   }
-  return array;
+  return array_sp;
 }
 
 static std::string RetrieveString(ValueObjectSP return_value_sp,
@@ -264,7 +265,7 @@
   ConvertToStructuredArray(
       data, ".threads", ".thread_count",
       [process_sp, &thread_id_map](ValueObjectSP o,
-                                   StructuredData::Dictionary *dict) {
+                                   StructuredData::DictionarySP dict) {
         uint64_t thread_id =
             o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0);
         uint64_t thread_os_id =
@@ -338,31 +339,31 @@
   std::map<uint64_t, user_id_t> thread_id_map;
   GetRenumberedThreadIds(process_sp, main_value, thread_id_map);
 
-  StructuredData::Dictionary *dict = new StructuredData::Dictionary();
+  auto dict = make_shared<StructuredData::Dictionary>();
   dict->AddStringItem("instrumentation_class", "ThreadSanitizer");
   dict->AddStringItem("issue_type",
                       RetrieveString(main_value, process_sp, ".description"));
   dict->AddIntegerItem("report_count",
                        main_value->GetValueForExpressionPath(".report_count")
                            ->GetValueAsUnsigned(0));
-  dict->AddItem("sleep_trace", StructuredData::ObjectSP(CreateStackTrace(
-                                   main_value, ".sleep_trace")));
+  dict->AddItem("sleep_trace", CreateStackTrace(
+                                   main_value, ".sleep_trace"));
 
-  StructuredData::Array *stacks = ConvertToStructuredArray(
+  StructuredData::ArraySP stacks = ConvertToStructuredArray(
       main_value, ".stacks", ".stack_count",
-      [thread_sp](ValueObjectSP o, StructuredData::Dictionary *dict) {
+      [thread_sp](ValueObjectSP o, StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
-        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
+        dict->AddItem("trace", CreateStackTrace(o));
         // "stacks" happen on the current thread
         dict->AddIntegerItem("thread_id", thread_sp->GetIndexID());
       });
-  dict->AddItem("stacks", StructuredData::ObjectSP(stacks));
+  dict->AddItem("stacks", stacks);
 
-  StructuredData::Array *mops = ConvertToStructuredArray(
+  StructuredData::ArraySP mops = ConvertToStructuredArray(
       main_value, ".mops", ".mop_count",
-      [&thread_id_map](ValueObjectSP o, StructuredData::Dictionary *dict) {
+      [&thread_id_map](ValueObjectSP o, StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
@@ -383,14 +384,14 @@
         dict->AddIntegerItem(
             "address",
             o->GetValueForExpressionPath(".addr")->GetValueAsUnsigned(0));
-        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
+        dict->AddItem("trace", CreateStackTrace(o));
       });
-  dict->AddItem("mops", StructuredData::ObjectSP(mops));
+  dict->AddItem("mops", mops);
 
-  StructuredData::Array *locs = ConvertToStructuredArray(
+  StructuredData::ArraySP locs = ConvertToStructuredArray(
       main_value, ".locs", ".loc_count",
       [process_sp, &thread_id_map](ValueObjectSP o,
-                                   StructuredData::Dictionary *dict) {
+                                   StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
@@ -415,15 +416,15 @@
         dict->AddIntegerItem("suppressable",
                              o->GetValueForExpressionPath(".suppressable")
                                  ->GetValueAsUnsigned(0));
-        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
+        dict->AddItem("trace", CreateStackTrace(o));
         dict->AddStringItem("object_type",
                             RetrieveString(o, process_sp, ".object_type"));
       });
-  dict->AddItem("locs", StructuredData::ObjectSP(locs));
+  dict->AddItem("locs", locs);
 
-  StructuredData::Array *mutexes = ConvertToStructuredArray(
+  StructuredData::ArraySP mutexes = ConvertToStructuredArray(
       main_value, ".mutexes", ".mutex_count",
-      [](ValueObjectSP o, StructuredData::Dictionary *dict) {
+      [](ValueObjectSP o, StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
@@ -436,14 +437,14 @@
         dict->AddIntegerItem(
             "destroyed",
             o->GetValueForExpressionPath(".destroyed")->GetValueAsUnsigned(0));
-        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
+        dict->AddItem("trace", CreateStackTrace(o));
       });
-  dict->AddItem("mutexes", StructuredData::ObjectSP(mutexes));
+  dict->AddItem("mutexes", mutexes);
 
-  StructuredData::Array *threads = ConvertToStructuredArray(
+  StructuredData::ArraySP threads = ConvertToStructuredArray(
       main_value, ".threads", ".thread_count",
       [process_sp, &thread_id_map](ValueObjectSP o,
-                                   StructuredData::Dictionary *dict) {
+                                   StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
@@ -464,13 +465,13 @@
             Renumber(o->GetValueForExpressionPath(".parent_tid")
                          ->GetValueAsUnsigned(0),
                      thread_id_map));
-        dict->AddItem("trace", StructuredData::ObjectSP(CreateStackTrace(o)));
+        dict->AddItem("trace", CreateStackTrace(o));
       });
-  dict->AddItem("threads", StructuredData::ObjectSP(threads));
+  dict->AddItem("threads", threads);
 
-  StructuredData::Array *unique_tids = ConvertToStructuredArray(
+  StructuredData::ArraySP unique_tids = ConvertToStructuredArray(
       main_value, ".unique_tids", ".unique_tid_count",
-      [&thread_id_map](ValueObjectSP o, StructuredData::Dictionary *dict) {
+      [&thread_id_map](ValueObjectSP o, StructuredData::DictionarySP dict) {
         dict->AddIntegerItem(
             "index",
             o->GetValueForExpressionPath(".idx")->GetValueAsUnsigned(0));
@@ -480,9 +481,9 @@
                 o->GetValueForExpressionPath(".tid")->GetValueAsUnsigned(0),
                 thread_id_map));
       });
-  dict->AddItem("unique_tids", StructuredData::ObjectSP(unique_tids));
+  dict->AddItem("unique_tids", unique_tids);
 
-  return StructuredData::ObjectSP(dict);
+  return dict;
 }
 
 std::string
@@ -1030,9 +1031,8 @@
             o->GetObjectForDotSeparatedPath("thread_os_id");
         tid_t tid = thread_id_obj ? thread_id_obj->GetIntegerValue() : 0;
 
-        HistoryThread *history_thread =
-            new HistoryThread(*process_sp, tid, pcs);
-        ThreadSP new_thread_sp(history_thread);
+        ThreadSP new_thread_sp =
+            make_shared<HistoryThread>(*process_sp, tid, pcs);
         new_thread_sp->SetName(GenerateThreadName(path, o, info).c_str());
 
         // Save this in the Process' ExtendedThreadList so a strong pointer
@@ -1047,8 +1047,8 @@
 lldb::ThreadCollectionSP
 InstrumentationRuntimeTSan::GetBacktracesFromExtendedStopInfo(
     StructuredData::ObjectSP info) {
-  ThreadCollectionSP threads;
-  threads = std::make_shared<ThreadCollection>();
+  
+  ThreadCollectionSP threads = make_shared<ThreadCollection>();
 
   if (info->GetObjectForDotSeparatedPath("instrumentation_class")
           ->GetStringValue() != "ThreadSanitizer")
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to