Fixing executable debug info as identified in #18996. (#18997)

diff --git a/runtime/src/iree/hal/drivers/cuda/native_executable.c b/runtime/src/iree/hal/drivers/cuda/native_executable.c
index 437b644..85ff2ea 100644
--- a/runtime/src/iree/hal/drivers/cuda/native_executable.c
+++ b/runtime/src/iree/hal/drivers/cuda/native_executable.c
@@ -269,11 +269,9 @@
       (CUmodule*)((uint8_t*)executable + sizeof(*executable) +
                   export_count * sizeof(executable->exports[0]));
   executable->export_count = export_count;
-  IREE_TRACE(
-      iree_hal_debug_export_info_t* export_infos =
-          (iree_hal_debug_export_info_t*)((uint8_t*)executable->modules +
-                                          module_count *
-                                              sizeof(executable->modules[0])));
+  IREE_TRACE(uint8_t* export_info_ptr =
+                 ((uint8_t*)executable->modules +
+                  module_count * sizeof(executable->modules[0])));
 
   // Publish any embedded source files to the tracing infrastructure.
   iree_hal_debug_publish_source_files(
@@ -376,13 +374,13 @@
           iree_hal_cuda_BindingBits_vec_len(binding_flags_vec);
 
       IREE_TRACE({
-        iree_hal_debug_copy_export_info(
-            iree_hal_cuda_ExportDef_debug_info_get(export_def),
-            &export_infos[i]);
-        kernel_info->debug_info.function_name = export_infos[i].function_name;
-        kernel_info->debug_info.source_filename =
-            export_infos[i].source_filename;
-        kernel_info->debug_info.source_line = export_infos[i].source_line;
+        iree_hal_debug_export_info_t* export_info =
+            (iree_hal_debug_export_info_t*)export_info_ptr;
+        export_info_ptr += iree_hal_debug_copy_export_info(
+            iree_hal_cuda_ExportDef_debug_info_get(export_def), export_info);
+        kernel_info->debug_info.function_name = export_info->function_name;
+        kernel_info->debug_info.source_filename = export_info->source_filename;
+        kernel_info->debug_info.source_line = export_info->source_line;
       });
     }
   }
diff --git a/runtime/src/iree/hal/drivers/hip/native_executable.c b/runtime/src/iree/hal/drivers/hip/native_executable.c
index 69a48ba..18b3d37 100644
--- a/runtime/src/iree/hal/drivers/hip/native_executable.c
+++ b/runtime/src/iree/hal/drivers/hip/native_executable.c
@@ -267,11 +267,9 @@
       (hipModule_t*)((uint8_t*)executable + sizeof(*executable) +
                      export_count * sizeof(executable->exports[0]));
   executable->export_count = export_count;
-  IREE_TRACE(
-      iree_hal_debug_export_info_t* export_infos =
-          (iree_hal_debug_export_info_t*)((uint8_t*)executable->modules +
-                                          module_count *
-                                              sizeof(executable->modules[0])));
+  IREE_TRACE(uint8_t* export_info_ptr =
+                 ((uint8_t*)executable->modules +
+                  module_count * sizeof(executable->modules[0])));
 
   // Publish any embedded source files to the tracing infrastructure.
   iree_hal_debug_publish_source_files(
@@ -376,13 +374,13 @@
           iree_hal_hip_BindingBits_vec_len(binding_flags_vec);
 
       IREE_TRACE({
-        iree_hal_debug_copy_export_info(
-            iree_hal_hip_ExportDef_debug_info_get(export_def),
-            &export_infos[i]);
-        kernel_info->debug_info.function_name = export_infos[i].function_name;
-        kernel_info->debug_info.source_filename =
-            export_infos[i].source_filename;
-        kernel_info->debug_info.source_line = export_infos[i].source_line;
+        iree_hal_debug_export_info_t* export_info =
+            (iree_hal_debug_export_info_t*)export_info_ptr;
+        export_info_ptr += iree_hal_debug_copy_export_info(
+            iree_hal_hip_ExportDef_debug_info_get(export_def), export_info);
+        kernel_info->debug_info.function_name = export_info->function_name;
+        kernel_info->debug_info.source_filename = export_info->source_filename;
+        kernel_info->debug_info.source_line = export_info->source_line;
       });
     }
   }
diff --git a/runtime/src/iree/hal/drivers/metal/executable.m b/runtime/src/iree/hal/drivers/metal/executable.m
index e4b8883..bebd31d 100644
--- a/runtime/src/iree/hal/drivers/metal/executable.m
+++ b/runtime/src/iree/hal/drivers/metal/executable.m
@@ -414,10 +414,8 @@
   iree_hal_resource_initialize(&iree_hal_metal_executable_vtable, &executable->resource);
   executable->host_allocator = host_allocator;
   executable->pipeline_count = pipeline_count;
