Reland changes to hygienic synthetics.

This reverts commit 900d93448e4bbf3fce30e0461c04517923e4761c.

Bug: 158159959
Change-Id: Ic486b54b8af8735af9bcf61de25c5c6b6aa68ae3
diff --git a/tools/toolhelper.py b/tools/toolhelper.py
index 45d84e2..1cfd0f0 100644
--- a/tools/toolhelper.py
+++ b/tools/toolhelper.py
@@ -27,6 +27,10 @@
   cmd.append(jdk.GetJavaExecutable())
   if extra_args:
     cmd.extend(extra_args)
+  agent, args = extract_debug_agent_from_args(args)
+  if agent:
+    cmd.append(
+        '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005')
   if debug:
     cmd.append('-ea')
   if profile:
@@ -103,3 +107,13 @@
     else:
       args.append(arg)
   return lib, args
+
+def extract_debug_agent_from_args(input_args):
+  agent = False
+  args = []
+  for arg in input_args:
+    if arg in ('--debug-agent', '--debug_agent'):
+      agent = True
+    else:
+      args.append(arg)
+  return agent, args