@@ -154,7 +154,7 @@ DecodeMemoryReference(llvm::StringRef memoryReference) {
154
154
std::vector<std::string> GetStrings (const llvm::json::Object *obj,
155
155
llvm::StringRef key) {
156
156
std::vector<std::string> strs;
157
- auto json_array = obj->getArray (key);
157
+ const auto * json_array = obj->getArray (key);
158
158
if (!json_array)
159
159
return strs;
160
160
for (const auto &value : *json_array) {
@@ -210,12 +210,6 @@ static bool IsClassStructOrUnionType(lldb::SBType t) {
210
210
// / glance.
211
211
static std::optional<std::string>
212
212
TryCreateAutoSummaryForContainer (lldb::SBValue &v) {
213
- // We gate this feature because it performs GetNumChildren(), which can
214
- // cause performance issues because LLDB needs to complete possibly huge
215
- // types.
216
- if (!g_dap.enable_auto_variable_summaries )
217
- return std::nullopt;
218
-
219
213
if (!v.MightHaveChildren ())
220
214
return std::nullopt;
221
215
// / As this operation can be potentially slow, we limit the total time spent
@@ -271,10 +265,7 @@ TryCreateAutoSummaryForContainer(lldb::SBValue &v) {
271
265
272
266
// / Try to create a summary string for the given value that doesn't have a
273
267
// / summary of its own.
274
- static std::optional<std::string> TryCreateAutoSummary (lldb::SBValue value) {
275
- if (!g_dap.enable_auto_variable_summaries )
276
- return std::nullopt;
277
-
268
+ static std::optional<std::string> TryCreateAutoSummary (lldb::SBValue &value) {
278
269
// We use the dereferenced value for generating the summary.
279
270
if (value.GetType ().IsPointerType () || value.GetType ().IsReferenceType ())
280
271
value = value.Dereference ();
@@ -485,10 +476,12 @@ static std::string ConvertDebugInfoSizeToString(uint64_t debug_info) {
485
476
}
486
477
return oss.str ();
487
478
}
488
- llvm::json::Value CreateModule (lldb::SBModule &module ) {
479
+
480
+ llvm::json::Value CreateModule (lldb::SBTarget &target, lldb::SBModule &module ) {
489
481
llvm::json::Object object;
490
- if (!module .IsValid ())
482
+ if (!target. IsValid () || ! module .IsValid ())
491
483
return llvm::json::Value (std::move (object));
484
+
492
485
const char *uuid = module .GetUUIDString ();
493
486
object.try_emplace (" id" , uuid ? std::string (uuid) : std::string (" " ));
494
487
object.try_emplace (" name" , std::string (module .GetFileSpec ().GetFilename ()));
@@ -514,7 +507,7 @@ llvm::json::Value CreateModule(lldb::SBModule &module) {
514
507
object.try_emplace (" symbolStatus" , " Symbols not found." );
515
508
}
516
509
std::string loaded_addr = std::to_string (
517
- module .GetObjectFileHeaderAddress ().GetLoadAddress (g_dap. target ));
510
+ module .GetObjectFileHeaderAddress ().GetLoadAddress (target));
518
511
object.try_emplace (" addressRange" , loaded_addr);
519
512
std::string version_str;
520
513
uint32_t version_nums[3 ];
@@ -705,7 +698,7 @@ llvm::json::Value CreateSource(llvm::StringRef source_path) {
705
698
return llvm::json::Value (std::move (source));
706
699
}
707
700
708
- std::optional<llvm::json::Value> CreateSource (lldb::SBFrame &frame) {
701
+ static std::optional<llvm::json::Value> CreateSource (lldb::SBFrame &frame) {
709
702
auto line_entry = frame.GetLineEntry ();
710
703
// A line entry of 0 indicates the line is compiler generated i.e. no source
711
704
// file is associated with the frame.
@@ -776,15 +769,15 @@ std::optional<llvm::json::Value> CreateSource(lldb::SBFrame &frame) {
776
769
// },
777
770
// "required": [ "id", "name", "line", "column" ]
778
771
// }
779
- llvm::json::Value CreateStackFrame (lldb::SBFrame &frame) {
772
+ llvm::json::Value CreateStackFrame (lldb::SBFrame &frame,
773
+ lldb::SBFormat &format) {
780
774
llvm::json::Object object;
781
775
int64_t frame_id = MakeDAPFrameID (frame);
782
776
object.try_emplace (" id" , frame_id);
783
777
784
778
std::string frame_name;
785
779
lldb::SBStream stream;
786
- if (g_dap.frame_format &&
787
- frame.GetDescriptionWithFormat (g_dap.frame_format , stream).Success ()) {
780
+ if (format && frame.GetDescriptionWithFormat (format, stream).Success ()) {
788
781
frame_name = stream.GetData ();
789
782
790
783
// `function_name` can be a nullptr, which throws an error when assigned to
@@ -801,7 +794,7 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
801
794
}
802
795
803
796
// We only include `[opt]` if a custom frame format is not specified.
804
- if (!g_dap. frame_format && frame.GetFunction ().GetIsOptimized ())
797
+ if (!format && frame.GetFunction ().GetIsOptimized ())
805
798
frame_name += " [opt]" ;
806
799
807
800
EmplaceSafeString (object, " name" , frame_name);
@@ -835,11 +828,11 @@ llvm::json::Value CreateStackFrame(lldb::SBFrame &frame) {
835
828
return llvm::json::Value (std::move (object));
836
829
}
837
830
838
- llvm::json::Value CreateExtendedStackFrameLabel (lldb::SBThread &thread) {
831
+ llvm::json::Value CreateExtendedStackFrameLabel (lldb::SBThread &thread,
832
+ lldb::SBFormat &format) {
839
833
std::string name;
840
834
lldb::SBStream stream;
841
- if (g_dap.thread_format &&
842
- thread.GetDescriptionWithFormat (g_dap.thread_format , stream).Success ()) {
835
+ if (format && thread.GetDescriptionWithFormat (format, stream).Success ()) {
843
836
name = stream.GetData ();
844
837
} else {
845
838
const uint32_t thread_idx = thread.GetExtendedBacktraceOriginatingIndexID ();
@@ -872,13 +865,12 @@ llvm::json::Value CreateExtendedStackFrameLabel(lldb::SBThread &thread) {
872
865
// },
873
866
// "required": [ "id", "name" ]
874
867
// }
875
- llvm::json::Value CreateThread (lldb::SBThread &thread) {
868
+ llvm::json::Value CreateThread (lldb::SBThread &thread, lldb::SBFormat &format ) {
876
869
llvm::json::Object object;
877
870
object.try_emplace (" id" , (int64_t )thread.GetThreadID ());
878
871
std::string thread_str;
879
872
lldb::SBStream stream;
880
- if (g_dap.thread_format &&
881
- thread.GetDescriptionWithFormat (g_dap.thread_format , stream).Success ()) {
873
+ if (format && thread.GetDescriptionWithFormat (format, stream).Success ()) {
882
874
thread_str = stream.GetData ();
883
875
} else {
884
876
const char *thread_name = thread.GetName ();
@@ -966,7 +958,7 @@ llvm::json::Value CreateThread(lldb::SBThread &thread) {
966
958
// "required": [ "event", "body" ]
967
959
// }]
968
960
// }
969
- llvm::json::Value CreateThreadStopped (lldb::SBThread &thread,
961
+ llvm::json::Value CreateThreadStopped (DAP &dap, lldb::SBThread &thread,
970
962
uint32_t stop_id) {
971
963
llvm::json::Object event (CreateEventObject (" stopped" ));
972
964
llvm::json::Object body;
@@ -976,13 +968,13 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
976
968
body.try_emplace (" reason" , " step" );
977
969
break ;
978
970
case lldb::eStopReasonBreakpoint: {
979
- ExceptionBreakpoint *exc_bp = g_dap .GetExceptionBPFromStopReason (thread);
971
+ ExceptionBreakpoint *exc_bp = dap .GetExceptionBPFromStopReason (thread);
980
972
if (exc_bp) {
981
973
body.try_emplace (" reason" , " exception" );
982
974
EmplaceSafeString (body, " description" , exc_bp->label );
983
975
} else {
984
976
InstructionBreakpoint *inst_bp =
985
- g_dap .GetInstructionBPFromStopReason (thread);
977
+ dap .GetInstructionBPFromStopReason (thread);
986
978
if (inst_bp) {
987
979
body.try_emplace (" reason" , " instruction breakpoint" );
988
980
} else {
@@ -1039,21 +1031,21 @@ llvm::json::Value CreateThreadStopped(lldb::SBThread &thread,
1039
1031
}
1040
1032
}
1041
1033
// "threadCausedFocus" is used in tests to validate breaking behavior.
1042
- if (tid == g_dap .focus_tid ) {
1034
+ if (tid == dap .focus_tid ) {
1043
1035
body.try_emplace (" threadCausedFocus" , true );
1044
1036
}
1045
- body.try_emplace (" preserveFocusHint" , tid != g_dap .focus_tid );
1037
+ body.try_emplace (" preserveFocusHint" , tid != dap .focus_tid );
1046
1038
body.try_emplace (" allThreadsStopped" , true );
1047
1039
event.try_emplace (" body" , std::move (body));
1048
1040
return llvm::json::Value (std::move (event));
1049
1041
}
1050
1042
1051
- const char *GetNonNullVariableName (lldb::SBValue v) {
1043
+ const char *GetNonNullVariableName (lldb::SBValue & v) {
1052
1044
const char *name = v.GetName ();
1053
1045
return name ? name : " <null>" ;
1054
1046
}
1055
1047
1056
- std::string CreateUniqueVariableNameForDisplay (lldb::SBValue v,
1048
+ std::string CreateUniqueVariableNameForDisplay (lldb::SBValue & v,
1057
1049
bool is_name_duplicated) {
1058
1050
lldb::SBStream name_builder;
1059
1051
name_builder.Print (GetNonNullVariableName (v));
@@ -1070,7 +1062,9 @@ std::string CreateUniqueVariableNameForDisplay(lldb::SBValue v,
1070
1062
return name_builder.GetData ();
1071
1063
}
1072
1064
1073
- VariableDescription::VariableDescription (lldb::SBValue v, bool format_hex,
1065
+ VariableDescription::VariableDescription (lldb::SBValue v,
1066
+ bool auto_variable_summaries,
1067
+ bool format_hex,
1074
1068
bool is_name_duplicated,
1075
1069
std::optional<std::string> custom_name)
1076
1070
: v(v) {
@@ -1101,7 +1095,7 @@ VariableDescription::VariableDescription(lldb::SBValue v, bool format_hex,
1101
1095
} else {
1102
1096
value = llvm::StringRef (v.GetValue ()).str ();
1103
1097
summary = llvm::StringRef (v.GetSummary ()).str ();
1104
- if (summary.empty ())
1098
+ if (summary.empty () && auto_variable_summaries )
1105
1099
auto_summary = TryCreateAutoSummary (v);
1106
1100
1107
1101
std::optional<std::string> effective_summary =
@@ -1185,7 +1179,7 @@ bool ValuePointsToCode(lldb::SBValue v) {
1185
1179
1186
1180
lldb::addr_t addr = v.GetValueAsAddress ();
1187
1181
lldb::SBLineEntry line_entry =
1188
- g_dap. target .ResolveLoadAddress (addr).GetLineEntry ();
1182
+ v. GetTarget () .ResolveLoadAddress (addr).GetLineEntry ();
1189
1183
1190
1184
return line_entry.IsValid ();
1191
1185
}
@@ -1346,9 +1340,12 @@ std::pair<int64_t, bool> UnpackLocation(int64_t location_id) {
1346
1340
// "required": [ "name", "value", "variablesReference" ]
1347
1341
// }
1348
1342
llvm::json::Value CreateVariable (lldb::SBValue v, int64_t var_ref,
1349
- bool format_hex, bool is_name_duplicated,
1343
+ bool format_hex, bool auto_variable_summaries,
1344
+ bool synthetic_child_debugging,
1345
+ bool is_name_duplicated,
1350
1346
std::optional<std::string> custom_name) {
1351
- VariableDescription desc (v, format_hex, is_name_duplicated, custom_name);
1347
+ VariableDescription desc (v, auto_variable_summaries, format_hex,
1348
+ is_name_duplicated, custom_name);
1352
1349
llvm::json::Object object;
1353
1350
EmplaceSafeString (object, " name" , desc.name );
1354
1351
EmplaceSafeString (object, " value" , desc.display_value );
@@ -1384,7 +1381,7 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t var_ref,
1384
1381
size_t num_children = v.GetNumChildren ();
1385
1382
// If we are creating a "[raw]" fake child for each synthetic type, we
1386
1383
// have to account for it when returning indexed variables.
1387
- if (g_dap. enable_synthetic_child_debugging )
1384
+ if (synthetic_child_debugging )
1388
1385
++num_children;
1389
1386
object.try_emplace (" indexedVariables" , num_children);
1390
1387
}
@@ -1415,7 +1412,7 @@ llvm::json::Value CreateVariable(lldb::SBValue v, int64_t var_ref,
1415
1412
return llvm::json::Value (std::move (object));
1416
1413
}
1417
1414
1418
- llvm::json::Value CreateCompileUnit (lldb::SBCompileUnit unit) {
1415
+ llvm::json::Value CreateCompileUnit (lldb::SBCompileUnit & unit) {
1419
1416
llvm::json::Object object;
1420
1417
char unit_path_arr[PATH_MAX];
1421
1418
unit.GetFileSpec ().GetPath (unit_path_arr, sizeof (unit_path_arr));
@@ -1436,7 +1433,7 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
1436
1433
// the terminal in a new window.
1437
1434
run_in_terminal_args.try_emplace (" kind" , " integrated" );
1438
1435
1439
- auto launch_request_arguments = launch_request.getObject (" arguments" );
1436
+ const auto * launch_request_arguments = launch_request.getObject (" arguments" );
1440
1437
// The program path must be the first entry in the "args" field
1441
1438
std::vector<std::string> args = {debug_adaptor_path.str (), " --comm-file" ,
1442
1439
comm_file.str ()};
@@ -1462,11 +1459,7 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
1462
1459
llvm::StringRef key = envs.GetNameAtIndex (index);
1463
1460
llvm::StringRef value = envs.GetValueAtIndex (index);
1464
1461
1465
- if (key.empty ())
1466
- g_dap.SendOutput (OutputType::Stderr,
1467
- " empty environment variable for value: \" " +
1468
- value.str () + ' \" ' );
1469
- else
1462
+ if (!key.empty ())
1470
1463
env_json.try_emplace (key, value);
1471
1464
}
1472
1465
run_in_terminal_args.try_emplace (" env" ,
@@ -1478,8 +1471,8 @@ CreateRunInTerminalReverseRequest(const llvm::json::Object &launch_request,
1478
1471
// Keep all the top level items from the statistics dump, except for the
1479
1472
// "modules" array. It can be huge and cause delay
1480
1473
// Array and dictionary value will return as <key, JSON string> pairs
1481
- void FilterAndGetValueForKey (const lldb::SBStructuredData data, const char *key ,
1482
- llvm::json::Object &out) {
1474
+ static void FilterAndGetValueForKey (const lldb::SBStructuredData data,
1475
+ const char *key, llvm::json::Object &out) {
1483
1476
lldb::SBStructuredData value = data.GetValueForKey (key);
1484
1477
std::string key_utf8 = llvm::json::fixUTF8 (key);
1485
1478
if (llvm::StringRef (key) == " modules" )
@@ -1521,8 +1514,8 @@ void FilterAndGetValueForKey(const lldb::SBStructuredData data, const char *key,
1521
1514
}
1522
1515
}
1523
1516
1524
- void addStatistic (llvm::json::Object &event) {
1525
- lldb::SBStructuredData statistics = g_dap. target .GetStatistics ();
1517
+ static void addStatistic (lldb::SBTarget &target, llvm::json::Object &event) {
1518
+ lldb::SBStructuredData statistics = target.GetStatistics ();
1526
1519
bool is_dictionary =
1527
1520
statistics.GetType () == lldb::eStructuredDataTypeDictionary;
1528
1521
if (!is_dictionary)
@@ -1539,9 +1532,9 @@ void addStatistic(llvm::json::Object &event) {
1539
1532
event.try_emplace (" statistics" , std::move (stats_body));
1540
1533
}
1541
1534
1542
- llvm::json::Object CreateTerminatedEventObject () {
1535
+ llvm::json::Object CreateTerminatedEventObject (lldb::SBTarget &target ) {
1543
1536
llvm::json::Object event (CreateEventObject (" terminated" ));
1544
- addStatistic (event);
1537
+ addStatistic (target, event);
1545
1538
return event;
1546
1539
}
1547
1540
0 commit comments