-  IREE_TRACE(
-      iree_hal_debug_export_info_t* export_infos =
-          (iree_hal_debug_export_info_t*)((uint8_t*)executable->pipelines +
-                                          pipeline_count * sizeof(executable->pipelines[0])));
+  IREE_TRACE(uint8_t* export_info_ptr = ((uint8_t*)executable->pipelines +
+                                         pipeline_count * sizeof(executable->pipelines[0])));
 
   // Publish any embedded source files to the tracing infrastructure.
   iree_hal_debug_publish_source_files(
@@ -442,11 +440,12 @@
       if (!iree_status_is_ok(status)) break;
 
       IREE_TRACE({
-        iree_hal_debug_copy_export_info(iree_hal_metal_PipelineDef_debug_info_get(pipeline_def),
-                                        &export_infos[i]);
-        pipeline->source_location.func_name = export_infos[i].function_name;
-        pipeline->source_location.file_name = export_infos[i].source_filename;
-        pipeline->source_location.line = export_infos[i].source_line;
+        iree_hal_debug_export_info_t* export_info = (iree_hal_debug_export_info_t*)export_info_ptr;
+        export_info_ptr += iree_hal_debug_copy_export_info(
+            iree_hal_metal_PipelineDef_debug_info_get(pipeline_def), export_info);
+        pipeline->source_location.func_name = export_info->function_name;
+        pipeline->source_location.file_name = export_info->source_filename;
+        pipeline->source_location.line = export_info->source_line;
       });
     }
   }
diff --git a/runtime/src/iree/hal/drivers/vulkan/native_executable.cc b/runtime/src/iree/hal/drivers/vulkan/native_executable.cc
index e143d56..cebb919 100644
--- a/runtime/src/iree/hal/drivers/vulkan/native_executable.cc
+++ b/runtime/src/iree/hal/drivers/vulkan/native_executable.cc
@@ -957,20 +957,21 @@
   // Populate tracing info for each pipeline.
   if (iree_status_is_ok(status)) {
     IREE_TRACE({
-      iree_hal_debug_export_info_t* export_infos =
-          (iree_hal_debug_export_info_t*)((uint8_t*)executable->pipelines +
-                                          pipeline_count *
-                                              sizeof(executable->pipelines[0]));
+      uint8_t* export_info_ptr =
+          ((uint8_t*)executable->pipelines +
+           pipeline_count * sizeof(executable->pipelines[0]));
       for (iree_host_size_t i = 0; i < pipeline_count; ++i) {
         iree_hal_vulkan_PipelineDef_table_t pipeline_def =
             iree_hal_vulkan_PipelineDef_vec_at(pipelines_vec, i);
-        iree_hal_vulkan_pipeline_t* pipeline = &executable->pipelines[i];
-        iree_hal_debug_copy_export_info(
+        iree_hal_debug_export_info_t* export_info =
+            (iree_hal_debug_export_info_t*)export_info_ptr;
+        export_info_ptr += iree_hal_debug_copy_export_info(
             iree_hal_vulkan_PipelineDef_debug_info_get(pipeline_def),
-            &export_infos[i]);
-        pipeline->source_location.file_name = export_infos[i].source_filename;
-        pipeline->source_location.line = export_infos[i].source_line;
-        pipeline->source_location.func_name = export_infos[i].function_name;
+            export_info);
+        iree_hal_vulkan_pipeline_t* pipeline = &executable->pipelines[i];
+        pipeline->source_location.file_name = export_info->source_filename;
+        pipeline->source_location.line = export_info->source_line;
+        pipeline->source_location.func_name = export_info->function_name;
       }
     });
   }
diff --git a/runtime/src/iree/hal/utils/executable_debug_info.c b/runtime/src/iree/hal/utils/executable_debug_info.c
index d0a8432..45368cf 100644
--- a/runtime/src/iree/hal/utils/executable_debug_info.c
+++ b/runtime/src/iree/hal/utils/executable_debug_info.c
@@ -88,17 +88,19 @@
   return total_size;
 }
 
-void iree_hal_debug_copy_export_info(
+iree_host_size_t iree_hal_debug_copy_export_info(
     iree_hal_debug_ExportDef_table_t export_def,
     iree_hal_debug_export_info_t* out_info) {
   memset(out_info, 0, sizeof(*out_info));
-  if (!export_def) return;
+  if (!export_def) return 0;
 
+  iree_host_size_t total_size = sizeof(iree_hal_debug_export_info_t);
   char* ptr = (char*)out_info + sizeof(*out_info);
 
   flatbuffers_string_t name = iree_hal_debug_ExportDef_name_get(export_def);
   if (name) {
     size_t name_length = flatbuffers_string_len(name);
+    total_size += name_length;
     memcpy(ptr, name, name_length);
     out_info->function_name = iree_make_string_view(ptr, name_length);
     ptr += name_length;
@@ -110,10 +112,13 @@
     flatbuffers_string_t filename =
         iree_hal_debug_FileLineLocDef_filename_get(location_def);
     size_t filename_length = flatbuffers_string_len(filename);
+    total_size += filename_length;
     memcpy(ptr, filename, filename_length);
     out_info->source_filename = iree_make_string_view(ptr, filename_length);
     ptr += filename_length;
   }
+
+  return total_size;
 }
 
 void iree_hal_debug_publish_source_files(
diff --git a/runtime/src/iree/hal/utils/executable_debug_info.h b/runtime/src/iree/hal/utils/executable_debug_info.h
index 48c3bb9..e8cfad2 100644
--- a/runtime/src/iree/hal/utils/executable_debug_info.h
+++ b/runtime/src/iree/hal/utils/executable_debug_info.h
@@ -39,8 +39,9 @@
 // Clones the given export flatbuffer data into a heap structure allocated with
 // at least the size as calculated by iree_hal_debug_calculate_export_info_size.
 // The storage is valid until freed by the caller and decoupled from the
-// Flatbuffer storage.
-void iree_hal_debug_copy_export_info(
+// Flatbuffer storage. Returns the size copied (matching
+// iree_hal_debug_calculate_export_info_size).
+iree_host_size_t iree_hal_debug_copy_export_info(
     iree_hal_debug_ExportDef_table_t export_def,
     iree_hal_debug_export_info_t* out_info);