2525#include " method_locals.h"
2626#include " model_util.h"
2727#include " object_evaluator.h"
28- #include " safe_method_caller.h"
2928#include " value_formatter.h"
3029
3130namespace devtools {
3231namespace cdbg {
3332
34- CaptureDataCollector::CaptureDataCollector () {
33+ CaptureDataCollector::CaptureDataCollector (JvmEvaluators* evaluators)
34+ : evaluators_(evaluators) {
3535 // Reserve "var_table_index" 0 for memory objects that we didn't capture
3636 // because collector ran out of quota.
3737 memory_objects_.push_back (MemoryObject ());
@@ -44,21 +44,14 @@ CaptureDataCollector::~CaptureDataCollector() {
4444
4545
4646void CaptureDataCollector::Collect (
47- const Config& config,
48- ClassFilesCache* class_files_cache,
49- EvalCallStack* eval_call_stack,
50- ClassIndexer* class_indexer,
51- ClassMetadataReader* class_metadata_reader,
52- MethodLocals* method_locals,
53- ObjectEvaluator* object_evaluator,
5447 const std::vector<CompiledExpression>& watches,
5548 jthread thread) {
56- DCHECK (eval_call_stack_ == nullptr ) << " Collect can only be called once " ;
57- eval_call_stack_ = CHECK_NOTNULL (eval_call_stack );
49+ std::unique_ptr<MethodCaller> pretty_printers_method_caller =
50+ evaluators_-> method_caller_factory (Config::PRETTY_PRINTERS );
5851
5952 // Walk the call stack.
6053 std::vector<EvalCallStack::JvmFrame> jvm_frames;
61- eval_call_stack_ ->Read (thread, &jvm_frames);
54+ evaluators_-> eval_call_stack ->Read (thread, &jvm_frames);
6255
6356 const int call_frames_count = jvm_frames.size ();
6457 call_frames_.resize (call_frames_count);
@@ -68,22 +61,13 @@ void CaptureDataCollector::Collect(
6861 // Collect local variables.
6962 if ((depth < kMethodLocalsFrames ) &&
7063 (jvm_frames[depth].code_location .method != nullptr )) {
71- // We don't expect any methods to be called while reading fields.
72- SafeMethodCaller method_caller (
73- &config,
74- Config::MethodCallQuota (), // Default quota of zero for everything.
75- class_indexer,
76- class_files_cache);
77-
7864 EvaluationContext evaluation_context;
7965 evaluation_context.thread = thread;
8066 evaluation_context.frame_depth = depth;
81- evaluation_context.method_caller = &method_caller ;
67+ evaluation_context.method_caller = pretty_printers_method_caller. get () ;
8268
8369 ReadLocalVariables (
8470 evaluation_context,
85- class_metadata_reader,
86- method_locals,
8771 jvm_frames[depth].code_location .method ,
8872 jvm_frames[depth].code_location .location ,
8973 &call_frames_[depth].arguments ,
@@ -107,20 +91,16 @@ void CaptureDataCollector::Collect(
10791 watch_results_[i].compile_error_message = {ExpressionSensitiveData, { }};
10892
10993 } else if (watches[i].evaluator != nullptr ) {
110- SafeMethodCaller method_caller (
111- &config,
112- config.GetQuota (Config::EXPRESSION_EVALUATION),
113- class_indexer,
114- class_files_cache);
94+ std::unique_ptr<MethodCaller> expression_method_caller =
95+ evaluators_->method_caller_factory (Config::EXPRESSION_EVALUATION);
11596
11697 EvaluationContext evaluation_context;
11798 evaluation_context.thread = thread;
11899 evaluation_context.frame_depth = 0 ;
119- evaluation_context.method_caller = &method_caller ;
100+ evaluation_context.method_caller = expression_method_caller. get () ;
120101
121102 EvaluateWatchedExpression (
122103 evaluation_context,
123- class_metadata_reader,
124104 *watches[i].evaluator ,
125105 &watch_results_[i].evaluation_result );
126106
@@ -142,16 +122,10 @@ void CaptureDataCollector::Collect(
142122 ++it_pending_object; // First entry has a special meaning of "buffer full".
143123 ++captured_variable_table_size;
144124
145- SafeMethodCaller method_caller (
146- &config,
147- config.GetQuota (Config::PRETTY_PRINTERS),
148- class_indexer,
149- class_files_cache);
150-
151125 while ((it_pending_object != memory_objects_.end ()) &&
152126 CanCollectMoreMemoryObjects ()) {
153- object_evaluator->Evaluate (
154- &method_caller ,
127+ evaluators_-> object_evaluator ->Evaluate (
128+ pretty_printers_method_caller. get () ,
155129 it_pending_object->object_ref ,
156130 &it_pending_object->members );
157131
@@ -227,6 +201,11 @@ void CaptureDataCollector::Format(BreakpointModel* breakpoint) const {
227201 } else {
228202 object_variable.reset (new VariableModel);
229203
204+ object_variable->type = TypeNameFromSignature ({
205+ JType::Object,
206+ GetObjectClassSignature (memory_object.object_ref )
207+ });
208+
230209 if (!memory_object.status .description .format .empty ()) {
231210 object_variable->status =
232211 StatusMessageBuilder (memory_object.status ).build ();
@@ -245,8 +224,6 @@ void CaptureDataCollector::Format(BreakpointModel* breakpoint) const {
245224
246225void CaptureDataCollector::ReadLocalVariables (
247226 const EvaluationContext& evaluation_context,
248- ClassMetadataReader* class_metadata_reader,
249- MethodLocals* method_locals,
250227 jmethodID method,
251228 jlocation location,
252229 std::vector<NamedJVariant>* arguments,
@@ -257,7 +234,7 @@ void CaptureDataCollector::ReadLocalVariables(
257234 }
258235
259236 std::shared_ptr<const MethodLocals::Entry> entry =
260- method_locals->GetLocalVariables (method);
237+ evaluators_-> method_locals ->GetLocalVariables (method);
261238
262239 // TODO(vlif): refactor this function to add locals and arguments to
263240 // output vectors as we go.
@@ -310,7 +287,6 @@ void CaptureDataCollector::ReadLocalVariables(
310287
311288void CaptureDataCollector::EvaluateWatchedExpression (
312289 const EvaluationContext& evaluation_context,
313- ClassMetadataReader* class_metadata_reader,
314290 const ExpressionEvaluator& watch_evaluator,
315291 NamedJVariant* result) {
316292 ErrorOr<JVariant> evaluation_result =
@@ -373,8 +349,9 @@ std::unique_ptr<VariableModel> CaptureDataCollector::FormatVariable(
373349 ValueFormatter::Format (
374350 source,
375351 ValueFormatter::Options (),
376- &formatted_value);
377- target->value = formatted_value;
352+ &formatted_value,
353+ &target->type );
354+ target->value = std::move (formatted_value);
378355 } else {
379356 jobject ref = nullptr ;
380357 const int * var_table_index = nullptr ;
@@ -408,7 +385,7 @@ std::unique_ptr<VariableModel> CaptureDataCollector::FormatVariable(
408385string CaptureDataCollector::GetFunctionName (int depth) const {
409386 const int frame_info_key = call_frames_[depth].frame_info_key ;
410387 const auto & frame_info =
411- eval_call_stack_ ->ResolveCallFrameKey (frame_info_key);
388+ evaluators_-> eval_call_stack ->ResolveCallFrameKey (frame_info_key);
412389
413390 string function_name =
414391 TypeNameFromJObjectSignature (frame_info.class_signature );
@@ -423,7 +400,7 @@ std::unique_ptr<SourceLocationModel>
423400CaptureDataCollector::GetCallFrameSourceLocation (int depth) const {
424401 const int frame_info_key = call_frames_[depth].frame_info_key ;
425402 const auto & frame_info =
426- eval_call_stack_ ->ResolveCallFrameKey (frame_info_key);
403+ evaluators_-> eval_call_stack ->ResolveCallFrameKey (frame_info_key);
427404
428405 std::unique_ptr<SourceLocationModel> location (new SourceLocationModel);
429406
0 commit comments