[vm] Account for --no_retain_function_objects in Code::Name.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/54344
Change-Id: Ic72b877efaf36a5b68285caa595604e203ea83b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341821
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/pkg/vm_service/test/fetch_all_types_test.dart b/pkg/vm_service/test/fetch_all_types_test.dart
index df3da27..860de48 100644
--- a/pkg/vm_service/test/fetch_all_types_test.dart
+++ b/pkg/vm_service/test/fetch_all_types_test.dart
@@ -4,6 +4,9 @@
 
 // See https://github.com/dart-lang/sdk/issues/52893
 
+// VMOptions=--retain_function_objects=true
+// VMOptions=--retain_function_objects=false
+
 import 'package:vm_service/vm_service.dart';
 
 import 'common/test_helper.dart';
diff --git a/runtime/observatory/tests/service/fetch_all_types_test.dart b/runtime/observatory/tests/service/fetch_all_types_test.dart
index 4d6dcf3..f3d4ef6 100644
--- a/runtime/observatory/tests/service/fetch_all_types_test.dart
+++ b/runtime/observatory/tests/service/fetch_all_types_test.dart
@@ -4,6 +4,9 @@
 
 // See https://github.com/dart-lang/sdk/issues/52893
 
+// VMOptions=--retain_function_objects=true
+// VMOptions=--retain_function_objects=false
+
 import 'package:observatory/service_io.dart';
 import 'test_helper.dart';
 
diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc
index 39a5d33..63cf72f 100644
--- a/runtime/vm/isolate.cc
+++ b/runtime/vm/isolate.cc
@@ -2986,6 +2986,7 @@
   } else {
     ServiceEvent pause_event(isolate, ServiceEvent::kResume);
 
+#if !defined(DART_PRECOMPILED_RUNTIME)
     if (isolate->debugger() != nullptr) {
       // TODO(turnidge): Don't compute a full stack trace.
       DebuggerStackTrace* stack = isolate->debugger()->StackTrace();
@@ -2993,6 +2994,7 @@
         pause_event.set_top_frame(stack->FrameAt(0));
       }
     }
+#endif
 
     return pause_event;
   }
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index ae81ed8..8980ad8 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -18396,16 +18396,14 @@
     // Type test stub.
     return OS::SCreate(zone, "[Stub] Type Test %s",
                        AbstractType::Cast(obj).ToCString());
-  } else {
-    ASSERT(IsFunctionCode());
+  } else if (obj.IsFunction()) {
     // Dart function.
     const char* opt = is_optimized() ? "[Optimized]" : "[Unoptimized]";
-    const char* function_name =
-        obj.IsFunction()
-            ? String::Handle(zone, Function::Cast(obj).UserVisibleName())
-                  .ToCString()
-            : WeakSerializationReference::Cast(obj).ToCString();
+    const char* function_name = Function::Cast(obj).UserVisibleNameCString();
     return OS::SCreate(zone, "%s %s", opt, function_name);
+  } else {
+    // --no_retain_function_objects etc
+    return "[unknown code]";
   }
 }